Import Upstream version 1.8.5
[hcoop/debian/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 #include <roken.h>
14
15
16 int statflag;
17
18 #include "AFS_component_version_number.c"
19
20 void
21 Perror(char *err, int a1, int a2, int a3)
22 {
23 char msg[200];
24 sprintf(msg, err, a1, a2, a3);
25 perror(msg);
26 }
27
28 int
29 main(int argc, char **argv)
30 {
31 #if defined(AFS_NT40_ENV) || defined(AFS_NAMEI_ENV)
32 fprintf(stderr, "gi not supported on NT or NAMEI systems.\n");
33 exit(1);
34 #else
35 int error = 0;
36 struct stat status;
37 int dev, fd, inode;
38
39 argc--;
40 argv++;
41 while (argc && **argv == '-') {
42 if (strcmp(*argv, "-stat") == 0)
43 statflag = 1;
44 else {
45 error = 1;
46 break;
47 }
48 argc--;
49 argv++;
50 }
51 if (error || argc != 2) {
52 fprintf(stderr, "Usage: gi [-stat] partition inodenumber\n");
53 exit(1);
54 }
55 if (stat(*argv, &status) != 0) {
56 fprintf(stderr,
57 "gi: cannot stat %s [should be mounted partition name]\n",
58 *argv);
59 exit(1);
60 }
61 dev = status.st_dev;
62 inode = atoi(*++argv);
63 fd = iopen(dev, inode, 0);
64 if (fd < 0) {
65 Perror("Unable to open inode %d", inode, 0, 0);
66 exit(1);
67 }
68 if (statflag) {
69 if (fstat(fd, &status) != 0) {
70 Perror("Unable to fstat the inode!", 0, 0, 0);
71 exit(1);
72 }
73 printf
74 ("Inode status: dev=%d, ino=%d, mode=%o, nlink=%d, uid=%d, gid=%d, size=%d, mtime=%d, blocks=%d\n",
75 status.st_dev, status.st_ino, status.st_mode, status.st_nlink,
76 status.st_uid, status.st_gid, status.st_size, status.st_mtime);
77 } else {
78 /* Send the inode to standard out */
79 char buf[4096];
80 int n;
81 while ((n = read(fd, buf, sizeof(buf))) > 0)
82 write(1, buf, n);
83 }
84 exit(0);
85 #endif /* AFS_NT40_ENV || AFS_NAMEI_ENV */
86 }