dfs_posix.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * File : dfs_posix.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2009-05-27 Yi.qiu The first version.
  23. * 2010-07-18 Bernard add stat and statfs structure definitions.
  24. * 2011-05-16 Yi.qiu Change parameter name of rename, "new" is C++ key word.
  25. */
  26. #ifndef __DFS_POSIX_H__
  27. #define __DFS_POSIX_H__
  28. #include <dfs_file.h>
  29. #include <dfs_def.h>
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. #if !defined(RT_USING_NEWLIB)
  34. #define O_RDONLY DFS_O_RDONLY
  35. #define O_WRONLY DFS_O_WRONLY
  36. #define O_RDWR DFS_O_RDWR
  37. #define O_ACCMODE DFS_O_ACCMODE
  38. #define O_CREAT DFS_O_CREAT
  39. #define O_EXCL DFS_O_EXCL
  40. #define O_TRUNC DFS_O_TRUNC
  41. #define O_APPEND DFS_O_APPEND
  42. #define O_BINARY DFS_O_BINARY
  43. #define O_DIRECTORY DFS_O_DIRECTORY
  44. #if !defined(_WIN32)
  45. #define S_IFMT DFS_S_IFMT
  46. #define S_IFSOCK DFS_S_IFSOCK
  47. #define S_IFLNK DFS_S_IFLNK
  48. #define S_IFREG DFS_S_IFREG
  49. #define S_IFBLK DFS_S_IFBLK
  50. #define S_IFDIR DFS_S_IFDIR
  51. #define S_IFCHR DFS_S_IFCHR
  52. #define S_IFIFO DFS_S_IFIFO
  53. #define S_ISUID DFS_S_ISUID
  54. #define S_ISGID DFS_S_ISGID
  55. #define S_ISVTX DFS_S_ISVTX
  56. #define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
  57. #define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
  58. #define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
  59. #define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
  60. #define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
  61. #define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
  62. #define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
  63. #define S_IRWXU DFS_S_IRWXU
  64. #define S_IRUSR DFS_S_IRUSR
  65. #define S_IWUSR DFS_S_IWUSR
  66. #define S_IXUSR DFS_S_IXUSR
  67. #define S_IRWXG DFS_S_IRWXG
  68. #define S_IRGRP DFS_S_IRGRP
  69. #define S_IWGRP DFS_S_IWGRP
  70. #define S_IXGRP DFS_S_IXGRP
  71. #define S_IRWXO DFS_S_IRWXO
  72. #define S_IROTH DFS_S_IROTH
  73. #define S_IWOTH DFS_S_IWOTH
  74. #define S_IXOTH DFS_S_IXOTH
  75. #endif
  76. #if defined(__CC_ARM)
  77. #include <stdio.h>
  78. #include <stdlib.h>
  79. #elif defined(_MSC_VER)
  80. #include <stdio.h>
  81. #else
  82. #define SEEK_SET DFS_SEEK_SET
  83. #define SEEK_CUR DFS_SEEK_CUR
  84. #define SEEK_END DFS_SEEK_END
  85. #endif
  86. typedef struct
  87. {
  88. int fd; /* directory file */
  89. char buf[512];
  90. int num;
  91. int cur;
  92. } DIR;
  93. /* directory api*/
  94. int mkdir(const char *path, mode_t mode);
  95. DIR *opendir(const char *name);
  96. struct dirent *readdir(DIR *d);
  97. long telldir(DIR *d);
  98. void seekdir(DIR *d, off_t offset);
  99. void rewinddir(DIR *d);
  100. int closedir(DIR* d);
  101. #else
  102. /* use newlib header file */
  103. #include <sys/stat.h>
  104. #endif
  105. struct stat;
  106. /* file api*/
  107. int open(const char *file, int flags, ...);
  108. int close(int d);
  109. #ifdef RT_USING_NEWLIB
  110. _READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte));
  111. _READ_WRITE_RETURN_TYPE _EXFUN(write, (int __fd, const void *__buf, size_t __nbyte));
  112. #else
  113. int read(int fd, void *buf, size_t len);
  114. int write(int fd, const void *buf, size_t len);
  115. #endif
  116. off_t lseek(int fd, off_t offset, int whence);
  117. int rename(const char *from, const char *to);
  118. int unlink(const char *pathname);
  119. int stat(const char *file, struct stat *buf);
  120. int fstat(int fildes, struct stat *buf);
  121. int fsync(int fildes);
  122. int ioctl(int fildes, long cmd, void *data);
  123. /* directory api*/
  124. int rmdir(const char *path);
  125. int chdir(const char *path);
  126. char *getcwd(char *buf, size_t size);
  127. /* file system api */
  128. int statfs(const char *path, struct statfs *buf);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif