-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.c
More file actions
110 lines (88 loc) · 2.5 KB
/
Copy pathstat.c
File metadata and controls
110 lines (88 loc) · 2.5 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
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
#ifndef STAT
#define STAT
int my_stat(char* pathname)
{
printf("********* stat **********\n");
// Use CWD
if (!pathname || !strlen(pathname))
return ls_dir(running->cwd);
// Use Path
int ino = getino(pathname);
// Path does not exist
if (!ino)
{
printf("ls> pathname: %s does not exist\n", pathname);
return -1;
}
MINODE *mip = iget(dev, ino);
if (!mip)
{
printf("ls> ino: %d does not exist in memory", ino);
return -1;
}
// // directory
// if ((mip->INODE.i_mode & 0xF000) == 0x4000) return ls_dir(mip);
// // file
// ls_file(mip, basename(pathname));
char ftime[26];
INODE *inode = &(mip->INODE);
printf("File: %s\n", pathname);
printf("Size: %d \t\tBlocks: %d \tIO Block: %d\t", inode->i_size, inode->i_blocks, 4096);
if ((mip->INODE.i_mode & 0xF000) == 0x4000)
{
printf("directory\n");
}
else if ((inode->i_mode & 0xF000)== 0xA000)
{
printf("Symbolic Link\n");
}
else
{
if (inode->i_size == 0)
{
printf("regular empty file\n");
}
else
{
printf("regular file\n");
}
}
printf("Inode: %d\t\tLinks: %d\n", mip->ino, inode->i_links_count);
short j = inode->i_mode;
j = (j << 6);
j = (j >> 6);
printf("Access: (0%o/", j);
if ((inode->i_mode & 0xF000) == 0x8000) // if (S_ISREG())
printf("%c",'-');
if ((inode->i_mode & 0xF000) == 0x4000) // if (S_ISDIR())
printf("%c",'d');
if ((inode->i_mode & 0xF000) == 0xA000) // if (S_ISLNK())
printf("%c",'l');
for (int i=8; i >= 0; i--){
if (inode->i_mode & (1 << i)) // print r|w|x
printf("%c", t1[i]);
else
printf("%c", t2[i]); // or print -
}
printf(")\t");
printf("Uid: (%d)\tGid: (%d)\n", inode->i_uid, inode->i_gid);
// print time
time_t t = inode->i_atime;
strcpy(ftime, ctime(&t)); // print time in calendar form
ftime[strlen(ftime)-1] = 0; // kill \n at end
printf("Access: %s\n", ftime);
// print time
t = inode->i_mtime;
strcpy(ftime, ctime(&t)); // print time in calendar form
ftime[strlen(ftime)-1] = 0; // kill \n at end
printf("Modify: %s\n", ftime);
// print time
t = inode->i_ctime;
strcpy(ftime, ctime(&t)); // print time in calendar form
ftime[strlen(ftime)-1] = 0; // kill \n at end
printf("Change: %s\n", ftime);
printf("\n");
iput(mip);
return 1;
}
#endif