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