1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker
3*6a54128fSAndroid Build Coastguard Worker /usr/src/ext2ed/dir_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 Handles directories.
9*6a54128fSAndroid Build Coastguard Worker --------------------
10*6a54128fSAndroid Build Coastguard Worker
11*6a54128fSAndroid Build Coastguard Worker This file contains the codes which allows the user to handle directories.
12*6a54128fSAndroid Build Coastguard Worker
13*6a54128fSAndroid Build Coastguard Worker Most of the functions use the global variable file_info (along with the special directory fields there) to save
14*6a54128fSAndroid Build Coastguard Worker information and pass it between them.
15*6a54128fSAndroid Build Coastguard Worker
16*6a54128fSAndroid Build Coastguard Worker Since a directory is just a big file which is composed of directory entries, you will find that
17*6a54128fSAndroid Build Coastguard Worker the functions here are a superset of those in the file_com.c source.
18*6a54128fSAndroid Build Coastguard Worker
19*6a54128fSAndroid Build Coastguard Worker We assume that the user reached here using the dir command of the inode type and not by using settype dir, so
20*6a54128fSAndroid Build Coastguard Worker that init_dir_info is indeed called to gather the required information.
21*6a54128fSAndroid Build Coastguard Worker
22*6a54128fSAndroid Build Coastguard Worker type_data is not changed! It still contains the inode of the file - We handle the directory in our own
23*6a54128fSAndroid Build Coastguard Worker variables, so that settype ext2_inode will "go back" to the inode of this directory.
24*6a54128fSAndroid Build Coastguard Worker
25*6a54128fSAndroid Build Coastguard Worker First written on: April 28 1995
26*6a54128fSAndroid Build Coastguard Worker
27*6a54128fSAndroid Build Coastguard Worker Copyright (C) 1995 Gadi Oxman
28*6a54128fSAndroid Build Coastguard Worker
29*6a54128fSAndroid Build Coastguard Worker */
30*6a54128fSAndroid Build Coastguard Worker
31*6a54128fSAndroid Build Coastguard Worker #include "config.h"
32*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
33*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
34*6a54128fSAndroid Build Coastguard Worker #include <string.h>
35*6a54128fSAndroid Build Coastguard Worker
36*6a54128fSAndroid Build Coastguard Worker #include "ext2ed.h"
37*6a54128fSAndroid Build Coastguard Worker
38*6a54128fSAndroid Build Coastguard Worker char name_search [80];
39*6a54128fSAndroid Build Coastguard Worker long entry_num_search;
40*6a54128fSAndroid Build Coastguard Worker
init_dir_info(struct struct_file_info * info_ptr)41*6a54128fSAndroid Build Coastguard Worker int init_dir_info (struct struct_file_info *info_ptr)
42*6a54128fSAndroid Build Coastguard Worker
43*6a54128fSAndroid Build Coastguard Worker /*
44*6a54128fSAndroid Build Coastguard Worker
45*6a54128fSAndroid Build Coastguard Worker This function is called by the inode of the directory when the user issues the dir command from the inode.
46*6a54128fSAndroid Build Coastguard Worker It is used to gather information about the inode and to reset some variables which we need in order to handle
47*6a54128fSAndroid Build Coastguard Worker directories.
48*6a54128fSAndroid Build Coastguard Worker
49*6a54128fSAndroid Build Coastguard Worker */
50*6a54128fSAndroid Build Coastguard Worker
51*6a54128fSAndroid Build Coastguard Worker {
52*6a54128fSAndroid Build Coastguard Worker struct ext2_inode *ptr;
53*6a54128fSAndroid Build Coastguard Worker
54*6a54128fSAndroid Build Coastguard Worker ptr=&type_data.u.t_ext2_inode; /* type_data contains the inode */
55*6a54128fSAndroid Build Coastguard Worker
56*6a54128fSAndroid Build Coastguard Worker info_ptr->inode_ptr=ptr;
57*6a54128fSAndroid Build Coastguard Worker info_ptr->inode_offset=device_offset; /* device offset contains the inode's offset */
58*6a54128fSAndroid Build Coastguard Worker
59*6a54128fSAndroid Build Coastguard Worker /* Reset the current position to the start */
60*6a54128fSAndroid Build Coastguard Worker
61*6a54128fSAndroid Build Coastguard Worker info_ptr->global_block_num=ptr->i_block [0];
62*6a54128fSAndroid Build Coastguard Worker info_ptr->global_block_offset=ptr->i_block [0]*file_system_info.block_size;
63*6a54128fSAndroid Build Coastguard Worker info_ptr->block_num=0;
64*6a54128fSAndroid Build Coastguard Worker info_ptr->file_offset=0;
65*6a54128fSAndroid Build Coastguard Worker /* Set the size of the directory */
66*6a54128fSAndroid Build Coastguard Worker
67*6a54128fSAndroid Build Coastguard Worker info_ptr->blocks_count=(ptr->i_size+file_system_info.block_size-1)/file_system_info.block_size;
68*6a54128fSAndroid Build Coastguard Worker info_ptr->file_length=ptr->i_size;
69*6a54128fSAndroid Build Coastguard Worker
70*6a54128fSAndroid Build Coastguard Worker info_ptr->level=0; /* We start using direct blocks */
71*6a54128fSAndroid Build Coastguard Worker info_ptr->display=HEX; /* This is not actually used */
72*6a54128fSAndroid Build Coastguard Worker
73*6a54128fSAndroid Build Coastguard Worker info_ptr->dir_entry_num=0;info_ptr->dir_entries_count=0; /* We'll start at the first directory entry */
74*6a54128fSAndroid Build Coastguard Worker info_ptr->dir_entry_offset=0;
75*6a54128fSAndroid Build Coastguard Worker
76*6a54128fSAndroid Build Coastguard Worker /* Find dir_entries_count */
77*6a54128fSAndroid Build Coastguard Worker
78*6a54128fSAndroid Build Coastguard Worker info_ptr->dir_entries_count=count_dir_entries (); /* Set the total number of entries */
79*6a54128fSAndroid Build Coastguard Worker
80*6a54128fSAndroid Build Coastguard Worker return (1);
81*6a54128fSAndroid Build Coastguard Worker }
82*6a54128fSAndroid Build Coastguard Worker
search_dir_entries(int (* action)(struct struct_file_info * info),int * status)83*6a54128fSAndroid Build Coastguard Worker struct struct_file_info search_dir_entries (int (*action) (struct struct_file_info *info),int *status)
84*6a54128fSAndroid Build Coastguard Worker
85*6a54128fSAndroid Build Coastguard Worker /*
86*6a54128fSAndroid Build Coastguard Worker This is the main function in this source file. Various actions are implemented using this basic function.
87*6a54128fSAndroid Build Coastguard Worker
88*6a54128fSAndroid Build Coastguard Worker This routine runs on all directory entries in the current directory.
89*6a54128fSAndroid Build Coastguard Worker For each entry, action is called. We'll act according to the return code of action:
90*6a54128fSAndroid Build Coastguard Worker
91*6a54128fSAndroid Build Coastguard Worker ABORT - Current dir entry is returned.
92*6a54128fSAndroid Build Coastguard Worker CONTINUE - Continue searching.
93*6a54128fSAndroid Build Coastguard Worker FOUND - Current dir entry is returned.
94*6a54128fSAndroid Build Coastguard Worker
95*6a54128fSAndroid Build Coastguard Worker If the last entry is reached, it is returned, along with an ABORT status.
96*6a54128fSAndroid Build Coastguard Worker
97*6a54128fSAndroid Build Coastguard Worker status is updated to the returned code of action.
98*6a54128fSAndroid Build Coastguard Worker */
99*6a54128fSAndroid Build Coastguard Worker
100*6a54128fSAndroid Build Coastguard Worker {
101*6a54128fSAndroid Build Coastguard Worker struct struct_file_info info; /* Temporary variables used to */
102*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr; /* contain the current search entries */
103*6a54128fSAndroid Build Coastguard Worker int return_code, next;
104*6a54128fSAndroid Build Coastguard Worker
105*6a54128fSAndroid Build Coastguard Worker info=first_file_info; /* Start from the first entry - Read it */
106*6a54128fSAndroid Build Coastguard Worker low_read (info.buffer,file_system_info.block_size,info.global_block_offset);
107*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
108*6a54128fSAndroid Build Coastguard Worker
109*6a54128fSAndroid Build Coastguard Worker while (info.file_offset < info.file_length) { /* While we haven't reached the end */
110*6a54128fSAndroid Build Coastguard Worker
111*6a54128fSAndroid Build Coastguard Worker *status=return_code=action (&info); /* Call the client function to test */
112*6a54128fSAndroid Build Coastguard Worker /* the current entry */
113*6a54128fSAndroid Build Coastguard Worker if (return_code==ABORT || return_code==FOUND)
114*6a54128fSAndroid Build Coastguard Worker return (info); /* Stop, if so asked */
115*6a54128fSAndroid Build Coastguard Worker
116*6a54128fSAndroid Build Coastguard Worker /* Pass to the next entry */
117*6a54128fSAndroid Build Coastguard Worker
118*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
119*6a54128fSAndroid Build Coastguard Worker
120*6a54128fSAndroid Build Coastguard Worker info.dir_entry_num++;
121*6a54128fSAndroid Build Coastguard Worker next = dir_entry_ptr->rec_len;
122*6a54128fSAndroid Build Coastguard Worker if (!next)
123*6a54128fSAndroid Build Coastguard Worker next = file_system_info.block_size - info.dir_entry_offset;
124*6a54128fSAndroid Build Coastguard Worker info.dir_entry_offset += next;
125*6a54128fSAndroid Build Coastguard Worker info.file_offset += next;
126*6a54128fSAndroid Build Coastguard Worker
127*6a54128fSAndroid Build Coastguard Worker if (info.file_offset >= info.file_length) break;
128*6a54128fSAndroid Build Coastguard Worker
129*6a54128fSAndroid Build Coastguard Worker if (info.dir_entry_offset >= file_system_info.block_size) { /* We crossed a block boundary */
130*6a54128fSAndroid Build Coastguard Worker /* Find the next block, */
131*6a54128fSAndroid Build Coastguard Worker info.block_num++;
132*6a54128fSAndroid Build Coastguard Worker info.global_block_num=file_block_to_global_block (info.block_num,&info);
133*6a54128fSAndroid Build Coastguard Worker info.global_block_offset=info.global_block_num*file_system_info.block_size;
134*6a54128fSAndroid Build Coastguard Worker info.file_offset=info.block_num*file_system_info.block_size;
135*6a54128fSAndroid Build Coastguard Worker info.dir_entry_offset=0;
136*6a54128fSAndroid Build Coastguard Worker /* read it and update the pointer */
137*6a54128fSAndroid Build Coastguard Worker
138*6a54128fSAndroid Build Coastguard Worker low_read (info.buffer,file_system_info.block_size,info.global_block_offset);
139*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (info.buffer+info.dir_entry_offset);
140*6a54128fSAndroid Build Coastguard Worker
141*6a54128fSAndroid Build Coastguard Worker }
142*6a54128fSAndroid Build Coastguard Worker
143*6a54128fSAndroid Build Coastguard Worker }
144*6a54128fSAndroid Build Coastguard Worker
145*6a54128fSAndroid Build Coastguard Worker *status=ABORT;return (info); /* There was no match */
146*6a54128fSAndroid Build Coastguard Worker }
147*6a54128fSAndroid Build Coastguard Worker
count_dir_entries(void)148*6a54128fSAndroid Build Coastguard Worker long count_dir_entries (void)
149*6a54128fSAndroid Build Coastguard Worker
150*6a54128fSAndroid Build Coastguard Worker /*
151*6a54128fSAndroid Build Coastguard Worker
152*6a54128fSAndroid Build Coastguard Worker This function counts the number of entries in the directory. We just call search_dir_entries till the end.
153*6a54128fSAndroid Build Coastguard Worker The client function is action_count, which just tell search_dir_entries to continue.
154*6a54128fSAndroid Build Coastguard Worker
155*6a54128fSAndroid Build Coastguard Worker */
156*6a54128fSAndroid Build Coastguard Worker
157*6a54128fSAndroid Build Coastguard Worker {
158*6a54128fSAndroid Build Coastguard Worker int status;
159*6a54128fSAndroid Build Coastguard Worker
160*6a54128fSAndroid Build Coastguard Worker return (search_dir_entries (&action_count,&status).dir_entry_num);
161*6a54128fSAndroid Build Coastguard Worker }
162*6a54128fSAndroid Build Coastguard Worker
action_count(struct struct_file_info * info)163*6a54128fSAndroid Build Coastguard Worker int action_count (struct struct_file_info *info)
164*6a54128fSAndroid Build Coastguard Worker
165*6a54128fSAndroid Build Coastguard Worker /*
166*6a54128fSAndroid Build Coastguard Worker
167*6a54128fSAndroid Build Coastguard Worker Used by count_dir_entries above - This function is called by search_dir_entries, and it tells it to continue
168*6a54128fSAndroid Build Coastguard Worker searching, until we get to the last entry.
169*6a54128fSAndroid Build Coastguard Worker
170*6a54128fSAndroid Build Coastguard Worker */
171*6a54128fSAndroid Build Coastguard Worker
172*6a54128fSAndroid Build Coastguard Worker {
173*6a54128fSAndroid Build Coastguard Worker return (CONTINUE); /* Just continue searching */
174*6a54128fSAndroid Build Coastguard Worker }
175*6a54128fSAndroid Build Coastguard Worker
type_dir___cd(char * command_line)176*6a54128fSAndroid Build Coastguard Worker void type_dir___cd (char *command_line)
177*6a54128fSAndroid Build Coastguard Worker
178*6a54128fSAndroid Build Coastguard Worker /*
179*6a54128fSAndroid Build Coastguard Worker Changes to a directory, relative to the current directory.
180*6a54128fSAndroid Build Coastguard Worker
181*6a54128fSAndroid Build Coastguard Worker This is a complicated operation, so I would repeat here the explanation from the design and
182*6a54128fSAndroid Build Coastguard Worker implementation document.
183*6a54128fSAndroid Build Coastguard Worker
184*6a54128fSAndroid Build Coastguard Worker 1. The path is checked that it is not an absolute path (from /). If it is, we let the general cd to do the job by
185*6a54128fSAndroid Build Coastguard Worker calling directly type_ext2___cd.
186*6a54128fSAndroid Build Coastguard Worker
187*6a54128fSAndroid Build Coastguard Worker 2. The path is divided into the nearest path and the rest of the path. For example, cd 1/2/3/4 is divided into
188*6a54128fSAndroid Build Coastguard Worker 1 and into 2/3/4.
189*6a54128fSAndroid Build Coastguard Worker
190*6a54128fSAndroid Build Coastguard Worker 3. It is the first part of the path that we need to search for in the current directory. We search for it using
191*6a54128fSAndroid Build Coastguard Worker search_dir_entries, which accepts the action_name function as the client function.
192*6a54128fSAndroid Build Coastguard Worker
193*6a54128fSAndroid Build Coastguard Worker 4. search_dir_entries will scan the entire entries and will call our action_name function for each entry.
194*6a54128fSAndroid Build Coastguard Worker In action_name, the required name will be checked against the name of the current entry, and FOUND will be
195*6a54128fSAndroid Build Coastguard Worker returned when a match occurs.
196*6a54128fSAndroid Build Coastguard Worker
197*6a54128fSAndroid Build Coastguard Worker 5. If the required entry is found, we dispatch a remember command to insert the current inode (remember that
198*6a54128fSAndroid Build Coastguard Worker type_data is still intact and contains the inode of the current directory) into the object memory.
199*6a54128fSAndroid Build Coastguard Worker This is required to easily support symbolic links - If we find later that the inode pointed by the entry is
200*6a54128fSAndroid Build Coastguard Worker actually a symbolic link, we'll need to return to this point, and the above inode doesn't have (and can't have,
201*6a54128fSAndroid Build Coastguard Worker because of hard links) the information necessary to "move back".
202*6a54128fSAndroid Build Coastguard Worker
203*6a54128fSAndroid Build Coastguard Worker 6. We then dispatch a followinode command to reach the inode pointed by the required entry. This command will
204*6a54128fSAndroid Build Coastguard Worker automatically change the type to ext2_inode - We are now at an inode, and all the inode commands are available.
205*6a54128fSAndroid Build Coastguard Worker
206*6a54128fSAndroid Build Coastguard Worker 7. We check the inode's type to see if it is a directory. If it is, we dispatch a dir command to "enter the directory",
207*6a54128fSAndroid Build Coastguard Worker and recursively call ourself (The type is dir again) by dispatching a cd command, with the rest of the path
208*6a54128fSAndroid Build Coastguard Worker as an argument.
209*6a54128fSAndroid Build Coastguard Worker
210*6a54128fSAndroid Build Coastguard Worker 8. If the inode's type is a symbolic link (only fast symbolic link were meanwhile implemented. I guess this is
211*6a54128fSAndroid Build Coastguard Worker typically the case.), we note the path it is pointing at, the saved inode is recalled, we dispatch dir to
212*6a54128fSAndroid Build Coastguard Worker get back to the original directory, and we call ourself again with the link path/rest of the path argument.
213*6a54128fSAndroid Build Coastguard Worker
214*6a54128fSAndroid Build Coastguard Worker 9. In any other case, we just stop at the resulting inode.
215*6a54128fSAndroid Build Coastguard Worker
216*6a54128fSAndroid Build Coastguard Worker */
217*6a54128fSAndroid Build Coastguard Worker
218*6a54128fSAndroid Build Coastguard Worker {
219*6a54128fSAndroid Build Coastguard Worker int status;
220*6a54128fSAndroid Build Coastguard Worker char *ptr,full_dir_name [500],dir_name [500],temp [500],temp2 [500];
221*6a54128fSAndroid Build Coastguard Worker struct struct_file_info info;
222*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr;
223*6a54128fSAndroid Build Coastguard Worker
224*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
225*6a54128fSAndroid Build Coastguard Worker
226*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,dir_name);
227*6a54128fSAndroid Build Coastguard Worker
228*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) { /* cd alone will enter the highlighted directory */
229*6a54128fSAndroid Build Coastguard Worker strncpy (full_dir_name,dir_entry_ptr->name,dir_entry_ptr->name_len);
230*6a54128fSAndroid Build Coastguard Worker full_dir_name [dir_entry_ptr->name_len]=0;
231*6a54128fSAndroid Build Coastguard Worker }
232*6a54128fSAndroid Build Coastguard Worker else
233*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,full_dir_name);
234*6a54128fSAndroid Build Coastguard Worker
235*6a54128fSAndroid Build Coastguard Worker ptr=strchr (full_dir_name,'/');
236*6a54128fSAndroid Build Coastguard Worker
237*6a54128fSAndroid Build Coastguard Worker if (ptr==full_dir_name) { /* Pathname is from root - Let the general cd do the job */
238*6a54128fSAndroid Build Coastguard Worker sprintf (temp,"cd %s",full_dir_name);type_ext2___cd (temp);return;
239*6a54128fSAndroid Build Coastguard Worker }
240*6a54128fSAndroid Build Coastguard Worker
241*6a54128fSAndroid Build Coastguard Worker if (ptr==NULL) {
242*6a54128fSAndroid Build Coastguard Worker strcpy (dir_name,full_dir_name);
243*6a54128fSAndroid Build Coastguard Worker full_dir_name [0]=0;
244*6a54128fSAndroid Build Coastguard Worker }
245*6a54128fSAndroid Build Coastguard Worker
246*6a54128fSAndroid Build Coastguard Worker else {
247*6a54128fSAndroid Build Coastguard Worker strncpy (dir_name,full_dir_name,ptr-full_dir_name);
248*6a54128fSAndroid Build Coastguard Worker dir_name [ptr-full_dir_name]=0;
249*6a54128fSAndroid Build Coastguard Worker strcpy (full_dir_name,++ptr);
250*6a54128fSAndroid Build Coastguard Worker }
251*6a54128fSAndroid Build Coastguard Worker /* dir_name contains the current entry, while */
252*6a54128fSAndroid Build Coastguard Worker /* full_dir_name contains the rest */
253*6a54128fSAndroid Build Coastguard Worker
254*6a54128fSAndroid Build Coastguard Worker strcpy (name_search,dir_name); /* name_search is used to hold the required entry name */
255*6a54128fSAndroid Build Coastguard Worker
256*6a54128fSAndroid Build Coastguard Worker if (dir_entry_ptr->name_len != strlen (dir_name) ||
257*6a54128fSAndroid Build Coastguard Worker strncmp (dir_name,dir_entry_ptr->name,dir_entry_ptr->name_len)!=0)
258*6a54128fSAndroid Build Coastguard Worker info=search_dir_entries (&action_name,&status); /* Search for the entry. Answer in info. */
259*6a54128fSAndroid Build Coastguard Worker else {
260*6a54128fSAndroid Build Coastguard Worker status=FOUND;info=file_info;
261*6a54128fSAndroid Build Coastguard Worker }
262*6a54128fSAndroid Build Coastguard Worker
263*6a54128fSAndroid Build Coastguard Worker if (status==FOUND) { /* If found */
264*6a54128fSAndroid Build Coastguard Worker file_info=info; /* Switch to it, by setting the global file_info */
265*6a54128fSAndroid Build Coastguard Worker dispatch ("remember internal_variable"); /* Move the inode into the objects memory */
266*6a54128fSAndroid Build Coastguard Worker
267*6a54128fSAndroid Build Coastguard Worker dispatch ("followinode"); /* Go to the inode pointed by this directory entry */
268*6a54128fSAndroid Build Coastguard Worker
269*6a54128fSAndroid Build Coastguard Worker if (S_ISLNK (type_data.u.t_ext2_inode.i_mode)) {/* Symbolic link ? */
270*6a54128fSAndroid Build Coastguard Worker
271*6a54128fSAndroid Build Coastguard Worker if (type_data.u.t_ext2_inode.i_size > 60) { /* I'm lazy, I guess :-) */
272*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Sorry, Only fast symbolic link following is currently supported\n");
273*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
274*6a54128fSAndroid Build Coastguard Worker return;
275*6a54128fSAndroid Build Coastguard Worker }
276*6a54128fSAndroid Build Coastguard Worker /* Get the pointed name and append the previous path */
277*6a54128fSAndroid Build Coastguard Worker
278*6a54128fSAndroid Build Coastguard Worker strcpy (temp2,(unsigned char *) &type_data.u.t_ext2_inode.i_block);
279*6a54128fSAndroid Build Coastguard Worker strcat (temp2,"/");
280*6a54128fSAndroid Build Coastguard Worker strcat (temp2,full_dir_name);
281*6a54128fSAndroid Build Coastguard Worker
282*6a54128fSAndroid Build Coastguard Worker dispatch ("recall internal_variable"); /* Return to the original inode */
283*6a54128fSAndroid Build Coastguard Worker dispatch ("dir"); /* and to the directory */
284*6a54128fSAndroid Build Coastguard Worker
285*6a54128fSAndroid Build Coastguard Worker sprintf (temp,"cd %s",temp2); /* And continue from there by dispatching a cd command */
286*6a54128fSAndroid Build Coastguard Worker dispatch (temp); /* (which can call ourself or the general cd) */
287*6a54128fSAndroid Build Coastguard Worker
288*6a54128fSAndroid Build Coastguard Worker return;
289*6a54128fSAndroid Build Coastguard Worker }
290*6a54128fSAndroid Build Coastguard Worker
291*6a54128fSAndroid Build Coastguard Worker if (S_ISDIR (type_data.u.t_ext2_inode.i_mode)) { /* Is it an inode of a directory ? */
292*6a54128fSAndroid Build Coastguard Worker
293*6a54128fSAndroid Build Coastguard Worker dispatch ("dir"); /* Yes - Pass to the pointed directory */
294*6a54128fSAndroid Build Coastguard Worker
295*6a54128fSAndroid Build Coastguard Worker if (full_dir_name [0] != 0) { /* And call ourself with the rest of the pathname */
296*6a54128fSAndroid Build Coastguard Worker sprintf (temp,"cd %s",full_dir_name);
297*6a54128fSAndroid Build Coastguard Worker dispatch (temp);
298*6a54128fSAndroid Build Coastguard Worker }
299*6a54128fSAndroid Build Coastguard Worker
300*6a54128fSAndroid Build Coastguard Worker return;
301*6a54128fSAndroid Build Coastguard Worker }
302*6a54128fSAndroid Build Coastguard Worker
303*6a54128fSAndroid Build Coastguard Worker else { /* If we can't continue from here, we'll just stop */
304*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Can\'t continue - Stopping at last inode\n");refresh_command_win ();
305*6a54128fSAndroid Build Coastguard Worker return;
306*6a54128fSAndroid Build Coastguard Worker }
307*6a54128fSAndroid Build Coastguard Worker }
308*6a54128fSAndroid Build Coastguard Worker
309*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Directory entry %s not found.\n",dir_name); /* Hmm, an invalid path somewhere */
310*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
311*6a54128fSAndroid Build Coastguard Worker }
312*6a54128fSAndroid Build Coastguard Worker
action_name(struct struct_file_info * info)313*6a54128fSAndroid Build Coastguard Worker int action_name (struct struct_file_info *info)
314*6a54128fSAndroid Build Coastguard Worker
315*6a54128fSAndroid Build Coastguard Worker /*
316*6a54128fSAndroid Build Coastguard Worker
317*6a54128fSAndroid Build Coastguard Worker Compares the current search entry name (somewhere inside info) with the required name (in name_search).
318*6a54128fSAndroid Build Coastguard Worker Returns FOUND if found, or CONTINUE if not found.
319*6a54128fSAndroid Build Coastguard Worker
320*6a54128fSAndroid Build Coastguard Worker */
321*6a54128fSAndroid Build Coastguard Worker
322*6a54128fSAndroid Build Coastguard Worker {
323*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr;
324*6a54128fSAndroid Build Coastguard Worker
325*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (info->buffer+info->dir_entry_offset);
326*6a54128fSAndroid Build Coastguard Worker
327*6a54128fSAndroid Build Coastguard Worker if (dir_entry_ptr->name_len != strlen (name_search))
328*6a54128fSAndroid Build Coastguard Worker return (CONTINUE);
329*6a54128fSAndroid Build Coastguard Worker
330*6a54128fSAndroid Build Coastguard Worker if (strncmp (dir_entry_ptr->name,name_search,dir_entry_ptr->name_len)==0)
331*6a54128fSAndroid Build Coastguard Worker return (FOUND);
332*6a54128fSAndroid Build Coastguard Worker
333*6a54128fSAndroid Build Coastguard Worker return (CONTINUE);
334*6a54128fSAndroid Build Coastguard Worker }
335*6a54128fSAndroid Build Coastguard Worker
type_dir___entry(char * command_line)336*6a54128fSAndroid Build Coastguard Worker void type_dir___entry (char *command_line)
337*6a54128fSAndroid Build Coastguard Worker
338*6a54128fSAndroid Build Coastguard Worker /*
339*6a54128fSAndroid Build Coastguard Worker
340*6a54128fSAndroid Build Coastguard Worker Selects a directory entry according to its number.
341*6a54128fSAndroid Build Coastguard Worker search_dir_entries is used along with action_entry_num, in the same fashion as the previous usage of search_dir_entries.
342*6a54128fSAndroid Build Coastguard Worker
343*6a54128fSAndroid Build Coastguard Worker */
344*6a54128fSAndroid Build Coastguard Worker
345*6a54128fSAndroid Build Coastguard Worker {
346*6a54128fSAndroid Build Coastguard Worker int status;
347*6a54128fSAndroid Build Coastguard Worker struct struct_file_info info;
348*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
349*6a54128fSAndroid Build Coastguard Worker
350*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
351*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
352*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Argument_not_specified\n");wrefresh (command_win);
353*6a54128fSAndroid Build Coastguard Worker return;
354*6a54128fSAndroid Build Coastguard Worker }
355*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
356*6a54128fSAndroid Build Coastguard Worker entry_num_search=atol (buffer);
357*6a54128fSAndroid Build Coastguard Worker
358*6a54128fSAndroid Build Coastguard Worker if (entry_num_search < 0 || entry_num_search >= file_info.dir_entries_count) {
359*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Entry number out of range\n");wrefresh (command_win);
360*6a54128fSAndroid Build Coastguard Worker return;
361*6a54128fSAndroid Build Coastguard Worker }
362*6a54128fSAndroid Build Coastguard Worker
363*6a54128fSAndroid Build Coastguard Worker info=search_dir_entries (&action_entry_num,&status);
364*6a54128fSAndroid Build Coastguard Worker if (status==FOUND) {
365*6a54128fSAndroid Build Coastguard Worker file_info=info;
366*6a54128fSAndroid Build Coastguard Worker dispatch ("show");
367*6a54128fSAndroid Build Coastguard Worker return;
368*6a54128fSAndroid Build Coastguard Worker }
369*6a54128fSAndroid Build Coastguard Worker #ifdef DEBUG
370*6a54128fSAndroid Build Coastguard Worker internal_error ("dir_com","type_dir___entry","According to our gathered data, we should have found this entry");
371*6a54128fSAndroid Build Coastguard Worker #endif
372*6a54128fSAndroid Build Coastguard Worker }
373*6a54128fSAndroid Build Coastguard Worker
action_entry_num(struct struct_file_info * info)374*6a54128fSAndroid Build Coastguard Worker int action_entry_num (struct struct_file_info *info)
375*6a54128fSAndroid Build Coastguard Worker
376*6a54128fSAndroid Build Coastguard Worker /*
377*6a54128fSAndroid Build Coastguard Worker
378*6a54128fSAndroid Build Coastguard Worker Used by the above function. Just compares the current number (in info) with the required one.
379*6a54128fSAndroid Build Coastguard Worker
380*6a54128fSAndroid Build Coastguard Worker */
381*6a54128fSAndroid Build Coastguard Worker
382*6a54128fSAndroid Build Coastguard Worker {
383*6a54128fSAndroid Build Coastguard Worker if (info->dir_entry_num == entry_num_search)
384*6a54128fSAndroid Build Coastguard Worker return (FOUND);
385*6a54128fSAndroid Build Coastguard Worker
386*6a54128fSAndroid Build Coastguard Worker return (CONTINUE);
387*6a54128fSAndroid Build Coastguard Worker }
388*6a54128fSAndroid Build Coastguard Worker
type_dir___followinode(char * command_line)389*6a54128fSAndroid Build Coastguard Worker void type_dir___followinode (char *command_line)
390*6a54128fSAndroid Build Coastguard Worker
391*6a54128fSAndroid Build Coastguard Worker /*
392*6a54128fSAndroid Build Coastguard Worker
393*6a54128fSAndroid Build Coastguard Worker Here we pass to the inode pointed by the current entry.
394*6a54128fSAndroid Build Coastguard Worker It involves computing the device offset of the inode and using directly the setoffset and settype commands.
395*6a54128fSAndroid Build Coastguard Worker
396*6a54128fSAndroid Build Coastguard Worker */
397*6a54128fSAndroid Build Coastguard Worker {
398*6a54128fSAndroid Build Coastguard Worker long inode_offset;
399*6a54128fSAndroid Build Coastguard Worker char buffer [80];
400*6a54128fSAndroid Build Coastguard Worker
401*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr;
402*6a54128fSAndroid Build Coastguard Worker
403*6a54128fSAndroid Build Coastguard Worker low_read (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
404*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
405*6a54128fSAndroid Build Coastguard Worker
406*6a54128fSAndroid Build Coastguard Worker inode_offset=inode_num_to_inode_offset (dir_entry_ptr->inode); /* Compute the inode's offset */
407*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"setoffset %ld",inode_offset);dispatch (buffer); /* Move to it */
408*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"settype ext2_inode");dispatch (buffer); /* and set the type to an inode */
409*6a54128fSAndroid Build Coastguard Worker }
410*6a54128fSAndroid Build Coastguard Worker
type_dir___inode(char * command_line)411*6a54128fSAndroid Build Coastguard Worker void type_dir___inode (char *command_line)
412*6a54128fSAndroid Build Coastguard Worker
413*6a54128fSAndroid Build Coastguard Worker /*
414*6a54128fSAndroid Build Coastguard Worker
415*6a54128fSAndroid Build Coastguard Worker Returns to the parent inode of the current directory.
416*6a54128fSAndroid Build Coastguard Worker This is trivial, as we type_data is still intact and contains the parent inode !
417*6a54128fSAndroid Build Coastguard Worker
418*6a54128fSAndroid Build Coastguard Worker */
419*6a54128fSAndroid Build Coastguard Worker
420*6a54128fSAndroid Build Coastguard Worker {
421*6a54128fSAndroid Build Coastguard Worker dispatch ("settype ext2_inode");
422*6a54128fSAndroid Build Coastguard Worker }
423*6a54128fSAndroid Build Coastguard Worker
424*6a54128fSAndroid Build Coastguard Worker
type_dir___show(char * command_line)425*6a54128fSAndroid Build Coastguard Worker void type_dir___show (char *command_line)
426*6a54128fSAndroid Build Coastguard Worker
427*6a54128fSAndroid Build Coastguard Worker /*
428*6a54128fSAndroid Build Coastguard Worker
429*6a54128fSAndroid Build Coastguard Worker We use search_dir_entries to run on all the entries. Each time, action_show will be called to show one entry.
430*6a54128fSAndroid Build Coastguard Worker
431*6a54128fSAndroid Build Coastguard Worker */
432*6a54128fSAndroid Build Coastguard Worker
433*6a54128fSAndroid Build Coastguard Worker {
434*6a54128fSAndroid Build Coastguard Worker int status;
435*6a54128fSAndroid Build Coastguard Worker
436*6a54128fSAndroid Build Coastguard Worker wmove (show_pad,0,0);
437*6a54128fSAndroid Build Coastguard Worker show_pad_info.max_line=-1;
438*6a54128fSAndroid Build Coastguard Worker
439*6a54128fSAndroid Build Coastguard Worker search_dir_entries (&action_show,&status);
440*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=file_info.dir_entry_num-show_pad_info.display_lines/2;
441*6a54128fSAndroid Build Coastguard Worker refresh_show_pad ();
442*6a54128fSAndroid Build Coastguard Worker show_dir_status ();
443*6a54128fSAndroid Build Coastguard Worker }
444*6a54128fSAndroid Build Coastguard Worker
action_show(struct struct_file_info * info)445*6a54128fSAndroid Build Coastguard Worker int action_show (struct struct_file_info *info)
446*6a54128fSAndroid Build Coastguard Worker
447*6a54128fSAndroid Build Coastguard Worker /*
448*6a54128fSAndroid Build Coastguard Worker
449*6a54128fSAndroid Build Coastguard Worker Show the current search entry (info) in one line. If the entry happens to be the current edited entry, it is highlighted.
450*6a54128fSAndroid Build Coastguard Worker
451*6a54128fSAndroid Build Coastguard Worker */
452*6a54128fSAndroid Build Coastguard Worker
453*6a54128fSAndroid Build Coastguard Worker {
454*6a54128fSAndroid Build Coastguard Worker unsigned char temp [80];
455*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr;
456*6a54128fSAndroid Build Coastguard Worker
457*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (info->buffer+info->dir_entry_offset);
458*6a54128fSAndroid Build Coastguard Worker
459*6a54128fSAndroid Build Coastguard Worker if (info->dir_entry_num == file_info.dir_entry_num) /* Highlight the current entry */
460*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_REVERSE);
461*6a54128fSAndroid Build Coastguard Worker
462*6a54128fSAndroid Build Coastguard Worker strncpy (temp,dir_entry_ptr->name,dir_entry_ptr->name_len); /* The name is not terminated */
463*6a54128fSAndroid Build Coastguard Worker temp [dir_entry_ptr->name_len]=0;
464*6a54128fSAndroid Build Coastguard Worker if (dir_entry_ptr->name_len > (COLS - 55) && COLS > 55)
465*6a54128fSAndroid Build Coastguard Worker temp [COLS-55]=0;
466*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"inode = %-8lu rec_len = %-4lu name_len = %-3lu name = %s\n", /* Display the various fields */
467*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr->inode,dir_entry_ptr->rec_len,dir_entry_ptr->name_len,temp);
468*6a54128fSAndroid Build Coastguard Worker
469*6a54128fSAndroid Build Coastguard Worker show_pad_info.max_line++;
470*6a54128fSAndroid Build Coastguard Worker
471*6a54128fSAndroid Build Coastguard Worker if (info->dir_entry_num == file_info.dir_entry_num)
472*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_NORMAL);
473*6a54128fSAndroid Build Coastguard Worker
474*6a54128fSAndroid Build Coastguard Worker return (CONTINUE); /* And pass to the next */
475*6a54128fSAndroid Build Coastguard Worker }
476*6a54128fSAndroid Build Coastguard Worker
type_dir___next(char * command_line)477*6a54128fSAndroid Build Coastguard Worker void type_dir___next (char *command_line)
478*6a54128fSAndroid Build Coastguard Worker
479*6a54128fSAndroid Build Coastguard Worker /*
480*6a54128fSAndroid Build Coastguard Worker
481*6a54128fSAndroid Build Coastguard Worker This function moves to the next directory entry. It just uses the current information and the entry command.
482*6a54128fSAndroid Build Coastguard Worker
483*6a54128fSAndroid Build Coastguard Worker */
484*6a54128fSAndroid Build Coastguard Worker
485*6a54128fSAndroid Build Coastguard Worker {
486*6a54128fSAndroid Build Coastguard Worker int offset=1;
487*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
488*6a54128fSAndroid Build Coastguard Worker
489*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
490*6a54128fSAndroid Build Coastguard Worker
491*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
492*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
493*6a54128fSAndroid Build Coastguard Worker offset*=atol (buffer);
494*6a54128fSAndroid Build Coastguard Worker }
495*6a54128fSAndroid Build Coastguard Worker
496*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"entry %ld",file_info.dir_entry_num+offset);dispatch (buffer);
497*6a54128fSAndroid Build Coastguard Worker
498*6a54128fSAndroid Build Coastguard Worker }
499*6a54128fSAndroid Build Coastguard Worker
type_dir___prev(char * command_line)500*6a54128fSAndroid Build Coastguard Worker void type_dir___prev (char *command_line)
501*6a54128fSAndroid Build Coastguard Worker
502*6a54128fSAndroid Build Coastguard Worker {
503*6a54128fSAndroid Build Coastguard Worker int offset=1;
504*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
505*6a54128fSAndroid Build Coastguard Worker
506*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
507*6a54128fSAndroid Build Coastguard Worker
508*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) {
509*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
510*6a54128fSAndroid Build Coastguard Worker offset*=atol (buffer);
511*6a54128fSAndroid Build Coastguard Worker }
512*6a54128fSAndroid Build Coastguard Worker
513*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"entry %ld",file_info.dir_entry_num-offset);dispatch (buffer);
514*6a54128fSAndroid Build Coastguard Worker }
515*6a54128fSAndroid Build Coastguard Worker
show_dir_status(void)516*6a54128fSAndroid Build Coastguard Worker void show_dir_status (void)
517*6a54128fSAndroid Build Coastguard Worker
518*6a54128fSAndroid Build Coastguard Worker /*
519*6a54128fSAndroid Build Coastguard Worker
520*6a54128fSAndroid Build Coastguard Worker Various statistics about the directory.
521*6a54128fSAndroid Build Coastguard Worker
522*6a54128fSAndroid Build Coastguard Worker */
523*6a54128fSAndroid Build Coastguard Worker
524*6a54128fSAndroid Build Coastguard Worker {
525*6a54128fSAndroid Build Coastguard Worker long inode_num;
526*6a54128fSAndroid Build Coastguard Worker
527*6a54128fSAndroid Build Coastguard Worker wmove (show_win,0,0);
528*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Directory listing. Block %ld. ",file_info.global_block_num);
529*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Directory entry %ld of %ld.\n",file_info.dir_entry_num,file_info.dir_entries_count-1);
530*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"Directory Offset %ld of %ld. ",file_info.file_offset,file_info.file_length-1);
531*6a54128fSAndroid Build Coastguard Worker
532*6a54128fSAndroid Build Coastguard Worker inode_num=inode_offset_to_inode_num (file_info.inode_offset);
533*6a54128fSAndroid Build Coastguard Worker wprintw (show_win,"File inode %ld. Indirection level %ld.\n",inode_num,file_info.level);
534*6a54128fSAndroid Build Coastguard Worker
535*6a54128fSAndroid Build Coastguard Worker refresh_show_win ();
536*6a54128fSAndroid Build Coastguard Worker }
537*6a54128fSAndroid Build Coastguard Worker
type_dir___remember(char * command_line)538*6a54128fSAndroid Build Coastguard Worker void type_dir___remember (char *command_line)
539*6a54128fSAndroid Build Coastguard Worker
540*6a54128fSAndroid Build Coastguard Worker /*
541*6a54128fSAndroid Build Coastguard Worker
542*6a54128fSAndroid Build Coastguard Worker This is overridden here because we don't remember a directory - It is too complicated. Instead, we remember the
543*6a54128fSAndroid Build Coastguard Worker inode of the current directory.
544*6a54128fSAndroid Build Coastguard Worker
545*6a54128fSAndroid Build Coastguard Worker */
546*6a54128fSAndroid Build Coastguard Worker
547*6a54128fSAndroid Build Coastguard Worker {
548*6a54128fSAndroid Build Coastguard Worker int found=0;
549*6a54128fSAndroid Build Coastguard Worker long entry_num;
550*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80];
551*6a54128fSAndroid Build Coastguard Worker struct struct_descriptor *descriptor_ptr;
552*6a54128fSAndroid Build Coastguard Worker
553*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
554*6a54128fSAndroid Build Coastguard Worker
555*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
556*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Argument not specified\n");wrefresh (command_win);
557*6a54128fSAndroid Build Coastguard Worker return;
558*6a54128fSAndroid Build Coastguard Worker }
559*6a54128fSAndroid Build Coastguard Worker
560*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer);
561*6a54128fSAndroid Build Coastguard Worker
562*6a54128fSAndroid Build Coastguard Worker entry_num=remember_lifo.entries_count++;
563*6a54128fSAndroid Build Coastguard Worker if (entry_num>REMEMBER_COUNT-1) {
564*6a54128fSAndroid Build Coastguard Worker entry_num=0;
565*6a54128fSAndroid Build Coastguard Worker remember_lifo.entries_count--;
566*6a54128fSAndroid Build Coastguard Worker }
567*6a54128fSAndroid Build Coastguard Worker
568*6a54128fSAndroid Build Coastguard Worker descriptor_ptr=first_type;
569*6a54128fSAndroid Build Coastguard Worker while (descriptor_ptr!=NULL && !found) {
570*6a54128fSAndroid Build Coastguard Worker if (strcmp (descriptor_ptr->name,"ext2_inode")==0)
571*6a54128fSAndroid Build Coastguard Worker found=1;
572*6a54128fSAndroid Build Coastguard Worker else
573*6a54128fSAndroid Build Coastguard Worker descriptor_ptr=descriptor_ptr->next;
574*6a54128fSAndroid Build Coastguard Worker }
575*6a54128fSAndroid Build Coastguard Worker
576*6a54128fSAndroid Build Coastguard Worker
577*6a54128fSAndroid Build Coastguard Worker remember_lifo.offset [entry_num]=device_offset;
578*6a54128fSAndroid Build Coastguard Worker remember_lifo.type [entry_num]=descriptor_ptr;
579*6a54128fSAndroid Build Coastguard Worker strcpy (remember_lifo.name [entry_num],buffer);
580*6a54128fSAndroid Build Coastguard Worker
581*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Object %s in Offset %ld remembered as %s\n",descriptor_ptr->name,device_offset,buffer);
582*6a54128fSAndroid Build Coastguard Worker wrefresh (command_win);
583*6a54128fSAndroid Build Coastguard Worker }
584*6a54128fSAndroid Build Coastguard Worker
type_dir___set(char * command_line)585*6a54128fSAndroid Build Coastguard Worker void type_dir___set (char *command_line)
586*6a54128fSAndroid Build Coastguard Worker
587*6a54128fSAndroid Build Coastguard Worker /*
588*6a54128fSAndroid Build Coastguard Worker
589*6a54128fSAndroid Build Coastguard Worker Since the dir object doesn't have variables, we provide the impression that it has here. ext2_dir_entry was not used
590*6a54128fSAndroid Build Coastguard Worker because it is of variable length.
591*6a54128fSAndroid Build Coastguard Worker
592*6a54128fSAndroid Build Coastguard Worker */
593*6a54128fSAndroid Build Coastguard Worker
594*6a54128fSAndroid Build Coastguard Worker {
595*6a54128fSAndroid Build Coastguard Worker int found=0;
596*6a54128fSAndroid Build Coastguard Worker unsigned char *ptr,buffer [80],variable [80],value [80],temp [80];
597*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry_2 *dir_entry_ptr;
598*6a54128fSAndroid Build Coastguard Worker
599*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset);
600*6a54128fSAndroid Build Coastguard Worker
601*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer);
602*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) {
603*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Missing arguments\n");refresh_command_win ();
604*6a54128fSAndroid Build Coastguard Worker return;
605*6a54128fSAndroid Build Coastguard Worker }
606*6a54128fSAndroid Build Coastguard Worker parse_word (ptr,buffer);
607*6a54128fSAndroid Build Coastguard Worker ptr=strchr (buffer,'=');
608*6a54128fSAndroid Build Coastguard Worker if (ptr==NULL) {
609*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Bad syntax\n");refresh_command_win ();return;
610*6a54128fSAndroid Build Coastguard Worker }
611*6a54128fSAndroid Build Coastguard Worker strncpy (variable,buffer,ptr-buffer);variable [ptr-buffer]=0;
612*6a54128fSAndroid Build Coastguard Worker strcpy (value,++ptr);
613*6a54128fSAndroid Build Coastguard Worker
614*6a54128fSAndroid Build Coastguard Worker if (strcasecmp ("inode",variable)==0) {
615*6a54128fSAndroid Build Coastguard Worker found=1;
616*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr->inode=atol (value);
617*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->inode);refresh_command_win ();
618*6a54128fSAndroid Build Coastguard Worker
619*6a54128fSAndroid Build Coastguard Worker }
620*6a54128fSAndroid Build Coastguard Worker
621*6a54128fSAndroid Build Coastguard Worker if (strcasecmp ("rec_len",variable)==0) {
622*6a54128fSAndroid Build Coastguard Worker found=1;
623*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr->rec_len=(unsigned int) atol (value);
624*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->rec_len);refresh_command_win ();
625*6a54128fSAndroid Build Coastguard Worker
626*6a54128fSAndroid Build Coastguard Worker }
627*6a54128fSAndroid Build Coastguard Worker
628*6a54128fSAndroid Build Coastguard Worker if (strcasecmp ("name_len",variable)==0) {
629*6a54128fSAndroid Build Coastguard Worker found=1;
630*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr->name_len=(unsigned int) atol (value);
631*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->name_len);refresh_command_win ();
632*6a54128fSAndroid Build Coastguard Worker
633*6a54128fSAndroid Build Coastguard Worker }
634*6a54128fSAndroid Build Coastguard Worker
635*6a54128fSAndroid Build Coastguard Worker if (strcasecmp ("name",variable)==0) {
636*6a54128fSAndroid Build Coastguard Worker found=1;
637*6a54128fSAndroid Build Coastguard Worker if (strlen (value) > dir_entry_ptr->name_len) {
638*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Length of name greater then name_len\n");
639*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();return;
640*6a54128fSAndroid Build Coastguard Worker }
641*6a54128fSAndroid Build Coastguard Worker strncpy (dir_entry_ptr->name,value,strlen (value));
642*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Variable %s set to %s\n",variable,value);refresh_command_win ();
643*6a54128fSAndroid Build Coastguard Worker
644*6a54128fSAndroid Build Coastguard Worker }
645*6a54128fSAndroid Build Coastguard Worker
646*6a54128fSAndroid Build Coastguard Worker if (found) {
647*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_REVERSE);
648*6a54128fSAndroid Build Coastguard Worker strncpy (temp,dir_entry_ptr->name,dir_entry_ptr->name_len);
649*6a54128fSAndroid Build Coastguard Worker temp [dir_entry_ptr->name_len]=0;
650*6a54128fSAndroid Build Coastguard Worker wmove (show_pad,file_info.dir_entry_num,0);
651*6a54128fSAndroid Build Coastguard Worker wprintw (show_pad,"inode = %-8lu rec_len = %-4lu name_len = %-3lu name = %s\n",
652*6a54128fSAndroid Build Coastguard Worker dir_entry_ptr->inode,dir_entry_ptr->rec_len,dir_entry_ptr->name_len,temp);
653*6a54128fSAndroid Build Coastguard Worker wattrset (show_pad,A_NORMAL);
654*6a54128fSAndroid Build Coastguard Worker show_pad_info.line=file_info.dir_entry_num-show_pad_info.display_lines/2;
655*6a54128fSAndroid Build Coastguard Worker refresh_show_pad ();
656*6a54128fSAndroid Build Coastguard Worker show_dir_status ();
657*6a54128fSAndroid Build Coastguard Worker }
658*6a54128fSAndroid Build Coastguard Worker
659*6a54128fSAndroid Build Coastguard Worker else {
660*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Variable %s not found\n",variable);
661*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();
662*6a54128fSAndroid Build Coastguard Worker }
663*6a54128fSAndroid Build Coastguard Worker
664*6a54128fSAndroid Build Coastguard Worker }
665*6a54128fSAndroid Build Coastguard Worker
type_dir___writedata(char * command_line)666*6a54128fSAndroid Build Coastguard Worker void type_dir___writedata (char *command_line)
667*6a54128fSAndroid Build Coastguard Worker
668*6a54128fSAndroid Build Coastguard Worker /*
669*6a54128fSAndroid Build Coastguard Worker
670*6a54128fSAndroid Build Coastguard Worker We need to override this since the data is not in type_data. Instead, we have to write the buffer which corresponds
671*6a54128fSAndroid Build Coastguard Worker to the current block.
672*6a54128fSAndroid Build Coastguard Worker
673*6a54128fSAndroid Build Coastguard Worker */
674*6a54128fSAndroid Build Coastguard Worker
675*6a54128fSAndroid Build Coastguard Worker {
676*6a54128fSAndroid Build Coastguard Worker low_write (file_info.buffer,file_system_info.block_size,file_info.global_block_offset);
677*6a54128fSAndroid Build Coastguard Worker return;
678*6a54128fSAndroid Build Coastguard Worker }
679