2 * Copyright (c) 1998 - 2001 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <sys/types.h>
47 #include <netinet/in.h>
50 #include <afs/venus.h>
51 #include <afs/afsint.h>
53 #include <afs/cellconfig.h>
56 enum { PIOCTL_MAXSIZE = 2000 };
64 * fs_getfid, the the `fid' that `path' points on.
68 fs_getfid(char *path, struct VenusFid *fid)
70 struct ViceIoctl a_params;
72 if (path == NULL || fid == NULL)
76 a_params.out_size = sizeof(struct VenusFid);
78 a_params.out = (void *)fid;
80 if (pioctl(path, VIOCGETFID, &a_params, 1) == -1)
93 struct ViceIoctl a_params;
96 a_params.out_size = 0;
100 if (pioctl(NULL, VIOCNOP, &a_params, 1) == -1)
107 * Get the `cell' that the `path' ends up in
111 fs_getfilecellname(char *path, char *cell, size_t len)
113 struct ViceIoctl a_params;
115 a_params.in_size = 0;
116 a_params.out_size = len;
120 if (pioctl(path, VIOC_FILE_CELL_NAME, &a_params, 1) == -1)
127 * set the level of crypt
130 #ifdef VIOC_SETRXKCRYPT
132 fs_setcrypt(afs_uint32 n)
134 struct ViceIoctl a_params;
136 a_params.in_size = sizeof(n);
137 a_params.out_size = 0;
138 a_params.in = (char *)&n;
141 if (pioctl(NULL, VIOC_SETRXKCRYPT, &a_params, 0) == -1)
149 * get currernt level of crypt
152 #ifdef VIOC_GETRXKCRYPT
154 fs_getcrypt(afs_uint32 * level)
156 struct ViceIoctl a_params;
158 a_params.in_size = 0;
159 a_params.out_size = sizeof(*level);
161 a_params.out = (char *)level;
163 if (pioctl(NULL, VIOC_GETRXKCRYPT, &a_params, 0) == -1)
171 * get and set the connect-mode
174 #ifdef VIOCCONNECTMODE
176 fs_connect(afs_int32 type, afs_int32 * flags)
178 struct ViceIoctl a_params;
180 a_params.in_size = sizeof(type);
181 a_params.out_size = sizeof(afs_int32);
182 a_params.in = (char *)&type;
183 a_params.out = (char *)flags;
185 if (pioctl(NULL, VIOCCONNECTMODE, &a_params, 0) == -1)
196 #ifdef VIOC_FPRIOSTATUS
198 fs_setfprio(struct VenusFid fid, int16_t prio)
200 struct ViceIoctl a_params;
201 struct vioc_fprio fprio;
203 fprio.cmd = FPRIO_SET;
204 fprio.Cell = fid.Cell;
205 fprio.Volume = fid.fid.Volume;
206 fprio.Vnode = fid.fid.Vnode;
207 fprio.Unique = fid.fid.Unique;
210 a_params.in_size = sizeof(fprio);
211 a_params.out_size = 0;
212 a_params.in = (char *)&fprio;
215 if (pioctl(NULL, VIOC_FPRIOSTATUS, &a_params, 0) == -1)
222 #ifdef VIOC_FPRIOSTATUS
224 fs_getfprio(struct VenusFid fid, int16_t * prio)
226 struct ViceIoctl a_params;
227 struct vioc_fprio fprio;
229 fprio.cmd = FPRIO_GET;
230 fprio.Cell = fid.Cell;
231 fprio.Volume = fid.fid.Volume;
232 fprio.Vnode = fid.fid.Vnode;
233 fprio.Unique = fid.fid.Unique;
235 a_params.in_size = sizeof(fprio);
236 a_params.out_size = sizeof(*prio);
237 a_params.in = (char *)&fprio;
238 a_params.out = (char *)prio;
240 if (pioctl(NULL, VIOC_FPRIOSTATUS, &a_params, 0) == -1)
247 #ifdef VIOC_FPRIOSTATUS
249 fs_setmaxfprio(int16_t maxprio)
251 struct ViceIoctl a_params;
252 struct vioc_fprio fprio;
254 fprio.cmd = FPRIO_SETMAX;
255 fprio.prio = maxprio;
257 a_params.in_size = sizeof(fprio);
258 a_params.out_size = 0;
259 a_params.in = (char *)&fprio;
262 if (pioctl(NULL, VIOC_FPRIOSTATUS, &a_params, 0) == -1)
269 #ifdef VIOC_FPRIOSTATUS
271 fs_getmaxfprio(int16_t * maxprio)
273 struct ViceIoctl a_params;
274 struct vioc_fprio fprio;
276 fprio.cmd = FPRIO_GETMAX;
278 a_params.in_size = sizeof(fprio);
279 a_params.out_size = sizeof(*maxprio);
280 a_params.in = (char *)&fprio;
281 a_params.out = (char *)maxprio;
283 if (pioctl(NULL, VIOC_FPRIOSTATUS, &a_params, 0) == -1)
294 #ifdef VIOCGETCACHEPARAMS
296 fs_getfilecachestats(afs_uint32 * max_bytes, afs_uint32 * used_bytes,
297 afs_uint32 * max_vnodes, afs_uint32 * used_vnodes)
299 afs_uint32 parms[16];
300 struct ViceIoctl a_params;
302 a_params.in_size = 0;
303 a_params.out_size = sizeof(parms);
305 a_params.out = (char *)parms;
307 memset(parms, 0, sizeof(parms));
309 if (pioctl(NULL, VIOCGETCACHEPARAMS, &a_params, 0) == -1)
312 /* param[0] and param[1] send maxbytes and usedbytes in kbytes */
315 *max_vnodes = parms[2];
317 *used_vnodes = parms[3];
319 *max_bytes = parms[4];
321 *used_bytes = parms[5];
333 fs_getaviatorstats(afs_uint32 * max_workers, afs_uint32 * used_workers)
335 afs_uint32 parms[16];
336 struct ViceIoctl a_params;
338 a_params.in_size = 0;
339 a_params.out_size = sizeof(parms);
341 a_params.out = (char *)parms;
343 if (pioctl(NULL, VIOC_AVIATOR, &a_params, 0) == -1)
347 *max_workers = parms[0];
349 *used_workers = parms[1];
363 struct ViceIoctl a_params;
365 a_params.in_size = 0;
366 a_params.out_size = 0;
371 if (pioctl(NULL, VIOC_GCPAGS, &a_params, 0) != 0)
382 #ifdef VIOC_CALCULATE_CACHE
384 fs_calculate_cache(afs_uint32 * calculated, afs_uint32 * usedbytes)
386 afs_uint32 parms[16];
387 struct ViceIoctl a_params;
389 a_params.in_size = 0;
390 a_params.out_size = sizeof(parms);
392 a_params.out = (char *)parms;
394 if (pioctl(NULL, VIOC_CALCULATE_CACHE, &a_params, 0) == -1)
398 *calculated = parms[0];
400 *usedbytes = parms[1];
410 #ifdef VIOC_BREAKCALLBACK
412 fs_invalidate(const char *path)
414 struct ViceIoctl a_params;
416 a_params.in_size = 0;
417 a_params.out_size = 0;
421 if (pioctl((char *)path, VIOC_BREAKCALLBACK, &a_params, 0) < 0)
429 * Get/set debug levels with pioctl_cmd.
431 * inflags == -1 -> don't change
432 * outflags == NULL -> don't return
436 debug(int pioctl_cmd, int inflags, int *outflags, char *pathname)
438 struct ViceIoctl a_params;
440 afs_int32 rinflags = inflags;
444 a_params.in_size = sizeof(rinflags);
445 a_params.in = (char *)&rinflags;
447 a_params.in_size = 0;
452 a_params.out_size = sizeof(routflags);
453 a_params.out = (char *)&routflags;
455 a_params.out_size = 0;
459 if (pioctl(pathname, pioctl_cmd, &a_params, 0) == -1)
463 *outflags = routflags;
474 xfs_debug(int inflags, int *outflags)
476 return debug(VIOC_XFSDEBUG, inflags, outflags, NULL);
484 #ifdef VIOC_XFSDEBUG_PRINT
486 xfs_debug_print(int inflags, char *pathname)
488 return debug(VIOC_XFSDEBUG_PRINT, inflags, NULL, pathname);
496 #ifdef VIOC_ARLADEBUG
498 arla_debug(int inflags, int *outflags)
500 return debug(VIOC_ARLADEBUG, inflags, outflags, NULL);
507 * flags is the same flags as in CKSERV flags
512 fs_checkservers(char *cell, afs_int32 flags, afs_uint32 * hosts, int numhosts)
514 struct ViceIoctl a_params;
520 insize = strlen(cell) + sizeof(afs_int32) + 1;
525 memcpy(in, &flags, sizeof(flags));
527 memcpy(in + sizeof(afs_int32), cell, strlen(cell));
528 in[sizeof(afs_int32) + strlen(cell)] = '\0';
530 a_params.in_size = insize;
533 a_params.in_size = sizeof(flags);
534 a_params.in = (caddr_t) & flags;
537 a_params.out_size = numhosts * sizeof(afs_uint32);
538 a_params.out = (caddr_t) hosts;
542 if (pioctl(NULL, VIOCCKSERV, &a_params, 0) == -1)
552 * check validity of cached volume information
556 fs_checkvolumes(void)
558 struct ViceIoctl a_params;
561 a_params.in_size = 0;
563 a_params.out_size = 0;
565 if (pioctl(NULL, VIOCCKBACK, &a_params, 0) < 0)
572 * set current sysname to `sys'
576 fs_set_sysname(const char *sys)
578 struct ViceIoctl a_params;
581 a_params.in_size = sizeof(set) + strlen(sys) + 1;
582 a_params.in = malloc(a_params.in_size);
583 if (a_params.in == NULL)
586 a_params.out_size = 0;
587 memcpy(a_params.in, &set, sizeof(set));
588 strcpy(a_params.in + sizeof(set), sys);
590 if (pioctl(NULL, VIOC_AFS_SYSNAME, &a_params, 1) < 0)
601 fs_setcache(int lv, int hv, int lb, int hb)
603 struct ViceIoctl a_params;
611 a_params.in_size = ((hv == 0) ? 1 : 4) * sizeof(afs_uint32);
612 a_params.out_size = 0;
613 a_params.in = (void *)s;
616 if (pioctl(NULL, VIOCSETCACHESIZE, &a_params, 0) < 0)
623 * return the local cell in `cell' (of size `cell_sz').
627 fs_wscell(char *cell, size_t cell_sz)
629 struct ViceIoctl a_params;
631 a_params.in_size = 0;
633 a_params.out_size = cell_sz;
636 if (pioctl(NULL, VIOC_GET_WS_CELL, &a_params, 0) < 0)
642 * Flush the contents of the volume pointed to by `path'.
646 fs_flushvolume(const char *path)
648 struct ViceIoctl a_params;
650 a_params.in_size = 0;
651 a_params.out_size = 0;
655 if (pioctl((char *)path, VIOC_FLUSHVOLUME, &a_params, 0) < 0)
662 * Flush the file `path' from the cache.
666 fs_flush(const char *path)
668 struct ViceIoctl a_params;
670 a_params.in_size = 0;
671 a_params.out_size = 0;
675 if (pioctl((char *)path, VIOCFLUSH, &a_params, 0) < 0)
688 struct ViceIoctl a_params;
689 afs_int32 status = 0; /* XXX not really right, but anyway */
691 a_params.in_size = sizeof(afs_int32);
692 a_params.out_size = 0;
693 a_params.in = (caddr_t) & status;
696 if (pioctl(NULL, VIOC_VENUSLOG, &a_params, 0) < 0)
703 * Get status for `cell' and put the flags in `flags'.
707 fs_getcellstatus(char *cellname, afs_uint32 * flags)
709 struct ViceIoctl a_params;
711 a_params.in_size = strlen(cellname) + 1;
712 a_params.out_size = sizeof(afs_uint32);
713 a_params.in = cellname;
714 a_params.out = (caddr_t) flags;
716 if (pioctl(NULL, VIOC_GETCELLSTATUS, &a_params, 0) < 0)
723 * Separate `path' into directory and last component and call
724 * pioctl with `pioctl_cmd'.
728 internal_mp(const char *path, int pioctl_cmd, char **res)
730 struct ViceIoctl a_params;
735 path_bkp = strdup(path);
736 if (path_bkp == NULL) {
737 printf("fs: Out of memory\n");
741 a_params.out = malloc(PIOCTL_MAXSIZE);
742 if (a_params.out == NULL) {
743 printf("fs: Out of memory\n");
748 /* If path contains more than the filename alone - split it */
750 last = strrchr(path_bkp, '/');
753 a_params.in = last + 1;
755 a_params.in = (char *)path;
757 a_params.in_size = strlen(a_params.in) + 1;
758 a_params.out_size = PIOCTL_MAXSIZE;
760 error = pioctl(last ? path_bkp : ".", pioctl_cmd, &a_params, 1);
777 fs_lsmount(const char *path)
780 int error = internal_mp(path, VIOC_AFS_STAT_MT_PT, &res);
783 printf("'%s' is a mount point for volume '%s'\n", path, res);
790 fs_rmmount(const char *path)
792 return internal_mp(path, VIOC_AFS_DELETE_MT_PT, NULL);
796 fs_incompat_renumber(int *ret)
798 struct ViceIoctl a_params;
799 unsigned char buf[1024];
801 a_params.in_size = 0;
802 a_params.out_size = sizeof(buf);
804 a_params.out = (caddr_t) buf;
806 /* getcrypt or getinitparams */
807 if (pioctl(NULL, _VICEIOCTL(49), &a_params, 0) < 0) {
808 if (errno == EINVAL) {
810 /* not openafs or old openafs */
812 a_params.in_size = 0;
813 a_params.out_size = 4;
815 a_params.out = (caddr_t) buf;
817 if (pioctl(NULL, _VICEIOCTL(49), &a_params, 0) < 0) {
818 if (errno == EINVAL) {
820 a_params.in_size = 0;
821 a_params.out_size = 4;
823 a_params.out = (caddr_t) buf;
825 /* might be new interface */
827 if (pioctl(NULL, _VICEIOCTL(55), &a_params, 0) < 0)
828 return errno; /* dunno */