1 /*
2 
3 /usr/src/ext2ed/ext2_com.c
4 
5 A part of the extended file system 2 disk editor.
6 
7 --------------------------------------
8 Extended-2 filesystem General commands
9 --------------------------------------
10 
11 The commands here will be registered when we are editing an ext2 filesystem
12 
13 First written on: July 28 1995
14 
15 Copyright (C) 1995 Gadi Oxman
16 
17 */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 
23 #include "ext2ed.h"
24 
type_ext2___super(char * command_line)25 void type_ext2___super (char *command_line)
26 
27 /*
28 
29 We are moving to the superblock - Just use setoffset and settype. The offset was gathered in the
30 initialization phase (but is constant - 1024).
31 
32 */
33 
34 {
35 	char buffer [80];
36 
37 	super_info.copy_num=0;
38 	sprintf (buffer,"setoffset %ld",file_system_info.super_block_offset);dispatch (buffer);
39 	sprintf (buffer,"settype ext2_super_block");dispatch (buffer);
40 }
41 
type_ext2___cd(char * command_line)42 void type_ext2___cd (char *command_line)
43 
44 /*
45 
46 A global cd command - The path should start with /.
47 
48 We implement it through dispatching to our primitive functions.
49 
50 */
51 
52 {
53 	char temp [80],buffer [80],*ptr;
54 
55 	ptr=parse_word (command_line,buffer);
56 	if (*ptr==0) {
57 		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
58 	}
59 	ptr=parse_word (ptr,buffer);
60 
61 	if (buffer [0] != '/') {
62 		wprintw (command_win,"Error - Use a full pathname (begin with '/')\n");refresh_command_win ();return;
63 	}
64 
65 	/* Note the various dispatches below - They should be intuitive if you know the ext2 filesystem structure */
66 
67 	dispatch ("super");dispatch ("group");dispatch ("inode");dispatch ("next");dispatch ("dir");
68 	if (buffer [1] != 0) {
69 		sprintf (temp,"cd %s",buffer+1);dispatch (temp);
70 	}
71 }
72 
type_ext2___group(char * command_line)73 void type_ext2___group (char *command_line)
74 
75 /*
76 
77 We go to the group descriptors.
78 First, we go to the first group descriptor in the main copy.
79 Then, we use the group's entry command to pass to another group.
80 
81 */
82 
83 {
84 	long group_num=0;
85 	char *ptr,buffer [80];
86 
87 	ptr=parse_word (command_line,buffer);
88 	if (*ptr!=0) {
89 		ptr=parse_word (ptr,buffer);
90 		group_num=atol (buffer);
91 	}
92 
93 	group_info.copy_num=0;group_info.group_num=0;
94 	sprintf (buffer,"setoffset %ld",file_system_info.first_group_desc_offset);dispatch (buffer);
95 	sprintf (buffer,"settype ext2_group_desc");dispatch (buffer);
96 	sprintf (buffer,"entry %ld",group_num);dispatch (buffer);
97 }
98