1583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o/*
2583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
3583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o/usr/src/ext2ed/inode_com.c
4583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
5583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'oA part of the extended file system 2 disk editor.
6583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
7583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'oCommands relevant to ext2_inode type.
8583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
9583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'oFirst written on: April 9 1995
10583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
11583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'oCopyright (C) 1995 Gadi Oxman
12583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
13583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o*/
14583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
15583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o#include <stdio.h>
16583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o#include <stdlib.h>
17583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o#include <string.h>
18583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o#include <time.h>
19583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
20583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o#include "ext2ed.h"
21583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
22583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___prev (char *command_line)
23583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
24583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
25583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
26583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char *ptr,buffer [80];
27583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
28583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,entry_num,block_num,first_entry,last_entry;
29583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long inode_num,mult=1;
30583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
31583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
32583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	ptr=parse_word (command_line,buffer);
33583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
34583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (*ptr!=0) {
35583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		ptr=parse_word (ptr,buffer);
36583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		mult=atol (buffer);
37583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
38583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
39583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=device_offset/file_system_info.block_size;
40583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
41583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (device_offset);
42583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
43583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
44583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
45583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
46583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
47583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
48583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
49583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num=0;
50583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
51583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num-mult+1>0) {
52583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		device_offset-=sizeof (struct ext2_inode)*mult;
53583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		entry_num-=mult;
54efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
55583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
56583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		strcpy (buffer,"show");dispatch (buffer);
57583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
58583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
59583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else {
60583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Entry out of limits\n");refresh_command_win ();
61583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
62efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
63583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num==0) {
64583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Reached first inode in current group descriptor\n");
65583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		refresh_command_win ();
66583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
67583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
68583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
69583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___next (char *command_line)
70583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
71583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
72583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
73583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char *ptr,buffer [80];
74583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
75583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,entry_num,block_num,first_entry,last_entry;
76583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long inode_num,mult=1;
77583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
78583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
79583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	ptr=parse_word (command_line,buffer);
80efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
81583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (*ptr!=0) {
82583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		ptr=parse_word (ptr,buffer);
83583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		mult=atol (buffer);
84583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
85583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
86583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
87583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=device_offset/file_system_info.block_size;
88583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
89583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (device_offset);
90583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
91583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
92583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
93583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
94583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
95583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
96583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
97583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num=0;
98583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
99583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num+mult-1<last_entry) {
100583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		device_offset+=sizeof (struct ext2_inode)*mult;
101583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		entry_num+=mult;
102efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
103583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
104583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		strcpy (buffer,"show");dispatch (buffer);
105583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
106583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
107583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else {
108583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Entry out of limits\n");refresh_command_win ();
109583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
110efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
111583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num==last_entry) {
112583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Reached last inode in current group descriptor\n");
113583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		refresh_command_win ();
114583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
115583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
116583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
117583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
118583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___show (char *command_line)
119583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
120583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
121583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_inode *inode_ptr;
122efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
123583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	unsigned short temp;
124583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	int i;
125efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
126583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,entry_num,block_num,first_entry,last_entry,inode_num;
127583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
128583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
129583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=device_offset/file_system_info.block_size;
130583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
131583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (device_offset);
132583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
133583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
134583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
135583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
136583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
137583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
138583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num=group_num*file_system_info.super_block.s_inodes_per_group+1;
139583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num+=entry_num;
140583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
141583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_ptr=&type_data.u.t_ext2_inode;
142583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
143583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	show (command_line);
144583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
145583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,0,40);wprintw (show_pad,"octal = %06o ",inode_ptr->i_mode);
146583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	for (i=6;i>=0;i-=3) {
147583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		temp=inode_ptr->i_mode & 0x1ff;
148583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		temp=temp >> i;
149583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		if (temp & 4)
150583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"r");
151583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		else
152583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"-");
153efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
154583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		if (temp & 2)
155583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"w");
156583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		else
157583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"-");
158583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
159583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		if (temp & 1)
160583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"x");
161583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		else
162583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"-");
163583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
164583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,3,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_atime));
165583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,4,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_ctime));
166583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,5,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_mtime));
167583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,6,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_dtime));
168583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
169583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_pad,10,40);
170583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	temp=inode_ptr->i_flags;
171efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
172583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_SECRM_FL)
173583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"s");
174583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
175583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
176583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
177583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
178583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_UNRM_FL)
179583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"u");
180583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
181583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
182583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
183583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_COMPR_FL)
184583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"c");
185583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
186583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
187583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
188583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_SYNC_FL)
189583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"S");
190583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
191583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
192583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
193583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_IMMUTABLE_FL)
194583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"i");
195583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
196583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
197583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
198583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_APPEND_FL)
199583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"a");
200583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
201583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
202583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
203583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (temp & EXT2_NODUMP_FL)
204583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"d");
205583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else
206583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_pad,"-");
207efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
208583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	refresh_show_pad ();
209583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
210583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wmove (show_win,1,0);
211583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
212583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wprintw (show_win,"Inode %ld of %ld. Entry %ld of %ld in group descriptor %ld.\n"
213583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		,inode_num,file_system_info.super_block.s_inodes_count,entry_num,last_entry,group_num);
214efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
215583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wprintw (show_win,"Inode type: ");
216583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
2170f31c737dbf999c90a0842e6a499416b8e1f0cb4Theodore Ts'o	if (inode_num < EXT2_GOOD_OLD_FIRST_INO) {
218583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		switch (inode_num) {
219583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			case EXT2_BAD_INO:
220583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				wprintw (show_win,"Bad blocks inode - ");
221583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
222583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			case EXT2_ROOT_INO:
223583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				wprintw (show_win,"Root inode - ");
224583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
225e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall			case EXT4_USR_QUOTA_INO:
226e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				wprintw (show_win,"User quota inode - ");
227583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
228e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall			case EXT4_GRP_QUOTA_INO:
229e0ed7404719a9ddd2ba427a80db5365c8bad18c0JP Abgrall				wprintw (show_win,"Group quota inode - ");
230583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
231583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			case EXT2_BOOT_LOADER_INO:
232583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				wprintw (show_win,"Boot loader inode - ");
233583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
234583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			case EXT2_UNDEL_DIR_INO:
235583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				wprintw (show_win,"Undelete directory inode - ");
236583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
237583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			default:
238583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				wprintw (show_win,"Reserved inode - ");
239583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o				break;
240583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		}
241583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
242583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (type_data.u.t_ext2_inode.i_mode==0)
243583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"Free.            ");
244efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
245583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (S_ISREG (type_data.u.t_ext2_inode.i_mode))
246583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"File.            ");
247583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
248583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (S_ISDIR (type_data.u.t_ext2_inode.i_mode))
249583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"Directory.       ");
250583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
251583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (S_ISLNK (type_data.u.t_ext2_inode.i_mode)) {
252583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"Symbolic link.   ");
253583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wmove (show_pad,12,40);
254583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
255583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		if (inode_ptr->i_size <= 60)
256583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			wprintw (show_pad,"-> %s",(char *) &type_data.u.t_ext2_inode.i_block [0]);
257583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		else
258efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o			wprintw (show_pad,"Slow symbolic link\n");
259583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		refresh_show_pad ();
260583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
261583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
262583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (S_ISCHR (type_data.u.t_ext2_inode.i_mode))
263583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"Character device.");
264583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
265583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (S_ISBLK (type_data.u.t_ext2_inode.i_mode))
266583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (show_win,"Block device.    ");
267583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
268583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wprintw (show_win,"\n");refresh_show_win ();
269efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
270583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num==last_entry) {
271583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Reached last inode in current group descriptor\n");
272583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		refresh_command_win ();
273583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
274583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
275583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (entry_num==first_entry) {
276583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Reached first inode in current group descriptor\n");
277583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		refresh_command_win ();
278583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
279583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
280583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
281583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
282583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___entry (char *command_line)
283583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
284583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
285583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char *ptr,buffer [80];
286583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
287583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,entry_num,block_num,wanted_entry;
288583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
289583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
290583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	ptr=parse_word (command_line,buffer);
291583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (*ptr==0) return;
292583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	ptr=parse_word (ptr,buffer);
293583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	wanted_entry=atol (buffer);
294583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
295583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=device_offset/file_system_info.block_size;
296583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
297583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (device_offset);
298583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
299583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
300583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
301583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
302583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
303583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
304583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (wanted_entry > entry_num) {
305583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		sprintf (buffer,"next %ld",wanted_entry-entry_num);
306583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		dispatch (buffer);
307583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
308efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
309583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	else if (wanted_entry < entry_num) {
310583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		sprintf (buffer,"prev %ld",entry_num-wanted_entry);
311583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		dispatch (buffer);
312583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
313583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
314583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
315583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___group (char *command_line)
316583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
317583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
318583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char buffer [80];
319efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
320583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset;
321efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
322583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (device_offset);
323583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
324efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
325583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	sprintf (buffer,"setoffset %ld",group_offset);dispatch (buffer);
326583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	sprintf (buffer,"settype ext2_group_desc");dispatch (buffer);
327583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
328583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
329583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___file (char *command_line)
330583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
331583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
332583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char buffer [80];
333efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
334583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (!S_ISREG (type_data.u.t_ext2_inode.i_mode)) {
335583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Inode type is not file\n");refresh_command_win ();
336efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o		return;
337583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
338efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
339583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (!init_file_info ()) {
340583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Unable to show file\n");refresh_command_win ();
341efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o		return;
342583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
343efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
344583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	sprintf (buffer,"settype file");dispatch (buffer);
345583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
346583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
347583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'ovoid type_ext2_inode___dir (char *command_line)
348583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
349583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
350583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	char buffer [80];
351efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
352583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (!S_ISDIR (type_data.u.t_ext2_inode.i_mode)) {
353583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Inode type is not directory\n");refresh_command_win ();
354efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o		return;
355583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
356583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
357efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* It is very important to init first_file_info first, as search_dir_entries relies on it */
358583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
359583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (!init_dir_info (&first_file_info)) {
360583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		wprintw (command_win,"Error - Unable to show directory\n");refresh_command_win ();
361efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o		return;
362583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
363efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
364583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	file_info=first_file_info;
365efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
366583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	sprintf (buffer,"settype dir");dispatch (buffer);
367583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
368583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
369583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'olong inode_offset_to_group_num (long inode_offset)
370583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
371583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
372583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	int found=0;
373583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
374efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
375583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long block_num,group_offset,group_num;
376efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
377583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=inode_offset/file_system_info.block_size;
378583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
379583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset;
380583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=(group_offset-file_system_info.first_group_desc_offset)/sizeof (struct ext2_group_desc);
381583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
382583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	while (!found && group_num>=0 && group_num<file_system_info.groups_count) {
383583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
384583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		if (block_num>=desc.bg_inode_table && block_num<desc.bg_inode_table+file_system_info.blocks_per_group)
385583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			found=1;
386583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		else
387583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o			group_offset+=sizeof (struct ext2_group_desc);
388583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		group_num=(group_offset-file_system_info.first_group_desc_offset)/sizeof (struct ext2_group_desc);
389583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	}
390efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
391583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	if (!found)
392583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o		return (-1);
393583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
394583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	return (group_num);
395583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
396583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
397efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
398583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
399583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'olong int inode_offset_to_inode_num (long inode_offset)
400583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
401583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
402583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,entry_num,block_num,first_entry,last_entry,inode_num;
403583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
404583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
405583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	block_num=inode_offset/file_system_info.block_size;
406583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
407583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_offset_to_group_num (inode_offset);
408583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
409583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
410583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
411583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
412583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	entry_num=(inode_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode);
413583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1;
414583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num=group_num*file_system_info.super_block.s_inodes_per_group+1;
415583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num+=entry_num;
416efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
417583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	return (inode_num);
418583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
419583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
420583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'olong int inode_num_to_inode_offset (long inode_num)
421583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
422583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o{
423583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	long group_num,group_offset,inode_offset,inode_entry;
424583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	struct ext2_group_desc desc;
425583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
426583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_num--;
427efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o
428583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_num=inode_num/file_system_info.super_block.s_inodes_per_group;
429583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_entry=inode_num%file_system_info.super_block.s_inodes_per_group;
430583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
431583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset);
432583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
433583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	inode_offset=desc.bg_inode_table*file_system_info.block_size+inode_entry*sizeof (struct ext2_inode);
434583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o
435583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o	return (inode_offset);
436583a1ce5d1b225a6b01fc2b30a3bcb21fd0d48c9Theodore Ts'o}
437