tholm@uvicctr.UUCP (Terrence W. Holm) (08/26/88)
EFTH MINIX report #37 - August 1988 - stat(1) There follows an implementation of stat(1) for Minix. This command is useful for looking at the file size of a special file. ---------------------------------------------------------- echo x - stat.1 gres '^X' '' > stat.1 << '/' XCOMMANDS X stat(1) - display inode contents X XINVOCATION X stat [ file ] X XEXPLANATION X Stat(1) prints the contents of the inode for <file>. X If <file> is not specified then standard input is X investigated. X X This command is used to obtain information that ls(1) X does not display: (a) The "size" of a special file X and (b) The major/minor unit number of the device X holding the <file>. X XREFERENCES X ls(1), stat(2) / echo x - stat.c gres '^X' '' > stat.c << '/' X/* stat(1) X * X * Author: Terrence W. Holm Aug. 1988 X * X * X * stat [ file ] X * X * Prints file statistics. Useful for determining X * the "size" of a MINIX special file, or the device X * containing a given file. X */ X X#include <sys/types.h> X#include <sys/stat.h> X#include <stdio.h> X Xextern char *ctime(); X X Xmain( argc, argv ) X int argc; X char *argv[]; X X { X struct stat s; X int stat_err; X int special = 0; X int m; X X if ( argc == 1 ) X stat_err = fstat( 0, &s ); X X else if ( argc == 2 ) X stat_err = stat( argv[1], &s ); X X else X { X fprintf( stderr, "Usage: %s [ file ]\n", argv[0] ); X exit( 1 ); X } X X X if ( stat_err != 0 ) X { X fprintf( stderr, "%s: can not stat() file\n", argv[0] ); X exit( 1 ); X } X X X printf( "file=%s\ntype=", (argc==1) ? "<stdin>" : argv[1] ); X X switch( s.st_mode & S_IFMT ) X { X case S_IFDIR : printf( "directory" ); X break; X X case S_IFCHR : printf( "character" ); X special = 1; X break; X X case S_IFBLK : printf( "block " ); X special = 1; X break; X X case S_IFREG : printf( "regular " ); X break; X#ifdef S_IFIFO X case S_IFIFO : printf( "fifo " ); X break; X#endif X default : printf( "unknown " ); X } X X printf( " mode= " ); X X for ( m = 11; m >= 0; --m ) X putchar( (s.st_mode & (1<<m)) ? "xwrxwrxwrtgu"[m] : '-' ); X X if ( special ) X printf( "\nmajor=%-7d minor=%d", major(s.st_rdev), minor(s.st_rdev) ); X X printf( "\nsize=%-8ld links=%d\n", s.st_size, s.st_nlink ); X X printf( "user=%-8d group=%d\n", s.st_uid, s.st_gid ); X X printf( "unit=%d/%d inode=%d\n", X major(s.st_dev), minor(s.st_dev), s.st_ino ); X X printf( "time=%s", ctime( &s.st_mtime ) ); X X exit( 0 ); X } / ---------------------------------------------------------- Edwin L. Froese uw-beaver!ubc-cs!mprg!handel!froese Terrence W. Holm uw-beaver!uvicctr!tholm