death-to-efs-20060802
[openafs.git] / src / vol / gi.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <stdio.h>
19
20 int statflag;
21
22 #include "AFS_component_version_number.c"
23
24 void
25 Perror(char *err, int a1, int a2, int a3)
26 {
27     char msg[200];
28     sprintf(msg, err, a1, a2, a3);
29     perror(msg);
30 }
31
32 int
33 main(int argc, char **argv)
34 {
35     int error = 0;
36     struct stat status;
37     int dev, fd, inode;
38
39 #if defined(AFS_NT40_ENV) || defined(AFS_NAMEI_ENV)
40     fprintf(stderr, "gi not supported on NT or NAMEI systems.\n");
41     exit(1);
42 #else
43
44     argc--;
45     argv++;
46     while (argc && **argv == '-') {
47         if (strcmp(*argv, "-stat") == 0)
48             statflag = 1;
49         else {
50             error = 1;
51             break;
52         }
53         argc--;
54         argv++;
55     }
56     if (error || argc != 2) {
57         fprintf(stderr, "Usage: gi [-stat] partition inodenumber\n");
58         exit(1);
59     }
60     if (stat(*argv, &status) != 0) {
61         fprintf(stderr,
62                 "gi: cannot stat %s [should be mounted partition name]\n",
63                 *argv);
64         exit(1);
65     }
66     dev = status.st_dev;
67     inode = atoi(*++argv);
68     fd = iopen(dev, inode, 0);
69     if (fd < 0) {
70         Perror("Unable to open inode %d", inode, 0, 0);
71         exit(1);
72     }
73     if (statflag) {
74         if (fstat(fd, &status) != 0) {
75             Perror("Unable to fstat the inode!", 0, 0, 0);
76             exit(1);
77         }
78         printf
79             ("Inode status: dev=%d, ino=%d, mode=%o, nlink=%d, uid=%d, gid=%d, size=%d, mtime=%d, blocks=%d\n",
80              status.st_dev, status.st_ino, status.st_mode, status.st_nlink,
81              status.st_uid, status.st_gid, status.st_size, status.st_mtime);
82     } else {
83         /* Send the inode to standard out */
84         char buf[4096];
85         int n;
86         while ((n = read(fd, buf, sizeof(buf))) > 0)
87             write(1, buf, n);
88     }
89     exit(0);
90 #endif /* AFS_NT40_ENV || AFS_NAMEI_ENV */
91 }