blob: e6022344b69be45c86775cf6665658c9a2c40eac [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
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22
23#include "ext2ed.h"
24
25
26void type_ext2_inode_bitmap___entry (char *command_line)
27
28{
29 unsigned long entry_num;
30 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040031
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040032 ptr=parse_word (command_line,buffer);
33 if (*ptr==0) {
34 wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
35 }
36 ptr=parse_word (ptr,buffer);
37
38 entry_num=atol (buffer);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040039
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040040 if (entry_num >= file_system_info.super_block.s_inodes_per_group) {
41 wprintw (command_win,"Error - Entry number out of bounds\n");refresh_command_win ();return;
42 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040043
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040044 inode_bitmap_info.entry_num=entry_num;
45 strcpy (buffer,"show");dispatch (buffer);
46}
47
48void type_ext2_inode_bitmap___next (char *command_line)
49
50{
51 long entry_offset=1;
52 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040053
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040054 ptr=parse_word (command_line,buffer);
55 if (*ptr!=0) {
56 ptr=parse_word (ptr,buffer);
57 entry_offset=atol (buffer);
58 }
59
60 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num+entry_offset);
61 dispatch (buffer);
62}
63
64void type_ext2_inode_bitmap___prev (char *command_line)
65
66{
67 long entry_offset=1;
68 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040069
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040070 ptr=parse_word (command_line,buffer);
71 if (*ptr!=0) {
72 ptr=parse_word (ptr,buffer);
73 entry_offset=atol (buffer);
74 }
75
76 sprintf (buffer,"entry %ld",inode_bitmap_info.entry_num-entry_offset);
77 dispatch (buffer);
78}
79
80void type_ext2_inode_bitmap___allocate (char *command_line)
81
82{
83 long entry_num,num=1;
84 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040085
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040086 ptr=parse_word (command_line,buffer);
87 if (*ptr!=0) {
88 ptr=parse_word (ptr,buffer);
89 num=atol (buffer);
90 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040091
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040092 entry_num=inode_bitmap_info.entry_num;
93 if (num > file_system_info.super_block.s_inodes_per_group-entry_num) {
Theodore Ts'oefc6f622008-08-27 23:07:54 -040094 wprintw (command_win,"Error - There aren't that much inodes in the group\n");
95 refresh_command_win ();return;
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040096 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040097
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040098 while (num) {
99 allocate_inode (entry_num);
100 num--;entry_num++;
101 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400102
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400103 dispatch ("show");
104}
105
106void type_ext2_inode_bitmap___deallocate (char *command_line)
107
108{
109 long entry_num,num=1;
110 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400111
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400112 ptr=parse_word (command_line,buffer);
113 if (*ptr!=0) {
114 ptr=parse_word (ptr,buffer);
115 num=atol (buffer);
116 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400117
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400118 entry_num=inode_bitmap_info.entry_num;
119 if (num > file_system_info.super_block.s_inodes_per_group-entry_num) {
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400120 wprintw (command_win,"Error - There aren't that much inodes in the group\n");
121 refresh_command_win ();return;
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400122 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400123
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400124 while (num) {
125 deallocate_inode (entry_num);
126 num--;entry_num++;
127 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400128
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400129 dispatch ("show");
130}
131
132
133void allocate_inode (long entry_num)
134
135{
136 unsigned char bit_mask=1;
137 int byte_offset,j;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400138
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400139 byte_offset=entry_num/8;
140 for (j=0;j<entry_num%8;j++)
141 bit_mask*=2;
142 type_data.u.buffer [byte_offset] |= bit_mask;
143}
144
145void deallocate_inode (long entry_num)
146
147{
148 unsigned char bit_mask=1;
149 int byte_offset,j;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400150
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400151 byte_offset=entry_num/8;
152 for (j=0;j<entry_num%8;j++)
153 bit_mask*=2;
154 bit_mask^=0xff;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400155
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400156 type_data.u.buffer [byte_offset] &= bit_mask;
157}
158
159void type_ext2_inode_bitmap___show (char *command_line)
160
161{
162 int i,j;
163 unsigned char *ptr;
164 unsigned long inode_num,entry_num;
165
166 ptr=type_data.u.buffer;
167 show_pad_info.line=0;show_pad_info.max_line=-1;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400168
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400169 wmove (show_pad,0,0);
170 for (i=0,entry_num=0;i<file_system_info.super_block.s_inodes_per_group/8;i++,ptr++) {
171 for (j=1;j<=128;j*=2) {
172 if (entry_num==inode_bitmap_info.entry_num) {
173 wattrset (show_pad,A_REVERSE);
174 show_pad_info.line=show_pad_info.max_line-show_pad_info.display_lines/2;
175 }
176
177 if ((*ptr) & j)
178 wprintw (show_pad,"1");
179 else
180 wprintw (show_pad,"0");
181
182 if (entry_num==inode_bitmap_info.entry_num)
183 wattrset (show_pad,A_NORMAL);
184
185 entry_num++;
186 }
187 wprintw (show_pad," ");
188 if (i%8==7) {
189 wprintw (show_pad,"\n");
190 show_pad_info.max_line++;
191 }
192 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400193
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400194 if (i%8!=7) {
195 wprintw (show_pad,"\n");
196 show_pad_info.max_line++;
197 }
198
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400199 refresh_show_pad ();
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400200 show_info ();
201 wmove (show_win,1,0);wprintw (show_win,"Inode bitmap of block group %ld\n",inode_bitmap_info.group_num);
202
203 inode_num=1+inode_bitmap_info.entry_num+inode_bitmap_info.group_num*file_system_info.super_block.s_inodes_per_group;
204 wprintw (show_win,"Status of inode %ld - ",inode_num);
205 ptr=type_data.u.buffer+inode_bitmap_info.entry_num/8;
206 j=1;
207 for (i=inode_bitmap_info.entry_num % 8;i>0;i--)
208 j*=2;
209 if ((*ptr) & j)
210 wprintw (show_win,"Allocated\n");
211 else
212 wprintw (show_win,"Free\n");
213 refresh_show_win ();
214}