1 /* 2 3 /usr/src/ext2ed/inodebitmap_com.c 4 5 A part of the extended file system 2 disk editor. 6 7 ------------------------- 8 Handles the inode bitmap. 9 ------------------------- 10 11 Please refer to the documentation in blockbitmap_com.c - Those two files are almost equal. 12 13 First written on: July 25 1995 14 15 Copyright (C) 1995 Gadi Oxman 16 17 */ 18 19 #include "config.h" 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <string.h> 23 24 #include "ext2ed.h" 25 26 27 void type_ext2_inode_bitmap___entry (char *command_line) 28 29 { 30 unsigned long entry_num; 31 char *ptr,buffer [80]; 32 33 ptr=parse_word (command_line,buffer); 34 if (*ptr==0) { 35 wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return; 36 } 37 ptr=parse_word (ptr,buffer); 38 39 entry_num=atol (buffer); 40 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; 43 } 44 45 inode_bitmap_info.entry_num=entry_num; 46 strcpy (buffer,"show");dispatch (buffer); 47 } 48 49 void type_ext2_inode_bitmap___next (char *command_line) 50 51 { 52 long entry_offset=1; 53 char *ptr,buffer [80]; 54 55 ptr=parse_word (command_line,buffer); 56 if (*ptr!=0) { 57 ptr=parse_word (ptr,buffer); 58 entry_offset=atol (buffer); 59 } 60 61 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num+entry_offset); 62 dispatch (buffer); 63 } 64 65 void type_ext2_inode_bitmap___prev (char *command_line) 66 67 { 68 long entry_offset=1; 69 char *ptr,buffer [80]; 70 71 ptr=parse_word (command_line,buffer); 72 if (*ptr!=0) { 73 ptr=parse_word (ptr,buffer); 74 entry_offset=atol (buffer); 75 } 76 77 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num-entry_offset); 78 dispatch (buffer); 79 } 80 81 void type_ext2_inode_bitmap___allocate (char *command_line) 82 83 { 84 long entry_num,num=1; 85 char *ptr,buffer [80]; 86 87 ptr=parse_word (command_line,buffer); 88 if (*ptr!=0) { 89 ptr=parse_word (ptr,buffer); 90 num=atol (buffer); 91 } 92 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; 97 } 98 99 while (num) { 100 allocate_inode (entry_num); 101 num--;entry_num++; 102 } 103 104 dispatch ("show"); 105 } 106 107 void type_ext2_inode_bitmap___deallocate (char *command_line) 108 109 { 110 long entry_num,num=1; 111 char *ptr,buffer [80]; 112 113 ptr=parse_word (command_line,buffer); 114 if (*ptr!=0) { 115 ptr=parse_word (ptr,buffer); 116 num=atol (buffer); 117 } 118 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; 123 } 124 125 while (num) { 126 deallocate_inode (entry_num); 127 num--;entry_num++; 128 } 129 130 dispatch ("show"); 131 } 132 133 134 void allocate_inode (long entry_num) 135 136 { 137 unsigned char bit_mask=1; 138 int byte_offset,j; 139 140 byte_offset=entry_num/8; 141 for (j=0;j<entry_num%8;j++) 142 bit_mask*=2; 143 type_data.u.buffer [byte_offset] |= bit_mask; 144 } 145 146 void deallocate_inode (long entry_num) 147 148 { 149 unsigned char bit_mask=1; 150 int byte_offset,j; 151 152 byte_offset=entry_num/8; 153 for (j=0;j<entry_num%8;j++) 154 bit_mask*=2; 155 bit_mask^=0xff; 156 157 type_data.u.buffer [byte_offset] &= bit_mask; 158 } 159 160 void type_ext2_inode_bitmap___show (char *command_line) 161 162 { 163 int i,j; 164 unsigned char *ptr; 165 unsigned long inode_num,entry_num; 166 167 ptr=type_data.u.buffer; 168 show_pad_info.line=0;show_pad_info.max_line=-1; 169 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; 176 } 177 178 if ((*ptr) & j) 179 wprintw (show_pad,"1"); 180 else 181 wprintw (show_pad,"0"); 182 183 if (entry_num==inode_bitmap_info.entry_num) 184 wattrset (show_pad,A_NORMAL); 185 186 entry_num++; 187 } 188 wprintw (show_pad," "); 189 if (i%8==7) { 190 wprintw (show_pad,"\n"); 191 show_pad_info.max_line++; 192 } 193 } 194 195 if (i%8!=7) { 196 wprintw (show_pad,"\n"); 197 show_pad_info.max_line++; 198 } 199 200 refresh_show_pad (); 201 show_info (); 202 wmove (show_win,1,0);wprintw (show_win,"Inode bitmap of block group %ld\n",inode_bitmap_info.group_num); 203 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; 207 j=1; 208 for (i=inode_bitmap_info.entry_num % 8;i>0;i--) 209 j*=2; 210 if ((*ptr) & j) 211 wprintw (show_win,"Allocated\n"); 212 else 213 wprintw (show_win,"Free\n"); 214 refresh_show_win (); 215 } 216