Ejemplo n.º 1
0
void enable_write (char *command_line)

{
	FILE *fp;

	if (device_handle==NULL) {
		wprintw (command_win,"Error - No device opened\n");refresh_command_win ();
		return;
	}

	if (!AllowChanges) {
		wprintw (command_win,"Sorry, write access is not allowed\n");
    		return;
    	}
    	
    	if (mounted) {
    		wprintw (command_win,"Error - Filesystem is mounted\n");
		return;    		
    	}
    	
	if ( (fp=fopen (device_name,"r+b"))==NULL) {
		wprintw (command_win,"Error - Can not open device %s for reading and writing\n",device_name);refresh_command_win ();
		return;
	}
	fclose (device_handle);
	device_handle=fp;write_access=1;
	wprintw (command_win,"Write access enabled - Be careful\n");refresh_command_win ();
}
Ejemplo n.º 2
0
void type_file___offset (char *command_line)

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

	ptr=parse_word (command_line,buffer);

	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		offset=atol (buffer);
	}
	else {
		wprintw (command_win,"Error - Argument not specified\n");refresh_command_win ();
		return;
	}

	if (offset < file_system_info.block_size) {
		file_info.offset_in_block=offset;
		sprintf (buffer,"show");dispatch (buffer);
	}

	else {
		wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
	}
}
Ejemplo n.º 3
0
void type_ext2___cd (char *command_line)

/*

A global cd command - The path should start with /.

We implement it through dispatching to our primitive functions.

*/

{
	char temp [80],buffer [80],*ptr;

	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);

	if (buffer [0] != '/') {
		wprintw (command_win,"Error - Use a full pathname (begin with '/')\n");refresh_command_win ();return;
	}

	/* Note the various dispatches below - They should be intuitive if you know the ext2 filesystem structure */

	dispatch ("super");dispatch ("group");dispatch ("inode");dispatch ("next");dispatch ("dir");
	if (buffer [1] != 0) {
		sprintf (temp,"cd %s",buffer+1);dispatch (temp);
	}
}
Ejemplo n.º 4
0
int low_read (unsigned char *buffer,unsigned long length,unsigned long offset)


