#include <stdio.h>
#include <fcntl.h> 
#include <sys/stat.h>
#include <sys/types.h>

void main(int argc, char * argv[] ) {

  /* Open file given in  argv[1] */
  /* Display information from i-node  */
  /* Then close file using file descriptor */
   
  int fd ;  /* file descriptor */
  struct stat buf ;
  if (( fd=open(argv[1], O_RDONLY ))==-1 ) 
    { fprintf ( stderr, "%s: can not open %s\n", argv[0], argv[1]) ;
       perror("Could not open file") ; 
    exit (1) ;
    }
  printf( "Success: Opened file: %s\n", argv[1] ) ;
    
  fstat( fd, & buf ) ;

  printf( "Device of i-node: %u\n", buf.st_dev ) ;
  printf( "This i-node's number: %u\n", buf.st_ino ) ;
  printf( "File type and mode: %o\n",buf.st_mode ) ;
  printf( "No of hardlinks: %d\n", buf.st_nlink ) ;
  printf( "User id: %d\n", buf.st_uid ) ;
  printf( "Group id: %d\n", buf.st_gid ) ;
  printf( "Device type: %d\n", buf.st_rdev ) ;
  printf( "Total size of file: %u\n", buf.st_size ) ;
  printf( "File last access time: %u\n", buf.st_atime ) ;
  printf( "File last modify time: %u\n", buf.st_mtime ) ;
  printf( "File last status change time: %u\n", buf.st_ctime ) ;
  printf( "Optimal block size: %d\n", buf.st_blksize ) ;
  printf( "Actual number of blocks: %d\n", buf.st_blocks ) ;

  close ( fd ) ;

    
}
