-
Notifications
You must be signed in to change notification settings - Fork 25
/
fm_cmd_utils.c
663 lines (566 loc) · 23.8 KB
/
fm_cmd_utils.c
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
/************************************************************************
* NASA Docket No. GSC-18,918-1, and identified as “Core Flight
* Software System (cFS) File Manager Application Version 2.6.1”
*
* Copyright (c) 2021 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/**
* @file
* File Manager (FM) Command Utility Functions
*
* Provides file manager utility function definitions for
* processing file manager commands
*/
#include "cfe.h"
#include "fm_app.h"
#include "fm_msg.h"
#include "fm_cmd_utils.h"
#include "fm_child.h"
#include "fm_perfids.h"
#include "fm_events.h"
#include <string.h>
#include <ctype.h>
static uint32 OpenFileCount = 0;
static bool FileIsOpen = false;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_IsValidCmdPktLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength, uint32 EventID, const char *CmdText)
{
bool FunctionResult = true;
size_t ActualLength = 0;
CFE_MSG_GetSize(MsgPtr, &ActualLength);
/* Verify command packet length */
if (ActualLength != ExpectedLength)
{
FunctionResult = false;
CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_ERROR,
"%s error: invalid command packet length: expected = %d, actual = %d", CmdText,
(int)ExpectedLength, (int)ActualLength);
}
return FunctionResult;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is not invalid */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyOverwrite(uint16 Overwrite, uint32 EventID, const char *CmdText)
{
bool FunctionResult = true;
/* Acceptable values are true (one) and false (zero) */
if ((Overwrite != true) && (Overwrite != false))
{
CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_ERROR, "%s error: invalid overwrite = %d", CmdText, Overwrite);
FunctionResult = false;
}
return FunctionResult;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- get open files data */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void LoadOpenFileData(osal_id_t ObjId, void *CallbackArg)
{
FM_OpenFilesEntry_t *OpenFilesData = (FM_OpenFilesEntry_t *)CallbackArg;
OS_task_prop_t TaskInfo;
OS_file_prop_t FdProp;
memset(&FdProp, 0, sizeof(FdProp));
if (OS_IdentifyObject(ObjId) == OS_OBJECT_TYPE_OS_STREAM)
{
if (OpenFilesData != (FM_OpenFilesEntry_t *)NULL)
{
if (OS_FDGetInfo(ObjId, &FdProp) == OS_SUCCESS)
{
strncpy(OpenFilesData[OpenFileCount].LogicalName, FdProp.Path, OS_MAX_PATH_LEN);
/* Get the name of the application that opened the file */
memset(&TaskInfo, 0, sizeof(TaskInfo));
if (OS_TaskGetInfo(FdProp.User, &TaskInfo) == OS_SUCCESS)
{
strncpy(OpenFilesData[OpenFileCount].AppName, (char *)TaskInfo.name, OS_MAX_API_NAME);
}
}
}
OpenFileCount++;
}
}
uint32 FM_GetOpenFilesData(FM_OpenFilesEntry_t *OpenFilesData)
{
OpenFileCount = 0;
OS_ForEachObject(OS_OBJECT_CREATOR_ANY, LoadOpenFileData, OpenFilesData);
return OpenFileCount;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- query filename state */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void SearchOpenFileData(osal_id_t ObjId, void *CallbackArg)
{
const char * Fname = (const char *)CallbackArg;
OS_file_prop_t FdProp;
memset(&FdProp, 0, sizeof(FdProp));
if (OS_IdentifyObject(ObjId) == OS_OBJECT_TYPE_OS_STREAM)
{
/* Get system info for each file descriptor table entry */
/* If the FD table entry is valid - then the file is open */
if (OS_FDGetInfo(ObjId, &FdProp) == OS_SUCCESS)
{
if (strcmp(Fname, FdProp.Path) == 0)
{
FileIsOpen = true;
}
}
}
}
uint32 FM_GetFilenameState(const char *Filename, uint32 BufferSize, bool FileInfoCmd)
{
os_fstat_t FileStatus;
uint32 FilenameState = FM_NAME_IS_INVALID;
bool FilenameIsValid = false;
int32 StringLength;
memset(&FileStatus, 0, sizeof(FileStatus));
if (Filename != NULL)
{
/* Search Filename for a string terminator */
for (StringLength = 0; StringLength < BufferSize; StringLength++)
{
if (Filename[StringLength] == '\0')
{
break;
}
}
/* Verify that Filename is not empty and has a terminator */
if ((StringLength > 0) && (StringLength < BufferSize))
{
FilenameIsValid = true;
}
}
/* If Filename is valid, then determine its state */
if (FilenameIsValid)
{
/* Check to see if Filename is in use */
if (OS_stat(Filename, &FileStatus) == OS_SUCCESS)
{
/* Filename is in use, is it also a directory? */
if (OS_FILESTAT_ISDIR(FileStatus))
{
/* Filename is a directory */
FilenameState = FM_NAME_IS_DIRECTORY;
}
else
{
/* Filename is a file, but is it open? */
FilenameState = FM_NAME_IS_FILE_CLOSED;
FileIsOpen = false;
OS_ForEachObject(OS_OBJECT_CREATOR_ANY, SearchOpenFileData, (void *)Filename);
if (FileIsOpen == true)
{
FilenameState = FM_NAME_IS_FILE_OPEN;
}
}
/* Save the last modify time and file size for File Info commands */
if (FileInfoCmd)
{
FM_GlobalData.FileStatTime = OS_FILESTAT_TIME(FileStatus);
FM_GlobalData.FileStatSize = OS_FILESTAT_SIZE(FileStatus);
FM_GlobalData.FileStatMode = OS_FILESTAT_MODE(FileStatus);
}
}
else
{
/* Cannot get file stat - therefore does not exist */
FilenameState = FM_NAME_IS_NOT_IN_USE;
/* Save the last modify time and file size for File Info commands */
if (FileInfoCmd)
{
FM_GlobalData.FileStatSize = 0;
FM_GlobalData.FileStatTime = 0;
FM_GlobalData.FileStatMode = 0;
}
}
}
return FilenameState;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is not invalid */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
uint32 FM_VerifyNameValid(const char *Name, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
char LocalFile[1 + OS_MAX_PATH_LEN];
uint32 FilenameState = FM_NAME_IS_INVALID;
/* Looking for filename state != FM_NAME_IS_INVALID */
FilenameState = FM_GetFilenameState(Name, BufferSize, true);
if (FilenameState == FM_NAME_IS_INVALID)
{
/*
* This function provided by SB will copy the string from a fixed size buffer,
* and always ensures the result is null terminated
*/
CFE_SB_MessageStringGet(LocalFile, Name, NULL, sizeof(LocalFile), BufferSize);
CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_ERROR, "%s error: invalid name: name = %s", CmdText, LocalFile);
}
return FilenameState;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state of file */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyFileState(FM_File_States State, const char *Filename, uint32 BufferSize, uint32 EventID,
const char *CmdText)
{
bool Result = false;
uint32 FilenameState = FM_NAME_IS_INVALID;
uint32 ErrorCode = FM_FNAME_INVALID_EID_OFFSET;
const char *ErrorDesc = "";
char LocalFile[1 + OS_MAX_PATH_LEN];
/* Get state of the filename */
FilenameState = FM_GetFilenameState(Filename, BufferSize, false);
switch (FilenameState)
{
case FM_NAME_IS_NOT_IN_USE:
if (State == FM_FILE_NOEXIST || State == FM_FILE_NOTOPEN || State == FM_DIR_NOEXIST)
{
Result = true;
}
else
{
ErrorCode = FM_FNAME_DNE_EID_OFFSET;
ErrorDesc = "file does not exist";
}
break;
case FM_NAME_IS_FILE_OPEN:
if (State == FM_FILE_EXISTS)
{
Result = true;
}
else if (State == FM_FILE_NOEXIST)
{
ErrorCode = FM_FNAME_EXIST_EID_OFFSET;
ErrorDesc = "file already exists";
}
else if (State == FM_DIR_EXISTS)
{
ErrorCode = FM_FNAME_ISFILE_EID_OFFSET;
ErrorDesc = "directory name exists as a file";
}
else if (State == FM_DIR_NOEXIST)
{
ErrorCode = FM_FNAME_DNE_EID_OFFSET;
ErrorDesc = "directory name exists as a file";
}
else
{
ErrorCode = FM_FNAME_ISOPEN_EID_OFFSET;
ErrorDesc = "file is already open";
}
break;
case FM_NAME_IS_FILE_CLOSED:
if (State == FM_FILE_CLOSED || State == FM_FILE_EXISTS || State == FM_FILE_NOTOPEN)
{
Result = true;
}
else if (State == FM_DIR_EXISTS)
{
ErrorCode = FM_FNAME_ISFILE_EID_OFFSET;
ErrorDesc = "directory name exists as a file";
}
else if (State == FM_DIR_NOEXIST)
{
ErrorCode = FM_FNAME_DNE_EID_OFFSET;
ErrorDesc = "directory name exists as a file";
}
else
{
ErrorCode = FM_FNAME_EXIST_EID_OFFSET;
ErrorDesc = "file already exists";
}
break;
case FM_NAME_IS_DIRECTORY:
if (State == FM_DIR_EXISTS)
{
Result = true;
}
else
{
ErrorCode = FM_FNAME_ISDIR_EID_OFFSET;
ErrorDesc = "filename is a directory";
}
break;
default: /* FilenameState == FM_NAME_IS_INVALID */
/* Insert a terminator in case the invalid string did not have one */
ErrorCode = FM_FNAME_INVALID_EID_OFFSET;
ErrorDesc = "filename is invalid";
break;
}
if (!Result)
{
/*
* This function provided by SB will copy the string from a fixed size buffer,
* and always ensures the result is null terminated
*/
CFE_SB_MessageStringGet(LocalFile, Filename, NULL, sizeof(LocalFile), BufferSize);
CFE_EVS_SendEvent((EventID + ErrorCode), CFE_EVS_EventType_ERROR, "%s error: %s: name = %s", CmdText, ErrorDesc,
LocalFile);
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is closed file */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyFileClosed(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_CLOSED, Filename, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is open or closed file */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyFileExists(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_EXISTS, Filename, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is unused */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyFileNoExist(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_NOEXIST, Filename, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is unused or closed file */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyFileNotOpen(const char *Filename, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_FILE_NOTOPEN, Filename, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is directory */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyDirExists(const char *Directory, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_DIR_EXISTS, Directory, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify state is unused */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyDirNoExist(const char *Name, uint32 BufferSize, uint32 EventID, const char *CmdText)
{
return FM_VerifyFileState(FM_DIR_NOEXIST, Name, BufferSize, EventID, CmdText);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- verify child task interface is alive */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool FM_VerifyChildTask(uint32 EventID, const char *CmdText)
{
bool Result = false;
/* Copy of child queue count that child task cannot change */
uint8 LocalQueueCount = FM_GlobalData.ChildQueueCount;
/* Verify child task is active and queue interface is healthy */
if (!OS_ObjectIdDefined(FM_GlobalData.ChildSemaphore))
{
CFE_EVS_SendEvent((EventID + FM_CHILD_DISABLED_EID_OFFSET), CFE_EVS_EventType_ERROR,
"%s error: child task is disabled", CmdText);
/* Child task disabled - cannot add another command */
Result = false;
}
else if (LocalQueueCount == FM_CHILD_QUEUE_DEPTH)
{
CFE_EVS_SendEvent((EventID + FM_CHILD_Q_FULL_EID_OFFSET), CFE_EVS_EventType_ERROR,
"%s error: child task queue is full", CmdText);
/* Queue full - cannot add another command */
Result = false;
}
else if ((LocalQueueCount > FM_CHILD_QUEUE_DEPTH) || (FM_GlobalData.ChildWriteIndex >= FM_CHILD_QUEUE_DEPTH))
{
CFE_EVS_SendEvent((EventID + FM_CHILD_BROKEN_EID_OFFSET), CFE_EVS_EventType_ERROR,
"%s error: child task interface is broken: count = %d, index = %d", CmdText, LocalQueueCount,
FM_GlobalData.ChildWriteIndex);
/* Queue broken - cannot add another command */
Result = false;
}
else
{
memset(&FM_GlobalData.ChildQueue[FM_GlobalData.ChildWriteIndex], 0, sizeof(FM_GlobalData.ChildQueue[0]));
/* OK to add another command to the queue */
Result = true;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- invoke child task command processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_InvokeChildTask(void)
{
/* Update callers queue index */
FM_GlobalData.ChildWriteIndex++;
if (FM_GlobalData.ChildWriteIndex >= FM_CHILD_QUEUE_DEPTH)
{
FM_GlobalData.ChildWriteIndex = 0;
}
/* Prevent parent/child updating queue counter at same time */
OS_MutSemTake(FM_GlobalData.ChildQueueCountSem);
FM_GlobalData.ChildQueueCount++;
OS_MutSemGive(FM_GlobalData.ChildQueueCountSem);
/* Does the child task still have a semaphore? */
if (OS_ObjectIdDefined(FM_GlobalData.ChildSemaphore))
{
/* Signal child task to call command handler */
OS_CountSemGive(FM_GlobalData.ChildSemaphore);
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- add path separator to directory name */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_AppendPathSep(char *Directory, uint32 BufferSize)
{
/*
** Previous verification tests ensure that the length of
** the string is both non-zero and less than the size
** of the string buffer.
*/
uint32 StringLength = 0;
StringLength = strlen(Directory);
/* Do nothing if string already ends with a path separator */
if ((StringLength != 0) && (Directory[StringLength - 1] != '/'))
{
/* Verify that string buffer has room for a path separator */
if (StringLength < (BufferSize - 1))
{
/*
* gcc 8+ will warn on strncat with constant of the same size as n
* OK to use strcat since available space already confirmed
*/
strcat(Directory, "/");
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- Facilitates monitoring free volume space */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 FM_GetVolumeFreeSpace(const char *FileSys, uint64 *BlockCount, uint64 *ByteCount)
{
OS_statvfs_t FileStats;
osal_status_t OS_Status;
int32 Result;
/* Get file system free space */
OS_Status = OS_FileSysStatVolume(FileSys, &FileStats);
if (OS_Status == OS_SUCCESS)
{
*BlockCount = FileStats.blocks_free;
*ByteCount = FileStats.block_size * FileStats.blocks_free;
Result = CFE_SUCCESS;
}
else
{
CFE_EVS_SendEvent(FM_OS_SYS_STAT_ERR_EID, CFE_EVS_EventType_ERROR,
"Could not get file system free space for %s. Returned %d", FileSys, (int)OS_Status);
Result = CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM utility function -- Facilitates monitoring directory usage */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 FM_GetDirectorySpaceEstimate(const char *Directory, uint64 *BlockCount, uint64 *ByteCount)
{
osal_id_t DirId;
os_dirent_t DirEntry;
os_fstat_t FileStat;
osal_status_t OS_Status;
int32 Result;
char FullPath[OS_MAX_PATH_LEN];
uint64 TotalBytes;
size_t DirLen;
TotalBytes = 0;
memset(&DirEntry, 0, sizeof(DirEntry));
strncpy(FullPath, Directory, sizeof(FullPath) - 1);
FullPath[sizeof(FullPath) - 1] = 0;
DirLen = strlen(FullPath);
if (DirLen < (sizeof(FullPath) - 2))
{
FullPath[DirLen] = '/';
++DirLen;
FullPath[DirLen] = 0;
/* Open directory so that we can read from it */
OS_Status = OS_DirectoryOpen(&DirId, Directory);
}
else
{
OS_Status = OS_ERR_NAME_TOO_LONG;
}
if (OS_Status != OS_SUCCESS)
{
/* Send command failure event (error) */
CFE_EVS_SendEvent(FM_DIRECTORY_ESTIMATE_ERR_EID, CFE_EVS_EventType_ERROR, "OS_DirectoryOpen err=%d, path=%s",
(int)OS_Status, Directory);
Result = CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}
else
{
/* Read each directory entry and stat the files */
while (OS_DirectoryRead(DirId, &DirEntry) == OS_SUCCESS)
{
strncpy(&FullPath[DirLen], OS_DIRENTRY_NAME(DirEntry), sizeof(FullPath) - DirLen - 1);
OS_Status = OS_stat(FullPath, &FileStat);
if (OS_Status != OS_SUCCESS)
{
CFE_EVS_SendEvent(FM_DIRECTORY_ESTIMATE_ERR_EID, CFE_EVS_EventType_ERROR, "OS_stat err=%d, path=%s",
(int)OS_Status, FullPath);
}
else if (!OS_FILESTAT_ISDIR(FileStat))
{
/*
* Only need to accumulate regular file entries, not dirs.
* Also note that OSAL does not currently report the number of
* blocks, only the number of bytes, so that is all that this function
* will export for now. This could change in a future version of OSAL.
*/
TotalBytes += FileStat.FileSize;
}
}
OS_DirectoryClose(DirId);
*ByteCount = TotalBytes;
Result = CFE_SUCCESS;
}
return Result;
}