dfs_file.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file dfs_file.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __DFS_FILE_H__
  35. #define __DFS_FILE_H__
  36. #include <dfs.h>
  37. #include <dfs_fs.h>
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. struct rt_pollreq;
  42. struct dfs_file_ops
  43. {
  44. int (*open) (struct dfs_fd *fd);
  45. int (*close) (struct dfs_fd *fd);
  46. int (*ioctl) (struct dfs_fd *fd, int cmd, void *args);
  47. int (*read) (struct dfs_fd *fd, void *buf, size_t count);
  48. int (*write) (struct dfs_fd *fd, const void *buf, size_t count);
  49. int (*flush) (struct dfs_fd *fd);
  50. int (*lseek) (struct dfs_fd *fd, off_t offset);
  51. int (*getdents) (struct dfs_fd *fd, struct dirent *dirp, uint32_t count);
  52. int (*poll) (struct dfs_fd *fd, struct rt_pollreq *req);
  53. };
  54. /* file descriptor */
  55. #define DFS_FD_MAGIC 0xfdfd
  56. struct dfs_fd
  57. {
  58. uint16_t magic; /* file descriptor magic number */
  59. uint16_t type; /* Type (regular or socket) */
  60. char *path; /* Name (below mount point) */
  61. int ref_count; /* Descriptor reference count */
  62. struct dfs_filesystem *fs;
  63. const struct dfs_file_ops *fops;
  64. uint32_t flags; /* Descriptor flags */
  65. size_t size; /* Size in bytes */
  66. off_t pos; /* Current file position */
  67. void *data; /* Specific file system data */
  68. };
  69. int dfs_file_open(struct dfs_fd *fd, const char *path, int flags);
  70. int dfs_file_close(struct dfs_fd *fd);
  71. int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args);
  72. int dfs_file_read(struct dfs_fd *fd, void *buf, size_t len);
  73. int dfs_file_getdents(struct dfs_fd *fd, struct dirent *dirp, size_t nbytes);
  74. int dfs_file_unlink(const char *path);
  75. int dfs_file_write(struct dfs_fd *fd, const void *buf, size_t len);
  76. int dfs_file_flush(struct dfs_fd *fd);
  77. int dfs_file_lseek(struct dfs_fd *fd, off_t offset);
  78. int dfs_file_stat(const char *path, struct stat *buf);
  79. int dfs_file_rename(const char *oldpath, const char *newpath);
  80. int dfs_file_ftruncate(struct dfs_fd *fd, off_t length);
  81. /* 0x5254 is just a magic number to make these relatively unique ("RT") */
  82. #define RT_FIOFTRUNCATE 0x52540000U
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif