blob: 25325533002ec53ac1a44616e4e61cdfaca4e6cb [file] [log] [blame]
Theodore Ts'o583a1ce2002-05-11 13:00:22 -04001/*
2
3/usr/src/ext2ed/group_com.c
4
5A part of the extended file system 2 disk editor.
6
7General user commands
8
9First written on: April 17 1995
10
11Copyright (C) 1995 Gadi Oxman
12
13*/
14
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18
19#include "ext2ed.h"
20
21void type_ext2_group_desc___next (char *command_line)
Theodore Ts'oefc6f622008-08-27 23:07:54 -040022
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040023{
24 long entry_offset=1;
25 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040026
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040027 ptr=parse_word (command_line,buffer);
28 if (*ptr!=0) {
29 ptr=parse_word (ptr,buffer);
30 entry_offset=atol (buffer);
31 }
32
33 sprintf (buffer,"entry %ld",group_info.group_num+entry_offset);
34 dispatch (buffer);
35}
36
37void type_ext2_group_desc___prev (char *command_line)
38
39{
40 long entry_offset=1;
41 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040042
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040043 ptr=parse_word (command_line,buffer);
44 if (*ptr!=0) {
45 ptr=parse_word (ptr,buffer);
46 entry_offset=atol (buffer);
47 }
48
49 sprintf (buffer,"entry %ld",group_info.group_num-entry_offset);
50 dispatch (buffer);
51}
52
53void type_ext2_group_desc___entry (char *command_line)
54
55{
56 long group_num;
57 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040058
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040059 ptr=parse_word (command_line,buffer);
60 if (*ptr==0) {
61 wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
62 }
63 ptr=parse_word (ptr,buffer);
64
65 group_num=atol (buffer);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040066
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040067 if (group_num < 0 || group_num >= file_system_info.groups_count) {
68 wprintw (command_win,"Error - Entry number out of bounds\n");refresh_command_win ();return;
69 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -040070
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040071 device_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
72
73 sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
74 strcpy (buffer,"show");dispatch (buffer);
75 group_info.group_num=group_num;
76}
77
78
79void type_ext2_group_desc___gocopy (char *command_line)
80
81{
82 unsigned long copy_num,offset;
83 char *ptr,buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -040084
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040085 ptr=parse_word (command_line,buffer);
86 if (*ptr==0) {
87 wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
88 }
89 ptr=parse_word (ptr,buffer);
90
91 copy_num=atol (buffer);
Theodore Ts'oefc6f622008-08-27 23:07:54 -040092
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040093 offset=file_system_info.first_group_desc_offset+copy_num*file_system_info.super_block.s_blocks_per_group*file_system_info.block_size;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040094
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040095 if (offset > file_system_info.file_system_size) {
96 wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
Theodore Ts'oefc6f622008-08-27 23:07:54 -040097 }
Theodore Ts'o583a1ce2002-05-11 13:00:22 -040098
99 group_info.copy_num=copy_num;
100 device_offset=offset+group_info.group_num*sizeof (struct ext2_group_desc);
101
102 sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
103 strcpy (buffer,"show");dispatch (buffer);
104}
105
106
107void type_ext2_group_desc___show (char *command_line)
108
109{
110 long group_num,temp;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400111
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400112 temp=(device_offset-file_system_info.first_group_desc_offset) % (file_system_info.super_block.s_blocks_per_group*file_system_info.block_size);
113 group_num=temp/sizeof (struct ext2_group_desc);
114
115 show (command_line);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400116
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400117 wmove (show_win,1,0);wprintw (show_win,"\n");wmove (show_win,2,0);
118 wprintw (show_win,"Group %ld of %ld ",group_num,file_system_info.groups_count-1);
119 wprintw (show_win,"in copy %ld ",group_info.copy_num);
120 if (group_info.copy_num==0) wprintw (show_win,"(Main copy)");
121 wprintw (show_win,"\n");refresh_show_win ();
122
123 if (group_num==0) {
124 wprintw (command_win,"Reached first group descriptor\n");
125 wrefresh (command_win);
126 }
127
128 if (group_num==file_system_info.groups_count-1) {
129 wprintw (command_win,"Reached last group descriptor\n");
130 wrefresh (command_win);
131 }
132}
133
134void type_ext2_group_desc___inode (char *command_line)
135
136{
137 long inode_offset;
138 char buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400139
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400140 inode_offset=type_data.u.t_ext2_group_desc.bg_inode_table;
141 sprintf (buffer,"setoffset block %ld",inode_offset);dispatch (buffer);
142 sprintf (buffer,"settype ext2_inode");dispatch (buffer);
143}
144
145void type_ext2_group_desc___blockbitmap (char *command_line)
146
147{
148 long block_bitmap_offset;
149 char buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400150
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400151 block_bitmap_info.entry_num=0;
152 block_bitmap_info.group_num=group_info.group_num;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400153
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400154 block_bitmap_offset=type_data.u.t_ext2_group_desc.bg_block_bitmap;
155 sprintf (buffer,"setoffset block %ld",block_bitmap_offset);dispatch (buffer);
156 sprintf (buffer,"settype block_bitmap");dispatch (buffer);
157}
158
159void type_ext2_group_desc___inodebitmap (char *command_line)
160
161{
162 long inode_bitmap_offset;
163 char buffer [80];
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400164
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400165 inode_bitmap_info.entry_num=0;
166 inode_bitmap_info.group_num=group_info.group_num;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400167
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400168 inode_bitmap_offset=type_data.u.t_ext2_group_desc.bg_inode_bitmap;
169 sprintf (buffer,"setoffset block %ld",inode_bitmap_offset);dispatch (buffer);
170 sprintf (buffer,"settype inode_bitmap");dispatch (buffer);
171}
172
173void type_ext2_group_desc___setactivecopy (char *command_line)
174
175{
176 struct ext2_group_desc gd;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400177
Theodore Ts'o583a1ce2002-05-11 13:00:22 -0400178 gd=type_data.u.t_ext2_group_desc;
179 dispatch ("gocopy 0");
180 type_data.u.t_ext2_group_desc=gd;
181 dispatch ("show");
182}