{

#ifdef DEBUG

	char temp [80];

	if (device_handle==NULL) {					/* Check that a device is indeed open */
		internal_error ("No device opened yet read requested","disk","low_read");
		return (0);
	}
	if (offset > file_system_info.file_system_size) {		/* Check that the offset is within limits */
		sprintf (temp,"Seek offset %ld is out of range",offset);
		internal_error (temp,"disk","low_read");
		return (0);
	}

#endif	

	if ( (fseek (device_handle,offset,SEEK_SET))==-1) {		/* Seek to the required offset */
		wprintw (command_win,"Error - Failed to seek to offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();
		return (0);
	};

	if ( (fread (buffer,1,length,device_handle))==-1) {		/* And do the actual reading */
		wprintw (command_win,"Error - Failed to read from offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();return (0);
	};
	
	return (1);
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
int log_changes (unsigned char *buffer,unsigned long length,unsigned long offset)

/*

Log the change in a primitive form - An hex dump of the data before the change and after the change.
The hex bytes are converted to text, so that they will be readable with a standard text editor.

*/

{
	unsigned char *original;

	int i;
	time_t current_time;
	FILE *fp;

	if ((fp=fopen (LogFile,"a+"))==NULL) {
		wprintw (command_win,"Error - Unable to open log file %s\n",LogFile);
		refresh_command_win ();return (0);
	};

	current_time=time (NULL);

	fprintf (fp,"\n----- EXT2ED log begin -----\n\n");
	fprintf (fp,"Time: %s\nDevice: %s\n",ctime ((time_t *) &current_time),device_name);
	fprintf (fp,"Offset: %lu\nLength: %lu\n",offset,length);

	original=(unsigned char *) malloc (length*sizeof (unsigned char));

	if (original==NULL) {
		wprintw (command_win,"Fatal error - Can\'t allocate %lu bytes!");
		refresh_command_win ();fclose (fp);return (0);
	}

	if (!low_read (original,length,offset)) {
		fclose (fp);return (0);
	}

	fprintf (fp,"\nOriginal data:\n\n");

	for (i=0;i<length;i++) {
		if (i%16==0 && i!=0) fprintf (fp,"\n");
		fprintf (fp,"%02x ",original [i]);
	}

	fprintf (fp,"\n\nNew data:\n\n");

	for (i=0;i<length;i++) {
		if (i%16==0 && i!=0) fprintf (fp,"\n");
		fprintf (fp,"%02x ",buffer [i]);
	}

	fprintf (fp,"\n----- EXT2ED log end  -----\n");

	fclose (fp);
	return (1);
}
Ejemplo n.º 7
0
int low_write (unsigned char *buffer,unsigned long length,unsigned long offset)

/*

This is used to change something in the filesystem.
write_access is checked to see if we are allowed to do the actual writing.
As a double safety measure, AllowChanges is rechecked here.
If logging is enabled, we log the change before writing it to the device.

*/
{
	char temp [80];

	if (!write_access) {
		wprintw (command_win,"Error - Write access not available (use enablewrite)\n");
		return (0);
	}

#ifdef DEBUG

	if (!AllowChanges) {
		internal_error ("AllowChanges=0 yet enablewrite succeeded","disk","low_write");
		return (0);
	}

	if (device_handle==NULL) {
		internal_error ("No device opened yet read requested","disk","low_write");
		return (0);
	}

	if (offset > file_system_info.file_system_size) {
		sprintf (temp,"Seek offset %ld is out of range",offset);
		internal_error (temp,"disk","low_write");
		return (0);
	}

#endif

	if (LogChanges)
		if (!log_changes (buffer,length,offset))
			return (0);

	if ( (fseek (device_handle,offset,SEEK_SET))==-1) {
		wprintw (command_win,"Error - Failed to seek to offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();return (0);
	};


	if ( (fwrite (buffer,1,length,device_handle))==-1) {
		wprintw (command_win,"Error - Failed to write to offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();return (0);
	};

	wprintw (command_win,"Data written");refresh_command_win ();
	return (1);
}
Ejemplo n.º 8
0
void set_device (char *command_line)

{
	char *ptr,new_device [80];
	
	ptr=parse_word (command_line,new_device);
	if (*ptr==0) {
		wprintw (command_win,"Error - Device name not specified\n");
		refresh_command_win ();return;
	}
	parse_word (ptr,new_device);	
	check_mounted (new_device);
	if (mounted && !AllowMountedRead) {
		wprintw (command_win,"Error - Filesystem is mounted, aborting\n");
		wprintw (command_win,"You may wish to use the AllowMountedRead on configuration option\n");
		refresh_command_win ();return;
	}
	
	if (mounted && AllowMountedRead) {
		wprintw (command_win,"Warning - Filesystem is mounted. Displayed data may be unreliable.\n");
		refresh_command_win ();
	}

	if (device_handle!=NULL)
		fclose (device_handle);
		
	if ( (device_handle=fopen (new_device,"rb"))==NULL) {
		wprintw (command_win,"Error - Can not open device %s\n",new_device);refresh_command_win ();
		return;
	}
	else {
		strcpy (device_name,new_device);
		write_access=0;				/* Write access disabled */
		current_type=NULL;			/* There is no type now */
		remember_lifo.entries_count=0;		/* Empty Object memory */
		free_user_commands (&ext2_commands);	/* Free filesystem specific objects */
		free_struct_descriptors ();
		if (!set_file_system_info ()) {		/* Error while getting info --> abort */
			free_user_commands (&ext2_commands);
			free_struct_descriptors ();
			fclose (device_handle);
			device_handle=NULL;		/* Notice that our device is still not set up */
			device_offset=-1;
			return;
		}
		if (*AlternateDescriptors)		/* Check if user defined objects exist */
			set_struct_descriptors (AlternateDescriptors);
		dispatch ("setoffset 0");
		dispatch ("help");			/* Show help screen */
		wprintw (command_win,"Device changed to %s",device_name);refresh_command_win ();
	}
}
Ejemplo n.º 9
0
int log_changes (unsigned char *buffer,unsigned long length,unsigned long offset)


{
	unsigned char *original;
	
	int i;
	time_t current_time;
	FILE *fp;
	
	if ((fp=fopen (LogFile,"a+"))==NULL) {
		wprintw (command_win,"Error - Unable to open log file %s\n",LogFile);
		refresh_command_win ();return (0);
	};

	current_time=time (NULL);
	
	fprintf (fp,"\n----- EXT2ED log begin -----\n\n");
	fprintf (fp,"Time: %s\nDevice: %s\n",ctime ((time_t *) &current_time),device_name);
	fprintf (fp,"Offset: %lu\nLength: %lu\n",offset,length);
	
	original=(unsigned char *) malloc (length*sizeof (unsigned char));

	if (original==NULL) {
		wprintw (command_win,"Fatal error - Can\'t allocate %lu bytes!");
		refresh_command_win ();fclose (fp);return (0);
	}
	
	if (!low_read (original,length,offset)) {
		fclose (fp);return (0);
	}

	fprintf (fp,"\nOriginal data:\n\n");

	for (i=0;i<length;i++) {
		if (i%16==0 && i!=0) fprintf (fp,"\n");
		fprintf (fp,"%02x ",original [i]);
	}
	
	fprintf (fp,"\n\nNew data:\n\n");	
	
	for (i=0;i<length;i++) {
		if (i%16==0 && i!=0) fprintf (fp,"\n");
		fprintf (fp,"%02x ",buffer [i]);
	}
	
	fprintf (fp,"\n----- EXT2ED log end  -----\n");

	fclose (fp);	
	return (1);
}
Ejemplo n.º 10
0
int low_write (unsigned char *buffer,unsigned long length,unsigned long offset)

{
	char temp [80];
	
	if (!write_access) {
		wprintw (command_win,"Error - Write access not aviable (use enablewrite)\n");
		return (0);
	}

#ifdef DEBUG

	if (!AllowChanges) {
		internal_error ("AllowChanges=0 yet enablewrite succeeded","disk","low_write");
		return (0);
	}
	
	if (device_handle==NULL) {
		internal_error ("No device opened yet read requested","disk","low_write");
		return (0);
	}

	if (offset > file_system_info.file_system_size) {
		sprintf (temp,"Seek offset %ld is out of range",offset);
		internal_error (temp,"disk","low_write");
		return (0);
	}

#endif	

	if (LogChanges)
		if (!log_changes (buffer,length,offset))
			return (0);

	if ( (fseek (device_handle,offset,SEEK_SET))==-1) {
		wprintw (command_win,"Error - Failed to seek to offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();return (0);
	};


	if ( (fwrite (buffer,1,length,device_handle))==-1) {
		wprintw (command_win,"Error - Failed to write to offset %ld in device %s\n",offset,device_name);
		refresh_command_win ();return (0);
	};

	wprintw (command_win,"Data written");refresh_command_win ();	
	return (1);
}
Ejemplo n.º 11
0
void type_ext2_block_bitmap___allocate (char *command_line)

/*

This function starts allocating block from the current position. Allocating involves setting the correct bits
in the bitmap. This function is a vector version of allocate_block below - We just run on the blocks that
we need to allocate, and call allocate_block for each one.

*/

{
	long entry_num,num=1;
	char *ptr,buffer [80];
	
	ptr=parse_word (command_line,buffer);					/* Get the number of blocks to allocate */
	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		num=atol (buffer);
	}
	
	entry_num=block_bitmap_info.entry_num;
										/* Check for limits */
	if (num > file_system_info.super_block.s_blocks_per_group-entry_num) {
		wprintw (command_win,"Error - There aren't that much blocks in the group\n");	
		refresh_command_win ();return;				
	}
	
	while (num) {								/* And call allocate_block */
		allocate_block (entry_num);					/* for each block */
		num--;entry_num++;
	}
	
	dispatch ("show");							/* Show the result */
}
Ejemplo n.º 12
0
void type_ext2_block_bitmap___deallocate (char *command_line)

/* This is the opposite of the above function - We call deallocate_block instead of allocate_block */

{
	long entry_num,num=1;
	char *ptr,buffer [80];
	
	ptr=parse_word (command_line,buffer);
	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		num=atol (buffer);
	}
	
	entry_num=block_bitmap_info.entry_num;
	if (num > file_system_info.super_block.s_blocks_per_group-entry_num) {
		wprintw (command_win,"Error - There aren't that much blocks in the group\n");	
		refresh_command_win ();return;				
	}
	
	while (num) {
		deallocate_block (entry_num);
		num--;entry_num++;
	}
	
	dispatch ("show");
}
Ejemplo n.º 13
0
void prev (char *command_line)

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

	ptr=parse_word (command_line,buffer);
	
	if (*ptr!=0) {
		ptr=parse_word (ptr,buffer);
		offset*=atol (buffer);
	}
	
	if (current_type!=NULL) {
		sprintf (buffer,"setoffset type -%ld",offset);
		dispatch (buffer);
		return;
	}

	if (type_data.offset_in_block-offset >= 0) {
		type_data.offset_in_block-=offset;
		sprintf (buffer,"show");dispatch (buffer);
	}
	
	else {
		wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
	}
}
Ejemplo n.º 14
0
/*
 * This function reports an internal error. It is almost not used. One
 * place in which I do check for internal errors is disk.c.
 * 
 * We just report the error, and try to continue ...
 */
void internal_error (char *description,char *source_name,char *function_name)
{
	wprintw (command_win,"Internal error - Found by source: %s.c , function: %s\n",source_name,function_name);
	wprintw (command_win,"\t%s\n",description);	
	wprintw (command_win,"Press enter to (hopefully) continue\n");
	refresh_command_win ();getch ();werase (command_win);
}
Ejemplo n.º 15
0
void type_ext2_inode___next (char *command_line)

{

	char *ptr,buffer [80];

	long group_num,group_offset,entry_num,block_num,first_entry,last_entry;
	long inode_num,mult=1;
	struct ext2_group_desc desc;

	ptr=parse_word (command_line,buffer);

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


	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=0;

	if (entry_num+mult-1<last_entry) {
		device_offset+=sizeof (struct ext2_inode)*mult;
		entry_num+=mult;

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

	else {
		wprintw (command_win,"Error - Entry out of limits\n");refresh_command_win ();
	}

	if (entry_num==last_entry) {
		wprintw (command_win,"Reached last inode in current group descriptor\n");
		refresh_command_win ();
	}
}
Ejemplo n.º 16
0
void type_ext2_inode___file (char *command_line)

{
	char buffer [80];

	if (!S_ISREG (type_data.u.t_ext2_inode.i_mode)) {
		wprintw (command_win,"Error - Inode type is not file\n");refresh_command_win ();
		return;
	}

	if (!init_file_info ()) {
		wprintw (command_win,"Error - Unable to show file\n");refresh_command_win ();
		return;
	}

	sprintf (buffer,"settype file");dispatch (buffer);
}
Ejemplo n.º 17
0
void disable_write (char *command_line)

{
	FILE *fp;

	if (device_handle==NULL) {
		wprintw (command_win,"Error - No device opened\n");refresh_command_win ();
		return;
	}

	if ( (fp=fopen (device_name,"rb"))==NULL) {
		wprintw (command_win,"Error - Can not open device %s\n",device_name);refresh_command_win ();
		return;
	}
	
	fclose (device_handle);
	device_handle=fp;write_access=0;
	wprintw (command_win,"Write access disabled\n");refresh_command_win ();
}
Ejemplo n.º 18
0
void recall (char *command_line)

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

	if (device_handle==NULL) {
		wprintw (command_win,"Error - No device opened\n");refresh_command_win ();
		return;
	}

	ptr=parse_word (command_line,buffer);

	if (*ptr==0) {
		wprintw (command_win,"Error - Argument not specified\n");refresh_command_win ();
		return;		
	}

	ptr=parse_word (ptr,buffer);

	
	for (entry_num=remember_lifo.entries_count-1;entry_num>=0;entry_num--) {
		if (strcmp (remember_lifo.name [entry_num],buffer)==0)
			break;	
	}
	
	if (entry_num==-1) {
		wprintw (command_win,"Error - Can not recall %s\n",buffer);refresh_command_win ();
		return;
	}

	sprintf (buffer,"setoffset %ld",remember_lifo.offset [entry_num]);dispatch (buffer);
	if (remember_lifo.type [entry_num] != NULL) {
		sprintf (buffer,"settype %s",remember_lifo.type [entry_num]->name);dispatch (buffer);	
	}

	else {
		sprintf (buffer,"settype none");dispatch (buffer);	
	}
			
	wprintw (command_win,"Object %s in Offset %ld recalled\n",current_type->name,device_offset);
	refresh_command_win ();
}
Ejemplo n.º 19
0
int write_type_data (void)

{
	if (device_handle==NULL) {
		wprintw (command_win,"Error - No device opened\n");
		refresh_command_win ();
		return (0);		
	}

	if (device_offset==-1) {
		wprintw (command_win,"Error - No offset set\n");
		refresh_command_win ();
		return (0);
	}
	
	if (low_write (type_data.u.buffer,file_system_info.block_size,device_offset)==0)
		return (0);
		
	return (1);
}
Ejemplo n.º 20
0
void type_ext2_inode___dir (char *command_line)

{
	char buffer [80];

	if (!S_ISDIR (type_data.u.t_ext2_inode.i_mode)) {
		wprintw (command_win,"Error - Inode type is not directory\n");refresh_command_win ();
		return;
	}


	if (!init_dir_info (&first_file_info)) {
		wprintw (command_win,"Error - Unable to show directory\n");refresh_command_win ();
		return;
	}

	file_info=first_file_info;

	sprintf (buffer,"settype dir");dispatch (buffer);
}
Ejemplo n.º 21
0
/*
 * This is a very important function. Its task is to recieve a command
 * name and link it to a C function.  There are three types of commands:
 * 
 * 1.	General commands - Always available and accessed through
 * general_commands. 
 * 2.	Ext2 specific commands - Available when editing an ext2
 * filesystem, accessed through ext2_commands. 
 * 3.	Type specific commands - Those are changing according to the
 * current type. The global variable current_type points to the
 * current object definition (of type struct_descriptor). In it, the
 * struct_commands entry contains the type specific commands links. 
 * 	
 * Overriding is an important feature - Much like in C++ : The same
 * command name can dispatch to different functions. The overriding
 * priority is 3,2,1; That is - A type specific command will always
 * override a general command. This is used through the program to
 * allow fine tuned operation. 
 * 
 * When an handling function is found, it is called along with the
 * command line that was passed to us. The handling function is then
 * free to interpert the arguments in its own style. 
 */
int dispatch (char *command_line)
{
	int i,found=0;
	
	char command [80];

	parse_word (command_line,command);
			
	if (strcasecmp (command,"quit")==0) return (1);	

	/* 1. Search for type specific commands FIRST - Allows
	overriding of a general command */

	if (current_type != NULL)
		for (i=0;
		     i<=current_type->type_commands.last_command && !found;
		     i++) {
			if (strcasecmp (command,current_type->type_commands.names [i])==0) {
				(*current_type->type_commands.callback [i]) (command_line);
				found=1;
			}
		}

	/* 2. Now search for ext2 filesystem general commands */

	if (!found)
		for (i=0;i<=ext2_commands.last_command && !found;i++) {
			if (strcasecmp (command,ext2_commands.names [i])==0) {
				(*ext2_commands.callback [i]) (command_line);
				found=1;
			}
		}

	
	/* 3. If not found, search the general commands */
	
	if (!found)
		for (i=0;i<=general_commands.last_command && !found;i++) {
			if (strcasecmp (command,general_commands.names [i])==0) {
				(*general_commands.callback [i]) (command_line);
				found=1;
			}
		}

	/* 4. If not found, issue an error message and return */
	
	if (!found) {
		wprintw (command_win,"Error: Unknown command\n");
		refresh_command_win ();
	}
	
	return (0);
}
Ejemplo n.º 22
0
/*
 * Read a character from the command window
 */
int command_read_key()
{
	int	key = 0;

	while (!key) {
		if (redraw_request) {
			redraw_all();
			redraw_request=0;
		}
		key = wgetch(command_win);
		switch (key) {
		case 0x1A:
			key = 0;
			kill(getpid(), SIGTSTP);
			break;
			
		case KEY_NPAGE:
			pgdn("");
			refresh_command_win ();
			break;

		case KEY_PPAGE:
			pgup("");
			refresh_command_win ();
			break;
		case ERR:
			key = 0;
			break;
			
		case KEY_BACKSPACE:
			key = '\b';
		}
		if ((key < 32 && key != '\b' && key != '\n') ||
		    (key > 127))
			key = 0;
	}
	return key;
}
Ejemplo n.º 23
0
void remember (char *command_line)

{
	long entry_num;
	char *ptr,buffer [80];
	
	if (device_handle==NULL) {
		wprintw (command_win,"Error - No device opened\n");refresh_command_win ();
		return;
	}

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

	entry_num=remember_lifo.entries_count++;
	if (entry_num>REMEMBER_COUNT-1) {
		entry_num=0;
		remember_lifo.entries_count--;
	}
	
	remember_lifo.offset [entry_num]=device_offset;
	remember_lifo.type [entry_num]=current_type;
	strcpy (remember_lifo.name [entry_num],buffer);
	
	if (current_type!=NULL)
		wprintw (command_win,"Object %s in Offset %ld remembered as %s\n",current_type->name,device_offset,buffer);
	else
		wprintw (command_win,"Offset %ld remembered as %s\n",device_offset,buffer);
			
	refresh_command_win ();
}
Ejemplo n.º 24
0
void type_ext2_block_bitmap___entry (char *command_line)

/*

This function changes the current entry in the bitmap. It just changes the entry_num variable in block_bitmap_info
and dispatches a show command to show the new entry.

*/

{
	unsigned long entry_num;
	char *ptr,buffer [80];
	
	
	
	ptr=parse_word (command_line,buffer);					/* Get the requested entry */
	if (*ptr==0) {
		wprintw (command_win,"Error - No argument specified\n");
		refresh_command_win ();	return;
	}
	ptr=parse_word (ptr,buffer);

	entry_num=atol (buffer);

	
	if (entry_num >= file_system_info.super_block.s_blocks_per_group) {	/* Check if it is a valid entry number */

		wprintw (command_win,"Error - Entry number out of bounds\n");
		refresh_command_win ();return;
	}
	
	
	
	block_bitmap_info.entry_num=entry_num;					/* If it is, just change entry_num and */
	strcpy (buffer,"show");dispatch (buffer);				/* dispatch a show command */
}
Ejemplo n.º 25
0
void set_type (char *command_line)

{
	struct struct_descriptor *descriptor_ptr;
	char *ptr,buffer [80],tmp_buffer [80];
	short found=0;

	if (!load_type_data ())
		return;

	ptr=parse_word (command_line,buffer);
	parse_word (ptr,buffer);
	
	if (strcmp (buffer,"none")==0 || strcmp (buffer,"hex")==0) {
		wprintw (command_win,"Data will be shown as hex dump\n");refresh_command_win ();
		current_type=NULL;
		sprintf (tmp_buffer,"show");dispatch (tmp_buffer);
		return;
	}
	
	descriptor_ptr=first_type;
	while (descriptor_ptr!=NULL && !found) {
		if (strcmp (descriptor_ptr->name,buffer)==0)
			found=1;
		else
			descriptor_ptr=descriptor_ptr->next;
	}
	if (found) {
		wprintw (command_win,"Structure type set to %s\n",buffer);refresh_command_win ();
		current_type=descriptor_ptr;
		sprintf (tmp_buffer,"show");dispatch (tmp_buffer);
	}
	else {
		wprintw (command_win,"Error - %s is not a valid type\n",buffer);refresh_command_win ();
	}
}    
Ejemplo n.º 26
0
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;
}
Ejemplo n.º 27
0
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 ();
}
Ejemplo n.º 28
0
void type_file___next (char *command_line)

{
	int offset=1;
	char *ptr,buffer [80];

	ptr=parse_word (command_line,buffer);

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

	if (file_info.offset_in_block+offset < file_system_info.block_size) {
		file_info.offset_in_block+=offset;
		sprintf (buffer,"show");dispatch (buffer);
	}

	else {
		wprintw (command_win,"Error - Offset out of block\n");refresh_command_win ();
	}
}
Ejemplo n.º 29
0
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);
}
Ejemplo n.º 30
0
void type_file___set (char *command_line)

