2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #ifdef IGNORE_SOME_GCC_WARNINGS
16 # pragma GCC diagnostic warning "-Wdeprecated-declarations"
26 #include <afs/afsutil.h>
30 #if defined(AFS_LINUX20_ENV)
31 #include <sys/resource.h>
34 #ifdef HAVE_SYS_FS_TYPES_H
35 #include <sys/fs_types.h>
38 #ifdef HAVE_SYS_MOUNT_H
39 #include <sys/mount.h>
42 #ifdef HAVE_SYS_FCNTL_H
43 #include <sys/fcntl.h>
46 #ifdef HAVE_SYS_MNTTAB_H
47 #include <sys/mnttab.h>
50 #ifdef HAVE_SYS_MNTENT_H
51 #include <sys/mntent.h>
58 #ifdef HAVE_SYS_MOUNT_H
59 #include <sys/mount.h>
66 #ifdef HAVE_SYS_FSTYP_H
67 #include <sys/fstyp.h>
73 #include <afs/afs_args.h>
74 #include <afs/cellconfig.h>
75 #include <afs/afssyscalls.h>
76 #include <afs/afsutil.h>
79 #ifdef AFS_DARWIN80_ENV
80 #include <sys/xattr.h>
82 #include <mach/mach.h>
83 #ifndef AFS_DARWIN100_ENV
84 /* Symbols from the DiskArbitration framework */
85 kern_return_t DiskArbStart(mach_port_t *);
86 kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
88 #define DISK_ARB_NETWORK_DISK_FLAG 8
90 #include <mach/mach_port.h>
91 #include <mach/mach_interface.h>
92 #include <mach/mach_init.h>
93 #endif /* AFS_DARWIN_ENV */
96 #define MOUNT_AFS AFS_MOUNT_AFS
97 #endif /* MOUNT_AFS */
101 # define SET_RTPRI(P) { \
102 struct sched_param sp; \
103 sp.sched_priority = P; \
104 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
105 perror("sched_setscheduler"); \
108 # define SET_AFSD_RTPRI() SET_RTPRI(68)
109 # define SET_RX_RTPRI() SET_RTPRI(199)
111 # ifdef AFS_LINUX20_ENV
112 # define SET_AFSD_RTPRI()
113 # define SET_RX_RTPRI() do { \
114 if (setpriority(PRIO_PROCESS, 0, -10) < 0) \
115 perror("setting rx priority"); \
118 # define SET_AFSD_RTPRI()
119 # define SET_RX_RTPRI()
124 afsd_set_rx_rtpri(void)
130 afsd_set_afsd_rtpri(void)
135 #if defined(AFS_LINUX20_ENV)
137 os_syscall(struct afsd_syscall_args *args)
140 struct afsprocdata syscall_data;
142 int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
144 fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
149 syscall_data.syscall = AFSCALL_CALL;
150 syscall_data.param1 = args->syscall;
151 syscall_data.param2 = args->params[0];
152 syscall_data.param3 = args->params[1];
153 syscall_data.param4 = (long) &args->params[2];
155 error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
160 #elif defined(AFS_DARWIN80_ENV)
162 # if defined(AFS_DARWIN100_ENV)
164 os_syscall64(struct afsd_syscall_args *args)
167 struct afssysargs64 syscall64_data;
168 int fd = open(SYSCALL_DEV_FNAME, O_RDWR);
173 syscall64_data.syscall = (int)AFSCALL_CALL;
174 syscall64_data.param1 = args->syscall;
175 syscall64_data.param2 = args->params[0];
176 syscall64_data.param3 = args->params[1];
177 syscall64_data.param4 = args->params[2];
178 syscall64_data.param5 = args->params[3];
179 syscall64_data.param6 = args->params[4];
181 error = ioctl(fd, VIOC_SYSCALL64, &syscall64_data);
187 return syscall64_data.retval;
192 os_syscall(struct afsd_syscall_args *args)
195 struct afssysargs syscall_data;
198 # ifdef AFS_DARWIN100_ENV
199 if (sizeof(long) == 8)
200 return os_syscall64(args);
203 fd = open(SYSCALL_DEV_FNAME, O_RDWR);
207 syscall_data.syscall = AFSCALL_CALL;
208 syscall_data.param1 = (unsigned int)(uintptr_t)args->syscall;
209 syscall_data.param2 = (unsigned int)(uintptr_t)args->params[0];
210 syscall_data.param3 = (unsigned int)(uintptr_t)args->params[1];
211 syscall_data.param4 = (unsigned int)(uintptr_t)args->params[2];
212 syscall_data.param5 = (unsigned int)(uintptr_t)args->params[3];
213 syscall_data.param6 = (unsigned int)(uintptr_t)args->params[4];
215 error = ioctl(fd, VIOC_SYSCALL, syscall_data);
221 return syscall_data.retval;
224 #elif defined(AFS_SUN511_ENV)
226 os_syscall(struct afsd_syscall_args *args)
230 error = ioctl_sun_afs_syscall(AFSCALL_CALL, args->syscall,
231 args->params[0], args->params[1],
232 args->params[2], args->params[3],
233 args->params[4], &retval);
239 #elif defined(AFS_SGI_ENV)
241 os_syscall(struct afsd_syscall_args *args)
243 return afs_syscall(args->syscall, args->params[0], args->params[1],
244 args->params[2], args->params[3], args->params[4]);
246 #elif defined(AFS_AIX32_ENV)
248 os_syscall(struct afsd_syscall_args *args)
250 return syscall(AFSCALL_CALL, args->syscall,
251 args->params[0], args->params[1], args->params[2],
252 args->params[3], args->params[4], args->params[5],
257 os_syscall(struct afsd_syscall_args *args)
259 return syscall(AFS_SYSCALL, AFSCALL_CALL, args->syscall,
260 args->params[0], args->params[1], args->params[2],
261 args->params[3], args->params[4], args->params[5]);
266 afsd_call_syscall(struct afsd_syscall_args *args)
270 error = os_syscall(args);
273 #ifdef AFS_NBSD40_ENV
274 char *s = strerror(errno);
275 printf("SScall(%d, %d, %d)=%d (%d, %s)\n", AFS_SYSCALL, AFSCALL_CALL,
276 (int)args->params[0], error, errno, s);
278 printf("SScall(%d, %d, %d)=%d ", AFS_SYSCALL, AFSCALL_CALL,
279 (int)args->params[0], error);
287 /* Special handling for AIX's afs mount operation since they require much more
288 * miscl. information before making the vmount(2) syscall */
291 #define ROUNDUP(x) (((x) + 3) & ~3)
293 aix_vmount(const char *cacheMountDir)
295 struct vmount *vmountp;
298 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
299 /* Malloc and zero the vmount structure */
300 if ((vmountp = calloc(1, size)) == NULL) {
301 printf("Can't allocate space for the vmount structure (AIX)\n");
305 /* transfer info into the vmount structure */
306 vmountp->vmt_revision = VMT_REVISION;
307 vmountp->vmt_length = size;
308 vmountp->vmt_fsid.fsid_dev = 0;
309 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
310 vmountp->vmt_vfsnumber = 0;
311 vmountp->vmt_time = 0; /* We'll put the time soon! */
312 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
313 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
314 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
316 /* Do the actual mount system call */
317 error = vmount(vmountp, size);
322 vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host,
323 char *hostsname, char *info, char *args)
331 vdp = (struct data *)vmtp->vmt_data;
332 vdp->vmt_off = sizeof(struct vmount);
333 size = ROUNDUP(strlen(obj) + 1);
334 vdp->vmt_size = size;
335 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
339 vdp->vmt_off = vdprev->vmt_off + size;
340 size = ROUNDUP(strlen(stub) + 1);
341 vdp->vmt_size = size;
342 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
346 vdp->vmt_off = vdprev->vmt_off + size;
347 size = ROUNDUP(strlen(host) + 1);
348 vdp->vmt_size = size;
349 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
353 vdp->vmt_off = vdprev->vmt_off + size;
354 size = ROUNDUP(strlen(hostsname) + 1);
355 vdp->vmt_size = size;
356 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
361 vdp->vmt_off = vdprev->vmt_off + size;
362 size = ROUNDUP(strlen(info) + 1);
363 vdp->vmt_size = size;
364 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
368 vdp->vmt_off = vdprev->vmt_off + size;
369 size = ROUNDUP(strlen(args) + 1);
370 vdp->vmt_size = size;
371 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
373 #endif /* AFS_AIX_ENV */
376 #define MOUNTED_TABLE MNT_MNTTAB
378 #define MOUNTED_TABLE MOUNTED
382 HandleMTab(char *cacheMountDir)
384 #if (defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV))
386 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
387 struct mntent tmntent;
391 tfilep = setmntent("/etc/mtab", "a+");
393 printf("Can't open /etc/mtab for writing (errno %d); not adding "
394 "an entry for AFS\n", errno);
398 dir = strdup(cacheMountDir);
400 /* trim trailing slashes; don't look at dir[0] in case we are somehow
402 for (i = strlen(dir)-1; i > 0; i--) {
410 tmntent.mnt_fsname = "AFS";
411 tmntent.mnt_dir = dir;
412 tmntent.mnt_type = "afs";
413 tmntent.mnt_opts = "rw";
414 tmntent.mnt_freq = 1;
415 tmntent.mnt_passno = 3;
416 addmntent(tfilep, &tmntent);
422 struct mntent tmntent;
424 memset(&tmntent, '\0', sizeof(struct mntent));
425 tfilep = setmntent(MOUNTED_TABLE, "a+");
427 printf("Can't open %s for write; Not adding afs entry to it\n",
431 tmntent.mnt_fsname = "AFS";
432 tmntent.mnt_dir = cacheMountDir;
433 tmntent.mnt_type = "xx";
434 tmntent.mnt_opts = "rw";
435 tmntent.mnt_freq = 1;
436 tmntent.mnt_passno = 3;
438 tmntent.mnt_type = "afs";
439 tmntent.mnt_time = time(0);
440 tmntent.mnt_cnode = 0;
442 addmntent(tfilep, &tmntent);
444 #endif /* AFS_SGI_ENV */
445 #endif /* unreasonable systems */
446 #ifdef AFS_DARWIN_ENV
447 #ifndef AFS_DARWIN100_ENV
448 mach_port_t diskarb_port;
449 kern_return_t status;
451 status = DiskArbStart(&diskarb_port);
452 if (status == KERN_SUCCESS) {
454 DiskArbDiskAppearedWithMountpointPing_auto("AFS",
455 DISK_ARB_NETWORK_DISK_FLAG,
461 #endif /* AFS_DARWIN_ENV */
466 afsd_mount_afs(const char *rn, const char *cacheMountDir)
468 int mountFlags; /*Flags passed to mount() */
469 char *mountDir; /* For HandleMTab() */
471 mountFlags = 0; /* Read/write file system, can do setuid() */
472 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
474 mountFlags |= MS_DATA;
476 mountFlags |= M_NEWTYPE; /* This searches by name in vfs_conf.c so don't need to recompile vfs.c because MOUNT_MAXTYPE has changed; it seems that Sun fixed this at last... */
480 #if defined(AFS_HPUX100_ENV)
481 mountFlags |= MS_DATA;
485 printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn,
486 cacheMountDir, mountFlags);
487 #if defined(AFS_FBSD60_ENV)
488 /* data must be non-NULL but is otherwise ignored */
489 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) {
490 #elif defined(AFS_FBSD_ENV)
491 if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
492 #elif defined(AFS_AIX_ENV)
493 if (aix_vmount(cacheMountDir)) {
494 #elif defined(AFS_HPUX100_ENV)
495 if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
496 #elif defined(AFS_SUN5_ENV)
497 if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
498 #elif defined(AFS_SGI_ENV)
500 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS))
502 #elif defined(AFS_LINUX20_ENV)
503 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) {
504 #elif defined(AFS_NBSD50_ENV)
505 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, NULL, 0)) < 0) {
507 /* This is the standard mount used by the suns and rts */
508 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
510 printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir,
515 mountDir = strdup(cacheMountDir);
516 HandleMTab(mountDir);
521 afsd_fork(int wait, afsd_callback_func cb, void *rock)
531 assert(waitpid(code, NULL, 0) != -1);
538 afsd_daemon(int nochdir, int noclose)
540 return daemon(nochdir, noclose);
544 afsd_check_mount(const char *rn, const char *mountdir)
548 if (stat(mountdir, &statbuf)) {
549 printf("%s: Mountpoint %s missing.\n", rn, mountdir);
551 } else if (!S_ISDIR(statbuf.st_mode)) {
552 printf("%s: Mountpoint %s is not a directory.\n", rn, mountdir);
559 main(int argc, char **argv)
565 code = afsd_parse(argc, argv);