blob: ed004f285c8d75d80371a959219c8ab08ee811de [file] [log] [blame]
Theodore Ts'o583a1ce2002-05-11 13:00:22 -04001/*
2
3/usr/src/ext2ed/ext2_com.c
4
5A part of the extended file system 2 disk editor.
6
7--------------------------------------
8Extended-2 filesystem General commands
9--------------------------------------
10
11The commands here will be registered when we are editing an ext2 filesystem
12
13First written on: July 28 1995
14
15Copyright (C) 1995 Gadi Oxman
16
17*/
18
Theodore Ts'od1154eb2011-09-18 17:34:37 -040019#include "config.h"
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040020#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include "ext2ed.h"
25
26void type_ext2___super (char *command_line)
27
28/*
29
30We are moving to the superblock - Just use setoffset and settype. The offset was gathered in the
31initialization phase (but is constant - 1024).
32
33*/
34
35{
36 char buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040037
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040038 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
43void type_ext2___cd (char *command_line)
44
45/*
46
47A global cd command - The path should start with /.
48
49We implement it through dispatching to our primitive functions.
50
51*/
52
53{
54 char temp [80],buffer [80],*ptr;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040055
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040056 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);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040061
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040062 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
74void type_ext2___group (char *command_line)
75
76/*
77
78We go to the group descriptors.
79First, we go to the first group descriptor in the main copy.
80Then, 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];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040087
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040088 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}