PatchworkOS
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1#include <errno.h>
2#include <stdbool.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6#include <sys/io.h>
7#include <time.h>
8
9static const char* type_to_string(inode_type_t type)
10{
11 switch (type)
12 {
13 case INODE_FILE:
14 return "File";
15 case INODE_DIR:
16 return "Directory";
17 default:
18 return "Unknown";
19 }
20}
21
22static void print_stat(const char* path)
23{
24 stat_t st;
25 if (stat(path, &st) == ERR)
26 {
27 printf("stat: failed to stat %s (%s)\n", path, strerror(errno));
28 return;
29 }
30
31 printf(" File: %s\n", path);
32 printf(" Name: %s\n", st.name);
33 printf("Number: %llu\n", st.number);
34 printf(" Type: %s\n", type_to_string(st.type));
35 printf(" Size: %llu\n", st.size);
36 printf("Blocks: %llu\n", st.blocks);
37 printf(" Links: %llu\n", st.linkAmount);
38
39 struct tm timeData;
40 char buffer[MAX_PATH];
41 localtime_r(&st.accessTime, &timeData);
42 printf("Access: %02d:%02d %d-%02d-%02d\n", timeData.tm_hour, timeData.tm_min, timeData.tm_year + 1900,
43 timeData.tm_mon + 1, timeData.tm_mday);
44 localtime_r(&st.modifyTime, &timeData);
45 printf("Modify: %02d:%02d %d-%02d-%02d\n", timeData.tm_hour, timeData.tm_min, timeData.tm_year + 1900,
46 timeData.tm_mon + 1, timeData.tm_mday);
47 localtime_r(&st.changeTime, &timeData);
48 printf("Change: %02d:%02d %d-%02d-%02d\n", timeData.tm_hour, timeData.tm_min, timeData.tm_year + 1900,
49 timeData.tm_mon + 1, timeData.tm_mday);
50 localtime_r(&st.createTime, &timeData);
51 printf("Create: %02d:%02d %d-%02d-%02d\n", timeData.tm_hour, timeData.tm_min, timeData.tm_year + 1900,
52 timeData.tm_mon + 1, timeData.tm_mday);
53}
54
55int main(int argc, char** argv)
56{
57 for (int i = 1; i < argc; i++)
58 {
59 print_stat(argv[i]);
60 }
61
62 return EXIT_SUCCESS;
63}
#define MAX_PATH
Maximum length of filepaths.
Definition MAX_PATH.h:11
#define errno
Error number variable.
Definition errno.h:27
uint64_t stat(const char *path, stat_t *stat)
System call for retrieving info about a file or directory.
Definition stat.c:9
inode_type_t
Inode type enum.
Definition io.h:344
@ INODE_FILE
Is a file.
Definition io.h:345
@ INODE_DIR
Is a directory.
Definition io.h:346
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
#define ERR
Definition main.c:44
int main()
Definition main.c:97
static void print_stat(const char *path)
Definition main.c:22
static const char * type_to_string(inode_type_t type)
Definition main.c:9
_PUBLIC int printf(const char *_RESTRICT format,...)
Definition printf.c:5
#define EXIT_SUCCESS
Definition stdlib.h:46
_PUBLIC char * strerror(int errnum)
Definition strerror.c:6
Stat type.
Definition io.h:360
time_t accessTime
Unix time stamp for the last inode access.
Definition io.h:366
uint64_t linkAmount
The amount of times the inode appears in dentries.
Definition io.h:365
inode_number_t number
The number of the entries inode.
Definition io.h:361
uint64_t size
The size of the file that is visible outside the filesystem.
Definition io.h:363
inode_type_t type
The type of the entries inode.
Definition io.h:362
time_t modifyTime
Unix time stamp for last file content alteration.
Definition io.h:367
time_t changeTime
Unix time stamp for the last file metadata alteration.
Definition io.h:368
char name[MAX_NAME]
The name of the entry, not the full filepath.
Definition io.h:370
uint64_t blocks
The amount of blocks used on disk to store the file.
Definition io.h:364
time_t createTime
Unix time stamp for the creation of the inode.
Definition io.h:369
Definition time.h:21
int tm_mon
Definition time.h:26
int tm_year
Definition time.h:27
int tm_hour
Definition time.h:24
int tm_mday
Definition time.h:25
int tm_min
Definition time.h:23
_PUBLIC struct tm * localtime_r(const time_t *timer, struct tm *buf)
Definition localtime_r.c:6