Home | History | Annotate | Download | only in ext2ed
      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 <stdio.h>
     16 #include <stdlib.h>
     17 #include <string.h>
     18 
     19 #include "ext2ed.h"
     20 
     21 void type_ext2_group_desc___next (char *command_line)
     22 
     23 {
     24 	long entry_offset=1;
     25 	char *ptr,buffer [80];
     26 
     27 	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 
     37 void type_ext2_group_desc___prev (char *command_line)
     38 
     39 {
     40 	long entry_offset=1;
     41 	char *ptr,buffer [80];
     42 
     43 	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 
     53 void type_ext2_group_desc___entry (char *command_line)
     54 
     55 {
     56 	long group_num;
     57 	char *ptr,buffer [80];
     58 
     59 	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);
     66 
     67 	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 	}
     70 
     71 	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 
     79 void type_ext2_group_desc___gocopy (char *command_line)
     80 
     81 {
     82 	unsigned long copy_num,offset;
     83 	char *ptr,buffer [80];
     84 
     85 	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);
     92 
     93 	offset=file_system_info.first_group_desc_offset+copy_num*file_system_info.super_block.s_blocks_per_group*file_system_info.block_size;
     94 
     95 	if (offset > file_system_info.file_system_size) {
     96 		wprintw (command_win,"Error - Copy number out of bounds\n");refresh_command_win ();return;
     97 	}
     98 
     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 
    107 void type_ext2_group_desc___show (char *command_line)
    108 
    109 {
    110 	long group_num,temp;
    111 
    112 	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);
    116 
    117 	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 
    134 void type_ext2_group_desc___inode (char *command_line)
    135 
    136 {
    137 	long inode_offset;
    138 	char buffer [80];
    139 
    140 	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 
    145 void type_ext2_group_desc___blockbitmap (char *command_line)
    146 
    147 {
    148 	long block_bitmap_offset;
    149 	char buffer [80];
    150 
    151 	block_bitmap_info.entry_num=0;
    152 	block_bitmap_info.group_num=group_info.group_num;
    153 
    154 	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 
    159 void type_ext2_group_desc___inodebitmap (char *command_line)
    160 
    161 {
    162 	long inode_bitmap_offset;
    163 	char buffer [80];
    164 
    165 	inode_bitmap_info.entry_num=0;
    166 	inode_bitmap_info.group_num=group_info.group_num;
    167 
    168 	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 
    173 void type_ext2_group_desc___setactivecopy (char *command_line)
    174 
    175 {
    176 	struct ext2_group_desc gd;
    177 
    178 	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 }
    183