Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / vol / gi.c
blobb825a2a17ba92c84735a539aeaa4b3cdb9101eb3
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <stdio.h>
17 #include <stdlib.h>
19 int statflag;
21 #include "AFS_component_version_number.c"
23 void
24 Perror(char *err, int a1, int a2, int a3)
26 char msg[200];
27 sprintf(msg, err, a1, a2, a3);
28 perror(msg);
31 int
32 main(int argc, char **argv)
34 #if defined(AFS_NT40_ENV) || defined(AFS_NAMEI_ENV)
35 fprintf(stderr, "gi not supported on NT or NAMEI systems.\n");
36 exit(1);
37 #else
38 int error = 0;
39 struct stat status;
40 int dev, fd, inode;
42 argc--;
43 argv++;
44 while (argc && **argv == '-') {
45 if (strcmp(*argv, "-stat") == 0)
46 statflag = 1;
47 else {
48 error = 1;
49 break;
51 argc--;
52 argv++;
54 if (error || argc != 2) {
55 fprintf(stderr, "Usage: gi [-stat] partition inodenumber\n");
56 exit(1);
58 if (stat(*argv, &status) != 0) {
59 fprintf(stderr,
60 "gi: cannot stat %s [should be mounted partition name]\n",
61 *argv);
62 exit(1);
64 dev = status.st_dev;
65 inode = atoi(*++argv);
66 fd = iopen(dev, inode, 0);
67 if (fd < 0) {
68 Perror("Unable to open inode %d", inode, 0, 0);
69 exit(1);
71 if (statflag) {
72 if (fstat(fd, &status) != 0) {
73 Perror("Unable to fstat the inode!", 0, 0, 0);
74 exit(1);
76 printf
77 ("Inode status: dev=%d, ino=%d, mode=%o, nlink=%d, uid=%d, gid=%d, size=%d, mtime=%d, blocks=%d\n",
78 status.st_dev, status.st_ino, status.st_mode, status.st_nlink,
79 status.st_uid, status.st_gid, status.st_size, status.st_mtime);
80 } else {
81 /* Send the inode to standard out */
82 char buf[4096];
83 int n;
84 while ((n = read(fd, buf, sizeof(buf))) > 0)
85 write(1, buf, n);
87 exit(0);
88 #endif /* AFS_NT40_ENV || AFS_NAMEI_ENV */