blob: 157807a2c3d6da3f5ed6b9bffc35a16b3436a9f0 [file] [log] [blame]
Theodore Ts'o583a1ce2002-05-11 13:00:22 -04001/*
2
3/usr/src/ext2ed/inodebitmap_com.c
4
5A part of the extended file system 2 disk editor.
6
7-------------------------
8Handles the inode bitmap.
9-------------------------
10
11Please refer to the documentation in blockbitmap_com.c - Those two files are almost equal.
12
13First written on: July 25 1995
14
15Copyright (C) 1995 Gadi Oxman
16
17*/
18
Theodore Ts'od1154eb2011-09-18 17:34:37 -040019#include "config.h"
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040020#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include "ext2ed.h"
25
26
27void type_ext2_inode_bitmap___entry (char *command_line)
28
29{
30 unsigned long entry_num;
31 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040032
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040033 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);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040040
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040041 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 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040044
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040045 inode_bitmap_info.entry_num=entry_num;
46 strcpy (buffer,"show");dispatch (buffer);
47}
48
49void type_ext2_inode_bitmap___next (char *command_line)
50
51{
52 long entry_offset=1;
53 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040054
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040055 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
65void type_ext2_inode_bitmap___prev (char *command_line)
66
67{
68 long entry_offset=1;
69 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040070
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040071 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
81void type_ext2_inode_bitmap___allocate (char *command_line)
82
83{
84 long entry_num,num=1;
85 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040086
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040087 ptr=parse_word (command_line,buffer);
88 if (*ptr!=0) {
89 ptr=parse_word (ptr,buffer);
90 num=atol (buffer);
91 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040092
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040093 entry_num=inode_bitmap_info.entry_num;
94 if (num > file_system_info.super_block.s_inodes_per_group-entry_num) {
Theodore Ts'oefc6f622008-08-27 23:07:54 -040095 wprintw (command_win,"Error - There aren't that much inodes in the group\n");
96 refresh_command_win ();return;
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040097 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040098
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040099 while (num) {
100 allocate_inode (entry_num);
101 num--;entry_num++;
102 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400103
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400104 dispatch ("show");
105}
106
107void type_ext2_inode_bitmap___deallocate (char *command_line)
108
109{
110 long entry_num,num=1;
111 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400112
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400113 ptr=parse_word (command_line,buffer);
114 if (*ptr!=0) {
115 ptr=parse_word (ptr,buffer);
116 num=atol (buffer);
117 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400118
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400119 entry_num=inode_bitmap_info.entry_num;
120 if (num > file_system_info.super_block.s_inodes_per_group-entry_num) {
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400121 wprintw (command_win,"Error - There aren't that much inodes in the group\n");
122 refresh_command_win ();return;
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400123 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400124
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400125 while (num) {
126 deallocate_inode (entry_num);
127 num--;entry_num++;
128 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400129
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400130 dispatch ("show");
131}
132
133
134void allocate_inode (long entry_num)
135
136{
137 unsigned char bit_mask=1;
138 int byte_offset,j;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400139
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400140 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
146void deallocate_inode (long entry_num)
147
148{
149 unsigned char bit_mask=1;
150 int byte_offset,j;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400151
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400152 byte_offset=entry_num/8;
153 for (j=0;j<entry_num%8;j++)
154 bit_mask*=2;
155 bit_mask^=0xff;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400156
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400157 type_data.u.buffer [byte_offset] &= bit_mask;
158}
159
160void 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;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400169
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400170 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 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400194
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400195 if (i%8!=7) {
196 wprintw (show_pad,"\n");
197 show_pad_info.max_line++;
198 }
199
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400200 refresh_show_pad ();
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400201 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}