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>
52 #include <afs/cellconfig.h>
54 #include <afs/sys_prototypes.h>
59 enum { PIOCTL_MAXSIZE
= 2000 };
62 * fs_getfid, the the `fid' that `path' points on.
66 fs_getfid(char *path
, struct VenusFid
*fid
)
68 struct ViceIoctl a_params
;
70 if (path
== NULL
|| fid
== NULL
)
74 a_params
.out_size
= sizeof(struct VenusFid
);
76 a_params
.out
= (void *)fid
;
78 if (pioctl(path
, VIOCGETFID
, &a_params
, 1) == -1)
91 struct ViceIoctl a_params
;
94 a_params
.out_size
= 0;
98 if (pioctl(NULL
, VIOCNOP
, &a_params
, 1) == -1)
105 * Get the `cell' that the `path' ends up in
109 fs_getfilecellname(char *path
, char *cell
, size_t len
)
111 struct ViceIoctl a_params
;
113 a_params
.in_size
= 0;
114 a_params
.out_size
= len
;
118 if (pioctl(path
, VIOC_FILE_CELL_NAME
, &a_params
, 1) == -1)
125 * set the level of crypt
128 #ifdef VIOC_SETRXKCRYPT
130 fs_setcrypt(afs_uint32 n
)
132 struct ViceIoctl a_params
;
134 a_params
.in_size
= sizeof(n
);
135 a_params
.out_size
= 0;
136 a_params
.in
= (char *)&n
;
139 if (pioctl(NULL
, VIOC_SETRXKCRYPT
, &a_params
, 0) == -1)
147 * get currernt level of crypt
150 #ifdef VIOC_GETRXKCRYPT
152 fs_getcrypt(afs_uint32
* level
)
154 struct ViceIoctl a_params
;
156 a_params
.in_size
= 0;
157 a_params
.out_size
= sizeof(*level
);
159 a_params
.out
= (char *)level
;
161 if (pioctl(NULL
, VIOC_GETRXKCRYPT
, &a_params
, 0) == -1)
169 * get and set the connect-mode
172 #ifdef VIOCCONNECTMODE
174 fs_connect(afs_int32 type
, afs_int32
* flags
)
176 struct ViceIoctl a_params
;
178 a_params
.in_size
= sizeof(type
);
179 a_params
.out_size
= sizeof(afs_int32
);
180 a_params
.in
= (char *)&type
;
181 a_params
.out
= (char *)flags
;
183 if (pioctl(NULL
, VIOCCONNECTMODE
, &a_params
, 0) == -1)
194 #ifdef VIOC_FPRIOSTATUS
196 fs_setfprio(struct VenusFid fid
, int16_t prio
)
198 struct ViceIoctl a_params
;
199 struct vioc_fprio fprio
;
201 fprio
.cmd
= FPRIO_SET
;
202 fprio
.Cell
= fid
.Cell
;
203 fprio
.Volume
= fid
.fid
.Volume
;
204 fprio
.Vnode
= fid
.fid
.Vnode
;
205 fprio
.Unique
= fid
.fid
.Unique
;
208 a_params
.in_size
= sizeof(fprio
);
209 a_params
.out_size
= 0;
210 a_params
.in
= (char *)&fprio
;
213 if (pioctl(NULL
, VIOC_FPRIOSTATUS
, &a_params
, 0) == -1)
220 #ifdef VIOC_FPRIOSTATUS
222 fs_getfprio(struct VenusFid fid
, int16_t * prio
)
224 struct ViceIoctl a_params
;
225 struct vioc_fprio fprio
;
227 fprio
.cmd
= FPRIO_GET
;
228 fprio
.Cell
= fid
.Cell
;
229 fprio
.Volume
= fid
.fid
.Volume
;
230 fprio
.Vnode
= fid
.fid
.Vnode
;
231 fprio
.Unique
= fid
.fid
.Unique
;
233 a_params
.in_size
= sizeof(fprio
);
234 a_params
.out_size
= sizeof(*prio
);
235 a_params
.in
= (char *)&fprio
;
236 a_params
.out
= (char *)prio
;
238 if (pioctl(NULL
, VIOC_FPRIOSTATUS
, &a_params
, 0) == -1)
245 #ifdef VIOC_FPRIOSTATUS
247 fs_setmaxfprio(int16_t maxprio
)
249 struct ViceIoctl a_params
;
250 struct vioc_fprio fprio
;
252 fprio
.cmd
= FPRIO_SETMAX
;
253 fprio
.prio
= maxprio
;
255 a_params
.in_size
= sizeof(fprio
);
256 a_params
.out_size
= 0;
257 a_params
.in
= (char *)&fprio
;
260 if (pioctl(NULL
, VIOC_FPRIOSTATUS
, &a_params
, 0) == -1)
267 #ifdef VIOC_FPRIOSTATUS
269 fs_getmaxfprio(int16_t * maxprio
)
271 struct ViceIoctl a_params
;
272 struct vioc_fprio fprio
;
274 fprio
.cmd
= FPRIO_GETMAX
;
276 a_params
.in_size
= sizeof(fprio
);
277 a_params
.out_size
= sizeof(*maxprio
);
278 a_params
.in
= (char *)&fprio
;
279 a_params
.out
= (char *)maxprio
;
281 if (pioctl(NULL
, VIOC_FPRIOSTATUS
, &a_params
, 0) == -1)
292 #ifdef VIOCGETCACHEPARAMS
294 fs_getfilecachestats(afs_uint32
* max_bytes
, afs_uint32
* used_bytes
,
295 afs_uint32
* max_vnodes
, afs_uint32
* used_vnodes
)
297 afs_uint32 parms
[16];
298 struct ViceIoctl a_params
;
300 a_params
.in_size
= 0;
301 a_params
.out_size
= sizeof(parms
);
303 a_params
.out
= (char *)parms
;
305 memset(parms
, 0, sizeof(parms
));
307 if (pioctl(NULL
, VIOCGETCACHEPARAMS
, &a_params
, 0) == -1)
310 /* param[0] and param[1] send maxbytes and usedbytes in kbytes */
313 *max_vnodes
= parms
[2];
315 *used_vnodes
= parms
[3];
317 *max_bytes
= parms
[4];
319 *used_bytes
= parms
[5];
331 fs_getaviatorstats(afs_uint32
* max_workers
, afs_uint32
* used_workers
)
333 afs_uint32 parms
[16];
334 struct ViceIoctl a_params
;
336 a_params
.in_size
= 0;
337 a_params
.out_size
= sizeof(parms
);
339 a_params
.out
= (char *)parms
;
341 if (pioctl(NULL
, VIOC_AVIATOR
, &a_params
, 0) == -1)
345 *max_workers
= parms
[0];
347 *used_workers
= parms
[1];
361 struct ViceIoctl a_params
;
363 a_params
.in_size
= 0;
364 a_params
.out_size
= 0;
369 if (pioctl(NULL
, VIOC_GCPAGS
, &a_params
, 0) != 0)
380 #ifdef VIOC_CALCULATE_CACHE
382 fs_calculate_cache(afs_uint32
* calculated
, afs_uint32
* usedbytes
)
384 afs_uint32 parms
[16];
385 struct ViceIoctl a_params
;
387 a_params
.in_size
= 0;
388 a_params
.out_size
= sizeof(parms
);
390 a_params
.out
= (char *)parms
;
392 if (pioctl(NULL
, VIOC_CALCULATE_CACHE
, &a_params
, 0) == -1)
396 *calculated
= parms
[0];
398 *usedbytes
= parms
[1];
408 #ifdef VIOC_BREAKCALLBACK
410 fs_invalidate(const char *path
)
412 struct ViceIoctl a_params
;
414 a_params
.in_size
= 0;
415 a_params
.out_size
= 0;
419 if (pioctl((char *)path
, VIOC_BREAKCALLBACK
, &a_params
, 0) < 0)
427 * Get/set debug levels with pioctl_cmd.
429 * inflags == -1 -> don't change
430 * outflags == NULL -> don't return
433 #if defined(VIOC_XFSDEBUG) || defined(VIOC_XFSDEBUG_PRINT) \
434 || defined(VIOC_ARLADEBUG)
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
;
475 xfs_debug(int inflags
, int *outflags
)
477 return debug(VIOC_XFSDEBUG
, inflags
, outflags
, NULL
);
485 #ifdef VIOC_XFSDEBUG_PRINT
487 xfs_debug_print(int inflags
, char *pathname
)
489 return debug(VIOC_XFSDEBUG_PRINT
, inflags
, NULL
, pathname
);
497 #ifdef VIOC_ARLADEBUG
499 arla_debug(int inflags
, int *outflags
)
501 return debug(VIOC_ARLADEBUG
, inflags
, outflags
, NULL
);
508 * flags is the same flags as in CKSERV flags
513 fs_checkservers(char *cell
, afs_int32 flags
, afs_uint32
* hosts
, int numhosts
)
515 struct ViceIoctl a_params
;
521 insize
= strlen(cell
) + sizeof(afs_int32
) + 1;
526 memcpy(in
, &flags
, sizeof(flags
));
528 memcpy(in
+ sizeof(afs_int32
), cell
, strlen(cell
));
529 in
[sizeof(afs_int32
) + strlen(cell
)] = '\0';
531 a_params
.in_size
= insize
;
534 a_params
.in_size
= sizeof(flags
);
535 a_params
.in
= (caddr_t
) & flags
;
538 a_params
.out_size
= numhosts
* sizeof(afs_uint32
);
539 a_params
.out
= (caddr_t
) hosts
;
543 if (pioctl(NULL
, VIOCCKSERV
, &a_params
, 0) == -1)
553 * check validity of cached volume information
557 fs_checkvolumes(void)
559 struct ViceIoctl a_params
;
562 a_params
.in_size
= 0;
564 a_params
.out_size
= 0;
566 if (pioctl(NULL
, VIOCCKBACK
, &a_params
, 0) < 0)
573 * set current sysname to `sys'
577 fs_set_sysname(const char *sys
)
579 struct ViceIoctl a_params
;
582 a_params
.in_size
= sizeof(set
) + strlen(sys
) + 1;
583 a_params
.in
= malloc(a_params
.in_size
);
584 if (a_params
.in
== NULL
)
587 a_params
.out_size
= 0;
588 memcpy(a_params
.in
, &set
, sizeof(set
));
589 strcpy(a_params
.in
+ sizeof(set
), sys
);
591 if (pioctl(NULL
, VIOC_AFS_SYSNAME
, &a_params
, 1) < 0)
602 fs_setcache(int lv
, int hv
, int lb
, int hb
)
604 struct ViceIoctl a_params
;
612 a_params
.in_size
= ((hv
== 0) ? 1 : 4) * sizeof(afs_uint32
);
613 a_params
.out_size
= 0;
614 a_params
.in
= (void *)s
;
617 if (pioctl(NULL
, VIOCSETCACHESIZE
, &a_params
, 0) < 0)
624 * return the local cell in `cell' (of size `cell_sz').
628 fs_wscell(char *cell
, size_t cell_sz
)
630 struct ViceIoctl a_params
;
632 a_params
.in_size
= 0;
634 a_params
.out_size
= cell_sz
;
637 if (pioctl(NULL
, VIOC_GET_WS_CELL
, &a_params
, 0) < 0)
643 * Flush the contents of the volume pointed to by `path'.
647 fs_flushvolume(const char *path
)
649 struct ViceIoctl a_params
;
651 a_params
.in_size
= 0;
652 a_params
.out_size
= 0;
656 if (pioctl((char *)path
, VIOC_FLUSHVOLUME
, &a_params
, 0) < 0)
663 * Flush the file `path' from the cache.
667 fs_flush(const char *path
)
669 struct ViceIoctl a_params
;
671 a_params
.in_size
= 0;
672 a_params
.out_size
= 0;
676 if (pioctl((char *)path
, VIOCFLUSH
, &a_params
, 0) < 0)
689 struct ViceIoctl a_params
;
690 afs_int32 status
= 0; /* XXX not really right, but anyway */
692 a_params
.in_size
= sizeof(afs_int32
);
693 a_params
.out_size
= 0;
694 a_params
.in
= (caddr_t
) & status
;
697 if (pioctl(NULL
, VIOC_VENUSLOG
, &a_params
, 0) < 0)
704 * Get status for `cell' and put the flags in `flags'.
708 fs_getcellstatus(char *cellname
, afs_uint32
* flags
)
710 struct ViceIoctl a_params
;
712 a_params
.in_size
= strlen(cellname
) + 1;
713 a_params
.out_size
= sizeof(afs_uint32
);
714 a_params
.in
= cellname
;
715 a_params
.out
= (caddr_t
) flags
;
717 if (pioctl(NULL
, VIOC_GETCELLSTATUS
, &a_params
, 0) < 0)
724 * Separate `path' into directory and last component and call
725 * pioctl with `pioctl_cmd'.
729 internal_mp(const char *path
, int pioctl_cmd
, char **res
)
731 struct ViceIoctl a_params
;
736 path_bkp
= strdup(path
);
737 if (path_bkp
== NULL
) {
738 printf("fs: Out of memory\n");
742 a_params
.out
= malloc(PIOCTL_MAXSIZE
);
743 if (a_params
.out
== NULL
) {
744 printf("fs: Out of memory\n");
749 /* If path contains more than the filename alone - split it */
751 last
= strrchr(path_bkp
, '/');
754 a_params
.in
= last
+ 1;
756 a_params
.in
= (char *)path
;
758 a_params
.in_size
= strlen(a_params
.in
) + 1;
759 a_params
.out_size
= PIOCTL_MAXSIZE
;
761 error
= pioctl(last
? path_bkp
: ".", pioctl_cmd
, &a_params
, 1);
778 fs_lsmount(const char *path
)
781 int error
= internal_mp(path
, VIOC_AFS_STAT_MT_PT
, &res
);
784 printf("'%s' is a mount point for volume '%s'\n", path
, res
);
791 fs_rmmount(const char *path
)
793 return internal_mp(path
, VIOC_AFS_DELETE_MT_PT
, NULL
);
797 fs_incompat_renumber(int *ret
)
799 struct ViceIoctl a_params
;
800 unsigned char buf
[1024];
802 a_params
.in_size
= 0;
803 a_params
.out_size
= sizeof(buf
);
805 a_params
.out
= (caddr_t
) buf
;
807 /* getcrypt or getinitparams */
808 if (pioctl(NULL
, _VICEIOCTL(49), &a_params
, 0) < 0) {
809 if (errno
== EINVAL
) {
811 /* not openafs or old openafs */
813 a_params
.in_size
= 0;
814 a_params
.out_size
= 4;
816 a_params
.out
= (caddr_t
) buf
;
818 if (pioctl(NULL
, _VICEIOCTL(49), &a_params
, 0) < 0) {
819 if (errno
== EINVAL
) {
821 a_params
.in_size
= 0;
822 a_params
.out_size
= 4;
824 a_params
.out
= (caddr_t
) buf
;
826 /* might be new interface */
828 if (pioctl(NULL
, _VICEIOCTL(55), &a_params
, 0) < 0)
829 return errno
; /* dunno */