-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs_stat.c
More file actions
50 lines (44 loc) · 1.66 KB
/
Copy pathfs_stat.c
File metadata and controls
50 lines (44 loc) · 1.66 KB
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
/**************************************************************
* Class:: CSC-415-02 Spring 2024
* Name:: Tushin Kulshreshtha
* Student IDs:: 922180763,
* GitHub-Name:: Dextron04
* Group-Name:: Something Simple
* Project:: Basic File System
*
* File:: fs_stat.c
*
* Description:: BThis file implements a function to retrieve
* file status information based on the provided file path.
*
**************************************************************/
#include "mfs.h"
#include "fileSystem.h"
int fs_stat(const char *path, struct fs_stat *buf){
// if either the path or the buffer is NULL the function
// will fail and return a -1.
if(path == NULL || buf == NULL){
return -1;
}
ppReturn pRet;
// duplicating the string as it is declared as a constant.
char * newPath = strdup(path);
int p = parsePath(newPath, &pRet);
// If the path is invalid or the directory entry doesn't exist in the
// parent the function will fail and return a -1.
if(pRet.deNum == -1 || p != 0){
return -1;
}
// The buffer will have the releavent data passed in to it
// about the directory entry and since it is a pass by reference
// the updated values in the buffer will be used by the rest of the
// fucntions.
buf->st_size = pRet.parent[pRet.deNum].size;
buf->st_blocks = bytesToBlocks(pRet.parent[pRet.deNum].size);
buf->st_blksize = BlockSize;
buf->st_createtime = pRet.parent[pRet.deNum].dateCreated;
buf->st_modtime = pRet.parent[pRet.deNum].dateModified;
// On a successful execution the function will return a status of 0
// indicating no errors encountred during execution.
return 0;
}