dfs_posix.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef 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. #define S_IFMT DFS_S_IFMT
  45. #define S_IFSOCK DFS_S_IFSOCK
  46. #define S_IFLNK DFS_S_IFLNK
  47. #define S_IFREG DFS_S_IFREG
  48. #define S_IFBLK DFS_S_IFBLK
  49. #define S_IFDIR DFS_S_IFDIR
  50. #define S_IFCHR DFS_S_IFCHR
  51. #define S_IFIFO DFS_S_IFIFO
  52. #define S_ISUID DFS_S_ISUID
  53. #define S_ISGID DFS_S_ISGID
  54. #define S_ISVTX DFS_S_ISVTX
  55. #define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
  56. #define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
  57. #define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
  58. #define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
  59. #define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
  60. #define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
  61. #define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
  62. #define S_IRWXU DFS_S_IRWXU
  63. #define S_IRUSR DFS_S_IRUSR
  64. #define S_IWUSR DFS_S_IWUSR
  65. #define S_IXUSR DFS_S_IXUSR
  66. #define S_IRWXG DFS_S_IRWXG
  67. #define S_IRGRP DFS_S_IRGRP
  68. #define S_IWGRP DFS_S_IWGRP
  69. #define S_IXGRP DFS_S_IXGRP
  70. #define S_IRWXO DFS_S_IRWXO
  71. #define S_IROTH DFS_S_IROTH
  72. #define S_IWOTH DFS_S_IWOTH
  73. #define S_IXOTH DFS_S_IXOTH
  74. #if defined(__CC_ARM)
  75. #include <stdio.h>
  76. #include <stdlib.h>
  77. #elif defined(_MSC_VER)
  78. #include <stdio.h>
  79. #else
  80. #define SEEK_SET DFS_SEEK_SET
  81. #define SEEK_CUR DFS_SEEK_CUR
  82. #define SEEK_END DFS_SEEK_END
  83. #endif
  84. typedef struct
  85. {
  86. int fd; /* directory file */
  87. char buf[512];
  88. int num;
  89. int cur;
  90. } DIR;
  91. /* directory api*/
  92. int mkdir(const char *path, mode_t mode);
  93. DIR *opendir(const char *name);
  94. struct dirent *readdir(DIR *d);
  95. long telldir(DIR *d);
  96. void seekdir(DIR *d, off_t offset);
  97. void rewinddir(DIR *d);
  98. int closedir(DIR* d);
  99. #else
  100. /* use newlib header file */
  101. #include <sys/stat.h>
  102. #endif
  103. /* file api*/
  104. int open(const char *file, int flags, int mode);
  105. int close(int d);
  106. int read(int fd, void *buf, size_t len);
  107. int write(int fd, const void *buf, size_t len);
  108. off_t lseek(int fd, off_t offset, int whence);
  109. int rename(const char *from, const char *to);
  110. int unlink(const char *pathname);
  111. int stat(const char *file, struct stat *buf);
  112. int fstat(int fildes, struct stat *buf);
  113. int statfs(const char *path, struct statfs *buf);
  114. /* directory api*/
  115. int rmdir(const char *path);
  116. int chdir(const char *path);
  117. char *getcwd(char *buf, size_t size);
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif