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>
20 #include <potpourri.h>
21 #include <afs/afsutil.h>
28 #include <sys/types.h>
37 #ifdef HAVE_SYS_PARAM_H
38 #include <sys/param.h>
41 #ifdef HAVE_SYS_FS_TYPES_H
42 #include <sys/fs_types.h>
45 #ifdef HAVE_SYS_MOUNT_H
46 #include <sys/mount.h>
49 #ifdef HAVE_SYS_FCNTL_H
50 #include <sys/fcntl.h>
53 #ifdef HAVE_SYS_MNTTAB_H
54 #include <sys/mnttab.h>
57 #ifdef HAVE_SYS_MNTENT_H
58 #include <sys/mntent.h>
65 #ifdef HAVE_SYS_MOUNT_H
66 #include <sys/mount.h>
73 #ifdef HAVE_SYS_FSTYP_H
74 #include <sys/fstyp.h>
85 #include <netinet/in.h>
86 #include <afs/afs_args.h>
87 #include <afs/cellconfig.h>
89 #include <afs/afssyscalls.h>
90 #include <afs/afsutil.h>
93 #ifdef AFS_DARWIN80_ENV
94 #include <sys/ioctl.h>
95 #include <sys/xattr.h>
97 #include <mach/mach.h>
98 #ifndef AFS_DARWIN100_ENV
99 /* Symbols from the DiskArbitration framework */
100 kern_return_t DiskArbStart(mach_port_t *);
101 kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
103 #define DISK_ARB_NETWORK_DISK_FLAG 8
105 #include <mach/mach_port.h>
106 #include <mach/mach_interface.h>
107 #include <mach/mach_init.h>
108 #endif /* AFS_DARWIN_ENV */
111 #define MOUNT_AFS AFS_MOUNT_AFS
112 #endif /* MOUNT_AFS */
115 # define SET_RTPRI(P) { \
116 struct sched_param sp; \
117 sp.sched_priority = P; \
118 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
119 perror("sched_setscheduler"); \
122 # define SET_AFSD_RTPRI() SET_RTPRI(68)
123 # define SET_RX_RTPRI() SET_RTPRI(199)
125 # ifdef AFS_LINUX20_ENV
126 # define SET_AFSD_RTPRI()
127 # define SET_RX_RTPRI() do { \
128 if (setpriority(PRIO_PROCESS, 0, -10) < 0) \
129 perror("setting rx priority"); \
132 # define SET_AFSD_RTPRI()
133 # define SET_RX_RTPRI()
138 afsd_set_rx_rtpri(void)
144 afsd_set_afsd_rtpri(void)
149 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
152 afsd_call_syscall(long param1, long param2, long param3, long param4, long param5,
153 long param6, long param7)
156 # ifdef AFS_LINUX20_ENV
158 struct afsprocdata syscall_data;
159 int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
161 fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
167 param4 = (long)eparm;
169 syscall_data.syscall = AFSCALL_CALL;
170 syscall_data.param1 = param1;
171 syscall_data.param2 = param2;
172 syscall_data.param3 = param3;
173 syscall_data.param4 = param4;
175 error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
178 # endif /* AFS_LINUX20_ENV */
179 # ifdef AFS_DARWIN80_ENV
180 struct afssysargs syscall_data;
182 int fd = open(SYSCALL_DEV_FNAME,O_RDWR);
184 #ifdef AFS_DARWIN100_ENV
186 struct afssysargs64 syscall64_data;
187 if (sizeof(param1) == 8) {
188 syscallnum = VIOC_SYSCALL64;
190 ioctldata = &syscall64_data;
191 syscall64_data.syscall = (int)AFSCALL_CALL;
192 syscall64_data.param1 = param1;
193 syscall64_data.param2 = param2;
194 syscall64_data.param3 = param3;
195 syscall64_data.param4 = param4;
196 syscall64_data.param5 = param5;
197 syscall64_data.param6 = param6;
200 syscallnum = VIOC_SYSCALL;
201 ioctldata = &syscall_data;
202 syscall_data.syscall = AFSCALL_CALL;
203 syscall_data.param1 = param1;
204 syscall_data.param2 = param2;
205 syscall_data.param3 = param3;
206 syscall_data.param4 = param4;
207 syscall_data.param5 = param5;
208 syscall_data.param6 = param6;
209 #ifdef AFS_DARWIN100_ENV
213 error = ioctl(fd, syscallnum, ioctldata);
219 #ifdef AFS_DARWIN100_ENV
221 error=syscall64_data.retval;
224 error=syscall_data.retval;
226 # else /* AFS_DARWIN80_ENV */
228 syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4,
229 param5, param6, param7);
230 # endif /* !AFS_DARWIN80_ENV */
233 #ifdef AFS_NBSD40_ENV
234 char *s = strerror(errno);
235 printf("SScall(%d, %d, %d)=%d (%d, %s)\n", AFS_SYSCALL, AFSCALL_CALL,
236 param1, error, errno, s);
238 printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
245 #else /* !AFS_SGI_ENV && !AFS_AIX32_ENV */
246 # if defined(AFS_SGI_ENV)
248 afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4)
253 error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
255 printf("SScall(%d, %d)=%d ", call, parm0, error);
259 # else /* AFS_SGI_ENV */
261 afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
264 return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4,
267 # endif /* !AFS_SGI_ENV */
268 #endif /* AFS_SGI_ENV || AFS_AIX32_ENV */
272 /* Special handling for AIX's afs mount operation since they require much more
273 * miscl. information before making the vmount(2) syscall */
276 #define ROUNDUP(x) (((x) + 3) & ~3)
280 struct vmount *vmountp;
283 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
284 /* Malloc the vmount structure */
285 if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
286 printf("Can't allocate space for the vmount structure (AIX)\n");
290 /* zero out the vmount structure */
291 memset(vmountp, '\0', size);
293 /* transfer info into the vmount structure */
294 vmountp->vmt_revision = VMT_REVISION;
295 vmountp->vmt_length = size;
296 vmountp->vmt_fsid.fsid_dev = 0;
297 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
298 vmountp->vmt_vfsnumber = 0;
299 vmountp->vmt_time = 0; /* We'll put the time soon! */
300 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
301 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
302 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
304 /* Do the actual mount system call */
305 error = vmount(vmountp, size);
310 vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host,
311 char *hostsname, char *info, char *args)
319 vdp = (struct data *)vmtp->vmt_data;
320 vdp->vmt_off = sizeof(struct vmount);
321 size = ROUNDUP(strlen(obj) + 1);
322 vdp->vmt_size = size;
323 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
327 vdp->vmt_off = vdprev->vmt_off + size;
328 size = ROUNDUP(strlen(stub) + 1);
329 vdp->vmt_size = size;
330 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
334 vdp->vmt_off = vdprev->vmt_off + size;
335 size = ROUNDUP(strlen(host) + 1);
336 vdp->vmt_size = size;
337 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
341 vdp->vmt_off = vdprev->vmt_off + size;
342 size = ROUNDUP(strlen(hostsname) + 1);
343 vdp->vmt_size = size;
344 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
349 vdp->vmt_off = vdprev->vmt_off + size;
350 size = ROUNDUP(strlen(info) + 1);
351 vdp->vmt_size = size;
352 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
356 vdp->vmt_off = vdprev->vmt_off + size;
357 size = ROUNDUP(strlen(args) + 1);
358 vdp->vmt_size = size;
359 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
361 #endif /* AFS_AIX_ENV */
364 #define MOUNTED_TABLE MNT_MNTTAB
367 #define MOUNTED_TABLE MNTTAB
369 #define MOUNTED_TABLE MOUNTED
374 HandleMTab(char *cacheMountDir)
376 #if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV)
380 struct mnttab tmntent;
382 memset(&tmntent, '\0', sizeof(struct mnttab));
383 if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
384 printf("Can't open %s\n", MOUNTED_TABLE);
388 tmntent.mnt_special = "AFS";
389 tmntent.mnt_mountp = cacheMountDir;
390 tmntent.mnt_fstype = "xx";
391 tmntent.mnt_mntopts = "rw";
392 sprintf(tbuf, "%ld", (long)time((time_t *) 0));
393 tmntent.mnt_time = tbuf;
394 putmntent(tfilep, &tmntent);
397 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
398 struct mntent tmntent;
400 tfilep = setmntent("/etc/mtab", "a+");
401 tmntent.mnt_fsname = "AFS";
402 tmntent.mnt_dir = cacheMountDir;
403 tmntent.mnt_type = "afs";
404 tmntent.mnt_opts = "rw";
405 tmntent.mnt_freq = 1;
406 tmntent.mnt_passno = 3;
407 addmntent(tfilep, &tmntent);
410 struct mntent tmntent;
412 memset(&tmntent, '\0', sizeof(struct mntent));
413 tfilep = setmntent(MOUNTED_TABLE, "a+");
415 printf("Can't open %s for write; Not adding afs entry to it\n",
419 tmntent.mnt_fsname = "AFS";
420 tmntent.mnt_dir = cacheMountDir;
421 tmntent.mnt_type = "xx";
422 tmntent.mnt_opts = "rw";
423 tmntent.mnt_freq = 1;
424 tmntent.mnt_passno = 3;
426 tmntent.mnt_type = "afs";
427 tmntent.mnt_time = time(0);
428 tmntent.mnt_cnode = 0;
430 addmntent(tfilep, &tmntent);
432 #endif /* AFS_SGI_ENV */
433 #endif /* AFS_SUN5_ENV */
434 #endif /* unreasonable systems */
435 #ifdef AFS_DARWIN_ENV
436 #ifndef AFS_DARWIN100_ENV
437 mach_port_t diskarb_port;
438 kern_return_t status;
440 status = DiskArbStart(&diskarb_port);
441 if (status == KERN_SUCCESS) {
443 DiskArbDiskAppearedWithMountpointPing_auto("AFS",
444 DISK_ARB_NETWORK_DISK_FLAG,
450 #endif /* AFS_DARWIN_ENV */
455 afsd_mount_afs(const char *rn, const char *cacheMountDir)
457 int mountFlags; /*Flags passed to mount() */
458 char *mountDir; /* For HandleMTab() */
460 mountFlags = 0; /* Read/write file system, can do setuid() */
461 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
463 mountFlags |= MS_DATA;
465 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... */
469 #if defined(AFS_HPUX100_ENV)
470 mountFlags |= MS_DATA;
474 printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn,
475 cacheMountDir, mountFlags);
476 #if defined(AFS_FBSD60_ENV)
477 /* data must be non-NULL but is otherwise ignored */
478 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) {
479 #elif defined(AFS_FBSD_ENV)
480 if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
481 #elif defined(AFS_AIX_ENV)
483 #elif defined(AFS_HPUX100_ENV)
484 if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
485 #elif defined(AFS_SUN5_ENV)
486 if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
487 #elif defined(AFS_SGI_ENV)
489 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS))
491 #elif defined(AFS_LINUX20_ENV)
492 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) {
493 #elif defined(AFS_NBSD50_ENV)
494 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, NULL, 0)) < 0) {
496 /* This is the standard mount used by the suns and rts */
497 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
499 printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir,
504 mountDir = strdup(cacheMountDir);
505 HandleMTab(mountDir);
510 afsd_fork(int wait, afsd_callback_func cb, void *rock)
520 assert(waitpid(code, NULL, 0) != -1);
527 afsd_daemon(int nochdir, int noclose)
529 return daemon(nochdir, noclose);
533 main(int argc, char **argv)
539 code = afsd_parse(argc, argv);