forked from wfelipe/rkfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.c
182 lines (161 loc) · 5.07 KB
/
utils.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
*
* utils.c
*
* R.K.Raja
*
* (C) Copyright 2002, 2003.
* All rights reserved.
*
*/
#include <linux/module.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/blkdev.h>
#include <asm/uaccess.h>
#include <rkfs.h>
void rkfs_dump_vfs_super_block(const struct super_block *sb,
const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
memset(buf, 0, RKFS_BIG_BUF_SIZE);
va_start(vptr, frmt);
vsprintf(buf, frmt, vptr);
va_end(vptr);
printk("\n%s\n", buf);
printk("VFS superblock: Device: %s\n", __bdevname(sb->s_dev, buf));
printk("VFS superblock: Block size: %ld\n", sb->s_blocksize);
printk("VFS superblock: Block size bits: %u\n", sb->s_blocksize_bits);
printk("VFS superblock: Dirt: %u\n", sb->s_dirt);
printk("VFS superblock: Max filesize: %ld Kb\n",
(long)(sb->s_maxbytes / 1024));
printk("VFS superblock: Magic: %ld\n", sb->s_magic);
}
void rkfs_dump_rkfs_super_block(const struct rkfs_super_block *rkfs_sb,
const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
int i = 0, cnt = 0;
memset(buf, 0, RKFS_BIG_BUF_SIZE);
va_start(vptr, frmt);
vsprintf(buf, frmt, vptr);
va_end(vptr);
printk("\n%s\n", buf);
printk("rkfs superblock: Filesystem ID: %d\n", rkfs_sb->s_fsid);
printk("rkfs superblock: Filesystem ver: %d\n", rkfs_sb->s_fsver);
printk("rkfs superblock: Used blocks:\n");
for (i = 0; i < RKFS_MIN_BLOCKS; i++) {
if (rkfs_test_bit(i, (volatile void *)rkfs_sb->s_block_map)) {
printk("%d ", i);
cnt++;
if (cnt > 15) {
printk("\n");
cnt = 0;
}
}
}
cnt = 0;
printk("\nrkfs superblock: Used inodes:\n");
for (i = 0; i < RKFS_MIN_BLOCKS; i++) {
if (rkfs_test_bit(i, (volatile void *)rkfs_sb->s_inode_map)) {
printk("%d ", i);
cnt++;
if (cnt > 15) {
printk("\n");
cnt = 0;
}
}
}
printk("\nrkfs superblock: Inode table map:\n");
for (i = 0; i < RKFS_INODE_TABLES_MAP_SIZE; i++)
if (rkfs_sb->s_itable_map[i][0] != 0)
printk("Index: %d, Block: %d, Count: %d\n", i,
rkfs_sb->s_itable_map[i][0],
rkfs_sb->s_itable_map[i][1]);
printk("rkfs superblock: Filesystem state: %d\n", rkfs_sb->s_state);
printk("rkfs superblock: Total blocks: %d\n", rkfs_sb->s_total_blocks);
}
void rkfs_dump_rkfs_inode(const struct rkfs_inode *rkfs_dinode,
const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
int i = 0;
memset(buf, 0, RKFS_BIG_BUF_SIZE);
va_start(vptr, frmt);
vsprintf(buf, frmt, vptr);
va_end(vptr);
printk("\n%s\n", buf);
printk("rkfs inode: User ID: %d\n", rkfs_dinode->i_uid);
printk("rkfs inode: Group ID: %d\n", rkfs_dinode->i_gid);
printk("rkfs inode: Mode: %o\n", rkfs_dinode->i_mode);
printk("rkfs inode: Links count: %d\n", rkfs_dinode->i_links_count);
printk("rkfs inode: Time: %d\n", rkfs_dinode->i_time);
printk("rkfs inode: Size: %d\n", rkfs_dinode->i_size);
printk("rkfs inode: Blocks: %d\n", rkfs_dinode->i_blocks);
printk("rkfs inode: Data blocks:\n");
for (i = 0; i < RKFS_N_BLOCKS; i++)
if (rkfs_dinode->i_block[i])
printk("Index: %d, Block %d\n", i,
rkfs_dinode->i_block[i]);
}
void rkfs_dump_vfs_inode(const struct inode *vfs_inode, const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
memset(buf, 0, RKFS_BIG_BUF_SIZE);
va_start(vptr, frmt);
vsprintf(buf, frmt, vptr);
va_end(vptr);
printk("\n%s", buf);
printk("VFS inode: Inode number: %ld\n", vfs_inode->i_ino);
printk("VFS inode: Device: %s\n", __bdevname(vfs_inode->i_sb->s_dev, buf));
printk("VFS inode: Mode: %o\n", vfs_inode->i_mode);
printk("VFS inode: Link count: %d\n", vfs_inode->i_nlink);
printk("VFS inode: User ID: %d\n", vfs_inode->i_uid);
printk("VFS inode: Group ID: %d\n", vfs_inode->i_gid);
printk("VFS inode: Size: %ld\n", (long)vfs_inode->i_size);
printk("VFS inode: Block bits: %d\n", vfs_inode->i_blkbits);
printk("VFS inode: Blocks: %ld\n", vfs_inode->i_blocks);
printk("VFS inode: Access time: %ld\n", (ulong) vfs_inode->i_atime.tv_sec);
printk("VFS inode: Modification time: %ld\n",
(ulong) vfs_inode->i_mtime.tv_sec);
printk("VFS inode: Change time: %ld\n", (ulong) vfs_inode->i_ctime.tv_sec);
}
/*
void rkfs_dump_buffer_head(const struct buffer_head *bh,
const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
if( !rkfs_debug )
return;
memset(buf,0,RKFS_BIG_BUF_SIZE);
va_start(vptr,frmt);
vsprintf(buf,frmt,vptr);
va_end(vptr);
printk("Dumping buffer head:\n%s\n",buf);
printk("Block number: %ld\n",bh->b_blocknr);
printk("Block size: %d\n",bh->b_size);
printk("Device: %s\n",bdevname(bh->b_dev));
}
*/
void rkfs_dump_rkfs_dir_entry(const struct rkfs_dir_entry *rkfs_de,
const char *frmt, ...)
{
va_list vptr;
char buf[RKFS_BIG_BUF_SIZE];
memset(buf, 0, RKFS_BIG_BUF_SIZE);
va_start(vptr, frmt);
vsprintf(buf, frmt, vptr);
va_end(vptr);
printk("\n%s\n", buf);
printk("Inode number: %d\n", rkfs_de->de_inode);
printk("Name: %s\n", rkfs_de->de_name);
printk("Name len: %d\n", rkfs_de->de_name_len);
}