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
9
static
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
22
static
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
55
int
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
}
MAX_PATH
#define MAX_PATH
Maximum length of filepaths.
Definition
MAX_PATH.h:11
errno.h
errno
#define errno
Error number variable.
Definition
errno.h:27
stat
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_t
Inode type enum.
Definition
io.h:344
INODE_FILE
@ INODE_FILE
Is a file.
Definition
io.h:345
INODE_DIR
@ INODE_DIR
Is a directory.
Definition
io.h:346
io.h
buffer
EFI_PHYSICAL_ADDRESS buffer
Definition
mem.c:15
ERR
#define ERR
Definition
main.c:44
main
int main()
Definition
main.c:97
print_stat
static void print_stat(const char *path)
Definition
main.c:22
type_to_string
static const char * type_to_string(inode_type_t type)
Definition
main.c:9
stdbool.h
stdio.h
printf
_PUBLIC int printf(const char *_RESTRICT format,...)
Definition
printf.c:5
stdlib.h
EXIT_SUCCESS
#define EXIT_SUCCESS
Definition
stdlib.h:46
string.h
strerror
_PUBLIC char * strerror(int errnum)
Definition
strerror.c:6
stat_t
Stat type.
Definition
io.h:360
stat_t::accessTime
time_t accessTime
Unix time stamp for the last inode access.
Definition
io.h:366
stat_t::linkAmount
uint64_t linkAmount
The amount of times the inode appears in dentries.
Definition
io.h:365
stat_t::number
inode_number_t number
The number of the entries inode.
Definition
io.h:361
stat_t::size
uint64_t size
The size of the file that is visible outside the filesystem.
Definition
io.h:363
stat_t::type
inode_type_t type
The type of the entries inode.
Definition
io.h:362
stat_t::modifyTime
time_t modifyTime
Unix time stamp for last file content alteration.
Definition
io.h:367
stat_t::changeTime
time_t changeTime
Unix time stamp for the last file metadata alteration.
Definition
io.h:368
stat_t::name
char name[MAX_NAME]
The name of the entry, not the full filepath.
Definition
io.h:370
stat_t::blocks
uint64_t blocks
The amount of blocks used on disk to store the file.
Definition
io.h:364
stat_t::createTime
time_t createTime
Unix time stamp for the creation of the inode.
Definition
io.h:369
tm
Definition
time.h:21
tm::tm_mon
int tm_mon
Definition
time.h:26
tm::tm_year
int tm_year
Definition
time.h:27
tm::tm_hour
int tm_hour
Definition
time.h:24
tm::tm_mday
int tm_mday
Definition
time.h:25
tm::tm_min
int tm_min
Definition
time.h:23
time.h
localtime_r
_PUBLIC struct tm * localtime_r(const time_t *timer, struct tm *buf)
Definition
localtime_r.c:6
src
programs
stat
main.c
Generated by
1.9.8