summaryrefslogtreecommitdiff
path: root/ext2ed/group_com.c
blob: aaed16e474a03bfc6f638d1ecbc9e84de2cb3b20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*

/usr/src/ext2ed/group_com.c

A part of the extended file system 2 disk editor.

General user commands

First written on: April 17 1995

Copyright (C) 1995 Gadi Oxman

*/

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ext2ed.h"

void type_ext2_group_desc___next (char *command_line)

{
	long entry_offset=1;
	char *ptr,buffer [80];

	ptr=parse_word (command_line,buffer);
	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		entry_offset=atol (buffer);
	}

	sprintf (buffer,"entry %ld",group_info.group_num+entry_offset);
	dispatch (buffer);
}

void type_ext2_group_desc___prev (char *command_line)

{
	long entry_offset=1;
	char *ptr,buffer [80];

	ptr=parse_word (command_line,buffer);
	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		entry_offset=atol (buffer);
	}

	sprintf (buffer,"entry %ld",group_info.group_num-entry_offset);
	dispatch (buffer);
}

void type_ext2_group_desc___entry (char *command_line)

{
	long group_num;
	char *ptr,buffer [80];

	ptr=parse_word (command_line,buffer);
	if (*ptr==0) {
		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
	}
	ptr=parse_word (ptr,buffer);

	group_num=atol (buffer);

	if (group_num < 0 || group_num >= file_system_info.groups_count) {
		wprintw (command_win,"Error - Entry number out of bounds\n");refresh_command_win ();return;
	}

	device_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc);

	sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
	strcpy (buffer,"show");dispatch (buffer);
	group_info.group_num=group_num;
}


void type_ext2_group_desc___gocopy (char *command_line)

{
	unsigned long copy_num,offset;
	char *ptr,buffer [80];

	ptr=parse_word (command_line,buffer);
	if (*ptr==0) {
		wprintw (command_win,"Error - No argument specified\n");refresh_command_win ();return;
	}
	ptr=parse_word (ptr,buffer);

	copy_num=atol (buffer);

	offset=file_system_info.first_group_desc_offset+copy_num*file_system_info.super_block.s_blocks_per_group*file_system_info.block_size;

	if (offset > file_system_info.file_system_size) {
		wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
	}

	group_info.copy_num=copy_num;
	device_offset=offset+group_info.group_num*sizeof (struct ext2_group_desc);

	sprintf (buffer,"setoffset %ld",device_offset);dispatch (buffer);
	strcpy (buffer,"show");dispatch (buffer);
}


void type_ext2_group_desc___show (char *command_line)

{
	long group_num,temp;

	temp=(device_offset-file_system_info.first_group_desc_offset) % (file_system_info.super_block.s_blocks_per_group*file_system_info.block_size);
	group_num=temp/sizeof (struct ext2_group_desc);

	show (command_line);

	wmove (show_win,1,0);wprintw (show_win,"\n");wmove (show_win,2,0);
	wprintw (show_win,"Group %ld of %ld ",group_num,file_system_info.groups_count-1);
	wprintw (show_win,"in copy %ld ",group_info.copy_num);
	if (group_info.copy_num==0) wprintw (show_win,"(Main copy)");
	wprintw (show_win,"\n");refresh_show_win ();

	if (group_num==0) {
		wprintw (command_win,"Reached first group descriptor\n");
		wrefresh (command_win);
	}

	if (group_num==file_system_info.groups_count-1) {
		wprintw (command_win,"Reached last group descriptor\n");
		wrefresh (command_win);
	}
}

void type_ext2_group_desc___inode (char *command_line)

{
	long inode_offset;
	char buffer [80];

	inode_offset=type_data.u.t_ext2_group_desc.bg_inode_table;
	sprintf (buffer,"setoffset block %ld",inode_offset);dispatch (buffer);
	sprintf (buffer,"settype ext2_inode");dispatch (buffer);
}

void type_ext2_group_desc___blockbitmap (char *command_line)

{
	long block_bitmap_offset;
	char buffer [80];

	block_bitmap_info.entry_num=0;
	block_bitmap_info.group_num=group_info.group_num;

	block_bitmap_offset=type_data.u.t_ext2_group_desc.bg_block_bitmap;
	sprintf (buffer,"setoffset block %ld",block_bitmap_offset);dispatch (buffer);
	sprintf (buffer,"settype block_bitmap");dispatch (buffer);
}

void type_ext2_group_desc___inodebitmap (char *command_line)

{
	long inode_bitmap_offset;
	char buffer [80];

	inode_bitmap_info.entry_num=0;
	inode_bitmap_info.group_num=group_info.group_num;

	inode_bitmap_offset=type_data.u.t_ext2_group_desc.bg_inode_bitmap;
	sprintf (buffer,"setoffset block %ld",inode_bitmap_offset);dispatch (buffer);
	sprintf (buffer,"settype inode_bitmap");dispatch (buffer);
}

void type_ext2_group_desc___setactivecopy (char *command_line)

{
	struct ext2_group_desc gd;

	gd=type_data.u.t_ext2_group_desc;
	dispatch ("gocopy 0");
	type_data.u.t_ext2_group_desc=gd;
	dispatch ("show");
}