dfs_def.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. +------------------------------------------------------------------------------
  3. | Device FileSystem
  4. +------------------------------------------------------------------------------
  5. | Copyright 2004, 2005 www.fayfayspace.org.
  6. | All rights reserved.
  7. |------------------------------------------------------------------------------
  8. | File : dfs_def.h, the definitions of Device FileSystem
  9. |------------------------------------------------------------------------------
  10. | Chang Logs:
  11. | Date Author notes
  12. | 2004-10-01 ffxz The first version.
  13. | 2004-10-14 ffxz Clean up the code.
  14. | 2005-01-22 ffxz Clean up the code, port to MinGW
  15. +------------------------------------------------------------------------------
  16. */
  17. #ifndef __DFS_DEF_H__
  18. #define __DFS_DEF_H__
  19. #include <rtthread.h>
  20. #include <dfs_config.h>
  21. #if defined(RT_USING_NEWLIB) || defined (RT_USING_MINILIBC)
  22. #include <string.h>
  23. #endif
  24. #ifndef __D_FS__
  25. #define __D_FS__
  26. #endif
  27. /* Device error codes */
  28. #define DFS_STATUS_OK 0 /* no error */
  29. #define DFS_STATUS_ENOENT 2 /* No such file or directory */
  30. #define DFS_STATUS_EIO 5 /* I/O error */
  31. #define DFS_STATUS_ENXIO 6 /* No such device or address */
  32. #define DFS_STATUS_EBADF 9 /* Bad file number */
  33. #define DFS_STATUS_EAGIAN 11 /* Try again */
  34. #define DFS_STATUS_ENOMEM 12 /* no memory */
  35. #define DFS_STATUS_EBUSY 16 /* Device or resource busy */
  36. #define DFS_STATUS_EEXIST 17 /* File exists */
  37. #define DFS_STATUS_EXDEV 18 /* Cross-device link */
  38. #define DFS_STATUS_ENODEV 19 /* No such device */
  39. #define DFS_STATUS_ENOTDIR 20 /* Not a directory */
  40. #define DFS_STATUS_EISDIR 21 /* Is a directory */
  41. #define DFS_STATUS_EINVAL 22 /* Invalid argument */
  42. #define DFS_STATUS_ENOSPC 28 /* No space left on device */
  43. #define DFS_STATUS_EROFS 30 /* Read-only file system */
  44. #define DFS_STATUS_ENOSYS 38 /* Function not implemented */
  45. #define DFS_STATUS_ENOTEMPTY 39 /* Directory not empty */
  46. #define DFS_STATUS_EMMOUNT 128 /* Filesystem table full */
  47. /* Operation flags */
  48. #define DFS_O_RDONLY 0000000
  49. #define DFS_O_WRONLY 0000001
  50. #define DFS_O_RDWR 0000002
  51. #define DFS_O_ACCMODE 0000003
  52. #define DFS_O_CREAT 0000100
  53. #define DFS_O_EXCL 0000200
  54. #define DFS_O_TRUNC 0001000
  55. #define DFS_O_APPEND 0002000
  56. #define DFS_O_DIRECTORY 0200000
  57. /* File flags */
  58. #define DFS_F_OPEN 0x01000000
  59. #define DFS_F_DIRECTORY 0x02000000
  60. #define DFS_F_EOF 0x04000000
  61. #define DFS_F_ERR 0x08000000
  62. /* Seek flags */
  63. #define DFS_SEEK_SET 0
  64. #define DFS_SEEK_CUR 1
  65. #define DFS_SEEK_END 2
  66. /* Stat codes */
  67. #define DFS_S_IFMT 00170000
  68. #define DFS_S_IFSOCK 0140000
  69. #define DFS_S_IFLNK 0120000
  70. #define DFS_S_IFREG 0100000
  71. #define DFS_S_IFBLK 0060000
  72. #define DFS_S_IFDIR 0040000
  73. #define DFS_S_IFCHR 0020000
  74. #define DFS_S_IFIFO 0010000
  75. #define DFS_S_ISUID 0004000
  76. #define DFS_S_ISGID 0002000
  77. #define DFS_S_ISVTX 0001000
  78. #define DFS_S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
  79. #define DFS_S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
  80. #define DFS_S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
  81. #define DFS_S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
  82. #define DFS_S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
  83. #define DFS_S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
  84. #define DFS_S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
  85. #define DFS_S_IRWXU 00700
  86. #define DFS_S_IRUSR 00400
  87. #define DFS_S_IWUSR 00200
  88. #define DFS_S_IXUSR 00100
  89. #define DFS_S_IRWXG 00070
  90. #define DFS_S_IRGRP 00040
  91. #define DFS_S_IWGRP 00020
  92. #define DFS_S_IXGRP 00010
  93. #define DFS_S_IRWXO 00007
  94. #define DFS_S_IROTH 00004
  95. #define DFS_S_IWOTH 00002
  96. #define DFS_S_IXOTH 00001
  97. #define DEVICE_GETGEOME 0
  98. #define DEVICE_GETINFO 1
  99. #define DEVICE_FORMAT 2
  100. #define DEVICE_CLEAN_SECTOR 3
  101. struct device_geometry
  102. {
  103. rt_uint32_t sector_count; /* count of sectors */
  104. rt_uint32_t cylinder_count; /* count of cylinder */
  105. rt_uint32_t sectors_per_track; /* number of sectors per track */
  106. rt_uint32_t head_count; /* count of head */
  107. rt_uint32_t bytes_per_sector; /* number of bytes per sector */
  108. };
  109. struct dfs_stat
  110. {
  111. rt_device_t st_dev;
  112. rt_uint16_t st_mode;
  113. rt_uint32_t st_size;
  114. rt_time_t st_mtime;
  115. rt_uint32_t st_blksize;
  116. };
  117. #define stat dfs_stat
  118. /* File types */
  119. #define FT_REGULAR 0 /* regular file */
  120. #define FT_SOCKET 1 /* socket file */
  121. #define FT_DIRECTORY 2 /* directory */
  122. #define FT_USER 3 /* user defined */
  123. /* file descriptor */
  124. struct dfs_fd
  125. {
  126. char path[DFS_PATH_MAX + 1];/* Name (below mount point) */
  127. int type; /* Type (regular or socket) */
  128. int ref_count; /* Descriptor reference count */
  129. struct dfs_filesystem* fs; /* Resident file system */
  130. rt_uint32_t flags; /* Descriptor flags */
  131. rt_size_t size; /* Size in bytes */
  132. rt_off_t pos; /* Current file position */
  133. void *data; /* Specific file system data */
  134. };
  135. #define DFS_DT_UNKNOWN 0x00
  136. #define DFS_DT_REG 0x01
  137. #define DFS_DT_DIR 0x02
  138. struct dfs_dirent
  139. {
  140. rt_uint8_t d_type; /* The type of the file */
  141. rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
  142. rt_uint16_t d_reclen; /* length of this record */
  143. char d_name[256]; /* The null-terminated file name */
  144. };
  145. #define dirent dfs_dirent
  146. struct dfs_session
  147. {
  148. rt_mailbox_t mbox;
  149. };
  150. #endif