Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!ssc-vax!uvicctr!tholm From: tholm@uvicctr.UUCP (Terrence W. Holm) Newsgroups: comp.os.minix Subject: stat(1) Message-ID: <481@uvicctr.UUCP> Date: 26 Aug 88 00:14:35 GMT Reply-To: tholm@uvicctr.UUCP (Terrence W. Holm) Organization: University of Victoria, Victoria B.C. Canada Lines: 132 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 . X If 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 . 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 X#include X#include 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) ? "" : 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<