Home | History | Annotate | Download | only in ext2ed
      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 "config.h"
     20 #include <stdio.h>
     21 #include <stdlib.h>
     22 #include <string.h>
     23 
     24 #include "ext2ed.h"
     25 
     26 void type_ext2___super (char *command_line)
     27 
     28 /*
     29 
     30 We are moving to the superblock - Just use setoffset and settype. The offset was gathered in the
     31 initialization phase (but is constant - 1024).
     32 
     33 */
     34 
     35 {
     36 	char buffer [80];
     37 
     38 	super_info.copy_num=0;
     39 	sprintf (buffer,"setoffset %ld",file_system_info.super_block_offset);dispatch (buffer);
     40 	sprintf (buffer,"settype ext2_super_block");dispatch (buffer);
     41 }
     42 
     43 void type_ext2___cd (char *command_line)
     44 
     45 /*
     46 
     47 A global cd command - The path should start with /.
     48 
     49 We implement it through dispatching to our primitive functions.
     50 
     51 */
     52 
     53 {
     54 	char temp [80],buffer [80],*ptr;
     55 
     56 	ptr=parse_word (command_line,buffer);
     57 	if (*ptr==0) {
     58 		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
     59 	}
     60 	ptr=parse_word (ptr,buffer);
     61 
     62 	if (buffer [0] != '/') {
     63 		wprintw (command_win,"Error - Use a full pathname (begin with '/')\n");refresh_command_win ();return;
     64 	}
     65 
     66 	/* Note the various dispatches below - They should be intuitive if you know the ext2 filesystem structure */
     67 
     68 	dispatch ("super");dispatch ("group");dispatch ("inode");dispatch ("next");dispatch ("dir");
     69 	if (buffer [1] != 0) {
     70 		sprintf (temp,"cd %s",buffer+1);dispatch (temp);
     71 	}
     72 }
     73 
     74 void type_ext2___group (char *command_line)
     75 
     76 /*
     77 
     78 We go to the group descriptors.
     79 First, we go to the first group descriptor in the main copy.
     80 Then, we use the group's entry command to pass to another group.
     81 
     82 */
     83 
     84 {
     85 	long group_num=0;
     86 	char *ptr,buffer [80];
     87 
     88 	ptr=parse_word (command_line,buffer);
     89 	if (*ptr!=0) {
     90 		ptr=parse_word (ptr,buffer);
     91 		group_num=atol (buffer);
     92 	}
     93 
     94 	group_info.copy_num=0;group_info.group_num=0;
     95 	sprintf (buffer,"setoffset %ld",file_system_info.first_group_desc_offset);dispatch (buffer);
     96 	sprintf (buffer,"settype ext2_group_desc");dispatch (buffer);
     97 	sprintf (buffer,"entry %ld",group_num);dispatch (buffer);
     98 }
     99