Update release notes, etc., for the 1.47.2 release
[e2fsprogs.git] / ext2ed / inodebitmap_com.c
blob157807a2c3d6da3f5ed6b9bffc35a16b3436a9f0
1 /*
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
19 #include "config.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
24 #include "ext2ed.h"
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);
34 if (*ptr==0) {
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)
52 long entry_offset=1;
53 char *ptr,buffer [80];
55 ptr=parse_word (command_line,buffer);
56 if (*ptr!=0) {
57 ptr=parse_word (ptr,buffer);
58 entry_offset=atol (buffer);
61 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num+entry_offset);
62 dispatch (buffer);
65 void type_ext2_inode_bitmap___prev (char *command_line)
68 long entry_offset=1;
69 char *ptr,buffer [80];
71 ptr=parse_word (command_line,buffer);
72 if (*ptr!=0) {
73 ptr=parse_word (ptr,buffer);
74 entry_offset=atol (buffer);
77 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num-entry_offset);
78 dispatch (buffer);
81 void type_ext2_inode_bitmap___allocate (char *command_line)
84 long entry_num,num=1;
85 char *ptr,buffer [80];
87 ptr=parse_word (command_line,buffer);
88 if (*ptr!=0) {
89 ptr=parse_word (ptr,buffer);
90 num=atol (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;
99 while (num) {
100 allocate_inode (entry_num);
101 num--;entry_num++;
104 dispatch ("show");
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);
114 if (*ptr!=0) {
115 ptr=parse_word (ptr,buffer);
116 num=atol (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;
125 while (num) {
126 deallocate_inode (entry_num);
127 num--;entry_num++;
130 dispatch ("show");
134 void allocate_inode (long entry_num)
137 unsigned char bit_mask=1;
138 int byte_offset,j;
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;
146 void deallocate_inode (long entry_num)
149 unsigned char bit_mask=1;
150 int byte_offset,j;
152 byte_offset=entry_num/8;
153 for (j=0;j<entry_num%8;j++)
154 bit_mask*=2;
155 bit_mask^=0xff;
157 type_data.u.buffer [byte_offset] &= bit_mask;
160 void type_ext2_inode_bitmap___show (char *command_line)
163 int i,j;
164 unsigned char *ptr;
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;
178 if ((*ptr) & j)
179 wprintw (show_pad,"1");
180 else
181 wprintw (show_pad,"0");
183 if (entry_num==inode_bitmap_info.entry_num)
184 wattrset (show_pad,A_NORMAL);
186 entry_num++;
188 wprintw (show_pad," ");
189 if (i%8==7) {
190 wprintw (show_pad,"\n");
191 show_pad_info.max_line++;
195 if (i%8!=7) {
196 wprintw (show_pad,"\n");
197 show_pad_info.max_line++;
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);
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 ();