xref: /aosp_15_r20/external/e2fsprogs/ext2ed/inode_com.c (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker 
3*6a54128fSAndroid Build Coastguard Worker /usr/src/ext2ed/inode_com.c
4*6a54128fSAndroid Build Coastguard Worker 
5*6a54128fSAndroid Build Coastguard Worker A part of the extended file system 2 disk editor.
6*6a54128fSAndroid Build Coastguard Worker 
7*6a54128fSAndroid Build Coastguard Worker Commands relevant to ext2_inode type.
8*6a54128fSAndroid Build Coastguard Worker 
9*6a54128fSAndroid Build Coastguard Worker First written on: April 9 1995
10*6a54128fSAndroid Build Coastguard Worker 
11*6a54128fSAndroid Build Coastguard Worker Copyright (C) 1995 Gadi Oxman
12*6a54128fSAndroid Build Coastguard Worker 
13*6a54128fSAndroid Build Coastguard Worker */
14*6a54128fSAndroid Build Coastguard Worker 
15*6a54128fSAndroid Build Coastguard Worker #include "config.h"
16*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
17*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
18*6a54128fSAndroid Build Coastguard Worker #include <string.h>
19*6a54128fSAndroid Build Coastguard Worker #include <time.h>
20*6a54128fSAndroid Build Coastguard Worker 
21*6a54128fSAndroid Build Coastguard Worker #include "ext2ed.h"
22*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___prev(char * command_line)23*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___prev (char *command_line)
24*6a54128fSAndroid Build Coastguard Worker 
25*6a54128fSAndroid Build Coastguard Worker {
26*6a54128fSAndroid Build Coastguard Worker 
27*6a54128fSAndroid Build Coastguard Worker 	char *ptr,buffer [80];
28*6a54128fSAndroid Build Coastguard Worker 
29*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,entry_num,block_num,first_entry,last_entry;
30*6a54128fSAndroid Build Coastguard Worker 	long inode_num,mult=1;
31*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
32*6a54128fSAndroid Build Coastguard Worker 
33*6a54128fSAndroid Build Coastguard Worker 	ptr=parse_word (command_line,buffer);
34*6a54128fSAndroid Build Coastguard Worker 
35*6a54128fSAndroid Build Coastguard Worker 	if (*ptr!=0) {
36*6a54128fSAndroid Build Coastguard Worker 		ptr=parse_word (ptr,buffer);
37*6a54128fSAndroid Build Coastguard Worker 		mult=atol (buffer);
38*6a54128fSAndroid Build Coastguard Worker 	}
39*6a54128fSAndroid Build Coastguard Worker 
40*6a54128fSAndroid Build Coastguard Worker 	block_num=device_offset/file_system_info.block_size;
41*6a54128fSAndroid Build Coastguard Worker 
42*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (device_offset);
43*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
44*6a54128fSAndroid Build Coastguard Worker 
45*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
46*6a54128fSAndroid Build Coastguard Worker 
47*6a54128fSAndroid Build Coastguard Worker 	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
48*6a54128fSAndroid Build Coastguard Worker 
49*6a54128fSAndroid Build Coastguard Worker 	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
50*6a54128fSAndroid Build Coastguard Worker 	inode_num=0;
51*6a54128fSAndroid Build Coastguard Worker 
52*6a54128fSAndroid Build Coastguard Worker 	if (entry_num-mult+1>0) {
53*6a54128fSAndroid Build Coastguard Worker 		device_offset-=sizeof (struct ext2_inode)*mult;
54*6a54128fSAndroid Build Coastguard Worker 		entry_num-=mult;
55*6a54128fSAndroid Build Coastguard Worker 
56*6a54128fSAndroid Build Coastguard Worker 		sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
57*6a54128fSAndroid Build Coastguard Worker 		strcpy (buffer,"show");dispatch (buffer);
58*6a54128fSAndroid Build Coastguard Worker 	}
59*6a54128fSAndroid Build Coastguard Worker 
60*6a54128fSAndroid Build Coastguard Worker 	else {
61*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Entry out of limits\n");refresh_command_win ();
62*6a54128fSAndroid Build Coastguard Worker 	}
63*6a54128fSAndroid Build Coastguard Worker 
64*6a54128fSAndroid Build Coastguard Worker 	if (entry_num==0) {
65*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Reached first inode in current group descriptor\n");
66*6a54128fSAndroid Build Coastguard Worker 		refresh_command_win ();
67*6a54128fSAndroid Build Coastguard Worker 	}
68*6a54128fSAndroid Build Coastguard Worker }
69*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___next(char * command_line)70*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___next (char *command_line)
71*6a54128fSAndroid Build Coastguard Worker 
72*6a54128fSAndroid Build Coastguard Worker {
73*6a54128fSAndroid Build Coastguard Worker 
74*6a54128fSAndroid Build Coastguard Worker 	char *ptr,buffer [80];
75*6a54128fSAndroid Build Coastguard Worker 
76*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,entry_num,block_num,first_entry,last_entry;
77*6a54128fSAndroid Build Coastguard Worker 	long inode_num,mult=1;
78*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
79*6a54128fSAndroid Build Coastguard Worker 
80*6a54128fSAndroid Build Coastguard Worker 	ptr=parse_word (command_line,buffer);
81*6a54128fSAndroid Build Coastguard Worker 
82*6a54128fSAndroid Build Coastguard Worker 	if (*ptr!=0) {
83*6a54128fSAndroid Build Coastguard Worker 		ptr=parse_word (ptr,buffer);
84*6a54128fSAndroid Build Coastguard Worker 		mult=atol (buffer);
85*6a54128fSAndroid Build Coastguard Worker 	}
86*6a54128fSAndroid Build Coastguard Worker 
87*6a54128fSAndroid Build Coastguard Worker 
88*6a54128fSAndroid Build Coastguard Worker 	block_num=device_offset/file_system_info.block_size;
89*6a54128fSAndroid Build Coastguard Worker 
90*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (device_offset);
91*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
92*6a54128fSAndroid Build Coastguard Worker 
93*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
94*6a54128fSAndroid Build Coastguard Worker 
95*6a54128fSAndroid Build Coastguard Worker 	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
96*6a54128fSAndroid Build Coastguard Worker 
97*6a54128fSAndroid Build Coastguard Worker 	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
98*6a54128fSAndroid Build Coastguard Worker 	inode_num=0;
99*6a54128fSAndroid Build Coastguard Worker 
100*6a54128fSAndroid Build Coastguard Worker 	if (entry_num+mult-1<last_entry) {
101*6a54128fSAndroid Build Coastguard Worker 		device_offset+=sizeof (struct ext2_inode)*mult;
102*6a54128fSAndroid Build Coastguard Worker 		entry_num+=mult;
103*6a54128fSAndroid Build Coastguard Worker 
104*6a54128fSAndroid Build Coastguard Worker 		sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
105*6a54128fSAndroid Build Coastguard Worker 		strcpy (buffer,"show");dispatch (buffer);
106*6a54128fSAndroid Build Coastguard Worker 	}
107*6a54128fSAndroid Build Coastguard Worker 
108*6a54128fSAndroid Build Coastguard Worker 	else {
109*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Entry out of limits\n");refresh_command_win ();
110*6a54128fSAndroid Build Coastguard Worker 	}
111*6a54128fSAndroid Build Coastguard Worker 
112*6a54128fSAndroid Build Coastguard Worker 	if (entry_num==last_entry) {
113*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Reached last inode in current group descriptor\n");
114*6a54128fSAndroid Build Coastguard Worker 		refresh_command_win ();
115*6a54128fSAndroid Build Coastguard Worker 	}
116*6a54128fSAndroid Build Coastguard Worker }
117*6a54128fSAndroid Build Coastguard Worker 
118*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___show(char * command_line)119*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___show (char *command_line)
120*6a54128fSAndroid Build Coastguard Worker 
121*6a54128fSAndroid Build Coastguard Worker {
122*6a54128fSAndroid Build Coastguard Worker 	struct ext2_inode *inode_ptr;
123*6a54128fSAndroid Build Coastguard Worker 
124*6a54128fSAndroid Build Coastguard Worker 	unsigned short temp;
125*6a54128fSAndroid Build Coastguard Worker 	int i;
126*6a54128fSAndroid Build Coastguard Worker 
127*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,entry_num,block_num,first_entry,last_entry,inode_num;
128*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
129*6a54128fSAndroid Build Coastguard Worker 
130*6a54128fSAndroid Build Coastguard Worker 	block_num=device_offset/file_system_info.block_size;
131*6a54128fSAndroid Build Coastguard Worker 
132*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (device_offset);
133*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
134*6a54128fSAndroid Build Coastguard Worker 
135*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
136*6a54128fSAndroid Build Coastguard Worker 
137*6a54128fSAndroid Build Coastguard Worker 	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
138*6a54128fSAndroid Build Coastguard Worker 	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
139*6a54128fSAndroid Build Coastguard Worker 	inode_num=group_num*file_system_info.super_block.s_inodes_per_group+1;
140*6a54128fSAndroid Build Coastguard Worker 	inode_num+=entry_num;
141*6a54128fSAndroid Build Coastguard Worker 
142*6a54128fSAndroid Build Coastguard Worker 	inode_ptr=&type_data.u.t_ext2_inode;
143*6a54128fSAndroid Build Coastguard Worker 
144*6a54128fSAndroid Build Coastguard Worker 	show (command_line);
145*6a54128fSAndroid Build Coastguard Worker 
146*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,0,40);wprintw (show_pad,"octal = %06o ",inode_ptr->i_mode);
147*6a54128fSAndroid Build Coastguard Worker 	for (i=6;i>=0;i-=3) {
148*6a54128fSAndroid Build Coastguard Worker 		temp=inode_ptr->i_mode & 0x1ff;
149*6a54128fSAndroid Build Coastguard Worker 		temp=temp >> i;
150*6a54128fSAndroid Build Coastguard Worker 		if (temp & 4)
151*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"r");
152*6a54128fSAndroid Build Coastguard Worker 		else
153*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"-");
154*6a54128fSAndroid Build Coastguard Worker 
155*6a54128fSAndroid Build Coastguard Worker 		if (temp & 2)
156*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"w");
157*6a54128fSAndroid Build Coastguard Worker 		else
158*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"-");
159*6a54128fSAndroid Build Coastguard Worker 
160*6a54128fSAndroid Build Coastguard Worker 		if (temp & 1)
161*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"x");
162*6a54128fSAndroid Build Coastguard Worker 		else
163*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"-");
164*6a54128fSAndroid Build Coastguard Worker 	}
165*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,3,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_atime));
166*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,4,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_ctime));
167*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,5,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_mtime));
168*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,6,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_dtime));
169*6a54128fSAndroid Build Coastguard Worker 
170*6a54128fSAndroid Build Coastguard Worker 	wmove (show_pad,10,40);
171*6a54128fSAndroid Build Coastguard Worker 	temp=inode_ptr->i_flags;
172*6a54128fSAndroid Build Coastguard Worker 
173*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_SECRM_FL)
174*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"s");
175*6a54128fSAndroid Build Coastguard Worker 	else
176*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
177*6a54128fSAndroid Build Coastguard Worker 
178*6a54128fSAndroid Build Coastguard Worker 
179*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_UNRM_FL)
180*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"u");
181*6a54128fSAndroid Build Coastguard Worker 	else
182*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
183*6a54128fSAndroid Build Coastguard Worker 
184*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_COMPR_FL)
185*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"c");
186*6a54128fSAndroid Build Coastguard Worker 	else
187*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
188*6a54128fSAndroid Build Coastguard Worker 
189*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_SYNC_FL)
190*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"S");
191*6a54128fSAndroid Build Coastguard Worker 	else
192*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
193*6a54128fSAndroid Build Coastguard Worker 
194*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_IMMUTABLE_FL)
195*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"i");
196*6a54128fSAndroid Build Coastguard Worker 	else
197*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
198*6a54128fSAndroid Build Coastguard Worker 
199*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_APPEND_FL)
200*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"a");
201*6a54128fSAndroid Build Coastguard Worker 	else
202*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
203*6a54128fSAndroid Build Coastguard Worker 
204*6a54128fSAndroid Build Coastguard Worker 	if (temp & EXT2_NODUMP_FL)
205*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"d");
206*6a54128fSAndroid Build Coastguard Worker 	else
207*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_pad,"-");
208*6a54128fSAndroid Build Coastguard Worker 
209*6a54128fSAndroid Build Coastguard Worker 	refresh_show_pad ();
210*6a54128fSAndroid Build Coastguard Worker 
211*6a54128fSAndroid Build Coastguard Worker 	wmove (show_win,1,0);
212*6a54128fSAndroid Build Coastguard Worker 
213*6a54128fSAndroid Build Coastguard Worker 	wprintw (show_win,"Inode %ld of %ld. Entry %ld of %ld in group descriptor %ld.\n"
214*6a54128fSAndroid Build Coastguard Worker 		,inode_num,file_system_info.super_block.s_inodes_count,entry_num,last_entry,group_num);
215*6a54128fSAndroid Build Coastguard Worker 
216*6a54128fSAndroid Build Coastguard Worker 	wprintw (show_win,"Inode type: ");
217*6a54128fSAndroid Build Coastguard Worker 
218*6a54128fSAndroid Build Coastguard Worker 	if (inode_num < EXT2_GOOD_OLD_FIRST_INO) {
219*6a54128fSAndroid Build Coastguard Worker 		switch (inode_num) {
220*6a54128fSAndroid Build Coastguard Worker 			case EXT2_BAD_INO:
221*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Bad blocks inode - ");
222*6a54128fSAndroid Build Coastguard Worker 				break;
223*6a54128fSAndroid Build Coastguard Worker 			case EXT2_ROOT_INO:
224*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Root inode - ");
225*6a54128fSAndroid Build Coastguard Worker 				break;
226*6a54128fSAndroid Build Coastguard Worker 			case EXT4_USR_QUOTA_INO:
227*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"User quota inode - ");
228*6a54128fSAndroid Build Coastguard Worker 				break;
229*6a54128fSAndroid Build Coastguard Worker 			case EXT4_GRP_QUOTA_INO:
230*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Group quota inode - ");
231*6a54128fSAndroid Build Coastguard Worker 				break;
232*6a54128fSAndroid Build Coastguard Worker 			case EXT2_BOOT_LOADER_INO:
233*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Boot loader inode - ");
234*6a54128fSAndroid Build Coastguard Worker 				break;
235*6a54128fSAndroid Build Coastguard Worker 			case EXT2_UNDEL_DIR_INO:
236*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Undelete directory inode - ");
237*6a54128fSAndroid Build Coastguard Worker 				break;
238*6a54128fSAndroid Build Coastguard Worker 			default:
239*6a54128fSAndroid Build Coastguard Worker 				wprintw (show_win,"Reserved inode - ");
240*6a54128fSAndroid Build Coastguard Worker 				break;
241*6a54128fSAndroid Build Coastguard Worker 		}
242*6a54128fSAndroid Build Coastguard Worker 	}
243*6a54128fSAndroid Build Coastguard Worker 	if (type_data.u.t_ext2_inode.i_mode==0)
244*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"Free.            ");
245*6a54128fSAndroid Build Coastguard Worker 
246*6a54128fSAndroid Build Coastguard Worker 	if (S_ISREG (type_data.u.t_ext2_inode.i_mode))
247*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"File.            ");
248*6a54128fSAndroid Build Coastguard Worker 
249*6a54128fSAndroid Build Coastguard Worker 	if (S_ISDIR (type_data.u.t_ext2_inode.i_mode))
250*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"Directory.       ");
251*6a54128fSAndroid Build Coastguard Worker 
252*6a54128fSAndroid Build Coastguard Worker 	if (S_ISLNK (type_data.u.t_ext2_inode.i_mode)) {
253*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"Symbolic link.   ");
254*6a54128fSAndroid Build Coastguard Worker 		wmove (show_pad,12,40);
255*6a54128fSAndroid Build Coastguard Worker 
256*6a54128fSAndroid Build Coastguard Worker 		if (inode_ptr->i_size <= 60)
257*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"-> %s",(char *) &type_data.u.t_ext2_inode.i_block [0]);
258*6a54128fSAndroid Build Coastguard Worker 		else
259*6a54128fSAndroid Build Coastguard Worker 			wprintw (show_pad,"Slow symbolic link\n");
260*6a54128fSAndroid Build Coastguard Worker 		refresh_show_pad ();
261*6a54128fSAndroid Build Coastguard Worker 	}
262*6a54128fSAndroid Build Coastguard Worker 
263*6a54128fSAndroid Build Coastguard Worker 	if (S_ISCHR (type_data.u.t_ext2_inode.i_mode))
264*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"Character device.");
265*6a54128fSAndroid Build Coastguard Worker 
266*6a54128fSAndroid Build Coastguard Worker 	if (S_ISBLK (type_data.u.t_ext2_inode.i_mode))
267*6a54128fSAndroid Build Coastguard Worker 		wprintw (show_win,"Block device.    ");
268*6a54128fSAndroid Build Coastguard Worker 
269*6a54128fSAndroid Build Coastguard Worker 	wprintw (show_win,"\n");refresh_show_win ();
270*6a54128fSAndroid Build Coastguard Worker 
271*6a54128fSAndroid Build Coastguard Worker 	if (entry_num==last_entry) {
272*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Reached last inode in current group descriptor\n");
273*6a54128fSAndroid Build Coastguard Worker 		refresh_command_win ();
274*6a54128fSAndroid Build Coastguard Worker 	}
275*6a54128fSAndroid Build Coastguard Worker 
276*6a54128fSAndroid Build Coastguard Worker 	if (entry_num==first_entry) {
277*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Reached first inode in current group descriptor\n");
278*6a54128fSAndroid Build Coastguard Worker 		refresh_command_win ();
279*6a54128fSAndroid Build Coastguard Worker 	}
280*6a54128fSAndroid Build Coastguard Worker 
281*6a54128fSAndroid Build Coastguard Worker }
282*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___entry(char * command_line)283*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___entry (char *command_line)
284*6a54128fSAndroid Build Coastguard Worker 
285*6a54128fSAndroid Build Coastguard Worker {
286*6a54128fSAndroid Build Coastguard Worker 	char *ptr,buffer [80];
287*6a54128fSAndroid Build Coastguard Worker 
288*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,entry_num,block_num,wanted_entry;
289*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
290*6a54128fSAndroid Build Coastguard Worker 
291*6a54128fSAndroid Build Coastguard Worker 	ptr=parse_word (command_line,buffer);
292*6a54128fSAndroid Build Coastguard Worker 	if (*ptr==0) return;
293*6a54128fSAndroid Build Coastguard Worker 	ptr=parse_word (ptr,buffer);
294*6a54128fSAndroid Build Coastguard Worker 	wanted_entry=atol (buffer);
295*6a54128fSAndroid Build Coastguard Worker 
296*6a54128fSAndroid Build Coastguard Worker 	block_num=device_offset/file_system_info.block_size;
297*6a54128fSAndroid Build Coastguard Worker 
298*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (device_offset);
299*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
300*6a54128fSAndroid Build Coastguard Worker 
301*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
302*6a54128fSAndroid Build Coastguard Worker 
303*6a54128fSAndroid Build Coastguard Worker 	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
304*6a54128fSAndroid Build Coastguard Worker 
305*6a54128fSAndroid Build Coastguard Worker 	if (wanted_entry > entry_num) {
306*6a54128fSAndroid Build Coastguard Worker 		sprintf (buffer,"next %ld",wanted_entry-entry_num);
307*6a54128fSAndroid Build Coastguard Worker 		dispatch (buffer);
308*6a54128fSAndroid Build Coastguard Worker 	}
309*6a54128fSAndroid Build Coastguard Worker 
310*6a54128fSAndroid Build Coastguard Worker 	else if (wanted_entry < entry_num) {
311*6a54128fSAndroid Build Coastguard Worker 		sprintf (buffer,"prev %ld",entry_num-wanted_entry);
312*6a54128fSAndroid Build Coastguard Worker 		dispatch (buffer);
313*6a54128fSAndroid Build Coastguard Worker 	}
314*6a54128fSAndroid Build Coastguard Worker }
315*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___group(char * command_line)316*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___group (char *command_line)
317*6a54128fSAndroid Build Coastguard Worker 
318*6a54128fSAndroid Build Coastguard Worker {
319*6a54128fSAndroid Build Coastguard Worker 	char buffer [80];
320*6a54128fSAndroid Build Coastguard Worker 
321*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset;
322*6a54128fSAndroid Build Coastguard Worker 
323*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (device_offset);
324*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
325*6a54128fSAndroid Build Coastguard Worker 
326*6a54128fSAndroid Build Coastguard Worker 	sprintf (buffer,"setoffset %ld",group_offset);dispatch (buffer);
327*6a54128fSAndroid Build Coastguard Worker 	sprintf (buffer,"settype ext2_group_desc");dispatch (buffer);
328*6a54128fSAndroid Build Coastguard Worker }
329*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___file(char * command_line)330*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___file (char *command_line)
331*6a54128fSAndroid Build Coastguard Worker 
332*6a54128fSAndroid Build Coastguard Worker {
333*6a54128fSAndroid Build Coastguard Worker 	char buffer [80];
334*6a54128fSAndroid Build Coastguard Worker 
335*6a54128fSAndroid Build Coastguard Worker 	if (!S_ISREG (type_data.u.t_ext2_inode.i_mode)) {
336*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Inode type is not file\n");refresh_command_win ();
337*6a54128fSAndroid Build Coastguard Worker 		return;
338*6a54128fSAndroid Build Coastguard Worker 	}
339*6a54128fSAndroid Build Coastguard Worker 
340*6a54128fSAndroid Build Coastguard Worker 	if (!init_file_info ()) {
341*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Unable to show file\n");refresh_command_win ();
342*6a54128fSAndroid Build Coastguard Worker 		return;
343*6a54128fSAndroid Build Coastguard Worker 	}
344*6a54128fSAndroid Build Coastguard Worker 
345*6a54128fSAndroid Build Coastguard Worker 	sprintf (buffer,"settype file");dispatch (buffer);
346*6a54128fSAndroid Build Coastguard Worker }
347*6a54128fSAndroid Build Coastguard Worker 
type_ext2_inode___dir(char * command_line)348*6a54128fSAndroid Build Coastguard Worker void type_ext2_inode___dir (char *command_line)
349*6a54128fSAndroid Build Coastguard Worker 
350*6a54128fSAndroid Build Coastguard Worker {
351*6a54128fSAndroid Build Coastguard Worker 	char buffer [80];
352*6a54128fSAndroid Build Coastguard Worker 
353*6a54128fSAndroid Build Coastguard Worker 	if (!S_ISDIR (type_data.u.t_ext2_inode.i_mode)) {
354*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Inode type is not directory\n");refresh_command_win ();
355*6a54128fSAndroid Build Coastguard Worker 		return;
356*6a54128fSAndroid Build Coastguard Worker 	}
357*6a54128fSAndroid Build Coastguard Worker 
358*6a54128fSAndroid Build Coastguard Worker /* It is very important to init first_file_info first, as search_dir_entries relies on it */
359*6a54128fSAndroid Build Coastguard Worker 
360*6a54128fSAndroid Build Coastguard Worker 	if (!init_dir_info (&first_file_info)) {
361*6a54128fSAndroid Build Coastguard Worker 		wprintw (command_win,"Error - Unable to show directory\n");refresh_command_win ();
362*6a54128fSAndroid Build Coastguard Worker 		return;
363*6a54128fSAndroid Build Coastguard Worker 	}
364*6a54128fSAndroid Build Coastguard Worker 
365*6a54128fSAndroid Build Coastguard Worker 	file_info=first_file_info;
366*6a54128fSAndroid Build Coastguard Worker 
367*6a54128fSAndroid Build Coastguard Worker 	sprintf (buffer,"settype dir");dispatch (buffer);
368*6a54128fSAndroid Build Coastguard Worker }
369*6a54128fSAndroid Build Coastguard Worker 
inode_offset_to_group_num(long inode_offset)370*6a54128fSAndroid Build Coastguard Worker long inode_offset_to_group_num (long inode_offset)
371*6a54128fSAndroid Build Coastguard Worker 
372*6a54128fSAndroid Build Coastguard Worker {
373*6a54128fSAndroid Build Coastguard Worker 	int found=0;
374*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
375*6a54128fSAndroid Build Coastguard Worker 
376*6a54128fSAndroid Build Coastguard Worker 	long block_num,group_offset,group_num;
377*6a54128fSAndroid Build Coastguard Worker 
378*6a54128fSAndroid Build Coastguard Worker 	block_num=inode_offset/file_system_info.block_size;
379*6a54128fSAndroid Build Coastguard Worker 
380*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset;
381*6a54128fSAndroid Build Coastguard Worker 	group_num=(group_offset-file_system_info.first_group_desc_offset)/sizeof (struct ext2_group_desc);
382*6a54128fSAndroid Build Coastguard Worker 
383*6a54128fSAndroid Build Coastguard Worker 	while (!found && group_num>=0 && group_num<file_system_info.groups_count) {
384*6a54128fSAndroid Build Coastguard Worker 		low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
385*6a54128fSAndroid Build Coastguard Worker 		if (block_num>=desc.bg_inode_table && block_num<desc.bg_inode_table+file_system_info.blocks_per_group)
386*6a54128fSAndroid Build Coastguard Worker 			found=1;
387*6a54128fSAndroid Build Coastguard Worker 		else
388*6a54128fSAndroid Build Coastguard Worker 			group_offset+=sizeof (struct ext2_group_desc);
389*6a54128fSAndroid Build Coastguard Worker 		group_num=(group_offset-file_system_info.first_group_desc_offset)/sizeof (struct ext2_group_desc);
390*6a54128fSAndroid Build Coastguard Worker 	}
391*6a54128fSAndroid Build Coastguard Worker 
392*6a54128fSAndroid Build Coastguard Worker 	if (!found)
393*6a54128fSAndroid Build Coastguard Worker 		return (-1);
394*6a54128fSAndroid Build Coastguard Worker 
395*6a54128fSAndroid Build Coastguard Worker 	return (group_num);
396*6a54128fSAndroid Build Coastguard Worker }
397*6a54128fSAndroid Build Coastguard Worker 
398*6a54128fSAndroid Build Coastguard Worker 
399*6a54128fSAndroid Build Coastguard Worker 
inode_offset_to_inode_num(long inode_offset)400*6a54128fSAndroid Build Coastguard Worker long int inode_offset_to_inode_num (long inode_offset)
401*6a54128fSAndroid Build Coastguard Worker 
402*6a54128fSAndroid Build Coastguard Worker {
403*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,entry_num,block_num,first_entry,last_entry,inode_num;
404*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
405*6a54128fSAndroid Build Coastguard Worker 
406*6a54128fSAndroid Build Coastguard Worker 	block_num=inode_offset/file_system_info.block_size;
407*6a54128fSAndroid Build Coastguard Worker 
408*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_offset_to_group_num (inode_offset);
409*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
410*6a54128fSAndroid Build Coastguard Worker 
411*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
412*6a54128fSAndroid Build Coastguard Worker 
413*6a54128fSAndroid Build Coastguard Worker 	entry_num=(inode_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
414*6a54128fSAndroid Build Coastguard Worker 	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
415*6a54128fSAndroid Build Coastguard Worker 	inode_num=group_num*file_system_info.super_block.s_inodes_per_group+1;
416*6a54128fSAndroid Build Coastguard Worker 	inode_num+=entry_num;
417*6a54128fSAndroid Build Coastguard Worker 
418*6a54128fSAndroid Build Coastguard Worker 	return (inode_num);
419*6a54128fSAndroid Build Coastguard Worker }
420*6a54128fSAndroid Build Coastguard Worker 
inode_num_to_inode_offset(long inode_num)421*6a54128fSAndroid Build Coastguard Worker long int inode_num_to_inode_offset (long inode_num)
422*6a54128fSAndroid Build Coastguard Worker 
423*6a54128fSAndroid Build Coastguard Worker {
424*6a54128fSAndroid Build Coastguard Worker 	long group_num,group_offset,inode_offset,inode_entry;
425*6a54128fSAndroid Build Coastguard Worker 	struct ext2_group_desc desc;
426*6a54128fSAndroid Build Coastguard Worker 
427*6a54128fSAndroid Build Coastguard Worker 	inode_num--;
428*6a54128fSAndroid Build Coastguard Worker 
429*6a54128fSAndroid Build Coastguard Worker 	group_num=inode_num/file_system_info.super_block.s_inodes_per_group;
430*6a54128fSAndroid Build Coastguard Worker 	inode_entry=inode_num%file_system_info.super_block.s_inodes_per_group;
431*6a54128fSAndroid Build Coastguard Worker 	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
432*6a54128fSAndroid Build Coastguard Worker 	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
433*6a54128fSAndroid Build Coastguard Worker 
434*6a54128fSAndroid Build Coastguard Worker 	inode_offset=desc.bg_inode_table*file_system_info.block_size+inode_entry*sizeof (struct ext2_inode);
435*6a54128fSAndroid Build Coastguard Worker 
436*6a54128fSAndroid Build Coastguard Worker 	return (inode_offset);
437*6a54128fSAndroid Build Coastguard Worker }
438