osapi-os-filesys.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. ** File: osapi-os-filesys.h
  3. **
  4. ** Copyright (c) 2004-2006, United States government as represented by the
  5. ** administrator of the National Aeronautics Space Administration.
  6. ** All rights reserved. This software was created at NASAs Goddard
  7. ** Space Flight Center pursuant to government contracts.
  8. **
  9. ** This is governed by the NASA Open Source Agreement and may be used,
  10. ** distributed and modified only pursuant to the terms of that agreement.
  11. **
  12. ** Author: Alan Cudmore Code 582
  13. **
  14. ** Purpose: Contains functions prototype definitions and variables declarations
  15. ** for the OS Abstraction Layer, File System module
  16. **
  17. ** $Revision: 1.11 $
  18. **
  19. ** $Date: 2013/12/16 12:57:41GMT-05:00 $
  20. **
  21. ** $Log: osapi-os-filesys.h $
  22. ** Revision 1.11 2013/12/16 12:57:41GMT-05:00 acudmore
  23. ** Added macros for Volume name length and physical device name length
  24. ** Revision 1.10 2013/07/29 12:05:48GMT-05:00 acudmore
  25. ** Added define for device and volume name length
  26. ** Revision 1.9 2013/07/25 14:31:21GMT-05:00 acudmore
  27. ** Added prototype and datatype for OS_GetFsInfo
  28. ** Revision 1.8 2011/12/05 12:04:21GMT-05:00 acudmore
  29. ** Added OS_rewinddir API
  30. ** Revision 1.7 2011/04/05 16:01:12EDT acudmore
  31. ** Added OS_CloseFileByName and OS_CloseAllFiles
  32. ** Revision 1.6 2010/11/15 11:04:38EST acudmore
  33. ** Added OS_FileOpenCheck function.
  34. ** Revision 1.5 2010/11/12 12:00:18EST acudmore
  35. ** replaced copyright character with (c) and added open source notice where needed.
  36. ** Revision 1.4 2010/02/01 12:28:57EST acudmore
  37. ** Added OS_fsBytesFree API
  38. ** Revision 1.3 2010/01/25 14:44:26EST acudmore
  39. ** renamed "new" variable to avoid C++ reserved name conflict.
  40. ** Revision 1.2 2009/07/14 15:16:05EDT acudmore
  41. ** Added OS_TranslatePath to the API
  42. ** Revision 1.1 2008/04/20 22:36:01EDT ruperera
  43. ** Initial revision
  44. ** Member added to project c:/MKSDATA/MKS-REPOSITORY/MKS-OSAL-REPOSITORY/src/os/inc/project.pj
  45. ** Revision 1.1 2007/10/16 16:14:52EDT apcudmore
  46. ** Initial revision
  47. ** Member added to project d:/mksdata/MKS-OSAL-REPOSITORY/src/os/inc/project.pj
  48. ** Revision 1.1 2007/08/24 13:43:24EDT apcudmore
  49. ** Initial revision
  50. ** Member added to project d:/mksdata/MKS-CFE-PROJECT/fsw/cfe-core/os/inc/project.pj
  51. ** Revision 1.17 2007/06/07 09:59:14EDT njyanchik
  52. ** I replaced the second OS_cp definition with OS_mv
  53. ** Revision 1.16 2007/06/05 16:25:33EDT apcudmore
  54. ** Increased Number of volume table entries from 10 to 14.
  55. ** Added 2 extra EEPROM disk mappings to RAD750 Volume table + 2 spares
  56. ** Added 4 spares to every other volume table.
  57. ** Revision 1.15 2007/05/25 09:17:56EDT njyanchik
  58. ** I added the rmfs call to the OSAL and updated the unit test stubs to match
  59. ** Revision 1.14 2007/03/21 10:15:29EST njyanchik
  60. ** I mistakenly put the wrong length in for the path in the OS_FDTableEntry structure, and I added
  61. ** some code that will set and out of range file descriptors .IsValid flag to false in OS_FDGetInfo
  62. ** Revision 1.13 2007/03/06 11:52:46EST njyanchik
  63. ** This change goes with the previous CP, I forgot to include it
  64. ** Revision 1.12 2007/02/28 14:57:45EST njyanchik
  65. ** The updates for supporting copying and moving files are now supported
  66. ** Revision 1.11 2007/02/27 15:22:11EST njyanchik
  67. ** This CP has the initial import of the new file descripor table mechanism
  68. ** Revision 1.10 2006/12/20 10:27:09EST njyanchik
  69. ** This change package incorporates all the changes necessary for the addition
  70. ** of a new API to get the real physical drive undernieth a mount point
  71. ** Revision 1.9 2006/11/14 14:44:28GMT-05:00 njyanchik
  72. ** Checks were added to the OS fs calls that look at the return of a function that
  73. ** changes the name of paths from abstracted to local path names.
  74. ** Revision 1.8 2006/10/30 16:12:19GMT-05:00 apcudmore
  75. ** Updated Compact flash and RAM device names for vxWorks 6.2 changes.
  76. ** Revision 1.7 2006/10/25 11:31:18EDT njyanchik
  77. ** This CP incorporates changes to every bsp_voltab.c file. I increased the number
  78. ** entries in the volume table to 10. I also changed the #define in the os_filesys.h
  79. ** file for the number of entries to match.
  80. **
  81. ** This update also includes adding the prototype for OS_initfs in os_filesys.h
  82. ** Revision 1.6 2006/09/26 09:03:46GMT-05:00 njyanchik
  83. ** Contains the initial import of the ES Shell commands interface
  84. ** Revision 1.5 2006/07/25 15:37:52EDT njyanchik
  85. ** It turns out the both the FS app and the OSAL were incorrect where file descriptors are
  86. ** concerned. the file descriptors should be int32 across the board.
  87. ** Revision 1.4 2006/01/20 11:56:18EST njyanchik
  88. ** Fixed header file information to match api document
  89. ** Revision 1.26 2005/07/12 17:13:56 nyanchik
  90. ** Moved the Volume table to a bsp table in the arch directories.
  91. **
  92. ** Revision 1.2 2005/07/11 16:26:57EDT apcudmore
  93. ** OSAPI 2.0 integration
  94. ** Revision 1.25 2005/07/06 16:11:17 nyanchik
  95. ** *** empty log message ***
  96. **
  97. ** Revision 1.24 2005/07/05 18:34:55 nyanchik
  98. ** fixed issues found in code walkthrogh. Also removed the OS_Info* functions that are going in the BSP
  99. **
  100. ** Revision 1.23 2005/06/17 19:46:34 nyanchik
  101. ** added new file system style to linux and rtems.
  102. **
  103. ** Revision 1.22 2005/06/15 16:43:48 nyanchik
  104. ** added extra parenthesis for the .h file # defines
  105. **
  106. ** Revision 1.21 2005/06/06 14:17:42 nyanchik
  107. ** added headers to osapi-os-core.h and osapi-os-filesys.h
  108. **
  109. ** Revision 1.20 2005/06/02 18:04:24 nyanchik
  110. ** *** empty log message ***
  111. **
  112. ** Revision 1.1 2005/03/15 18:26:32 nyanchik
  113. ** *** empty log message ***
  114. **
  115. **
  116. ** Date Written:
  117. **
  118. **
  119. */
  120. #ifndef _osapi_filesys_
  121. #define _osapi_filesys_
  122. #include <stdio.h>
  123. #include <stdlib.h>
  124. #include <dirent.h>
  125. #include <sys/stat.h>
  126. #define OS_READ_ONLY 0
  127. #define OS_WRITE_ONLY 1
  128. #define OS_READ_WRITE 2
  129. #define OS_SEEK_SET 0
  130. #define OS_SEEK_CUR 1
  131. #define OS_SEEK_END 2
  132. #define OS_CHK_ONLY 0
  133. #define OS_REPAIR 1
  134. #define FS_BASED 0
  135. #define RAM_DISK 1
  136. #define EEPROM_DISK 2
  137. #define ATA_DISK 3
  138. /*
  139. ** Number of entries in the internal volume table
  140. */
  141. #define NUM_TABLE_ENTRIES 14
  142. /*
  143. ** Length of a Device and Volume name
  144. */
  145. #define OS_FS_DEV_NAME_LEN 32
  146. #define OS_FS_PHYS_NAME_LEN 64
  147. #define OS_FS_VOL_NAME_LEN 32
  148. /*
  149. ** Defines for File System Calls
  150. */
  151. #define OS_FS_SUCCESS 0
  152. #define OS_FS_ERROR (-1)
  153. #define OS_FS_ERR_INVALID_POINTER (-2)
  154. #define OS_FS_ERR_PATH_TOO_LONG (-3)
  155. #define OS_FS_ERR_NAME_TOO_LONG (-4)
  156. #define OS_FS_UNIMPLEMENTED (-5)
  157. #define OS_FS_ERR_DRIVE_NOT_CREATED (-6)
  158. #define OS_FS_ERR_DEVICE_NOT_FREE (-7)
  159. #define OS_FS_ERR_PATH_INVALID (-8)
  160. #define OS_FS_ERR_NO_FREE_FDS (-9)
  161. #define OS_FS_ERR_INVALID_FD (-10)
  162. /* This typedef is for the OS_FS_GetErrorName function, to ensure
  163. * everyone is making an array of the same length */
  164. typedef char os_fs_err_name_t[35];
  165. /*
  166. ** Internal structure of the OS volume table for
  167. ** mounted file systems and path translation
  168. */
  169. typedef struct
  170. {
  171. char DeviceName [OS_FS_DEV_NAME_LEN];
  172. char PhysDevName [OS_FS_PHYS_NAME_LEN];
  173. uint32 VolumeType;
  174. uint8 VolatileFlag;
  175. uint8 FreeFlag;
  176. uint8 IsMounted;
  177. char VolumeName [OS_FS_VOL_NAME_LEN];
  178. char MountPoint [OS_MAX_PATH_LEN];
  179. uint32 BlockSize;
  180. }OS_VolumeInfo_t;
  181. typedef struct
  182. {
  183. int32 OSfd; /* The underlying OS's file descriptor */
  184. char Path[OS_MAX_PATH_LEN]; /* The path of the file opened */
  185. uint32 User; /* The task id of the task who opened the file*/
  186. uint8 IsValid; /* Whether or not this entry is valid */
  187. }OS_FDTableEntry;
  188. typedef struct
  189. {
  190. uint32 MaxFds; /* Total number of file descriptors */
  191. uint32 FreeFds; /* Total number that are free */
  192. uint32 MaxVolumes; /* Maximum number of volumes */
  193. uint32 FreeVolumes; /* Total number of volumes free */
  194. } os_fsinfo_t;
  195. /* modified to posix calls, since all of the
  196. * applicable OSes use the posix calls */
  197. typedef struct stat os_fstat_t;
  198. typedef DIR* os_dirp_t;
  199. typedef struct dirent os_dirent_t;
  200. /* still don't know what this should be*/
  201. typedef unsigned long int os_fshealth_t;
  202. /*
  203. * Exported Functions
  204. */
  205. /******************************************************************************
  206. ** Standard File system API
  207. ******************************************************************************/
  208. /*
  209. * Initializes the File System functions
  210. */
  211. int32 OS_FS_Init(void);
  212. /*
  213. * Creates a file specified by path
  214. */
  215. int32 OS_creat (const char *path, int32 access);
  216. /*
  217. * Opend a file for reading/writing. Returns file descriptor
  218. */
  219. int32 OS_open (const char *path, int32 access, uint32 mode);
  220. /*
  221. * Closes an open file.
  222. */
  223. int32 OS_close (int32 filedes);
  224. /*
  225. * Reads nbytes bytes from file into buffer
  226. */
  227. int32 OS_read (int32 filedes, void *buffer, uint32 nbytes);
  228. /*
  229. * Write nybytes bytes of buffer into the file
  230. */
  231. int32 OS_write (int32 filedes, void *buffer, uint32 nbytes);
  232. /*
  233. * Changes the permissions of a file
  234. */
  235. int32 OS_chmod (const char *path, uint32 access);
  236. /*
  237. * Returns file status information in filestats
  238. */
  239. int32 OS_stat (const char *path, os_fstat_t *filestats);
  240. /*
  241. * Seeks to the specified position of an open file
  242. */
  243. int32 OS_lseek (int32 filedes, int32 offset, uint32 whence);
  244. /*
  245. * Removes a file from the file system
  246. */
  247. int32 OS_remove (const char *path);
  248. /*
  249. * Renames a file in the file system
  250. */
  251. int32 OS_rename (const char *old_filename, const char *new_filename);
  252. /*
  253. * copies a single file from src to dest
  254. */
  255. int32 OS_cp (const char *src, const char *dest);
  256. /*
  257. * moves a single file from src to dest
  258. */
  259. int32 OS_mv (const char *src, const char *dest);
  260. /*
  261. * Copies the info of an open file to the structure
  262. */
  263. int32 OS_FDGetInfo (int32 filedes, OS_FDTableEntry *fd_prop);
  264. /*
  265. ** Check to see if a file is open
  266. */
  267. int32 OS_FileOpenCheck(char *Filename);
  268. /*
  269. ** Close all open files
  270. */
  271. int32 OS_CloseAllFiles(void);
  272. /*
  273. ** Close a file by filename
  274. */
  275. int32 OS_CloseFileByName(char *Filename);
  276. /******************************************************************************
  277. ** Directory API
  278. ******************************************************************************/
  279. /*
  280. * Makes a new directory
  281. */
  282. int32 OS_mkdir (const char *path, uint32 access);
  283. /*
  284. * Opens a directory for searching
  285. */
  286. os_dirp_t OS_opendir (const char *path);
  287. /*
  288. * Closes an open directory
  289. */
  290. int32 OS_closedir(os_dirp_t directory);
  291. /*
  292. * Rewinds an open directory
  293. */
  294. void OS_rewinddir(os_dirp_t directory);
  295. /*
  296. * Reads the next object in the directory
  297. */
  298. os_dirent_t * OS_readdir (os_dirp_t directory);
  299. /*
  300. * Removes an empty directory from the file system.
  301. */
  302. int32 OS_rmdir (const char *path);
  303. /******************************************************************************
  304. ** System Level API
  305. ******************************************************************************/
  306. /*
  307. * Makes a file system
  308. */
  309. int32 OS_mkfs (char *address,char *devname, char *volname,
  310. uint32 blocksize, uint32 numblocks);
  311. /*
  312. * Mounts a file system
  313. */
  314. int32 OS_mount (const char *devname, char *mountpoint);
  315. /*
  316. * Initializes an existing file system
  317. */
  318. int32 OS_initfs (char *address,char *devname, char *volname,
  319. uint32 blocksize, uint32 numblocks);
  320. /*
  321. * removes a file system
  322. */
  323. int32 OS_rmfs (char *devname);
  324. /*
  325. * Unmounts a mounted file system
  326. */
  327. int32 OS_unmount (const char *mountpoint);
  328. /*
  329. * Returns the number of free blocks in a file system
  330. */
  331. int32 OS_fsBlocksFree (const char *name);
  332. /*
  333. ** Returns the number of free bytes in a file system
  334. ** Note the 64 bit data type to support filesystems that
  335. ** are greater than 4 Gigabytes
  336. */
  337. int32 OS_fsBytesFree (const char *name, uint64 *bytes_free);
  338. /*
  339. * Checks the health of a file system and repairs it if neccesary
  340. */
  341. os_fshealth_t OS_chkfs (const char *name, boolean repair);
  342. /*
  343. * Returns in the parameter the physical drive underneith the mount point
  344. */
  345. int32 OS_FS_GetPhysDriveName (char * PhysDriveName, char * MountPoint);
  346. /*
  347. ** Translates a OSAL Virtual file system path to a host Local path
  348. */
  349. int32 OS_TranslatePath ( const char *VirtualPath, char *LocalPath);
  350. /*
  351. ** Returns information about the file system in an os_fsinfo_t
  352. */
  353. int32 OS_GetFsInfo(os_fsinfo_t *filesys_info);
  354. /******************************************************************************
  355. ** Shell API
  356. ******************************************************************************/
  357. /* executes the shell command passed into is and writes the output of that
  358. * command to the file specified by the given OSAPI file descriptor */
  359. int32 OS_ShellOutputToFile(char* Cmd, int32 OS_fd);
  360. #endif