-
Notifications
You must be signed in to change notification settings - Fork 0
/
showstat.c
57 lines (52 loc) · 1.98 KB
/
showstat.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
#include "fsfileops.h"
#include <string.h>
void PrintFileSystemInfo()
{
printf("========================\n");
printf("File system info:\n");
printf("free_inodes_count = %ld\n", free_inodes_count);
printf("max_inodes_count = %ld\n", max_inodes_count);
printf("free_blocks_count = %ld\n", free_blocks_count);
printf("max_blocks_count = %ld\n", max_blocks_count);
printf("block_size = %ld\n", block_size);
printf("========================\n");
}
void PrintDir(const char *path)
{
long i;
long index = GetInodeIndexByPath(path);
printf("index = %ld\n", index);
struct dinode n = ReadInode(index);
if(n.di_size < 0)
return;
//TruncFile(&n, 268*0);
int count = n.di_size / sizeof(struct dirent);
struct dirent items[count];
printf("---------------------------------------------------\n");
printf("[%s]: size = %ld, index = %ld, links = %d\n", path, n.di_size, index, n.di_nlink);
ReadFile(&n, (void *)items, 0*sizeof(struct dirent), (count)*sizeof(struct dirent));
for(i = 0; i<count; i++)
{
struct dinode item = ReadInode((items)[i].d_ino);
printf(" %s: inode = %ld, offs = %ld, mode = %o, size = %ld\n", (items)[i].d_name, (items)[i].d_ino, (items)[i].d_off, item.di_mode, item.di_size);
if((strcmp(items[i].d_name, "..") != 0) && (strcmp(items[i].d_name, ".") != 0) && (item.di_mode & S_IFDIR))
{
char newpath[strlen(path)+strlen(items[i].d_name)+2];
strcpy(newpath, path);
if(strcmp(path, "/") != 0) strcat(newpath, "/");
strcat(newpath, items[i].d_name);
PrintDir(newpath);
}
}
printf("---------------------------------------------------\n");
}
int main(int argc, char *argv[])
{
fsfilename = FILE_PATH;
Load(fsfilename);
/*int i;
for(i = 0; i < 100; i++)
printf("index = %ld\n", GetInodeIndexByPath("/Безымянная папка/FUSE.htm"));*/
PrintDir("/");
PrintFileSystemInfo();
}