1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker
3*6a54128fSAndroid Build Coastguard Worker /usr/src/ext2ed/file_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 ----------------------------
8*6a54128fSAndroid Build Coastguard Worker Commands which handle a file
9*6a54128fSAndroid Build Coastguard Worker ----------------------------
10*6a54128fSAndroid Build Coastguard Worker
11*6a54128fSAndroid Build Coastguard Worker First written on: April 18 1995
12*6a54128fSAndroid Build Coastguard Worker
13*6a54128fSAndroid Build Coastguard Worker Copyright (C) 1995 Gadi Oxman
14*6a54128fSAndroid Build Coastguard Worker
15*6a54128fSAndroid Build Coastguard Worker */
16*6a54128fSAndroid Build Coastguard Worker
17*6a54128fSAndroid Build Coastguard Worker #include "config.h"
18*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
19*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
20*6a54128fSAndroid Build Coastguard Worker #include <string.h>
21*6a54128fSAndroid Build Coastguard Worker
22*6a54128fSAndroid Build Coastguard Worker #include "ext2ed.h"
23*6a54128fSAndroid Build Coastguard Worker
init_file_info(void)24*6a54128fSAndroid Build Coastguard Worker int init_file_info (void)
25*6a54128fSAndroid Build Coastguard Worker
26*6a54128fSAndroid Build Coastguard Worker {
27*6a54128fSAndroid Build Coastguard Worker struct ext2_inode *ptr;
28*6a54128fSAndroid Build Coastguard Worker
29*6a54128fSAndroid Build Coastguard Worker ptr=&type_data.u.t_ext2_inode;
30*6a54128fSAndroid Build Coastguard Worker
31*6a54128fSAndroid Build Coastguard Worker file_info.inode_ptr=ptr;
32*6a54128fSAndroid Build Coastguard Worker file_info.inode_offset=device_offset;
33*6a54128fSAndroid Build Coastguard Worker
34*6a54128fSAndroid Build Coastguard Worker file_info.global_block_num=ptr->i_block [0];
35*6a54128fSAndroid Build Coastguard Worker file_info.global_block_offset=ptr->i_block [0]*file_system_info.block_size;
36*6a54128fSAndroid Build Coastguard Worker file_info.block_num=0;
37*6a54128fSAndroid Build Coastguard Worker file_info.blocks_count=(ptr->i_size+file_system_info.block_size-1)/file_system_info.block_size;
38*6a54128fSAndroid Build Coastguard Worker file_info.file_offset=0;
39*6a54128fSAndroid Build Coastguard Worker file_info.file_length=ptr->i_size;
40*6a54128fSAndroid Build Coastguard Worker file_info.level=0;
41*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block=0;
42*6a54128fSAndroid Build Coastguard Worker
43*6a54128fSAndroid Build Coastguard Worker file_info.display=HEX;
44*6a54128fSAndroid Build Coastguard Worker
45*6a54128fSAndroid Build Coastguard Worker low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
46*6a54128fSAndroid Build Coastguard Worker
47*6a54128fSAndroid Build Coastguard Worker return (1);
48*6a54128fSAndroid Build Coastguard Worker }
49*6a54128fSAndroid Build Coastguard Worker
50*6a54128fSAndroid Build Coastguard Worker
type_file___inode(char * command_line)51*6a54128fSAndroid Build Coastguard Worker void type_file___inode (char *command_line)
52*6a54128fSAndroid Build Coastguard Worker
53*6a54128fSAndroid Build Coastguard Worker {
54*6a54128fSAndroid Build Coastguard Worker dispatch ("settype ext2_inode");
55*6a54128fSAndroid Build Coastguard Worker }
56*6a54128fSAndroid Build Coastguard Worker
type_file___show(char * command_line)57*6a54128fSAndroid Build Coastguard Worker void type_file___show (char *command_line)
58*6a54128fSAndroid Build Coastguard Worker
59*6a54128fSAndroid Build Coastguard Worker {
60*6a54128fSAndroid Build Coastguard Worker if (file_info.display==HEX)
61*6a54128fSAndroid Build Coastguard Worker file_show_hex ();
62*6a54128fSAndroid Build Coastguard Worker if (file_info.display==TEXT)
63*6a54128fSAndroid Build Coastguard Worker file_show_text ();
64*6a54128fSAndroid Build Coastguard Worker }
65*6a54128fSAndroid Build Coastguard Worker
type_file___nextblock(char * command_line)66*6a54128fSAndroid Build Coastguard Worker void type_file___nextblock (char *command_line)
67*6a54128fSAndroid Build Coastguard Worker
68*6a54128fSAndroid Build Coastguard Worker {
69*6a54128fSAndroid Build Coastguard Worker long block_offset=1;
70*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
71*6a54128fSAndroid Build Coastguard Worker
72*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
73*6a54128fSAndroid Build Coastguard Worker
74*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
75*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
76*6a54128fSAndroid Build Coastguard Worker block_offset*=atol (buffer);
77*6a54128fSAndroid Build Coastguard Worker }
78*6a54128fSAndroid Build Coastguard Worker
79*6a54128fSAndroid Build Coastguard Worker if (file_info.block_num+block_offset >= file_info.blocks_count) {
80*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Block offset out of range\n");wrefresh (command_win);
81*6a54128fSAndroid Build Coastguard Worker return;
82*6a54128fSAndroid Build Coastguard Worker }
83*6a54128fSAndroid Build Coastguard Worker
84*6a54128fSAndroid Build Coastguard Worker file_info.block_num+=block_offset;
85*6a54128fSAndroid Build Coastguard Worker file_info.global_block_num=file_block_to_global_block (file_info.block_num,&file_info);
86*6a54128fSAndroid Build Coastguard Worker file_info.global_block_offset=file_info.global_block_num*file_system_info.block_size;
87*6a54128fSAndroid Build Coastguard Worker file_info.file_offset=file_info.block_num*file_system_info.block_size;
88*6a54128fSAndroid Build Coastguard Worker
89*6a54128fSAndroid Build Coastguard Worker low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
90*6a54128fSAndroid Build Coastguard Worker
91*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,"show");dispatch (buffer);
92*6a54128fSAndroid Build Coastguard Worker }
93*6a54128fSAndroid Build Coastguard Worker
type_file___next(char * command_line)94*6a54128fSAndroid Build Coastguard Worker void type_file___next (char *command_line)
95*6a54128fSAndroid Build Coastguard Worker
96*6a54128fSAndroid Build Coastguard Worker {
97*6a54128fSAndroid Build Coastguard Worker int offset=1;
98*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
99*6a54128fSAndroid Build Coastguard Worker
100*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
101*6a54128fSAndroid Build Coastguard Worker
102*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
103*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
104*6a54128fSAndroid Build Coastguard Worker offset*=atol (buffer);
105*6a54128fSAndroid Build Coastguard Worker }
106*6a54128fSAndroid Build Coastguard Worker
107*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block+offset < file_system_info.block_size) {
108*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block+=offset;
109*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"show");dispatch (buffer);
110*6a54128fSAndroid Build Coastguard Worker }
111*6a54128fSAndroid Build Coastguard Worker
112*6a54128fSAndroid Build Coastguard Worker else {
113*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
114*6a54128fSAndroid Build Coastguard Worker }
115*6a54128fSAndroid Build Coastguard Worker }
116*6a54128fSAndroid Build Coastguard Worker
type_file___offset(char * command_line)117*6a54128fSAndroid Build Coastguard Worker void type_file___offset (char *command_line)
118*6a54128fSAndroid Build Coastguard Worker
119*6a54128fSAndroid Build Coastguard Worker {
120*6a54128fSAndroid Build Coastguard Worker unsigned long offset;
121*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
122*6a54128fSAndroid Build Coastguard Worker
123*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
124*6a54128fSAndroid Build Coastguard Worker
125*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
126*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
127*6a54128fSAndroid Build Coastguard Worker offset=atol (buffer);
128*6a54128fSAndroid Build Coastguard Worker }
129*6a54128fSAndroid Build Coastguard Worker else {
130*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Argument not specified\n");refresh_command_win ();
131*6a54128fSAndroid Build Coastguard Worker return;
132*6a54128fSAndroid Build Coastguard Worker }
133*6a54128fSAndroid Build Coastguard Worker
134*6a54128fSAndroid Build Coastguard Worker if (offset < file_system_info.block_size) {
135*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block=offset;
136*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"show");dispatch (buffer);
137*6a54128fSAndroid Build Coastguard Worker }
138*6a54128fSAndroid Build Coastguard Worker
139*6a54128fSAndroid Build Coastguard Worker else {
140*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
141*6a54128fSAndroid Build Coastguard Worker }
142*6a54128fSAndroid Build Coastguard Worker }
143*6a54128fSAndroid Build Coastguard Worker
type_file___prev(char * command_line)144*6a54128fSAndroid Build Coastguard Worker void type_file___prev (char *command_line)
145*6a54128fSAndroid Build Coastguard Worker
146*6a54128fSAndroid Build Coastguard Worker {
147*6a54128fSAndroid Build Coastguard Worker int offset=1;
148*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
149*6a54128fSAndroid Build Coastguard Worker
150*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
151*6a54128fSAndroid Build Coastguard Worker
152*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
153*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
154*6a54128fSAndroid Build Coastguard Worker offset*=atol (buffer);
155*6a54128fSAndroid Build Coastguard Worker }
156*6a54128fSAndroid Build Coastguard Worker
157*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block-offset >= 0) {
158*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block-=offset;
159*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"show");dispatch (buffer);
160*6a54128fSAndroid Build Coastguard Worker }
161*6a54128fSAndroid Build Coastguard Worker
162*6a54128fSAndroid Build Coastguard Worker else {
163*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
164*6a54128fSAndroid Build Coastguard Worker }
165*6a54128fSAndroid Build Coastguard Worker }
166*6a54128fSAndroid Build Coastguard Worker
type_file___prevblock(char * command_line)167*6a54128fSAndroid Build Coastguard Worker void type_file___prevblock (char *command_line)
168*6a54128fSAndroid Build Coastguard Worker
169*6a54128fSAndroid Build Coastguard Worker {
170*6a54128fSAndroid Build Coastguard Worker long block_offset=1;
171*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
172*6a54128fSAndroid Build Coastguard Worker
173*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
174*6a54128fSAndroid Build Coastguard Worker
175*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
176*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
177*6a54128fSAndroid Build Coastguard Worker block_offset*=atol (buffer);
178*6a54128fSAndroid Build Coastguard Worker }
179*6a54128fSAndroid Build Coastguard Worker
180*6a54128fSAndroid Build Coastguard Worker if (file_info.block_num-block_offset < 0) {
181*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Block offset out of range\n");wrefresh (command_win);
182*6a54128fSAndroid Build Coastguard Worker return;
183*6a54128fSAndroid Build Coastguard Worker }
184*6a54128fSAndroid Build Coastguard Worker
185*6a54128fSAndroid Build Coastguard Worker file_info.block_num-=block_offset;
186*6a54128fSAndroid Build Coastguard Worker file_info.global_block_num=file_block_to_global_block (file_info.block_num,&file_info);
187*6a54128fSAndroid Build Coastguard Worker file_info.global_block_offset=file_info.global_block_num*file_system_info.block_size;
188*6a54128fSAndroid Build Coastguard Worker file_info.file_offset=file_info.block_num*file_system_info.block_size;
189*6a54128fSAndroid Build Coastguard Worker
190*6a54128fSAndroid Build Coastguard Worker low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
191*6a54128fSAndroid Build Coastguard Worker
192*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,"show");dispatch (buffer);
193*6a54128fSAndroid Build Coastguard Worker }
194*6a54128fSAndroid Build Coastguard Worker
type_file___block(char * command_line)195*6a54128fSAndroid Build Coastguard Worker void type_file___block (char *command_line)
196*6a54128fSAndroid Build Coastguard Worker
197*6a54128fSAndroid Build Coastguard Worker {
198*6a54128fSAndroid Build Coastguard Worker long block_offset=1;
199*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
200*6a54128fSAndroid Build Coastguard Worker
201*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
202*6a54128fSAndroid Build Coastguard Worker
203*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
204*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Invalid arguments\n");wrefresh (command_win);
205*6a54128fSAndroid Build Coastguard Worker return;
206*6a54128fSAndroid Build Coastguard Worker }
207*6a54128fSAndroid Build Coastguard Worker
208*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
209*6a54128fSAndroid Build Coastguard Worker block_offset=atol (buffer);
210*6a54128fSAndroid Build Coastguard Worker
211*6a54128fSAndroid Build Coastguard Worker if (block_offset < 0 || block_offset >= file_info.blocks_count) {
212*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Block offset out of range\n");wrefresh (command_win);
213*6a54128fSAndroid Build Coastguard Worker return;
214*6a54128fSAndroid Build Coastguard Worker }
215*6a54128fSAndroid Build Coastguard Worker
216*6a54128fSAndroid Build Coastguard Worker file_info.block_num=block_offset;
217*6a54128fSAndroid Build Coastguard Worker file_info.global_block_num=file_block_to_global_block (file_info.block_num,&file_info);
218*6a54128fSAndroid Build Coastguard Worker file_info.global_block_offset=file_info.global_block_num*file_system_info.block_size;
219*6a54128fSAndroid Build Coastguard Worker file_info.file_offset=file_info.block_num*file_system_info.block_size;
220*6a54128fSAndroid Build Coastguard Worker
221*6a54128fSAndroid Build Coastguard Worker low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
222*6a54128fSAndroid Build Coastguard Worker
223*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,"show");dispatch (buffer);
224*6a54128fSAndroid Build Coastguard Worker }
225*6a54128fSAndroid Build Coastguard Worker
type_file___display(char * command_line)226*6a54128fSAndroid Build Coastguard Worker void type_file___display (char *command_line)
227*6a54128fSAndroid Build Coastguard Worker
228*6a54128fSAndroid Build Coastguard Worker {
229*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
230*6a54128fSAndroid Build Coastguard Worker
231*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
232*6a54128fSAndroid Build Coastguard Worker if (*ptr==0)
233*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,"hex");
234*6a54128fSAndroid Build Coastguard Worker else
235*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
236*6a54128fSAndroid Build Coastguard Worker
237*6a54128fSAndroid Build Coastguard Worker if (strcasecmp (buffer,"hex")==0) {
238*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Display set to hex\n");wrefresh (command_win);
239*6a54128fSAndroid Build Coastguard Worker file_info.display=HEX;
240*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"show");dispatch (buffer);
241*6a54128fSAndroid Build Coastguard Worker }
242*6a54128fSAndroid Build Coastguard Worker
243*6a54128fSAndroid Build Coastguard Worker else if (strcasecmp (buffer,"text")==0) {
244*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Display set to text\n");wrefresh (command_win);
245*6a54128fSAndroid Build Coastguard Worker file_info.display=TEXT;
246*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"show");dispatch (buffer);
247*6a54128fSAndroid Build Coastguard Worker }
248*6a54128fSAndroid Build Coastguard Worker
249*6a54128fSAndroid Build Coastguard Worker else {
250*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Invalid arguments\n");wrefresh (command_win);
251*6a54128fSAndroid Build Coastguard Worker }
252*6a54128fSAndroid Build Coastguard Worker }
253*6a54128fSAndroid Build Coastguard Worker
file_show_hex(void)254*6a54128fSAndroid Build Coastguard Worker void file_show_hex (void)
255*6a54128fSAndroid Build Coastguard Worker
256*6a54128fSAndroid Build Coastguard Worker {
257*6a54128fSAndroid Build Coastguard Worker long offset=0,l,i;
258*6a54128fSAndroid Build Coastguard Worker unsigned char *ch_ptr;
259*6a54128fSAndroid Build Coastguard Worker
260*6a54128fSAndroid Build Coastguard Worker /* device_offset and type_data points to the inode */
261*6a54128fSAndroid Build Coastguard Worker
262*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=0;
263*6a54128fSAndroid Build Coastguard Worker
264*6a54128fSAndroid Build Coastguard Worker wmove (show_pad,0,0);
265*6a54128fSAndroid Build Coastguard Worker ch_ptr=file_info.buffer;
266*6a54128fSAndroid Build Coastguard Worker for (l=0;l<file_system_info.block_size/16;l++) {
267*6a54128fSAndroid Build Coastguard Worker if (file_info.file_offset+offset>file_info.file_length-1) break;
268*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"%08ld : ",offset);
269*6a54128fSAndroid Build Coastguard Worker for (i=0;i<16;i++) {
270*6a54128fSAndroid Build Coastguard Worker
271*6a54128fSAndroid Build Coastguard Worker if (file_info.file_offset+offset+i>file_info.file_length-1) {
272*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad," ");
273*6a54128fSAndroid Build Coastguard Worker }
274*6a54128fSAndroid Build Coastguard Worker
275*6a54128fSAndroid Build Coastguard Worker else {
276*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset+i)
277*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_REVERSE);
278*6a54128fSAndroid Build Coastguard Worker
279*6a54128fSAndroid Build Coastguard Worker if (ch_ptr [i]>=' ' && ch_ptr [i]<='z')
280*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"%c",ch_ptr [i]);
281*6a54128fSAndroid Build Coastguard Worker else
282*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,".");
283*6a54128fSAndroid Build Coastguard Worker
284*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset+i)
285*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_NORMAL);
286*6a54128fSAndroid Build Coastguard Worker }
287*6a54128fSAndroid Build Coastguard Worker }
288*6a54128fSAndroid Build Coastguard Worker
289*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad," ");
290*6a54128fSAndroid Build Coastguard Worker for (i=0;i<16;i++) {
291*6a54128fSAndroid Build Coastguard Worker if (file_info.file_offset+offset+i>file_info.file_length-1) break;
292*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset+i)
293*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_REVERSE);
294*6a54128fSAndroid Build Coastguard Worker
295*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"%02x",ch_ptr [i]);
296*6a54128fSAndroid Build Coastguard Worker
297*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset+i) {
298*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_NORMAL);
299*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=l-l % show_pad_info.display_lines;
300*6a54128fSAndroid Build Coastguard Worker }
301*6a54128fSAndroid Build Coastguard Worker
302*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad," ");
303*6a54128fSAndroid Build Coastguard Worker
304*6a54128fSAndroid Build Coastguard Worker }
305*6a54128fSAndroid Build Coastguard Worker
306*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"\n");
307*6a54128fSAndroid Build Coastguard Worker offset+=i;
308*6a54128fSAndroid Build Coastguard Worker ch_ptr+=i;
309*6a54128fSAndroid Build Coastguard Worker }
310*6a54128fSAndroid Build Coastguard Worker
311*6a54128fSAndroid Build Coastguard Worker show_pad_info.max_line=l-1;
312*6a54128fSAndroid Build Coastguard Worker
313*6a54128fSAndroid Build Coastguard Worker refresh_show_pad ();
314*6a54128fSAndroid Build Coastguard Worker
315*6a54128fSAndroid Build Coastguard Worker show_status ();
316*6a54128fSAndroid Build Coastguard Worker }
317*6a54128fSAndroid Build Coastguard Worker
file_show_text(void)318*6a54128fSAndroid Build Coastguard Worker void file_show_text (void)
319*6a54128fSAndroid Build Coastguard Worker
320*6a54128fSAndroid Build Coastguard Worker {
321*6a54128fSAndroid Build Coastguard Worker long offset=0,last_offset,l=0,cols=0;
322*6a54128fSAndroid Build Coastguard Worker unsigned char *ch_ptr;
323*6a54128fSAndroid Build Coastguard Worker
324*6a54128fSAndroid Build Coastguard Worker /* device_offset and type_data points to the inode */
325*6a54128fSAndroid Build Coastguard Worker
326*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=0;
327*6a54128fSAndroid Build Coastguard Worker wmove (show_pad,0,0);
328*6a54128fSAndroid Build Coastguard Worker ch_ptr=file_info.buffer;
329*6a54128fSAndroid Build Coastguard Worker
330*6a54128fSAndroid Build Coastguard Worker last_offset=file_system_info.block_size-1;
331*6a54128fSAndroid Build Coastguard Worker
332*6a54128fSAndroid Build Coastguard Worker if (file_info.file_offset+last_offset > file_info.file_length-1)
333*6a54128fSAndroid Build Coastguard Worker last_offset=file_info.file_length-1-file_info.file_offset;
334*6a54128fSAndroid Build Coastguard Worker
335*6a54128fSAndroid Build Coastguard Worker while ( (offset <= last_offset) && l<SHOW_PAD_LINES) {
336*6a54128fSAndroid Build Coastguard Worker
337*6a54128fSAndroid Build Coastguard Worker if (cols==SHOW_PAD_COLS-1) {
338*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"\n");
339*6a54128fSAndroid Build Coastguard Worker l++;cols=0;
340*6a54128fSAndroid Build Coastguard Worker }
341*6a54128fSAndroid Build Coastguard Worker
342*6a54128fSAndroid Build Coastguard Worker
343*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset)
344*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_REVERSE);
345*6a54128fSAndroid Build Coastguard Worker
346*6a54128fSAndroid Build Coastguard Worker if (*ch_ptr >= ' ' && *ch_ptr <= 'z')
347*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"%c",*ch_ptr);
348*6a54128fSAndroid Build Coastguard Worker
349*6a54128fSAndroid Build Coastguard Worker
350*6a54128fSAndroid Build Coastguard Worker else {
351*6a54128fSAndroid Build Coastguard Worker if (*ch_ptr == 0xa) {
352*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"\n");
353*6a54128fSAndroid Build Coastguard Worker l++;cols=0;
354*6a54128fSAndroid Build Coastguard Worker }
355*6a54128fSAndroid Build Coastguard Worker
356*6a54128fSAndroid Build Coastguard Worker else if (*ch_ptr == 0x9)
357*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad," ");
358*6a54128fSAndroid Build Coastguard Worker
359*6a54128fSAndroid Build Coastguard Worker else
360*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,".");
361*6a54128fSAndroid Build Coastguard Worker }
362*6a54128fSAndroid Build Coastguard Worker
363*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==offset) {
364*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_NORMAL);
365*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=l-l % show_pad_info.display_lines;
366*6a54128fSAndroid Build Coastguard Worker }
367*6a54128fSAndroid Build Coastguard Worker
368*6a54128fSAndroid Build Coastguard Worker
369*6a54128fSAndroid Build Coastguard Worker offset++;cols++;ch_ptr++;
370*6a54128fSAndroid Build Coastguard Worker }
371*6a54128fSAndroid Build Coastguard Worker
372*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"\n");
373*6a54128fSAndroid Build Coastguard Worker show_pad_info.max_line=l;
374*6a54128fSAndroid Build Coastguard Worker
375*6a54128fSAndroid Build Coastguard Worker refresh_show_pad ();
376*6a54128fSAndroid Build Coastguard Worker
377*6a54128fSAndroid Build Coastguard Worker show_status ();
378*6a54128fSAndroid Build Coastguard Worker }
379*6a54128fSAndroid Build Coastguard Worker
show_status(void)380*6a54128fSAndroid Build Coastguard Worker void show_status (void)
381*6a54128fSAndroid Build Coastguard Worker
382*6a54128fSAndroid Build Coastguard Worker {
383*6a54128fSAndroid Build Coastguard Worker long inode_num;
384*6a54128fSAndroid Build Coastguard Worker
385*6a54128fSAndroid Build Coastguard Worker werase (show_win);wmove (show_win,0,0);
386*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"File contents. Block %ld. ",file_info.global_block_num);
387*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"File block %ld of %ld. ",file_info.block_num,file_info.blocks_count-1);
388*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"File Offset %ld of %ld.",file_info.file_offset,file_info.file_length-1);
389*6a54128fSAndroid Build Coastguard Worker
390*6a54128fSAndroid Build Coastguard Worker wmove (show_win,1,0);
391*6a54128fSAndroid Build Coastguard Worker inode_num=inode_offset_to_inode_num (file_info.inode_offset);
392*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"File inode %ld. Indirection level %ld.",inode_num,file_info.level);
393*6a54128fSAndroid Build Coastguard Worker
394*6a54128fSAndroid Build Coastguard Worker refresh_show_win ();
395*6a54128fSAndroid Build Coastguard Worker }
396*6a54128fSAndroid Build Coastguard Worker
type_file___remember(char * command_line)397*6a54128fSAndroid Build Coastguard Worker void type_file___remember (char *command_line)
398*6a54128fSAndroid Build Coastguard Worker
399*6a54128fSAndroid Build Coastguard Worker {
400*6a54128fSAndroid Build Coastguard Worker int found=0;
401*6a54128fSAndroid Build Coastguard Worker long entry_num;
402*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
403*6a54128fSAndroid Build Coastguard Worker struct struct_descriptor *descriptor_ptr;
404*6a54128fSAndroid Build Coastguard Worker
405*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
406*6a54128fSAndroid Build Coastguard Worker
407*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
408*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Argument not specified\n");wrefresh (command_win);
409*6a54128fSAndroid Build Coastguard Worker return;
410*6a54128fSAndroid Build Coastguard Worker }
411*6a54128fSAndroid Build Coastguard Worker
412*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
413*6a54128fSAndroid Build Coastguard Worker
414*6a54128fSAndroid Build Coastguard Worker entry_num=remember_lifo.entries_count++;
415*6a54128fSAndroid Build Coastguard Worker if (entry_num>REMEMBER_COUNT-1) {
416*6a54128fSAndroid Build Coastguard Worker entry_num=0;
417*6a54128fSAndroid Build Coastguard Worker remember_lifo.entries_count--;
418*6a54128fSAndroid Build Coastguard Worker }
419*6a54128fSAndroid Build Coastguard Worker
420*6a54128fSAndroid Build Coastguard Worker descriptor_ptr=first_type;
421*6a54128fSAndroid Build Coastguard Worker while (descriptor_ptr!=NULL && !found) {
422*6a54128fSAndroid Build Coastguard Worker if (strcmp (descriptor_ptr->name,"ext2_inode")==0)
423*6a54128fSAndroid Build Coastguard Worker found=1;
424*6a54128fSAndroid Build Coastguard Worker else
425*6a54128fSAndroid Build Coastguard Worker descriptor_ptr=descriptor_ptr->next;
426*6a54128fSAndroid Build Coastguard Worker }
427*6a54128fSAndroid Build Coastguard Worker
428*6a54128fSAndroid Build Coastguard Worker
429*6a54128fSAndroid Build Coastguard Worker remember_lifo.offset [entry_num]=device_offset;
430*6a54128fSAndroid Build Coastguard Worker remember_lifo.type [entry_num]=descriptor_ptr;
431*6a54128fSAndroid Build Coastguard Worker strcpy (remember_lifo.name [entry_num],buffer);
432*6a54128fSAndroid Build Coastguard Worker
433*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Object %s in Offset %ld remembered as %s\n",descriptor_ptr->name,device_offset,buffer);
434*6a54128fSAndroid Build Coastguard Worker wrefresh (command_win);
435*6a54128fSAndroid Build Coastguard Worker }
436*6a54128fSAndroid Build Coastguard Worker
type_file___set(char * command_line)437*6a54128fSAndroid Build Coastguard Worker void type_file___set (char *command_line)
438*6a54128fSAndroid Build Coastguard Worker
439*6a54128fSAndroid Build Coastguard Worker {
440*6a54128fSAndroid Build Coastguard Worker unsigned char tmp;
441*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80],*ch_ptr;
442*6a54128fSAndroid Build Coastguard Worker int mode=HEX;
443*6a54128fSAndroid Build Coastguard Worker
444*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
445*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
446*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Argument not specified\n");refresh_command_win ();return;
447*6a54128fSAndroid Build Coastguard Worker }
448*6a54128fSAndroid Build Coastguard Worker
449*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
450*6a54128fSAndroid Build Coastguard Worker
451*6a54128fSAndroid Build Coastguard Worker if (strcasecmp (buffer,"text")==0) {
452*6a54128fSAndroid Build Coastguard Worker mode=TEXT;
453*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,ptr);
454*6a54128fSAndroid Build Coastguard Worker }
455*6a54128fSAndroid Build Coastguard Worker
456*6a54128fSAndroid Build Coastguard Worker else if (strcasecmp (buffer,"hex")==0) {
457*6a54128fSAndroid Build Coastguard Worker mode=HEX;
458*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
459*6a54128fSAndroid Build Coastguard Worker }
460*6a54128fSAndroid Build Coastguard Worker
461*6a54128fSAndroid Build Coastguard Worker if (*buffer==0) {
462*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Data not specified\n");refresh_command_win ();return;
463*6a54128fSAndroid Build Coastguard Worker }
464*6a54128fSAndroid Build Coastguard Worker
465*6a54128fSAndroid Build Coastguard Worker if (mode==HEX) {
466*6a54128fSAndroid Build Coastguard Worker do {
467*6a54128fSAndroid Build Coastguard Worker tmp=(unsigned char) strtol (buffer,NULL,16);
468*6a54128fSAndroid Build Coastguard Worker file_info.buffer [file_info.offset_in_block]=tmp;
469*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block++;
470*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
471*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==file_system_info.block_size) {
472*6a54128fSAndroid Build Coastguard Worker if (*ptr) {
473*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Ending offset outside block, only partial string changed\n");
474*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
475*6a54128fSAndroid Build Coastguard Worker }
476*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block--;
477*6a54128fSAndroid Build Coastguard Worker }
478*6a54128fSAndroid Build Coastguard Worker } while (*buffer) ;
479*6a54128fSAndroid Build Coastguard Worker }
480*6a54128fSAndroid Build Coastguard Worker
481*6a54128fSAndroid Build Coastguard Worker else {
482*6a54128fSAndroid Build Coastguard Worker ch_ptr=buffer;
483*6a54128fSAndroid Build Coastguard Worker while (*ch_ptr) {
484*6a54128fSAndroid Build Coastguard Worker tmp=(unsigned char) *ch_ptr++;
485*6a54128fSAndroid Build Coastguard Worker file_info.buffer [file_info.offset_in_block]=tmp;
486*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block++;
487*6a54128fSAndroid Build Coastguard Worker if (file_info.offset_in_block==file_system_info.block_size) {
488*6a54128fSAndroid Build Coastguard Worker if (*ch_ptr) {
489*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Ending offset outside block, only partial string changed\n");
490*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
491*6a54128fSAndroid Build Coastguard Worker }
492*6a54128fSAndroid Build Coastguard Worker file_info.offset_in_block--;
493*6a54128fSAndroid Build Coastguard Worker }
494*6a54128fSAndroid Build Coastguard Worker }
495*6a54128fSAndroid Build Coastguard Worker }
496*6a54128fSAndroid Build Coastguard Worker
497*6a54128fSAndroid Build Coastguard Worker strcpy (buffer,"show");dispatch (buffer);
498*6a54128fSAndroid Build Coastguard Worker }
499*6a54128fSAndroid Build Coastguard Worker
type_file___writedata(char * command_line)500*6a54128fSAndroid Build Coastguard Worker void type_file___writedata (char *command_line)
501*6a54128fSAndroid Build Coastguard Worker
502*6a54128fSAndroid Build Coastguard Worker {
503*6a54128fSAndroid Build Coastguard Worker low_write (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
504*6a54128fSAndroid Build Coastguard Worker return;
505*6a54128fSAndroid Build Coastguard Worker }
506*6a54128fSAndroid Build Coastguard Worker
file_block_to_global_block(long file_block,struct struct_file_info * file_info_ptr)507*6a54128fSAndroid Build Coastguard Worker long file_block_to_global_block (long file_block,struct struct_file_info *file_info_ptr)
508*6a54128fSAndroid Build Coastguard Worker
509*6a54128fSAndroid Build Coastguard Worker {
510*6a54128fSAndroid Build Coastguard Worker long last_direct,last_indirect,last_dindirect;
511*6a54128fSAndroid Build Coastguard Worker
512*6a54128fSAndroid Build Coastguard Worker last_direct=EXT2_NDIR_BLOCKS-1;
513*6a54128fSAndroid Build Coastguard Worker last_indirect=last_direct+file_system_info.block_size/4;
514*6a54128fSAndroid Build Coastguard Worker last_dindirect=last_indirect+(file_system_info.block_size/4)*(file_system_info.block_size/4);
515*6a54128fSAndroid Build Coastguard Worker
516*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_direct) {
517*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=0;
518*6a54128fSAndroid Build Coastguard Worker return (file_info_ptr->inode_ptr->i_block [file_block]);
519*6a54128fSAndroid Build Coastguard Worker }
520*6a54128fSAndroid Build Coastguard Worker
521*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_indirect) {
522*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=1;
523*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_direct-1;
524*6a54128fSAndroid Build Coastguard Worker return (return_indirect (file_info_ptr->inode_ptr->i_block [EXT2_IND_BLOCK],file_block));
525*6a54128fSAndroid Build Coastguard Worker }
526*6a54128fSAndroid Build Coastguard Worker
527*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_dindirect) {
528*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=2;
529*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_indirect-1;
530*6a54128fSAndroid Build Coastguard Worker return (return_dindirect (file_info_ptr->inode_ptr->i_block [EXT2_DIND_BLOCK],file_block));
531*6a54128fSAndroid Build Coastguard Worker }
532*6a54128fSAndroid Build Coastguard Worker
533*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=3;
534*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_dindirect-1;
535*6a54128fSAndroid Build Coastguard Worker return (return_tindirect (file_info_ptr->inode_ptr->i_block [EXT2_TIND_BLOCK],file_block));
536*6a54128fSAndroid Build Coastguard Worker }
537*6a54128fSAndroid Build Coastguard Worker
return_indirect(long table_block,long block_num)538*6a54128fSAndroid Build Coastguard Worker long return_indirect (long table_block,long block_num)
539*6a54128fSAndroid Build Coastguard Worker
540*6a54128fSAndroid Build Coastguard Worker {
541*6a54128fSAndroid Build Coastguard Worker long block_table [EXT2_MAX_BLOCK_SIZE/4];
542*6a54128fSAndroid Build Coastguard Worker
543*6a54128fSAndroid Build Coastguard Worker low_read ((char *) block_table,file_system_info.block_size,table_block*file_system_info.block_size);
544*6a54128fSAndroid Build Coastguard Worker return (block_table [block_num]);
545*6a54128fSAndroid Build Coastguard Worker }
546*6a54128fSAndroid Build Coastguard Worker
return_dindirect(long table_block,long block_num)547*6a54128fSAndroid Build Coastguard Worker long return_dindirect (long table_block,long block_num)
548*6a54128fSAndroid Build Coastguard Worker
549*6a54128fSAndroid Build Coastguard Worker {
550*6a54128fSAndroid Build Coastguard Worker long f_indirect;
551*6a54128fSAndroid Build Coastguard Worker
552*6a54128fSAndroid Build Coastguard Worker f_indirect=block_num/(file_system_info.block_size/4);
553*6a54128fSAndroid Build Coastguard Worker f_indirect=return_indirect (table_block,f_indirect);
554*6a54128fSAndroid Build Coastguard Worker return (return_indirect (f_indirect,block_num%(file_system_info.block_size/4)));
555*6a54128fSAndroid Build Coastguard Worker }
556*6a54128fSAndroid Build Coastguard Worker
return_tindirect(long table_block,long block_num)557*6a54128fSAndroid Build Coastguard Worker long return_tindirect (long table_block,long block_num)
558*6a54128fSAndroid Build Coastguard Worker
559*6a54128fSAndroid Build Coastguard Worker {
560*6a54128fSAndroid Build Coastguard Worker long s_indirect;
561*6a54128fSAndroid Build Coastguard Worker
562*6a54128fSAndroid Build Coastguard Worker s_indirect=block_num/((file_system_info.block_size/4)*(file_system_info.block_size/4));
563*6a54128fSAndroid Build Coastguard Worker s_indirect=return_indirect (table_block,s_indirect);
564*6a54128fSAndroid Build Coastguard Worker return (return_dindirect (s_indirect,block_num%((file_system_info.block_size/4)*(file_system_info.block_size/4))));
565*6a54128fSAndroid Build Coastguard Worker }
566