3 /usr/src/ext2ed/inodebitmap_com.c
5 A part of the extended file system 2 disk editor.
7 -------------------------
8 Handles the inode bitmap.
9 -------------------------
11 Please refer to the documentation in blockbitmap_com.c - Those two files are almost equal.
13 First written on: July 25 1995
15 Copyright (C) 1995 Gadi Oxman
27 void type_ext2_inode_bitmap___entry (char *command_line
)
30 unsigned long entry_num
;
31 char *ptr
,buffer
[80];
33 ptr
=parse_word (command_line
,buffer
);
35 wprintw (command_win
,"Error - No argument specified\n");refresh_command_win ();return;
37 ptr
=parse_word (ptr
,buffer
);
39 entry_num
=atol (buffer
);
41 if (entry_num
>= file_system_info
.super_block
.s_inodes_per_group
) {
42 wprintw (command_win
,"Error - Entry number out of bounds\n");refresh_command_win ();return;
45 inode_bitmap_info
.entry_num
=entry_num
;
46 strcpy (buffer
,"show");dispatch (buffer
);
49 void type_ext2_inode_bitmap___next (char *command_line
)
53 char *ptr
,buffer
[80];
55 ptr
=parse_word (command_line
,buffer
);
57 ptr
=parse_word (ptr
,buffer
);
58 entry_offset
=atol (buffer
);
61 sprintf (buffer
,"entry %ld",inode_bitmap_info
.entry_num
+entry_offset
);
65 void type_ext2_inode_bitmap___prev (char *command_line
)
69 char *ptr
,buffer
[80];
71 ptr
=parse_word (command_line
,buffer
);
73 ptr
=parse_word (ptr
,buffer
);
74 entry_offset
=atol (buffer
);
77 sprintf (buffer
,"entry %ld",inode_bitmap_info
.entry_num
-entry_offset
);
81 void type_ext2_inode_bitmap___allocate (char *command_line
)
85 char *ptr
,buffer
[80];
87 ptr
=parse_word (command_line
,buffer
);
89 ptr
=parse_word (ptr
,buffer
);
93 entry_num
=inode_bitmap_info
.entry_num
;
94 if (num
> file_system_info
.super_block
.s_inodes_per_group
-entry_num
) {
95 wprintw (command_win
,"Error - There aren't that much inodes in the group\n");
96 refresh_command_win ();return;
100 allocate_inode (entry_num
);
107 void type_ext2_inode_bitmap___deallocate (char *command_line
)
110 long entry_num
,num
=1;
111 char *ptr
,buffer
[80];
113 ptr
=parse_word (command_line
,buffer
);
115 ptr
=parse_word (ptr
,buffer
);
119 entry_num
=inode_bitmap_info
.entry_num
;
120 if (num
> file_system_info
.super_block
.s_inodes_per_group
-entry_num
) {
121 wprintw (command_win
,"Error - There aren't that much inodes in the group\n");
122 refresh_command_win ();return;
126 deallocate_inode (entry_num
);
134 void allocate_inode (long entry_num
)
137 unsigned char bit_mask
=1;
140 byte_offset
=entry_num
/8;
141 for (j
=0;j
<entry_num
%8;j
++)
143 type_data
.u
.buffer
[byte_offset
] |= bit_mask
;
146 void deallocate_inode (long entry_num
)
149 unsigned char bit_mask
=1;
152 byte_offset
=entry_num
/8;
153 for (j
=0;j
<entry_num
%8;j
++)
157 type_data
.u
.buffer
[byte_offset
] &= bit_mask
;
160 void type_ext2_inode_bitmap___show (char *command_line
)
165 unsigned long inode_num
,entry_num
;
167 ptr
=type_data
.u
.buffer
;
168 show_pad_info
.line
=0;show_pad_info
.max_line
=-1;
170 wmove (show_pad
,0,0);
171 for (i
=0,entry_num
=0;i
<file_system_info
.super_block
.s_inodes_per_group
/8;i
++,ptr
++) {
172 for (j
=1;j
<=128;j
*=2) {
173 if (entry_num
==inode_bitmap_info
.entry_num
) {
174 wattrset (show_pad
,A_REVERSE
);
175 show_pad_info
.line
=show_pad_info
.max_line
-show_pad_info
.display_lines
/2;
179 wprintw (show_pad
,"1");
181 wprintw (show_pad
,"0");
183 if (entry_num
==inode_bitmap_info
.entry_num
)
184 wattrset (show_pad
,A_NORMAL
);
188 wprintw (show_pad
," ");
190 wprintw (show_pad
,"\n");
191 show_pad_info
.max_line
++;
196 wprintw (show_pad
,"\n");
197 show_pad_info
.max_line
++;
202 wmove (show_win
,1,0);wprintw (show_win
,"Inode bitmap of block group %ld\n",inode_bitmap_info
.group_num
);
204 inode_num
=1+inode_bitmap_info
.entry_num
+inode_bitmap_info
.group_num
*file_system_info
.super_block
.s_inodes_per_group
;
205 wprintw (show_win
,"Status of inode %ld - ",inode_num
);
206 ptr
=type_data
.u
.buffer
+inode_bitmap_info
.entry_num
/8;
208 for (i
=inode_bitmap_info
.entry_num
% 8;i
>0;i
--)
211 wprintw (show_win
,"Allocated\n");
213 wprintw (show_win
,"Free\n");