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