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;
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;
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 (u_int32_t 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 (u_int32_t *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(int32_t type, int32_t *flags)
178 struct ViceIoctl a_params;
180 a_params.in_size = sizeof(type);
181 a_params.out_size = sizeof (int32_t);
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(u_int32_t *max_bytes,
297 u_int32_t *used_bytes,
298 u_int32_t *max_vnodes,
299 u_int32_t *used_vnodes)
302 struct ViceIoctl a_params;
304 a_params.in_size = 0;
305 a_params.out_size = sizeof(parms);
307 a_params.out = (char *) parms;
309 memset (parms, 0, sizeof(parms));
311 if (pioctl (NULL, VIOCGETCACHEPARAMS , &a_params, 0) == -1)
314 /* param[0] and param[1] send maxbytes and usedbytes in kbytes */
317 *max_vnodes = parms[2];
319 *used_vnodes = parms[3];
321 *max_bytes = parms[4];
323 *used_bytes = parms[5];
335 fs_getaviatorstats(u_int32_t *max_workers,
336 u_int32_t *used_workers)
339 struct ViceIoctl a_params;
341 a_params.in_size = 0;
342 a_params.out_size = sizeof(parms);
344 a_params.out = (char *) parms;
346 if (pioctl (NULL, VIOC_AVIATOR , &a_params, 0) == -1)
350 *max_workers = parms[0];
352 *used_workers = parms[1];
366 struct ViceIoctl a_params;
368 a_params.in_size = 0;
369 a_params.out_size = 0;
374 if (pioctl(NULL, VIOC_GCPAGS, &a_params, 0) != 0)
385 #ifdef VIOC_CALCULATE_CACHE
387 fs_calculate_cache(u_int32_t *calculated,
388 u_int32_t *usedbytes)
391 struct ViceIoctl a_params;
393 a_params.in_size = 0;
394 a_params.out_size = sizeof(parms);
396 a_params.out = (char *) parms;
398 if (pioctl (NULL, VIOC_CALCULATE_CACHE , &a_params, 0) == -1)
402 *calculated = parms[0];
404 *usedbytes = parms[1];
414 #ifdef VIOC_BREAKCALLBACK
416 fs_invalidate (const char *path)
418 struct ViceIoctl a_params;
420 a_params.in_size = 0;
421 a_params.out_size = 0;
425 if (pioctl ((char *)path, VIOC_BREAKCALLBACK, &a_params, 0) < 0)
433 * Get/set debug levels with pioctl_cmd.
435 * inflags == -1 -> don't change
436 * outflags == NULL -> don't return
440 debug (int pioctl_cmd, int inflags, int *outflags, char *pathname)
442 struct ViceIoctl a_params;
444 int32_t rinflags = inflags;
448 a_params.in_size = sizeof(rinflags);
449 a_params.in = (char *) &rinflags;
451 a_params.in_size = 0;
456 a_params.out_size = sizeof(routflags);
457 a_params.out = (char *) &routflags;
459 a_params.out_size = 0;
463 if (pioctl (pathname, pioctl_cmd, &a_params, 0) == -1)
467 *outflags = routflags;
478 xfs_debug(int inflags, int *outflags)
480 return debug (VIOC_XFSDEBUG, inflags, outflags, NULL);
488 #ifdef VIOC_XFSDEBUG_PRINT
490 xfs_debug_print(int inflags, char *pathname)
492 return debug (VIOC_XFSDEBUG_PRINT, inflags, NULL, pathname);
500 #ifdef VIOC_ARLADEBUG
502 arla_debug (int inflags, int *outflags)
504 return debug (VIOC_ARLADEBUG, inflags, outflags, NULL);
511 * flags is the same flags as in CKSERV flags
516 fs_checkservers(char *cell, int32_t flags, u_int32_t *hosts, int numhosts)
518 struct ViceIoctl a_params;
524 insize = strlen(cell) + sizeof(int32_t) + 1;
525 in = malloc (insize);
529 memcpy (in, &flags, sizeof(flags));
531 memcpy (in + sizeof(int32_t), cell, strlen(cell));
532 in[sizeof(int32_t) + strlen(cell)] = '\0';
534 a_params.in_size = insize;
537 a_params.in_size = sizeof(flags);
538 a_params.in = (caddr_t )&flags;
541 a_params.out_size = numhosts * sizeof(u_int32_t);
542 a_params.out = (caddr_t)hosts;
546 if (pioctl (NULL, VIOCCKSERV, &a_params, 0) == -1)
556 * check validity of cached volume information
560 fs_checkvolumes (void)
562 struct ViceIoctl a_params;
565 a_params.in_size = 0;
567 a_params.out_size = 0;
569 if (pioctl (NULL, VIOCCKBACK, &a_params, 0) < 0)
576 * set current sysname to `sys'
580 fs_set_sysname (const char *sys)
582 struct ViceIoctl a_params;
585 a_params.in_size = sizeof(set) + strlen(sys) + 1;
586 a_params.in = malloc(a_params.in_size);
587 if (a_params.in == NULL)
590 a_params.out_size = 0;
591 memcpy (a_params.in, &set, sizeof(set));
592 strcpy (a_params.in + sizeof(set), sys);
594 if(pioctl (NULL, VIOC_AFS_SYSNAME, &a_params, 1) < 0)
605 fs_setcache(int lv, int hv, int lb, int hb)
607 struct ViceIoctl a_params;
615 a_params.in_size = ((hv == 0) ? 1 : 4) * sizeof(u_int32_t);
616 a_params.out_size = 0;
617 a_params.in = (void *)s;
620 if (pioctl(NULL, VIOCSETCACHESIZE, &a_params, 0) < 0)
627 * return the local cell in `cell' (of size `cell_sz').
631 fs_wscell (char *cell, size_t cell_sz)
633 struct ViceIoctl a_params;
635 a_params.in_size = 0;
637 a_params.out_size = cell_sz;
640 if (pioctl (NULL, VIOC_GET_WS_CELL, &a_params, 0) < 0)
646 * Flush the contents of the volume pointed to by `path'.
650 fs_flushvolume (const char *path)
652 struct ViceIoctl a_params;
654 a_params.in_size = 0;
655 a_params.out_size = 0;
659 if (pioctl ((char *)path, VIOC_FLUSHVOLUME, &a_params, 0) < 0)
666 * Flush the file `path' from the cache.
670 fs_flush (const char *path)
672 struct ViceIoctl a_params;
674 a_params.in_size = 0;
675 a_params.out_size = 0;
679 if (pioctl ((char *)path, VIOCFLUSH, &a_params, 0) < 0)
692 struct ViceIoctl a_params;
693 int32_t status = 0; /* XXX not really right, but anyway */
695 a_params.in_size = sizeof(int32_t);
696 a_params.out_size = 0;
697 a_params.in = (caddr_t) &status;
700 if (pioctl (NULL, VIOC_VENUSLOG, &a_params, 0) < 0)
707 * Get status for `cell' and put the flags in `flags'.
711 fs_getcellstatus (char *cellname, u_int32_t *flags)
713 struct ViceIoctl a_params;
715 a_params.in_size = strlen (cellname) + 1;
716 a_params.out_size = sizeof (u_int32_t);
717 a_params.in = cellname;
718 a_params.out = (caddr_t) flags;
720 if (pioctl (NULL, VIOC_GETCELLSTATUS, &a_params, 0) < 0)
727 * Separate `path' into directory and last component and call
728 * pioctl with `pioctl_cmd'.
732 internal_mp (const char *path, int pioctl_cmd, char **res)
734 struct ViceIoctl a_params;
739 path_bkp = strdup (path);
740 if (path_bkp == NULL) {
741 printf ("fs: Out of memory\n");
745 a_params.out = malloc (PIOCTL_MAXSIZE);
746 if (a_params.out == NULL) {
747 printf ("fs: Out of memory\n");
752 /* If path contains more than the filename alone - split it */
754 last = strrchr (path_bkp, '/');
757 a_params.in = last + 1;
759 a_params.in = (char *)path;
761 a_params.in_size = strlen (a_params.in) + 1;
762 a_params.out_size = PIOCTL_MAXSIZE;
764 error = pioctl (last ? path_bkp : "." ,
765 pioctl_cmd, &a_params, 1);
782 fs_lsmount (const char *path)
785 int error = internal_mp (path, VIOC_AFS_STAT_MT_PT, &res);
788 printf ("'%s' is a mount point for volume '%s'\n", path, res);
795 fs_rmmount (const char *path)
797 return internal_mp (path, VIOC_AFS_DELETE_MT_PT, NULL);
801 fs_incompat_renumber (int *ret)
803 struct ViceIoctl a_params;
804 unsigned char buf[1024];
806 a_params.in_size = 0;
807 a_params.out_size = sizeof(buf);
809 a_params.out = (caddr_t) buf;
811 /* getcrypt or getinitparams */
812 if (pioctl (NULL, _VICEIOCTL(49), &a_params, 0) < 0) {
813 if (errno == EINVAL) {
815 /* not openafs or old openafs */
817 a_params.in_size = 0;
818 a_params.out_size = 4;
820 a_params.out = (caddr_t) buf;
822 if (pioctl (NULL, _VICEIOCTL(49), &a_params, 0) < 0) {
823 if (errno == EINVAL) {
825 a_params.in_size = 0;
826 a_params.out_size = 4;
828 a_params.out = (caddr_t) buf;
830 /* might be new interface */
832 if (pioctl (NULL, _VICEIOCTL(55), &a_params, 0) < 0)
833 return errno; /* dunno */