dfs_def.h 4.8 KB

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