-
Notifications
You must be signed in to change notification settings - Fork 215
/
osapi-os-filesys.h
978 lines (887 loc) · 36.2 KB
/
osapi-os-filesys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
/*
** File: osapi-os-filesys.h
**
** Copyright (c) 2004-2006, United States government as represented by the
** administrator of the National Aeronautics Space Administration.
** All rights reserved. This software was created at NASAs Goddard
** Space Flight Center pursuant to government contracts.
**
** This is governed by the NASA Open Source Agreement and may be used,
** distributed and modified only pursuant to the terms of that agreement.
**
** Author: Alan Cudmore Code 582
**
** Purpose: Contains functions prototype definitions and variables declarations
** for the OS Abstraction Layer, File System module
**
*/
#ifndef _osapi_filesys_
#define _osapi_filesys_
/** @defgroup OSFileAccess OSAL File Access Option Defines
* @{
*/
#define OS_READ_ONLY 0 /**< Read only file access */
#define OS_WRITE_ONLY 1 /**< Write only file access */
#define OS_READ_WRITE 2 /**< Read write file access */
/**@}*/
/** @defgroup OSFileOffset OSAL Refernce Point For Seek Offset Defines
* @{
*/
#define OS_SEEK_SET 0 /**< Seek offset set */
#define OS_SEEK_CUR 1 /**< Seek offset current */
#define OS_SEEK_END 2 /**< Seek offset end */
/**@}*/
#define OS_CHK_ONLY 0 /**< Unused, API takes bool */
#define OS_REPAIR 1 /**< Unused, API takes bool */
/** @defgroup OSVolType OSAL Volume Type Defines
* @{
*/
#define FS_BASED 0 /**< Volume type FS based */
#define RAM_DISK 1 /**< Volume type RAM disk */
#define EEPROM_DISK 2 /**< Volume type EEPROM disk */
#define ATA_DISK 3 /**< Volume type ATA disk */
/**@}*/
/**
* @brief Number of entries in the internal volume table
*/
#define NUM_TABLE_ENTRIES 14
/*
** Length of a Device and Volume name
*/
#define OS_FS_DEV_NAME_LEN 32 /**< Device name length */
#define OS_FS_PHYS_NAME_LEN 64 /**< Physical drive name length */
#define OS_FS_VOL_NAME_LEN 32 /**< Volume name length */
/** @addtogroup OSReturnCodes
* @{
*/
/*
** Defines for File System Calls
*/
/*
* NOTE - these values used to overlap with the
* other OSAPI error codes. They now start at -100
* to avoid this overlap.
*/
#define OS_FS_ERR_PATH_TOO_LONG (-103) /**< @brief FS path too long */
#define OS_FS_ERR_NAME_TOO_LONG (-104) /**< @brief FS name too long */
#define OS_FS_ERR_DRIVE_NOT_CREATED (-106) /**< @brief FS drive not created */
#define OS_FS_ERR_DEVICE_NOT_FREE (-107) /**< @brief FS device not free */
#define OS_FS_ERR_PATH_INVALID (-108) /**< @brief FS path invalid */
/*
* Map some codes used by the file API back to the generic counterparts
* where there is overlap between them. Do not duplicate error codes.
*/
#define OS_FS_SUCCESS OS_SUCCESS /**< @brief Successful execution */
#define OS_FS_ERROR OS_ERROR /**< @brief Failed execution */
#define OS_FS_ERR_INVALID_POINTER OS_INVALID_POINTER /**< @brief Invalid pointer */
#define OS_FS_ERR_NO_FREE_FDS OS_ERR_NO_FREE_IDS /**< @brief No free IDs */
#define OS_FS_ERR_INVALID_FD OS_ERR_INVALID_ID /**< @brief Invalid ID */
#define OS_FS_UNIMPLEMENTED OS_ERR_NOT_IMPLEMENTED /**< @brief Not implemented */
/**@}*/
/* This typedef is for OS_FS_GetErrorName(), to ensure
* everyone is making an array of the same length
*
* Implementation note for developers:
*
* os_fs_err_name_t is now equivalent to the OSAL "os_err_name_t" typedef,
* to preserve source code compatibility with anything using the OS_FS_GetErrorName api
*
* The sizes of strings in OSAL functions are built with os_fs_err_name_t's
* limits in mind. Always check the uses of os_fs_err_name_t when changing
* os_err_name_t.
*/
typedef os_err_name_t os_fs_err_name_t;
/**
* @brief Internal structure of the OS volume table for
* mounted file systems and path translation
*/
typedef struct
{
char DeviceName [OS_FS_DEV_NAME_LEN];
char PhysDevName [OS_FS_PHYS_NAME_LEN];
uint32 VolumeType;
uint8 VolatileFlag;
uint8 FreeFlag;
uint8 IsMounted;
char VolumeName [OS_FS_VOL_NAME_LEN];
char MountPoint [OS_MAX_PATH_LEN];
uint32 BlockSize;
} OS_VolumeInfo_t;
/** @brief OSAL file system info */
typedef struct
{
uint32 MaxFds; /**< @brief Total number of file descriptors */
uint32 FreeFds; /**< @brief Total number that are free */
uint32 MaxVolumes; /**< @brief Maximum number of volumes */
uint32 FreeVolumes; /**< @brief Total number of volumes free */
} os_fsinfo_t;
/** @brief OSAL file properties */
typedef struct
{
char Path[OS_MAX_PATH_LEN];
uint32 User;
uint8 IsValid; /* For backward compatibility -- always true if OS_FDGetInfo returned true */
}OS_file_prop_t;
/**
* @brief File system status
*
* @note This used to be directly typedef'ed to the "struct stat" from the C library
*
* Some C libraries (glibc in particular) actually define member names to reference into
* sub-structures, so attempting to reuse a name like "st_mtime" might not work.
*/
typedef struct
{
uint32 FileModeBits;
int32 FileTime;
uint32 FileSize;
} os_fstat_t;
/**
* @brief File stat mode bits
*
* We must also define replacements for the stat structure's mode bits.
* This is currently just a small subset since the OSAL just presents a very
* simplified view of the filesystem to the upper layers. And since not all
* OS'es are POSIX, the more POSIX-specific bits are not relevant anyway.
*/
enum
{
OS_FILESTAT_MODE_EXEC = 0x00001,
OS_FILESTAT_MODE_WRITE = 0x00002,
OS_FILESTAT_MODE_READ = 0x00004,
OS_FILESTAT_MODE_DIR = 0x10000
};
/** @brief Access file stat mode bits */
#define OS_FILESTAT_MODE(x) ((x).FileModeBits)
/** @brief File stat is directory logical */
#define OS_FILESTAT_ISDIR(x) ((x).FileModeBits & OS_FILESTAT_MODE_DIR)
/** @brief File stat is executable logical */
#define OS_FILESTAT_EXEC(x) ((x).FileModeBits & OS_FILESTAT_MODE_EXEC)
/** @brief File stat is write enabled logical */
#define OS_FILESTAT_WRITE(x) ((x).FileModeBits & OS_FILESTAT_MODE_WRITE)
/** @brief File stat is read enabled logical */
#define OS_FILESTAT_READ(x) ((x).FileModeBits & OS_FILESTAT_MODE_READ)
/** @brief Access file stat size field */
#define OS_FILESTAT_SIZE(x) ((x).FileSize)
/** @brief Access file stat time field */
#define OS_FILESTAT_TIME(x) ((x).FileTime)
/** @brief Directory entry */
typedef struct
{
char FileName[OS_MAX_PATH_LEN];
} os_dirent_t;
#ifndef OSAL_OMIT_DEPRECATED
/*
* Preserve the old type names for compatibility;
* but instead of DIR* it is now just a void*
*/
/* Provide something to implement os_dirp_t */
typedef void * os_dirp_t; /**< @deprecated */
#endif
/** @brief Access filename part of the dirent structure */
#define OS_DIRENTRY_NAME(x) ((x).FileName)
#ifndef OSAL_OMIT_DEPRECATED
/*
* Several old type names can be aliases for compatibility
*/
typedef int32 os_fshealth_t; /**< @deprecated type no longer used */
typedef OS_file_prop_t OS_FDTableEntry; /**< @deprecated Use OS_file_prop_t */
#endif
/*
* Exported Functions
*/
/** @defgroup OSAPIFile OSAL Standard File APIs
* @{
*/
/*-------------------------------------------------------------------------------------*/
/**
* @brief Creates a file specified by path
*
* Creates a file specified by const char *path, with read/write
* permissions by access. The file is also automatically opened by the
* create call.
*
* @param[in] path File name to create
* @param[in] access Intended access mode - see @ref OSFileAccess
*
* @note Valid handle IDs are never negative. Failure of this
* call can be checked by testing if the result is less than 0.
*
* @return A file handle ID or appropriate error code, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if path is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long
* @retval #OS_ERROR if permissions are unknown or OS call fails
* @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left
*/
int32 OS_creat (const char *path, int32 access);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Opens a file
*
* Opens a file.
*
* @param[in] path File name to create
* @param[in] access Intended access mode - see @ref OSFileAccess
* @param[in] mode The file permissions. This parameter is passed through to the
* native open call, but will be ignored. The file mode (or permissions)
* are ignored by the POSIX open call when the O_CREAT access flag is not passed in.
*
* @note Valid handle IDs are never negative. Failure of this
* call can be checked by testing if the result is less than 0.
*
* @return A file handle ID or appropriate error code, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if path is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if path exceeds the maximum number of chars
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long
* @retval #OS_ERROR if permissions are unknown or OS call fails
* @retval #OS_ERR_NO_FREE_IDS if there are no free file descriptors left
*/
int32 OS_open (const char *path, int32 access, uint32 mode);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Closes an open file handle
*
* This closes regular file handles and any other file-like resource, such as
* network streams or pipes.
*
* @param[in] filedes The handle ID to operate on
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if file descriptor could not be closed
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
*/
int32 OS_close (uint32 filedes);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Read from a file handle
*
* Reads up to nbytes from a file, and puts them into buffer.
*
* @param[in] filedes The handle ID to operate on
* @param[out] buffer Storage location for file data
* @param[in] nbytes Maximum number of bytes to read
*
* @note All OSAL error codes are negative int32 values. Failure of this
* call can be checked by testing if the result is less than 0.
*
* @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if buffer is a null pointer
* @retval #OS_ERROR if OS call failed
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
*/
int32 OS_read (uint32 filedes, void *buffer, uint32 nbytes);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Write to a file handle
*
* Writes to a file. copies up to a maximum of nbytes of buffer to the file
* described in filedes
*
* @param[in] filedes The handle ID to operate on
* @param[in] buffer Source location for file data
* @param[in] nbytes Maximum number of bytes to read
*
* @note All OSAL error codes are negative int32 values. Failure of this
* call can be checked by testing if the result is less than 0.
*
* @return A non-negative byte count or appropriate error code, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if buffer is NULL
* @retval #OS_ERROR if OS call failed
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
*/
int32 OS_write (uint32 filedes, const void *buffer, uint32 nbytes);
/*-------------------------------------------------------------------------------------*/
/**
* @brief File/Stream input read with a timeout
*
* This implements a time-limited read and is primarily intended for use with
* sockets but may also work with any other stream-like resource that the underlying
* OS supports.
*
* If data is immediately available on the file/socket, this will return that data
* along with the actual number of bytes that were immediately available. It will
* not block.
*
* If no data is immediately available, this will wait up to the given timeout for
* data to appear. If no data appears within the timeout period, then this returns
* an error code (not zero).
*
* In all cases this will return successfully as soon as at least 1 byte of actual
* data is available. It will not attempt to read the entire input buffer.
*
* If an EOF condition occurs prior to timeout, this function returns zero.
*
* @param[in] filedes The handle ID to operate on
* @param[in] buffer Source location for file data
* @param[in] nbytes Maximum number of bytes to read
* @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever)
*
* @return Byte count on success, zero for timeout, or appropriate error code,
* see @ref OSReturnCodes
*/
int32 OS_TimedRead(uint32 filedes, void *buffer, uint32 nbytes, int32 timeout);
/*-------------------------------------------------------------------------------------*/
/**
* @brief File/Stream output write with a timeout
*
* This implements a time-limited write and is primarily intended for use with
* sockets but may also work with any other stream-like resource that the underlying
* OS supports.
*
* If output buffer space is immediately available on the file/socket, this will
* place data into the buffer and return the actual number of bytes that were
* queued for output. It will not block.
*
* If no output buffer space is immediately available, this will wait up to the
* given timeout for space to become available. If no space becomes available within
* the timeout period, then this returns an error code (not zero).
*
* In all cases this will return successfully as soon as at least 1 byte of actual
* data is output. It will _not_ attempt to write the entire output buffer.
*
* If an EOF condition occurs prior to timeout, this function returns zero.
*
* @param[in] filedes The handle ID to operate on
* @param[in] buffer Source location for file data
* @param[in] nbytes Maximum number of bytes to read
* @param[in] timeout Maximum time to wait, in milliseconds (OS_PEND = forever)
*
* @return Byte count on success, zero for timeout, or appropriate error code,
* see @ref OSReturnCodes
*/
int32 OS_TimedWrite(uint32 filedes, const void *buffer, uint32 nbytes, int32 timeout);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Changes the permissions of a file
*
* @param[in] path File to change
* @param[in] access Desired access mode - see @ref OSFileAccess
*
* @note Some file systems do not implement permissions
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_chmod (const char *path, uint32 access);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtain information about a file or directory
*
* Returns information about a file or directory in a os_fstat_t structure
*
* @param[in] path The file to operate on
* @param[out] filestats Buffer to store file information
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if path or filestats is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally
* @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file is too long to be stored
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_ERROR if the OS call failed
*/
int32 OS_stat (const char *path, os_fstat_t *filestats);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Seeks to the specified position of an open file
*
* Sets the read/write pointer to a specific offset in a specific file.
*
* @param[in] filedes The handle ID to operate on
* @param[in] offset The file offset to seek to
* @param[in] whence The reference point for offset, see @ref OSFileOffset
*
* @return Byte offset from the beginning of the file or appropriate error code,
see @ref OSReturnCodes
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
* @retval #OS_ERROR if OS call failed
*/
int32 OS_lseek (uint32 filedes, int32 offset, uint32 whence);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Removes a file from the file system
*
* Removes a given filename from the drive
*
* @note The behvior of this API on an open file is not defined at the OSAL level
* due to dependencies on the underlying OS which may or may not allow the related
* operation based on a varienty of potential configurations. For portability,
* it is recommended that applications ensure the file is closed prior to removal.
*
* @param[in] path The file to operate on
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if there is no device or the driver returns error
* @retval #OS_INVALID_POINTER if path is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if path is too long to be stored locally
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_NAME_TOO_LONG if the name of the file to remove is too long
*/
int32 OS_remove (const char *path);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Renames a file
*
* Changes the name of a file, where the source and destination
* reside on the same file system.
*
* @note The behvior of this API on an open file is not defined at the OSAL level
* due to dependencies on the underlying OS which may or may not allow the related
* operation based on a varienty of potential configurations. For portability,
* it is recommended that applications ensure the file is closed prior to removal.
*
* @param[in] old_filename The original filename
* @param[in] new_filename The desired filename
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if the file could not be opened or renamed.
* @retval #OS_INVALID_POINTER if old or new are NULL
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally
* @retval #OS_FS_ERR_NAME_TOO_LONG if the new name is too long to be stored locally
*/
int32 OS_rename (const char *old_filename, const char *new_filename);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Copies a single file from src to dest
*
* @note The behvior of this API on an open file is not defined at the OSAL level
* due to dependencies on the underlying OS which may or may not allow the related
* operation based on a varienty of potential configurations. For portability,
* it is recommended that applications ensure the file is closed prior to removal.
*
* @param[in] src The source file to operate on
* @param[in] dest The destination file
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if the file could not be accessed
* @retval #OS_INVALID_POINTER if src or dest are NULL
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally
* @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally
*/
int32 OS_cp (const char *src, const char *dest);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Move a single file from src to dest
*
* This first attempts to rename the file, which is faster if
* the source and destination reside on the same file system.
*
* If this fails, it falls back to copying the file and removing
* the original.
*
* @note The behvior of this API on an open file is not defined at the OSAL level
* due to dependencies on the underlying OS which may or may not allow the related
* operation based on a varienty of potential configurations. For portability,
* it is recommended that applications ensure the file is closed prior to removal.
*
* @param[in] src The source file to operate on
* @param[in] dest The destination file
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if the file could not be renamed.
* @retval #OS_INVALID_POINTER if src or dest are NULL
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally
* @retval #OS_FS_ERR_NAME_TOO_LONG if the dest name is too long to be stored locally
*/
int32 OS_mv (const char *src, const char *dest);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtain information about an open file
*
* Copies the information of the given file descriptor into a structure passed in
*
* @param[in] filedes The handle ID to operate on
* @param[out] fd_prop Storage buffer for file information
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
*/
int32 OS_FDGetInfo (uint32 filedes, OS_file_prop_t *fd_prop);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Checks to see if a file is open
*
* This function takes a filename and determines if the file is open. The function
* will return success if the file is open.
*
* @param[in] Filename The file to operate on
*
* @return OS_SUCCESS if the file is open, or appropriate error code
* @retval #OS_ERROR if the file is not open
*/
int32 OS_FileOpenCheck(const char *Filename);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Close all open files
*
* Closes All open files that were opened through the OSAL
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if one or more file close returned an error
*/
int32 OS_CloseAllFiles(void);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Close a file by filename
*
* Allows a file to be closed by name.
* This will only work if the name passed in is the same name used to open
* the file.
*
* @param[in] Filename The file to close
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_FS_ERR_PATH_INVALID if the file is not found
* @retval #OS_ERROR if the file close returned an error
*/
int32 OS_CloseFileByName(const char *Filename);
/**@}*/
/** @defgroup OSAPIDir OSAL Directory APIs
* @{
*/
#ifndef OSAL_OMIT_DEPRECATED
/**
* @brief Opens a directory for searching
* @deprecated Replaced by OS_DirectoryOpen()
*/
os_dirp_t OS_opendir (const char *path);
/*
* @brief Closes an open directory
* @deprecated Replaced by OS_DirectoryClose()
*/
int32 OS_closedir(os_dirp_t directory);
/*
* @brief Rewinds an open directory
* @deprecated Replaced by OS_DirectoryRewind()
*/
void OS_rewinddir(os_dirp_t directory);
/*
* @brief Reads the next object in the directory
* @deprecated Replaced by OS_DirectoryRead()
*/
os_dirent_t * OS_readdir (os_dirp_t directory);
#endif
/*-------------------------------------------------------------------------------------*/
/**
* @brief Opens a directory
*
* Prepares for reading the files within a directory
*
* @param[out] dir_id The handle ID of the directory
* @param[in] path The directory to open
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_DirectoryOpen(uint32 *dir_id, const char *path);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Closes an open directory
*
* The directory referred to by dir_id will be closed
*
* @param[in] dir_id The handle ID of the directory
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_DirectoryClose(uint32 dir_id);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Rewinds an open directory
*
* Resets a directory read handle back to the first file.
*
* @param[in] dir_id The handle ID of the directory
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_DirectoryRewind(uint32 dir_id);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Reads the next name in the directory
*
* Obtains directory entry data for the next file from an open directory
*
* @param[in] dir_id The handle ID of the directory
* @param[out] dirent Buffer to store directory entry information
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_DirectoryRead(uint32 dir_id, os_dirent_t *dirent);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Makes a new directory
*
* Makes a directory specified by path.
*
* @param[in] path The new directory name
* @param[in] access The permissions for the directory (reserved for future use)
*
* @note Current implementations do not utilize the "access" parameter. Applications
* should still pass the intended value (#OS_READ_WRITE or #OS_READ_ONLY) to be compatible
* with future implementations.
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if path is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_ERROR if the OS call fails
*/
int32 OS_mkdir (const char *path, uint32 access);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Removes a directory from the file system.
*
* Removes a directory from the structure.
* The directory must be empty prior to this operation.
*
* @param[in] path The directory to remove
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if path is NULL
* @retval #OS_FS_ERR_PATH_INVALID if path cannot be parsed
* @retval #OS_FS_ERR_PATH_TOO_LONG
* @retval #OS_ERROR if the directory remove operation failed
*/
int32 OS_rmdir (const char *path);
/**@}*/
/** @defgroup OSAPIFileSys OSAL File System Level APIs
* @{
*/
/*-------------------------------------------------------------------------------------*/
/**
* @brief Create a fixed mapping between an existing directory and a virtual OSAL mount point.
*
* This mimics the behavior of a "FS_BASED" entry in the VolumeTable but is registered
* at runtime. It is intended to be called by the PSP/BSP prior to starting the OSAL.
*
* @param[out] filesys_id An OSAL ID reflecting the file system
* @param[in] phys_path The native system directory (an existing mount point)
* @param[in] virt_path The virtual mount point of this filesystem
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path,
const char *virt_path);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Makes a file system on the target
*
* Makes a file system on the target. Highly dependent on underlying OS and
* dependent on OS volume table definition.
*
* @param[in] address The address at which to start the new disk. If address == 0
* space will be allocated by the OS.
* @param[in] devname The name of the "generic" drive
* @param[in] volname The name of the volume (if needed, used on VxWorks)
* @param[in] blocksize The size of a single block on the drive
* @param[in] numblocks The number of blocks to allocate for the drive
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if devname is NULL
* @retval #OS_FS_ERR_DRIVE_NOT_CREATED if the OS calls to create the the drive failed
* @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full
* @retval #OS_FS_SUCCESS on creating the disk
*/
int32 OS_mkfs (char *address, const char *devname, const char *volname,
uint32 blocksize, uint32 numblocks);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Mounts a file system
*
* Mounts a file system / block device at the given mount point.
*
* @param[in] devname The name of the drive to mount. devname is the same from #OS_mkfs
* @param[in] mountpoint The name to call this disk from now on
*
* @return Execution status, see @ref OSReturnCodes
*/
int32 OS_mount (const char *devname, const char *mountpoint);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Initializes an existing file system
*
* Initializes a file system on the target.
*
* @param[in] address The address at which to start the new disk. If address == 0,
* then space will be allocated by the OS
* @param[in] devname The name of the "generic" drive
* @param[in] volname The name of the volume (if needed, used on VxWorks)
* @param[in] blocksize The size of a single block on the drive
* @param[in] numblocks The number of blocks to allocate for the drive
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if devname or volname are NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_FS_ERR_DEVICE_NOT_FREE if the volume table is full
* @retval #OS_FS_ERR_DRIVE_NOT_CREATED on error
*/
int32 OS_initfs (char *address, const char *devname, const char *volname,
uint32 blocksize, uint32 numblocks);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Removes a file system
*
* This function will remove or un-map the target file system. Note that this is not
* the same as un-mounting the file system.
*
* @param[in] devname The name of the "generic" drive
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if devname is NULL
* @retval #OS_ERROR is the drive specified cannot be located
*/
int32 OS_rmfs (const char *devname);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Unmounts a mounted file system
*
* This function will unmount a drive from the file system and make all open file
* descriptors useless.
*
* @note Any open file descriptors referencing this file system should
* be closed prior to unmounting a drive
*
* @param[in] mountpoint The mount point to remove from #OS_mount
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the absolute path given is too long
* @retval #OS_ERROR if the OS calls failed
*/
int32 OS_unmount (const char *mountpoint);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtain number of blocks free
*
* Returns the number of free blocks in a volume
*
* @param[in] name The device/path to operate on
*
* @return Block count or appropriate error code, see @ref OSReturnCodes
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*/
int32 OS_fsBlocksFree (const char *name);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtains the number of free bytes in a volume
*
* Returns the number of free bytes in a volume
*
* @note uses a 64 bit data type to support filesystems that
* are greater than 4 Gigabytes
*
* @param[in] name The device/path to operate on
* @param[out] bytes_free The number of free bytes
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if name is NULL
* @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long
* @retval #OS_ERROR if the OS call failed
*/
int32 OS_fsBytesFree (const char *name, uint64 *bytes_free);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Checks the health of a file system and repairs it if necessary
*
* Checks the drives for inconsistencies and optionally also repairs it
*
* @note not all operating systems implement this function
*
* @param[in] name The device/path to operate on
* @param[in] repair Whether to also repair inconsistencies
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER Name is NULL
* @retval #OS_ERR_NOT_IMPLEMENTED @copybrief OS_ERR_NOT_IMPLEMENTED
* @retval #OS_ERROR @copybrief OS_ERROR
*/
int32 OS_chkfs (const char *name, bool repair);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Obtains the physical drive name associated with a mount point
*
* Returns the name of the physical volume associated with the drive,
* when given the OSAL mount point of the drive
*
* @param[out] PhysDriveName Buffer to store physical drive name
* @param[in] MountPoint OSAL mount point
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if either parameter is NULL
* @retval #OS_ERROR if the mountpoint could not be found
*/
int32 OS_FS_GetPhysDriveName (char * PhysDriveName, const char * MountPoint);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Translates a OSAL Virtual file system path to a host Local path
*
* Translates a virtual path to an actual system path name
*
* @param[in] VirtualPath OSAL virtual path name
* @param[out] LocalPath Buffer to store native/translated path name
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if either parameter is NULL
*/
int32 OS_TranslatePath ( const char *VirtualPath, char *LocalPath);
/*-------------------------------------------------------------------------------------*/
/**
* @brief Returns information about the file system
*
* Returns information about the file system in an os_fsinfo_t.
* This includes the number of open files and file systems
*
* @param[out] filesys_info Buffer to store filesystem information
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if filesys_info is NULL
*/
int32 OS_GetFsInfo(os_fsinfo_t *filesys_info);
/**@}*/
/** @defgroup OSAPIShell OSAL Shell APIs
* @{
*/
/*-------------------------------------------------------------------------------------*/
/**
* @brief Executes the command and sends output to a file
*
* Takes a shell command in and writes the output of that command to the specified file
* The output file must be opened previously with write access (OS_WRITE_ONLY or OS_READ_WRITE).
*
* @param[in] Cmd Command to pass to shell
* @param[in] filedes File to send output to.
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_ERROR if the command was not executed properly
* @retval #OS_ERR_INVALID_ID if the file descriptor passed in is invalid
*/
int32 OS_ShellOutputToFile(const char* Cmd, uint32 filedes);
/**@}*/
#endif