• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 
3 /usr/src/ext2ed/group_com.c
4 
5 A part of the extended file system 2 disk editor.
6 
7 General user commands
8 
9 First written on: April 17 1995
10 
11 Copyright (C) 1995 Gadi Oxman
12 
13 */
14 
15 #include "config.h"
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "ext2ed.h"
21 
type_ext2_group_desc___next(char * command_line)22 void type_ext2_group_desc___next (char *command_line)
23 
24 {
25 	long entry_offset=1;
26 	char *ptr,buffer [80];
27 
28 	ptr=parse_word (command_line,buffer);
29 	if (*ptr!=0) {
30 		ptr=parse_word (ptr,buffer);
31 		entry_offset=atol (buffer);
32 	}
33 
34 	sprintf (buffer,"entry %ld",group_info.group_num+entry_offset);
35 	dispatch (buffer);
36 }
37 
type_ext2_group_desc___prev(char * command_line)38 void type_ext2_group_desc___prev (char *command_line)
39 
40 {
41 	long entry_offset=1;
42 	char *ptr,buffer [80];
43 
44 	ptr=parse_word (command_line,buffer);
45 	if (*ptr!=0) {
46 		ptr=parse_word (ptr,buffer);
47 		entry_offset=atol (buffer);
48 	}
49 
50 	sprintf (buffer,"entry %ld",group_info.group_num-entry_offset);
51 	dispatch (buffer);
52 }
53 
type_ext2_group_desc___entry(char * command_line)54 void type_ext2_group_desc___entry (char *command_line)
55 
56 {
57 	long group_num;
58 	char *ptr,buffer [80];
59 
60 	ptr=parse_word (command_line,buffer);
61 	if (*ptr==0) {
62 		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
63 	}
64 	ptr=parse_word (ptr,buffer);
65 
66 	group_num=atol (buffer);
67 
68 	if (group_num < 0 || group_num >= file_system_info.groups_count) {
69 		wprintw (command_win,"Error - Entry number out of bounds\n");refresh_command_win ();return;
70 	}
71 
72 	device_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);
73 
74 	sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
75 	strcpy (buffer,"show");dispatch (buffer);
76 	group_info.group_num=group_num;
77 }
78 
79 
type_ext2_group_desc___gocopy(char * command_line)80 void type_ext2_group_desc___gocopy (char *command_line)
81 
82 {
83 	unsigned long copy_num,offset;
84 	char *ptr,buffer [80];
85 
86 	ptr=parse_word (command_line,buffer);
87 	if (*ptr==0) {
88 		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
89 	}
90 	ptr=parse_word (ptr,buffer);
91 
92 	copy_num=atol (buffer);
93 
94 	offset=file_system_info.first_group_desc_offset+copy_num*file_system_info.super_block.s_blocks_per_group*file_system_info.block_size;
95 
96 	if (offset > file_system_info.file_system_size) {
97 		wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
98 	}
99 
100 	group_info.copy_num=copy_num;
101 	device_offset=offset+group_info.group_num*sizeof (struct ext2_group_desc);
102 
103 	sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
104 	strcpy (buffer,"show");dispatch (buffer);
105 }
106 
107 
type_ext2_group_desc___show(char * command_line)108 void type_ext2_group_desc___show (char *command_line)
109 
110 {
111 	long group_num,temp;
112 
113 	temp=(device_offset-file_system_info.first_group_desc_offset) % (file_system_info.super_block.s_blocks_per_group*file_system_info.block_size);
114 	group_num=temp/sizeof (struct ext2_group_desc);
115 
116 	show (command_line);
117 
118 	wmove (show_win,1,0);wprintw (show_win,"\n");wmove (show_win,2,0);
119 	wprintw (show_win,"Group %ld of %ld ",group_num,file_system_info.groups_count-1);
120 	wprintw (show_win,"in copy %ld ",group_info.copy_num);
121 	if (group_info.copy_num==0) wprintw (show_win,"(Main copy)");
122 	wprintw (show_win,"\n");refresh_show_win ();
123 
124 	if (group_num==0) {
125 		wprintw (command_win,"Reached first group descriptor\n");
126 		wrefresh (command_win);
127 	}
128 
129 	if (group_num==file_system_info.groups_count-1) {
130 		wprintw (command_win,"Reached last group descriptor\n");
131 		wrefresh (command_win);
132 	}
133 }
134 
type_ext2_group_desc___inode(char * command_line)135 void type_ext2_group_desc___inode (char *command_line)
136 
137 {
138 	long inode_offset;
139 	char buffer [80];
140 
141 	inode_offset=type_data.u.t_ext2_group_desc.bg_inode_table;
142 	sprintf (buffer,"setoffset block %ld",inode_offset);dispatch (buffer);
143 	sprintf (buffer,"settype ext2_inode");dispatch (buffer);
144 }
145 
type_ext2_group_desc___blockbitmap(char * command_line)146 void type_ext2_group_desc___blockbitmap (char *command_line)
147 
148 {
149 	long block_bitmap_offset;
150 	char buffer [80];
151 
152 	block_bitmap_info.entry_num=0;
153 	block_bitmap_info.group_num=group_info.group_num;
154 
155 	block_bitmap_offset=type_data.u.t_ext2_group_desc.bg_block_bitmap;
156 	sprintf (buffer,"setoffset block %ld",block_bitmap_offset);dispatch (buffer);
157 	sprintf (buffer,"settype block_bitmap");dispatch (buffer);
158 }
159 
type_ext2_group_desc___inodebitmap(char * command_line)160 void type_ext2_group_desc___inodebitmap (char *command_line)
161 
162 {
163 	long inode_bitmap_offset;
164 	char buffer [80];
165 
166 	inode_bitmap_info.entry_num=0;
167 	inode_bitmap_info.group_num=group_info.group_num;
168 
169 	inode_bitmap_offset=type_data.u.t_ext2_group_desc.bg_inode_bitmap;
170 	sprintf (buffer,"setoffset block %ld",inode_bitmap_offset);dispatch (buffer);
171 	sprintf (buffer,"settype inode_bitmap");dispatch (buffer);
172 }
173 
type_ext2_group_desc___setactivecopy(char * command_line)174 void type_ext2_group_desc___setactivecopy (char *command_line)
175 
176 {
177 	struct ext2_group_desc gd;
178 
179 	gd=type_data.u.t_ext2_group_desc;
180 	dispatch ("gocopy 0");
181 	type_data.u.t_ext2_group_desc=gd;
182 	dispatch ("show");
183 }
184