⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 de_std~1.c

📁 操作系统源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************//*								*//*	de_stdout.c						*//*								*//*		Displaying information from the "Disk editor".	*//*								*//****************************************************************//*  origination         1989-Jan-15        Terrence W. Holm	*//****************************************************************/#include <minix/config.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <limits.h>#include <grp.h>#include <pwd.h>#include <stdarg.h>#include <stdlib.h>#include <string.h>#include <termcap.h>#include <time.h>#include <unistd.h>#include <minix/const.h>#include <minix/type.h>#include "../../fs/const.h"#include "../../fs/type.h"#include "../../fs/inode.h"#include <minix/fslib.h>#include "de.h"#define major(x) ( (x>>8) & 0377)#define minor(x) (x & 0377)/****************************************************************//*   		Code for handling termcap			*//****************************************************************/#define  TC_BUFFER  1024	/* Size of termcap(3) buffer	*/#define  TC_STRINGS  200	/* Enough room for cm,cl,so,se	*/static  char  *Tmove;		/* (cm) - Format for tgoto	*/static  char  *Tclr_all;	/* (cl) - Clear screen  	*/static  char  *Treverse;	/* (so) - Start reverse mode 	*/static  char  *Tnormal;		/* (se) - End reverse mode	*/char   Kup    = 0;		/* (ku) - Up arrow key		*/char   Kdown  = 0;		/* (kd) - Down arrow key	*/char   Kleft  = 0;		/* (kl) - Left arrow key	*/char   Kright = 0;		/* (kr) - Right arrow key	*/_PROTOTYPE(void Goto , (int column , int line ));_PROTOTYPE(void Block_Type , (de_state *s ));_PROTOTYPE(void Draw_Words , (de_state *s ));_PROTOTYPE(void Draw_Info , (de_state *s ));_PROTOTYPE(void Draw_Block , (char *block ));_PROTOTYPE(void Draw_Map , (char *block , int max_bits ));_PROTOTYPE(void Draw_Offset , (de_state *s ));_PROTOTYPE(void Word_Pointers , (off_t old_addr , off_t new_addr ));_PROTOTYPE(void Block_Pointers , (off_t old_addr , off_t new_addr ));_PROTOTYPE(void Map_Pointers , (off_t old_addr , off_t new_addr ));_PROTOTYPE(void Print_Number , (Word_t number , int output_base ));_PROTOTYPE(void Draw_Zone_Numbers , (de_state *s , struct inode *inode ,						int zindex , int zrow ));/****************************************************************//*								*//*	Init_Termcap()						*//*								*//*		Initializes the external variables for the	*//*		current terminal.				*//*								*//****************************************************************/int Init_Termcap()  {  char  *term;  char   buffer[ TC_BUFFER ];  static char strings[ TC_STRINGS ];  char  *s = &strings[0];  char  *Kcode;  term = getenv( "TERM" );  if ( term == NULL )    return( 0 );  if ( tgetent( buffer, term ) != 1 )    return( 0 );  if ( (Tmove = tgetstr( "cm", &s )) == NULL )    return( 0 );  if ( (Tclr_all = tgetstr( "cl", &s )) == NULL )    return( 0 );  if ( (Treverse = tgetstr( "so", &s )) == NULL )    {    Treverse = Tnormal = s;    *s = '\0';    ++s;    }  else if ( (Tnormal = tgetstr( "se", &s )) == NULL )    return( 0 );  /*  See if there are single character arrow key codes  */  if ( (Kcode = tgetstr( "ku", &s )) != NULL  &&  strlen( Kcode ) == 1 )    Kup = Kcode[0];  if ( (Kcode = tgetstr( "kd", &s )) != NULL  &&  strlen( Kcode ) == 1 )    Kdown = Kcode[0];  if ( (Kcode = tgetstr( "kl", &s )) != NULL  &&  strlen( Kcode ) == 1 )    Kleft = Kcode[0];  if ( (Kcode = tgetstr( "kr", &s )) != NULL  &&  strlen( Kcode ) == 1 )    Kright = Kcode[0];  return( 1 );  }/****************************************************************//*								*//*	Goto( column, line )					*//*								*//*		Use the termcap string to move the cursor.	*//*								*//****************************************************************/void Goto( column, line )  int  column;  int  line;  {  fputs( tgoto( Tmove, column, line ), stdout );  }/****************************************************************//*   		       Output routines				*//****************************************************************//****************************************************************//*								*//*	Draw_Help_Screen()					*//*								*//****************************************************************/void Draw_Help_Screen( s )  de_state *s;  {  int down;  int right;  switch ( s->mode )    {    case WORD  :   down = 2;    right = 32;  break;    case BLOCK :   down = 64;   right = 1;   break;    case MAP   :   down = 256;  right = 4;   break;    }  printf( "%s                             ", Tclr_all );  printf( "%sDE  COMMANDS%s\r\n\n\n", Treverse, Tnormal );  printf( "   PGUP   b   Back one block              h   Help\r\n" );  printf( "   PGDN   f   Forward one block           q   Quit\r\n" );  printf( "   HOME   B   Goto first block            m   Minix shell\r\n" );  printf( "   END    F   Goto last block\r\n" );  printf( "                                          v   Visual mode (w b m)\r\n" );  printf( "          g   Goto specified block        o   Output base (h d o b)\r\n" );  printf( "          G   Goto block indirectly\r\n" );  printf( "          i   Goto i-node                 c   Change file name\r\n" );  printf( "          I   Filename to i-node          w   Write ASCII block\r\n" );  printf( "                                          W   Write block exactly\r\n" );  printf( "          /   Search\r\n" );  printf( "          n   Next occurrence             x   Extract lost entry\r\n" );  printf( "          p   Previous address            X   Extract lost blocks\r\n" );  printf( "                                          s   Store word\r\n" );  printf( "   UP     u   Move back %d bytes\r\n", down );  printf( "   DOWN   d   Move forward %d bytes\r\n", down );  printf( "   LEFT   l   Move back %d byte%s\r\n", right,					right == 1 ? "" : "s" );  printf( "   RIGHT  r   Move forward %d byte%s\r\n\n\n", right,					right == 1 ? "" : "s" );  }/****************************************************************//*								*//*	Wait_For_Key()						*//*								*//*		The user must press a key to continue.		*//*								*//****************************************************************/void Wait_For_Key()  {  Draw_Prompt( "Press a key to continue..." );  Get_Char();  }/****************************************************************//*								*//*	Draw_Prompt( string )					*//*								*//*		Write a message in the "prompt" area.		*//*								*//****************************************************************/void Draw_Prompt( string )  char  *string;  {  Goto( PROMPT_COLUMN, PROMPT_LINE );  printf( "%s%s%s ", Treverse, string, Tnormal );  }/****************************************************************//*								*//*	Erase_Prompt()						*//*								*//*		Erase the message in the "prompt" area.		*//*								*//****************************************************************/void Erase_Prompt()  {  Goto( PROMPT_COLUMN, PROMPT_LINE );  printf( "%77c", ' ' );  Goto( PROMPT_COLUMN, PROMPT_LINE );  }/****************************************************************//*								*//*	Draw_Screen( state )					*//*								*//*		Redraw everything, except pointers.		*//*								*//****************************************************************/void Draw_Screen( s )  de_state *s;  {  fputs( Tclr_all, stdout );  Draw_Strings( s );  Block_Type( s );  switch ( s->mode )    {    case WORD :   Draw_Words( s );		  Draw_Info( s );		  break;    case BLOCK :  Draw_Block( s->buffer );		  break;    case MAP :	  {		  int max_bits = 2 * K;		  /*  Don't display the bits after the end  */		  /*  of the i-node or zone bit maps.	    */		  if ( s->block == 2 + s->inode_maps - 1 )		    max_bits = (int)			       (s->inodes_in_map				- CHAR_BIT * K * (ino_t) (s->inode_maps - 1)				- CHAR_BIT * (ino_t) (s->offset & ~ MAP_MASK));		  else if ( s->block == 2 + s->inode_maps + s->zone_maps - 1 )		    max_bits = (int)			       (s->zones_in_map			        - CHAR_BIT * K * (zone_t) (s->zone_maps - 1)				- CHAR_BIT * (zone_t) (s->offset & ~ MAP_MASK));		  if ( max_bits < 0 )		      max_bits = 0;		  Draw_Map( &s->buffer[ s->offset & ~ MAP_MASK ], max_bits );		  break;		  }    }  }/****************************************************************//*								*//*	Draw_Strings( state )					*//*								*//*		The first status line contains the device name,	*//*		the current write file name (if one is open)	*//*		and the current search string (if one has	*//*		been defined).					*//*								*//*		Long strings are truncated.			*//*								*//****************************************************************/void Draw_Strings( s )  de_state *s;  {  int len;  int i;  Goto( STATUS_COLUMN, STATUS_LINE );  printf( "Device %s= %-14.14s  ",	     s->device_mode == O_RDONLY ? "" : "(w) ", s->device_name );  switch ( s->magic )    {    case SUPER_MAGIC :	printf( "V1 file system  ");			break;    case SUPER_REV :	printf( "V1-bytes-swapped file system (?)  ");			break;    case SUPER_V2 :	printf( "V2 file system  ");			break;    case SUPER_V2_REV :	printf( "V2-bytes-swapped file system (?)  ");			break;    default :		printf( "not a Minix file system  ");			break;    }  len = strlen( s->file_name );  if ( len == 0 )    printf( "%29s", " " );  else if ( len <= 20 )    printf( "File = %-20s  ", s->file_name );  else    printf( "File = ...%17.17s  ", s->file_name + len - 17 );  len = strlen( s->search_string );  if ( len == 0 )    printf( "%20s", " " );  else    {    printf( "Search = " );    if ( len <= 11 )      {      for ( i = 0;  i < len;  ++i )        Print_Ascii( s->search_string[ i ] );      for ( ;  i < 11;  ++i )	putchar( ' ' );      }    else      {      for ( i = 0;  i < 8;  ++i )        Print_Ascii( s->search_string[ i ] );      printf( "..." );      }    }  }/****************************************************************//*								*//*	Block_Type( state )					*//*								*//*		Display the current block type.			*//*								*//****************************************************************/void Block_Type( s )  de_state *s;  {  Goto( STATUS_COLUMN, STATUS_LINE + 1 );  printf( "Block  = %5u of %-5u  ", s->block, s->zones );  if ( !s->is_fs )    return;  if ( s->block == BOOT_BLOCK )    printf( "Boot block" );  else if ( s->block == SUPER_BLOCK )    printf( "Super block" );  else if ( s->block < 2 + s->inode_maps )    printf( "I-node bit map" );  else if ( s->block < 2 + s->inode_maps + s->zone_maps )    printf( "Zone bit map" );  else if ( s->block < s->first_data )    printf( "I-nodes" );  else    printf( "Data block  (%sin use)",	In_Use( (bit_t) (s->block - (s->first_data - 1)), s->zone_map )	? "" : "not " );  }/****************************************************************//*								*//*	Draw_Words( state )					*//*								*//*		Draw a page in word format.			*//*								*//****************************************************************/void Draw_Words( s )  de_state *s;  {  int line;  int addr = s->offset & ~ PAGE_MASK;  for ( line = 0;  line < 16;  ++line, addr += 2 )    {    Goto( BLOCK_COLUMN, BLOCK_LINE + line );    printf( "%5d  ", addr );    Print_Number( *( (word_t *) &s->buffer[ addr ] ), s->output_base );    }  Goto( BLOCK_COLUMN + 64, BLOCK_LINE  );  printf( "(base %d)", s->output_base );  }/****************************************************************//*								*//*	Draw_Info( state )					*//*								*//*		Add information to a page drawn in word format.	*//*		The routine recognizes the super block, inodes,	*//*		executables and "ar" archives. If the current	*//*		page is not one of these, then ASCII characters	*//*		are printed from the data words.		*//*								*//****************************************************************/char *super_block_info[] =  {	"number of inodes",				"V1 number of zones",				"inode bit map blocks",				"zone bit map blocks",				"first data zone",				"blocks per zone shift & flags",				"maximum file size",				"",				"magic number",				"fsck magic number",				"V2 number of zones"  };void Draw_Info( s )  de_state *s;  {  int i;  int page = s->offset >> PAGE_SHIFT;  dev_t dev;  if ( s->is_fs  &&  s->block == SUPER_BLOCK  &&  page == 0 )      for ( i = 0;  i < 11;  ++i ) 	{	Goto( INFO_COLUMN, INFO_LINE + i );	printf( "%s", super_block_info[ i ] );	}  else if ( s->is_fs  &&  s->block >= s->first_data - s->inode_blocks  &&	    s->block < s->first_data )      {      struct inode core_inode;      d1_inode *dip1;      d2_inode *dip2;      struct inode *inode = &core_inode;      int special = 0;      int m;      struct passwd *user;      struct group *grp;      dip1 = (d1_inode *) &s->buffer[ s->offset & ~ PAGE_MASK ];      dip2 = (d2_inode *) &s->buffer[ s->offset & ~ PAGE_MASK						& ~ (V2_INODE_SIZE-1) ];      conv_inode( inode, dip1, dip2, READING, s->magic );      user = getpwuid( inode->i_uid );      grp  = getgrgid( inode->i_gid );      if ( s->magic != SUPER_MAGIC  &&  page & 1 )	{	Draw_Zone_Numbers( s, inode, 2, 0 );	return;	}      Goto( INFO_COLUMN, INFO_LINE  );      switch( inode->i_mode & S_IFMT )    	{    	case S_IFDIR :  printf( "directory  " );		    	break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -