void detailed_help (char *text) { int i; if (current_type != NULL) for (i=0;i<=current_type->type_commands.last_command;i++) { if (strcmp (current_type->type_commands.names [i],text)==0) { wprintw (show_pad,"%s - %s\n",text,current_type->type_commands.descriptions [i]); refresh_show_pad ();return; } } for (i=0;i<=ext2_commands.last_command;i++) { if (strcmp (ext2_commands.names [i],text)==0) { wprintw (show_pad,"%s - %s\n",text,ext2_commands.descriptions [i]); refresh_show_pad ();return; } } for (i=0;i<=general_commands.last_command;i++) { if (strcmp (general_commands.names [i],text)==0) { wprintw (show_pad,"%s - %s\n",text,general_commands.descriptions [i]); refresh_show_pad ();return; } } if (strcmp ("quit",text)==0) { wprintw (show_pad,"quit - Exists EXT2ED"); refresh_show_pad ();return; } wprintw (show_pad,"Error - Command %s not aviable now\n",text); refresh_show_pad ();return; }
void type_dir___show (char *command_line) { int status; wmove (show_pad,0,0); show_pad_info.max_line=-1; search_dir_entries (&action_show,&status); show_pad_info.line=file_info.dir_entry_num-show_pad_info.display_lines/2; refresh_show_pad (); show_dir_status (); }
void redraw_all (void) { int min_lines = TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3; struct winsize ws; int save_col, save_lines; /* get the size of the terminal connected to stdout */ ioctl(1, TIOCGWINSZ, &ws); /* * Do it again because GDB doesn't stop before the first ioctl * call, we want an up-to-date size when we're * single-stepping. */ if (ioctl(1, TIOCGWINSZ, &ws) == 0) { if (ws.ws_row < min_lines) ws.ws_row = min_lines; if ((ws.ws_row != LINES) || (ws.ws_col != COLS)) { wmove (show_win,2,COLS-18); wclrtoeol(show_win); wrefresh(show_win); resizeterm(ws.ws_row, ws.ws_col); wresize(title_win, TITLE_WIN_LINES,COLS); wresize(show_win, SHOW_WIN_LINES,COLS); wresize(command_win, COMMAND_WIN_LINES,COLS); wresize(mt_win1, 1,COLS); wresize(mt_win2, 1,COLS); mvwin(mt_win2, LINES-COMMAND_WIN_LINES-1,0); mvwin(command_win, LINES-COMMAND_WIN_LINES,0); draw_title_win(); show_pad_info.display_lines=LINES-TITLE_WIN_LINES-SHOW_WIN_LINES-COMMAND_WIN_LINES-2; show_pad_info.display_cols=COLS; } } clearok(title_win, 1); clearok(show_win, 1); clearok(command_win, 1); clearok(mt_win1, 1); clearok(mt_win2, 1); wrefresh(mt_win1); wrefresh(mt_win2); refresh_show_pad(); refresh_show_win(); refresh_title_win (); refresh_command_win (); }
void type_dir___show (char *command_line) /* We use search_dir_entries to run on all the entries. Each time, action_show will be called to show one entry. */ { int status; wmove (show_pad,0,0); show_pad_info.max_line=-1; search_dir_entries (&action_show,&status); show_pad_info.line=file_info.dir_entry_num-show_pad_info.display_lines/2; refresh_show_pad (); show_dir_status (); }
void init_windows (void) { initscr (); tcgetattr(0,&termioInit); /* save initial config */ termioCurrent = termioInit; termioCurrent.c_lflag |= ECHO; /* set echo on */ tcsetattr(0,TCSANOW,&termioCurrent); if (LINES<TITLE_WIN_LINES+SHOW_WIN_LINES+COMMAND_WIN_LINES+3) { printf ("Sorry, your terminal screen is too small\n"); printf ("Error - Can not initialize windows\n"); exit (1); } title_win=newwin (TITLE_WIN_LINES,COLS,0,0); show_win=newwin (SHOW_WIN_LINES,COLS,TITLE_WIN_LINES,0); show_pad=newpad (SHOW_PAD_LINES,SHOW_PAD_COLS); mt_win1=newwin (1,COLS,TITLE_WIN_LINES+SHOW_WIN_LINES,0); mt_win2=newwin (1,COLS,LINES-COMMAND_WIN_LINES-1,0); command_win=newwin (COMMAND_WIN_LINES,COLS,LINES-COMMAND_WIN_LINES,0); if (title_win==NULL || show_win==NULL || show_pad==NULL || command_win==NULL) { printf ("Error - Not enough memory - Can not initialize windows\n");exit (1); } draw_title_win(); setup_show_win(); scrollok (command_win,TRUE); refresh_title_win (); refresh_show_win (); refresh_show_pad(); refresh_command_win (); wrefresh(mt_win1); wrefresh(mt_win2); }
void file_show_text (void) { long offset=0,last_offset,l=0,cols=0; unsigned char *ch_ptr; /* device_offset and type_data points to the inode */ show_pad_info.line=0; wmove (show_pad,0,0); ch_ptr=file_info.buffer; last_offset=file_system_info.block_size-1; if (file_info.file_offset+last_offset > file_info.file_length-1) last_offset=file_info.file_length-1-file_info.file_offset; while ( (offset <= last_offset) && l<SHOW_PAD_LINES) { if (cols==SHOW_PAD_COLS-1) { wprintw (show_pad,"\n"); l++;cols=0; } if (file_info.offset_in_block==offset) wattrset (show_pad,A_REVERSE); if (*ch_ptr >= ' ' && *ch_ptr <= 'z') wprintw (show_pad,"%c",*ch_ptr); else { if (*ch_ptr == 0xa) { wprintw (show_pad,"\n"); l++;cols=0; } else if (*ch_ptr == 0x9) wprintw (show_pad," "); else wprintw (show_pad,"."); } if (file_info.offset_in_block==offset) { wattrset (show_pad,A_NORMAL); show_pad_info.line=l-l % show_pad_info.display_lines; } offset++;cols++;ch_ptr++; } wprintw (show_pad,"\n"); show_pad_info.max_line=l; refresh_show_pad (); show_status (); }
void file_show_hex (void) { long offset=0,l,i; unsigned char *ch_ptr; /* device_offset and type_data points to the inode */ show_pad_info.line=0; wmove (show_pad,0,0); ch_ptr=file_info.buffer; for (l=0;l<file_system_info.block_size/16;l++) { if (file_info.file_offset+offset>file_info.file_length-1) break; wprintw (show_pad,"%08ld : ",offset); for (i=0;i<16;i++) { if (file_info.file_offset+offset+i>file_info.file_length-1) { wprintw (show_pad," "); } else { if (file_info.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); if (ch_ptr [i]>=' ' && ch_ptr [i]<='z') wprintw (show_pad,"%c",ch_ptr [i]); else wprintw (show_pad,"."); if (file_info.offset_in_block==offset+i) wattrset (show_pad,A_NORMAL); } } wprintw (show_pad," "); for (i=0;i<16;i++) { if (file_info.file_offset+offset+i>file_info.file_length-1) break; if (file_info.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); wprintw (show_pad,"%02x",ch_ptr [i]); if (file_info.offset_in_block==offset+i) { wattrset (show_pad,A_NORMAL); show_pad_info.line=l-l % show_pad_info.display_lines; } wprintw (show_pad," "); } wprintw (show_pad,"\n"); offset+=i; ch_ptr+=i; } show_pad_info.max_line=l-1; refresh_show_pad (); show_status (); }
void help (char *command_line) { int i,max_line=0; char argument [80],*ptr; werase (show_pad);wmove (show_pad,0,0); ptr=parse_word (command_line,argument); if (*ptr!=0) { ptr=parse_word (ptr,argument); if (*argument!=0) { detailed_help (argument); return; } } if (current_type!=NULL) { wprintw (show_pad,"Type %s specific commands:\n",current_type->name);max_line++; if (current_type->type_commands.last_command==-1) { wprintw (show_pad,"\nnone\n");max_line+=2; } else for (i=0;i<=current_type->type_commands.last_command;i++) { if (i%5==0) { wprintw (show_pad,"\n");max_line++; } wprintw (show_pad,"%-13s",current_type->type_commands.names [i]); if (i%5!=4) wprintw (show_pad,"; "); } wprintw (show_pad,"\n\n");max_line+=2; } if (ext2_commands.last_command != -1) { wprintw (show_pad,"ext2 filesystem general commands: \n");max_line++; for (i=0;i<=ext2_commands.last_command;i++) { if (i%5==0) { wprintw (show_pad,"\n");max_line++; } wprintw (show_pad,"%-13s",ext2_commands.names [i]); if (i%5!=4) wprintw (show_pad,"; "); } wprintw (show_pad,"\n\n");max_line+=2; } wprintw (show_pad,"General commands: \n"); for (i=0;i<=general_commands.last_command;i++) { if (i%5==0) { wprintw (show_pad,"\n");max_line++; } wprintw (show_pad,"%-13s",general_commands.names [i]); if (i%5!=4) wprintw (show_pad,"; "); } wprintw (show_pad,"\n\n");max_line+=2; wprintw (show_pad,"EXT2ED ver %s (%s)\n",E2FSPROGS_VERSION, E2FSPROGS_DATE); wprintw (show_pad,"Copyright (C) 1995 Gadi Oxman\n"); wprintw (show_pad,"Reviewed 2001 Christian Bac\n"); wprintw (show_pad,"Modified and enchanced by Theodore Ts'o, 2002\n"); wprintw (show_pad,"EXT2ED is hereby placed under the terms of the GNU General Public License.\n\n"); wprintw (show_pad,"EXT2ED was programmed as a student project in the software laboratory\n"); wprintw (show_pad,"of the faculty of electrical engineering in the\n"); wprintw (show_pad,"Technion - Israel Institute of Technology\n"); wprintw (show_pad,"with the guide of Avner Lottem and Dr. Ilana David.\n"); max_line+=10; show_pad_info.line=0;show_pad_info.max_line=max_line; werase (show_win);wmove (show_win,0,0); wprintw (show_win,"EXT2ED help"); refresh_show_win (); refresh_show_pad (); }
void pgup (char *command_line) { show_pad_info.line-=show_pad_info.display_lines; refresh_show_pad ();refresh_show_win (); }
void pgdn (char *commnad_line) { show_pad_info.line+=show_pad_info.display_lines; refresh_show_pad ();refresh_show_win (); }
void show (char *command_line) { unsigned int i,l,len,temp_int; unsigned long offset=0,temp_long; unsigned char temp_char,*ch_ptr; void *ptr; if (device_handle==NULL) return; show_pad_info.line=0; if (current_type==NULL) { wmove (show_pad,0,0); ch_ptr=type_data.u.buffer; for (l=0;l<file_system_info.block_size/16;l++) { wprintw (show_pad,"%08ld : ",offset); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); if (ch_ptr [i]>=' ' && ch_ptr [i]<='z') wprintw (show_pad,"%c",ch_ptr [i]); else wprintw (show_pad,"."); if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_NORMAL); } wprintw (show_pad," "); for (i=0;i<16;i++) { if (type_data.offset_in_block==offset+i) wattrset (show_pad,A_REVERSE); wprintw (show_pad,"%02x",ch_ptr [i]); if (type_data.offset_in_block==offset+i) { wattrset (show_pad,A_NORMAL); show_pad_info.line=l-l % show_pad_info.display_lines; } wprintw (show_pad," "); } wprintw (show_pad,"\n"); offset+=16; ch_ptr+=16; } show_pad_info.max_line=l-1;show_pad_info.max_col=COLS-1; refresh_show_pad ();show_info (); } else { wmove (show_pad,0,0);l=0; for (i=0;i<current_type->fields_num;i++) { wprintw (show_pad,"%-20s = ",current_type->field_names [i]); ptr=type_data.u.buffer+offset; len = current_type->field_lengths[i]; switch (current_type->field_types[i]) { case FIELD_TYPE_INT: show_int(len, ptr); break; case FIELD_TYPE_UINT: show_uint(len, ptr); break; case FIELD_TYPE_CHAR: show_char(len, ptr); break; default: wprintw (show_pad, "unimplemented\n"); break; } offset+=len; l++; } current_type->length=offset; show_pad_info.max_line=l-1; refresh_show_pad ();show_info (); } }
void type_ext2_inode___show (char *command_line) { struct ext2_inode *inode_ptr; unsigned short temp; int i; long group_num,group_offset,entry_num,block_num,first_entry,last_entry,inode_num; struct ext2_group_desc desc; block_num=device_offset/file_system_info.block_size; group_num=inode_offset_to_group_num (device_offset); group_offset=file_system_info.first_group_desc_offset+group_num*sizeof (struct ext2_group_desc); low_read ((char *) &desc,sizeof (struct ext2_group_desc),group_offset); entry_num=(device_offset-desc.bg_inode_table*file_system_info.block_size)/sizeof (struct ext2_inode); first_entry=0;last_entry=file_system_info.super_block.s_inodes_per_group-1; inode_num=group_num*file_system_info.super_block.s_inodes_per_group+1; inode_num+=entry_num; inode_ptr=&type_data.u.t_ext2_inode; show (command_line); wmove (show_pad,0,40);wprintw (show_pad,"octal = %06o ",inode_ptr->i_mode); for (i=6;i>=0;i-=3) { temp=inode_ptr->i_mode & 0x1ff; temp=temp >> i; if (temp & 4) wprintw (show_pad,"r"); else wprintw (show_pad,"-"); if (temp & 2) wprintw (show_pad,"w"); else wprintw (show_pad,"-"); if (temp & 1) wprintw (show_pad,"x"); else wprintw (show_pad,"-"); } wmove (show_pad,3,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_atime)); wmove (show_pad,4,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_ctime)); wmove (show_pad,5,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_mtime)); wmove (show_pad,6,40);wprintw (show_pad,"%s",ctime ((time_t *) &type_data.u.t_ext2_inode.i_dtime)); wmove (show_pad,10,40); temp=inode_ptr->i_flags; if (temp & EXT2_SECRM_FL) wprintw (show_pad,"s"); else wprintw (show_pad,"-"); if (temp & EXT2_UNRM_FL) wprintw (show_pad,"u"); else wprintw (show_pad,"-"); if (temp & EXT2_COMPR_FL) wprintw (show_pad,"c"); else wprintw (show_pad,"-"); if (temp & EXT2_SYNC_FL) wprintw (show_pad,"S"); else wprintw (show_pad,"-"); if (temp & EXT2_IMMUTABLE_FL) wprintw (show_pad,"i"); else wprintw (show_pad,"-"); if (temp & EXT2_APPEND_FL) wprintw (show_pad,"a"); else wprintw (show_pad,"-"); if (temp & EXT2_NODUMP_FL) wprintw (show_pad,"d"); else wprintw (show_pad,"-"); refresh_show_pad (); wmove (show_win,1,0); wprintw (show_win,"Inode %ld of %ld. Entry %ld of %ld in group descriptor %ld.\n" ,inode_num,file_system_info.super_block.s_inodes_count,entry_num,last_entry,group_num); wprintw (show_win,"Inode type: "); if (inode_num < EXT2_GOOD_OLD_FIRST_INO) { switch (inode_num) { case EXT2_BAD_INO: wprintw (show_win,"Bad blocks inode - "); break; case EXT2_ROOT_INO: wprintw (show_win,"Root inode - "); break; case EXT2_ACL_IDX_INO: wprintw (show_win,"ACL index inode - "); break; case EXT2_ACL_DATA_INO: wprintw (show_win,"ACL data inode - "); break; case EXT2_BOOT_LOADER_INO: wprintw (show_win,"Boot loader inode - "); break; case EXT2_UNDEL_DIR_INO: wprintw (show_win,"Undelete directory inode - "); break; default: wprintw (show_win,"Reserved inode - "); break; } } if (type_data.u.t_ext2_inode.i_mode==0) wprintw (show_win,"Free. "); if (S_ISREG (type_data.u.t_ext2_inode.i_mode)) wprintw (show_win,"File. "); if (S_ISDIR (type_data.u.t_ext2_inode.i_mode)) wprintw (show_win,"Directory. "); if (S_ISLNK (type_data.u.t_ext2_inode.i_mode)) { wprintw (show_win,"Symbolic link. "); wmove (show_pad,12,40); if (inode_ptr->i_size <= 60) wprintw (show_pad,"-> %s",(char *) &type_data.u.t_ext2_inode.i_block [0]); else wprintw (show_pad,"Slow symbolic link\n"); refresh_show_pad (); } if (S_ISCHR (type_data.u.t_ext2_inode.i_mode)) wprintw (show_win,"Character device."); if (S_ISBLK (type_data.u.t_ext2_inode.i_mode)) wprintw (show_win,"Block device. "); wprintw (show_win,"\n");refresh_show_win (); if (entry_num==last_entry) { wprintw (command_win,"Reached last inode in current group descriptor\n"); refresh_command_win (); } if (entry_num==first_entry) { wprintw (command_win,"Reached first inode in current group descriptor\n"); refresh_command_win (); } }
void type_ext2_block_bitmap___show (char *command_line) /* We show the bitmap as a series of bits, grouped at 8-bit intervals. We display 8 such groups on each line. The current position (as known from block_bitmap_info.entry_num) is highlighted. */ { int i,j; unsigned char *ptr; unsigned long block_num,entry_num; ptr=type_data.u.buffer; show_pad_info.line=0;show_pad_info.max_line=-1; wmove (show_pad,0,0); for (i=0,entry_num=0;i<file_system_info.super_block.s_blocks_per_group/8;i++,ptr++) { for (j=1;j<=128;j*=2) { /* j contains the and bit mask */ if (entry_num==block_bitmap_info.entry_num) { /* Highlight the current entry */ wattrset (show_pad,A_REVERSE); show_pad_info.line=show_pad_info.max_line-show_pad_info.display_lines/2; } if ((*ptr) & j) /* Apply the mask */ wprintw (show_pad,"1"); else wprintw (show_pad,"0"); if (entry_num==block_bitmap_info.entry_num) wattrset (show_pad,A_NORMAL); entry_num++; /* Pass to the next entry */ } wprintw (show_pad," "); if (i%8==7) { /* Display 8 groups in a row */ wprintw (show_pad,"\n"); show_pad_info.max_line++; } } refresh_show_pad (); show_info (); /* Show the usual information */ /* Show the group number */ wmove (show_win,1,0); wprintw (show_win,"Block bitmap of block group %ld\n",block_bitmap_info.group_num); /* Show the block number */ block_num=block_bitmap_info.entry_num+block_bitmap_info.group_num*file_system_info.super_block.s_blocks_per_group; block_num+=file_system_info.super_block.s_first_data_block; wprintw (show_win,"Status of block %ld - ",block_num); /* and the allocation status */ ptr=type_data.u.buffer+block_bitmap_info.entry_num/8; j=1; for (i=block_bitmap_info.entry_num % 8;i>0;i--) j*=2; if ((*ptr) & j) wprintw (show_win,"Allocated\n"); else wprintw (show_win,"Free\n"); refresh_show_win (); }
void type_dir___set (char *command_line) { int found=0; unsigned char *ptr,buffer [80],variable [80],value [80],temp [80]; struct ext2_dir_entry_2 *dir_entry_ptr; dir_entry_ptr=(struct ext2_dir_entry_2 *) (file_info.buffer+file_info.dir_entry_offset); ptr=parse_word (command_line,buffer); if (*ptr==0) { wprintw (command_win,"Error - Missing arguments\n");refresh_command_win (); return; } parse_word (ptr,buffer); ptr=strchr (buffer,'='); if (ptr==NULL) { wprintw (command_win,"Error - Bad syntax\n");refresh_command_win ();return; } strncpy (variable,buffer,ptr-buffer);variable [ptr-buffer]=0; strcpy (value,++ptr); if (strcasecmp ("inode",variable)==0) { found=1; dir_entry_ptr->inode=atol (value); wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->inode);refresh_command_win (); } if (strcasecmp ("rec_len",variable)==0) { found=1; dir_entry_ptr->rec_len=(unsigned int) atol (value); wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->rec_len);refresh_command_win (); } if (strcasecmp ("name_len",variable)==0) { found=1; dir_entry_ptr->name_len=(unsigned int) atol (value); wprintw (command_win,"Variable %s set to %lu\n",variable,dir_entry_ptr->name_len);refresh_command_win (); } if (strcasecmp ("name",variable)==0) { found=1; if (strlen (value) > dir_entry_ptr->name_len) { wprintw (command_win,"Error - Length of name greater then name_len\n"); refresh_command_win ();return; } strncpy (dir_entry_ptr->name,value,strlen (value)); wprintw (command_win,"Variable %s set to %s\n",variable,value);refresh_command_win (); } if (found) { wattrset (show_pad,A_REVERSE); strncpy (temp,dir_entry_ptr->name,dir_entry_ptr->name_len); temp [dir_entry_ptr->name_len]=0; wmove (show_pad,file_info.dir_entry_num,0); wprintw (show_pad,"inode = %-8lu rec_len = %-4lu name_len = %-3lu name = %s\n", dir_entry_ptr->inode,dir_entry_ptr->rec_len,dir_entry_ptr->name_len,temp); wattrset (show_pad,A_NORMAL); show_pad_info.line=file_info.dir_entry_num-show_pad_info.display_lines/2; refresh_show_pad (); show_dir_status (); } else { wprintw (command_win,"Error - Variable %s not found\n",variable); refresh_command_win (); } }