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