vfs.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef __VFS_H__
  2. #define __VFS_H__
  3. #include "vfs_int.h"
  4. // DEPRECATED, DON'T USE
  5. // Check for fd != 0 instead
  6. #define FS_OPEN_OK 1
  7. // ---------------------------------------------------------------------------
  8. // file functions
  9. //
  10. // vfs_close - close file descriptor and free memory
  11. // fd: file descriptor
  12. // Returns: VFS_RES_OK or negative value in case of error
  13. inline sint32_t vfs_close( int fd ) {
  14. vfs_file *f = (vfs_file *)fd;
  15. return f ? f->fns->close( f ) : VFS_RES_ERR;
  16. }
  17. // vfs_read - read data from file
  18. // fd: file descriptor
  19. // ptr: destination data buffer
  20. // len: requested length
  21. // Returns: Number of bytes read, or VFS_RES_ERR in case of error
  22. inline sint32_t vfs_read( int fd, void *ptr, size_t len ) {
  23. vfs_file *f = (vfs_file *)fd;
  24. return f ? f->fns->read( f, ptr, len ) : VFS_RES_ERR;
  25. }
  26. // vfs_write - write data to file
  27. // fd: file descriptor
  28. // ptr: source data buffer
  29. // len: requested length
  30. // Returns: Number of bytes written, or VFS_RES_ERR in case of error
  31. inline sint32_t vfs_write( int fd, const void *ptr, size_t len ) {
  32. vfs_file *f = (vfs_file *)fd;
  33. return f ? f->fns->write( f, ptr, len ) : VFS_RES_ERR;
  34. }
  35. int vfs_getc( int fd );
  36. int vfs_ungetc( int c, int fd );
  37. // vfs_lseek - move read/write pointer
  38. // fd: file descriptor
  39. // off: offset
  40. // whence: VFS_SEEK_SET - set pointer to off
  41. // VFS_SEEK_CUR - set pointer to current position + off
  42. // VFS_SEEK_END - set pointer to end of file + off
  43. // Returns: New position, or VFS_RES_ERR in case of error
  44. inline sint32_t vfs_lseek( int fd, sint32_t off, int whence ) {
  45. vfs_file *f = (vfs_file *)fd;
  46. return f ? f->fns->lseek( f, off, whence ) : VFS_RES_ERR;
  47. }
  48. // vfs_eof - test for end-of-file
  49. // fd: file descriptor
  50. // Returns: 0 if not at end, != 0 if end of file
  51. inline sint32_t vfs_eof( int fd ) {
  52. vfs_file *f = (vfs_file *)fd;
  53. return f ? f->fns->eof( f ) : VFS_RES_ERR;
  54. }
  55. // vfs_tell - get read/write position
  56. // fd: file descriptor
  57. // Returns: Current position
  58. inline sint32_t vfs_tell( int fd ) {
  59. vfs_file *f = (vfs_file *)fd;
  60. return f ? f->fns->tell( f ) : VFS_RES_ERR;
  61. }
  62. // vfs_flush - flush write cache to file
  63. // fd: file descriptor
  64. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  65. inline sint32_t vfs_flush( int fd ) {
  66. vfs_file *f = (vfs_file *)fd;
  67. return f ? f->fns->flush( f ) : VFS_RES_ERR;
  68. }
  69. // vfs_size - get current file size
  70. // fd: file descriptor
  71. // Returns: File size
  72. inline uint32_t vfs_size( int fd ) {
  73. vfs_file *f = (vfs_file *)fd;
  74. return f && f->fns->size ? f->fns->size( f ) : 0;
  75. }
  76. // vfs_ferrno - get file system specific errno
  77. // fd: file descriptor
  78. // Returns: errno
  79. sint32_t vfs_ferrno( int fd );
  80. // ---------------------------------------------------------------------------
  81. // dir functions
  82. //
  83. // vfs_closedir - close directory descriptor and free memory
  84. // dd: dir descriptor
  85. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  86. inline sint32_t vfs_closedir( vfs_dir *dd ) { return dd->fns->close( dd ); }
  87. // vfs_readdir - read next directory item
  88. // dd: dir descriptor
  89. // Returns: item object, or NULL in case of error
  90. inline vfs_item *vfs_readdir( vfs_dir *dd ) { return dd->fns->readdir( dd ); }
  91. // ---------------------------------------------------------------------------
  92. // dir item functions
  93. //
  94. // vfs_closeitem - close directory item and free memory
  95. // di: item descriptor
  96. // Returns: nothing
  97. inline void vfs_closeitem( vfs_item *di ) { return di->fns->close( di ); }
  98. // vfs_item_size - get item's size
  99. // di: item descriptor
  100. // Returns: Item size
  101. inline uint32_t vfs_item_size( vfs_item *di ) { return di->fns->size( di ); }
  102. // vfs_item_time - get item's modification time
  103. // di: item descriptor
  104. // Returns: Item modification time
  105. inline sint32_t vfs_item_time( vfs_item *di, struct vfs_time *tm ) { return di->fns->time ? di->fns->time( di, tm ) : VFS_RES_ERR; }
  106. // vfs_item_name - get item's name
  107. // di: item descriptor
  108. // Returns: Item name
  109. inline const char *vfs_item_name( vfs_item *di ) { return di->fns->name( di ); }
  110. // vfs_item_is_dir - check for directory
  111. // di: item descriptor
  112. // Returns: >0 if item is a directory, 0 if not
  113. inline sint32_t vfs_item_is_dir( vfs_item *di ) { return di->fns->is_dir ? di->fns->is_dir( di ) : 0; }
  114. // vfs_item_is_rdonly - check for read-only
  115. // di: item descriptor
  116. // Returns: >0 if item is read only, 0 if not
  117. inline sint32_t vfs_item_is_rdonly( vfs_item *di ) { return di->fns->is_rdonly ? di->fns->is_rdonly( di ) : 0; }
  118. // vfs_item_is_hidden - check for hidden attribute
  119. // di: item descriptor
  120. // Returns: >0 if item is hidden, 0 if not
  121. inline sint32_t vfs_item_is_hidden( vfs_item *di ) { return di->fns->is_hidden ? di->fns->is_hidden( di ) : 0; }
  122. // vfs_item_is_sys - check for sys attribute
  123. // di: item descriptor
  124. // Returns: >0 if item is sys, 0 if not
  125. inline sint32_t vfs_item_is_sys( vfs_item *di ) { return di->fns->is_sys ? di->fns->is_sys( di ) : 0; }
  126. // vfs_item_is_arch - check for archive attribute
  127. // di: item descriptor
  128. // Returns: >0 if item is archive, 0 if not
  129. inline sint32_t vfs_item_is_arch( vfs_item *di ) { return di->fns->is_arch ? di->fns->is_arch( di ) : 0; }
  130. // ---------------------------------------------------------------------------
  131. // volume functions
  132. //
  133. // vfs_umount - unmount logical drive and free memory
  134. // vol: volume object
  135. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  136. inline sint32_t vfs_umount( vfs_vol *vol ) { return vol->fns->umount( vol ); }
  137. // ---------------------------------------------------------------------------
  138. // file system functions
  139. //
  140. // vfs_mount - unmount logical drive
  141. // name: name of logical drive
  142. // num: drive's physical number (eg. SS/CS pin), negative values are ignored
  143. // Returns: Volume object, or NULL in case of error
  144. vfs_vol *vfs_mount( const char *name, int num );
  145. // vfs_open - open file
  146. // name: file name
  147. // mode: open mode
  148. // Returns: File descriptor, or NULL in case of error
  149. int vfs_open( const char *name, const char *mode );
  150. // vfs_opendir - open directory
  151. // name: dir name
  152. // Returns: Directory descriptor, or NULL in case of error
  153. vfs_dir *vfs_opendir( const char *name );
  154. // vfs_stat - stat file or directory
  155. // name: file or directory name
  156. // Returns: Item object, or NULL in case of error
  157. vfs_item *vfs_stat( const char *name );
  158. // vfs_remove - remove file or directory
  159. // name: file or directory name
  160. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  161. sint32_t vfs_remove( const char *name );
  162. // vfs_rename - rename file or directory
  163. // name: file or directory name
  164. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  165. sint32_t vfs_rename( const char *oldname, const char *newname );
  166. // vfs_mkdir - create directory
  167. // name: directory name
  168. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  169. sint32_t vfs_mkdir( const char *name );
  170. // vfs_fsinfo - get file system info
  171. // name: logical drive identifier
  172. // total: receives total amount
  173. // used: received used amount
  174. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  175. sint32_t vfs_fsinfo( const char *name, uint32_t *total, uint32_t *used );
  176. // vfs_format - format file system
  177. // Returns: 1, or 0 in case of error
  178. sint32_t vfs_format( void );
  179. // vfs_chdir - change default directory
  180. // path: new default directory
  181. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  182. sint32_t vfs_chdir( const char *path );
  183. // vfs_fscfg - query configuration settings of file system
  184. // phys_addr: pointer to store physical address information
  185. // phys_size: pointer to store physical size information
  186. // Returns: VFS_RES_OK, or VFS_RES_ERR in case of error
  187. sint32_t vfs_fscfg( const char *name, uint32_t *phys_addr, uint32_t *phys_size);
  188. // vfs_errno - get file system specific errno
  189. // name: logical drive identifier
  190. // Returns: errno
  191. sint32_t vfs_errno( const char *name );
  192. // vfs_clearerr - cleaer file system specific errno
  193. void vfs_clearerr( const char *name );
  194. // vfs_register_rtc_cb - register callback function for RTC query
  195. // cb: pointer to callback function
  196. void vfs_register_rtc_cb( sint32_t (*cb)( vfs_time *tm ) );
  197. // vfs_basename - identify basename (incl. extension)
  198. // path: full file system path
  199. // Returns: pointer to basename within path string
  200. const char *vfs_basename( const char *path );
  201. #endif