©2004 by Marc J. Rochkind. All rights reserved. Portions marked "Open Source" may be copied under license.

 

Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

c3/inode.c

Go to the documentation of this file.
00001 /*
00002     Display i-node
00003     AUP2, Sec. 3.2.2
00004 
00005     Copyright 2003 by Marc J. Rochkind. All rights reserved.
00006     May be copied only for purposes and under conditions described
00007     on the Web page www.basepath.com/aup/copyright.htm.
00008 
00009     The Example Files are provided "as is," without any warranty;
00010     without even the implied warranty of merchantability or fitness
00011     for a particular purpose. The author and his publisher are not
00012     responsible for any damages, direct or incidental, resulting
00013     from the use or non-use of these Example Files.
00014 
00015     The Example Files may contain defects, and some contain deliberate
00016     coding mistakes that were included for educational reasons.
00017     You are responsible for determining if and how the Example Files
00018     are to be used.
00019 
00020 */
00021 #ifndef FREEBSD
00022 #include "defs.h"
00023 
00024 int main(void)
00025 {
00026     printf("Program is for FreeBSD only.\n");
00027     exit(EXIT_FAILURE);
00028 }
00029 #else
00030 
00031 /*[inode]*/
00032 #include "defs.h"
00033 #include <sys/param.h>
00034 #include <ufs/ffs/fs.h>
00035 #include <ufs/ufs/dinode.h>
00036 
00037 #define DEVICE "/dev/ad0s1g"
00038 
00039 int main(int argc, char *argv[])
00040 {
00041     int fd;
00042     long inumber;
00043     char sb_buf[((sizeof(struct fs) / DEV_BSIZE) + 1) * DEV_BSIZE];
00044     struct fs *superblock = (struct fs *)sb_buf;
00045     struct dinode *d;
00046     ssize_t nread;
00047     off_t fsbo, fsba;
00048     char *inode_buf;
00049     size_t inode_buf_size;
00050 
00051     if (argc < 2) {
00052         printf("(AUP) Usage: inode n\n");
00053         exit(EXIT_FAILURE);
00054     }
00055     inumber = atol(argv[1]);
00056 
00057     ec_neg1( fd = open(DEVICE, O_RDONLY) )
00058     ec_neg1( lseek(fd, SBLOCK * DEV_BSIZE, SEEK_SET) )
00059     switch (nread = read(fd, sb_buf, sizeof(sb_buf))) {
00060     case 0:
00061         errno = 0;
00062         printf("EOF from read (1)\n");
00063         EC_FAIL
00064     case -1:
00065         EC_FAIL
00066     default:
00067         if (nread != sizeof(sb_buf)) {
00068             errno = 0;
00069             printf("Read only %d bytes instead of %d\n", nread, sizeof(sb_buf));
00070             EC_FAIL
00071         }
00072     }
00073     printf("Superblock info for %s:\n", DEVICE);
00074     printf("\tlast time written = %s", ctime(&superblock->fs_time));
00075     printf("\tnumber of blocks in fs = %ld\n", (long)superblock->fs_size);
00076     printf("\tnumber of data blocks in fs = %ld\n", (long)superblock->fs_dsize);
00077     printf("\tsize of basic blocks in fs = %ld\n", (long)superblock->fs_bsize);
00078     printf("\tsize of frag blocks in fs = %ld\n", (long)superblock->fs_fsize);
00079     printf("\tname mounted on = %s\n", superblock->fs_fsmnt);
00080 
00081     inode_buf_size = superblock->fs_bsize;
00082     ec_null( inode_buf = malloc(inode_buf_size) )
00083 
00084     fsba = ino_to_fsba(superblock, inumber);
00085     fsbo = ino_to_fsbo(superblock, inumber);
00086 
00087     ec_neg1( lseek(fd, fsbtodb(superblock, fsba) * DEV_BSIZE, SEEK_SET) )
00088     switch (nread = read(fd, inode_buf, inode_buf_size)) {
00089     case 0:
00090         errno = 0;
00091         printf("EOF from read (2)\n");
00092         EC_FAIL
00093     case -1:
00094         EC_FAIL
00095     default:
00096         if (nread != inode_buf_size) {
00097             errno = 0;
00098             printf("Read only %d bytes instead of %d\n", nread, inode_buf_size);
00099             EC_FAIL
00100         }
00101     }
00102     d = (struct dinode *)&inode_buf[fsbo * sizeof(struct dinode)];
00103     printf("\ninumber %ld info:\n", inumber);
00104     printf("\tmode = 0%o\n", d->di_mode);
00105     printf("\tlinks = %d\n", d->di_nlink);
00106     printf("\towner = %d\n", d->di_uid);
00107     printf("\tmod. time = %s", ctime((time_t *)&d->di_mtime));
00108     exit(EXIT_SUCCESS);
00109 
00110 EC_CLEANUP_BGN
00111     exit(EXIT_FAILURE);
00112 EC_CLEANUP_END
00113 }
00114 /*[]*/
00115 #endif /* FREEBSD */

Generated on Fri Apr 23 10:56:55 2004 for AUP2 Example Source by doxygen 1.3.1