{
	unsigned char tmp;
	char *ptr,buffer [80],*ch_ptr;
	int mode=HEX;

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

	ptr=parse_word (ptr,buffer);

	if (strcasecmp (buffer,"text")==0) {
		mode=TEXT;
		strcpy (buffer,ptr);
	}

	else if (strcasecmp (buffer,"hex")==0) {
		mode=HEX;
		ptr=parse_word (ptr,buffer);
	}

	if (*buffer==0) {
		wprintw (command_win,"Error - Data not specified\n");refresh_command_win ();return;
	}

	if (mode==HEX) {
		do {
			tmp=(unsigned char) strtol (buffer,NULL,16);
			file_info.buffer [file_info.offset_in_block]=tmp;
			file_info.offset_in_block++;
			ptr=parse_word (ptr,buffer);
			if (file_info.offset_in_block==file_system_info.block_size) {
				if (*ptr) {
					wprintw (command_win,"Error - Ending offset outside block, only partial string changed\n");
					refresh_command_win ();
				}
				file_info.offset_in_block--;
			}
		} while (*buffer) ;
	}

	else {
		ch_ptr=buffer;
		while (*ch_ptr) {
			tmp=(unsigned char) *ch_ptr++;
			file_info.buffer [file_info.offset_in_block]=tmp;
			file_info.offset_in_block++;
			if (file_info.offset_in_block==file_system_info.block_size) {
				if (*ch_ptr) {
					wprintw (command_win,"Error - Ending offset outside block, only partial string changed\n");
					refresh_command_win ();
				}
				file_info.offset_in_block--;
			}
		}
	}

	strcpy (buffer,"show");dispatch (buffer);
}