reindent-20030715
[openafs.git] / src / venus / whatfid.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 /* file         whatfid.c */
11
12
13 #include <afsconfig.h>
14 #include <afs/param.h>
15
16 RCSID
17     ("$Header$");
18
19 #include <stdio.h>
20 #include <errno.h>
21 #ifdef  AFS_AIX32_ENV
22 #include <signal.h>
23 #endif
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <netdb.h>
27 #include <netinet/in.h>
28 #include <afs/stds.h>
29 #include <afs/vice.h>
30 #include <afs/venus.h>
31 #include "afs/prs_fs.h"
32 #include <afs/afsint.h>
33 #include <afs/auth.h>
34 #include <afs/cellconfig.h>
35 #include <afs/cmd.h>
36 #include <strings.h>
37
38
39 struct VenusFid {
40     afs_int32 Cell;
41     struct AFSFid Fid;
42 };
43
44
45 char *pn;
46 void PioctlError();
47
48 #include "AFS_component_version_number.c"
49
50 int WhatFidCmd_FileParm;
51 int WhatFidCmd_FollowLinkParm;
52 int
53 WhatFidCmd(as)
54      register struct cmd_syndesc *as;
55 {
56     register afs_int32 code;
57     struct ViceIoctl blob;
58     struct VenusFid vFid;
59     register struct cmd_item *ti;
60     struct VolumeStatus *status;
61     char *name;
62     int follow = 1;
63
64     if (as->parms[1].items)
65         follow = 0;
66     for (ti = as->parms[0].items; ti; ti = ti->next) {
67         /* once per file */
68         blob.out_size = sizeof(struct VenusFid);
69         blob.in_size = 0;
70         blob.out = (char *)&vFid;
71         code = pioctl(ti->data, VIOCGETFID, &blob, follow);
72         if (code) {
73             PioctlError(code, ti->data);
74             continue;
75         }
76         printf("%s: %x:%d.%d.%d\n", ti->data, vFid.Cell, vFid.Fid.Volume,
77                vFid.Fid.Vnode, vFid.Fid.Unique);
78     }
79     return 0;
80 }
81
82
83
84 main(argc, argv)
85      int argc;
86      char **argv;
87 {
88     register afs_int32 code;
89     register struct cmd_syndesc *ts;
90
91 #ifdef  AFS_AIX32_ENV
92     /*
93      * The following signal action for AIX is necessary so that in case of a 
94      * crash (i.e. core is generated) we can include the user's data section 
95      * in the core dump. Unfortunately, by default, only a partial core is
96      * generated which, in many cases, isn't too useful.
97      */
98     struct sigaction nsa;
99
100     sigemptyset(&nsa.sa_mask);
101     nsa.sa_handler = SIG_DFL;
102     nsa.sa_flags = SA_FULLDUMP;
103     sigaction(SIGSEGV, &nsa, NULL);
104 #endif
105
106     pn = argv[0];
107
108     ts = cmd_CreateSyntax("initcmd", WhatFidCmd, 0, "list fid for file(s)");
109     WhatFidCmd_FileParm = cmd_AddParm(ts, "-path", CMD_LIST, 0, "pathnames");
110     WhatFidCmd_FollowLinkParm =
111         cmd_AddParm(ts, "-link", CMD_FLAG, CMD_OPTIONAL,
112                     "do not follow symlinks");
113
114     exit(cmd_Dispatch(argc, argv));
115 }
116
117 void
118 PioctlError(code, filename)
119      int code;
120      char *filename;
121 {                               /*Die */
122
123     if (errno == EINVAL) {
124         if (filename)
125             fprintf(stderr,
126                     "%s: Invalid argument; it is possible that %s is not in AFS.\n",
127                     pn, filename);
128         else
129             fprintf(stderr, "%s: Invalid argument.\n", pn);
130     } else if (errno == ENOENT) {
131         if (filename)
132             fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
133         else
134             fprintf(stderr, "%s: no such file returned\n", pn);
135     } else if (errno == EROFS)
136         fprintf(stderr,
137                 "%s: You can not change a backup or readonly volume\n", pn);
138     else if (errno == EACCES || errno == EPERM) {
139         if (filename)
140             fprintf(stderr,
141                     "%s: You don't have the required access rights on '%s'\n",
142                     pn, filename);
143         else
144             fprintf(stderr,
145                     "%s: You do not have the required rights to do this operation\n",
146                     pn);
147     } else {
148         if (filename)
149             fprintf(stderr, "%s:'%s'", pn, filename);
150         else
151             fprintf(stderr, "%s", pn);
152         fprintf(stderr, ": %s\n", error_message(errno));
153     }
154 }                               /*Die */