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>
109 #include <CoreFoundation/CoreFoundation.h>
111 #include <SystemConfiguration/SystemConfiguration.h>
112 #include <SystemConfiguration/SCDynamicStore.h>
114 #include <IOKit/pwr_mgt/IOPMLib.h>
115 #include <IOKit/IOMessage.h>
119 typedef struct DNSSDState
121 DNSServiceRef service;
122 CFRunLoopSourceRef source;
126 #endif /* AFS_DARWIN_ENV */
129 #define MOUNT_AFS AFS_MOUNT_AFS
130 #endif /* MOUNT_AFS */
133 # define SET_RTPRI(P) { \
134 struct sched_param sp; \
135 sp.sched_priority = P; \
136 if (sched_setscheduler(0, SCHED_RR, &sp)<0) { \
137 perror("sched_setscheduler"); \
140 # define SET_AFSD_RTPRI() SET_RTPRI(68)
141 # define SET_RX_RTPRI() SET_RTPRI(199)
143 # ifdef AFS_LINUX20_ENV
144 # define SET_AFSD_RTPRI()
145 # define SET_RX_RTPRI() do { \
146 if (setpriority(PRIO_PROCESS, 0, -10) < 0) \
147 perror("setting rx priority"); \
150 # define SET_AFSD_RTPRI()
151 # define SET_RX_RTPRI()
156 afsd_set_rx_rtpri(void)
162 afsd_set_afsd_rtpri(void)
167 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
170 afsd_call_syscall(long param1, long param2, long param3, long param4, long param5,
171 long param6, long param7)
174 # ifdef AFS_LINUX20_ENV
176 struct afsprocdata syscall_data;
177 int fd = open(PROC_SYSCALL_FNAME, O_RDWR);
179 fd = open(PROC_SYSCALL_ARLA_FNAME, O_RDWR);
185 param4 = (long)eparm;
187 syscall_data.syscall = AFSCALL_CALL;
188 syscall_data.param1 = param1;
189 syscall_data.param2 = param2;
190 syscall_data.param3 = param3;
191 syscall_data.param4 = param4;
193 error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
196 # endif /* AFS_LINUX20_ENV */
197 # ifdef AFS_DARWIN80_ENV
198 struct afssysargs syscall_data;
199 int fd = open(SYSCALL_DEV_FNAME,O_RDWR);
200 syscall_data.syscall = AFSCALL_CALL;
201 syscall_data.param1 = param1;
202 syscall_data.param2 = param2;
203 syscall_data.param3 = param3;
204 syscall_data.param4 = param4;
205 syscall_data.param5 = param5;
206 syscall_data.param6 = param6;
208 error = ioctl(fd, VIOC_SYSCALL, &syscall_data);
214 error=syscall_data.retval;
215 # else /* AFS_DARWIN80_ENV */
217 syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4,
218 param5, param6, param7);
219 # endif /* !AFS_DARWIN80_ENV */
222 printf("SScall(%d, %d, %ld)=%d ", AFS_SYSCALL, AFSCALL_CALL, param1,
226 #else /* !AFS_SGI_ENV && !AFS_AIX32_ENV */
227 # if defined(AFS_SGI_ENV)
229 afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4)
234 error = afs_syscall(call, parm0, parm1, parm2, parm3, parm4);
236 printf("SScall(%d, %d)=%d ", call, parm0, error);
240 # else /* AFS_SGI_ENV */
242 afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
245 return syscall(AFSCALL_CALL, call, parm0, parm1, parm2, parm3, parm4,
248 # endif /* !AFS_SGI_ENV */
249 #endif /* AFS_SGI_ENV || AFS_AIX32_ENV */
253 /* Special handling for AIX's afs mount operation since they require much more
254 * miscl. information before making the vmount(2) syscall */
257 #define ROUNDUP(x) (((x) + 3) & ~3)
261 struct vmount *vmountp;
264 size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
265 /* Malloc the vmount structure */
266 if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
267 printf("Can't allocate space for the vmount structure (AIX)\n");
271 /* zero out the vmount structure */
272 memset(vmountp, '\0', size);
274 /* transfer info into the vmount structure */
275 vmountp->vmt_revision = VMT_REVISION;
276 vmountp->vmt_length = size;
277 vmountp->vmt_fsid.fsid_dev = 0;
278 vmountp->vmt_fsid.fsid_type = AFS_MOUNT_AFS;
279 vmountp->vmt_vfsnumber = 0;
280 vmountp->vmt_time = 0; /* We'll put the time soon! */
281 vmountp->vmt_flags = VFS_DEVMOUNT; /* read/write permission */
282 vmountp->vmt_gfstype = AFS_MOUNT_AFS;
283 vmountdata(vmountp, "AFS", cacheMountDir, "", "", "", "rw");
285 /* Do the actual mount system call */
286 error = vmount(vmountp, size);
291 vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host,
292 char *hostsname, char *info, char *args)
300 vdp = (struct data *)vmtp->vmt_data;
301 vdp->vmt_off = sizeof(struct vmount);
302 size = ROUNDUP(strlen(obj) + 1);
303 vdp->vmt_size = size;
304 strcpy(vmt2dataptr(vmtp, VMT_OBJECT), obj);
308 vdp->vmt_off = vdprev->vmt_off + size;
309 size = ROUNDUP(strlen(stub) + 1);
310 vdp->vmt_size = size;
311 strcpy(vmt2dataptr(vmtp, VMT_STUB), stub);
315 vdp->vmt_off = vdprev->vmt_off + size;
316 size = ROUNDUP(strlen(host) + 1);
317 vdp->vmt_size = size;
318 strcpy(vmt2dataptr(vmtp, VMT_HOST), host);
322 vdp->vmt_off = vdprev->vmt_off + size;
323 size = ROUNDUP(strlen(hostsname) + 1);
324 vdp->vmt_size = size;
325 strcpy(vmt2dataptr(vmtp, VMT_HOSTNAME), hostsname);
330 vdp->vmt_off = vdprev->vmt_off + size;
331 size = ROUNDUP(strlen(info) + 1);
332 vdp->vmt_size = size;
333 strcpy(vmt2dataptr(vmtp, VMT_INFO), info);
337 vdp->vmt_off = vdprev->vmt_off + size;
338 size = ROUNDUP(strlen(args) + 1);
339 vdp->vmt_size = size;
340 strcpy(vmt2dataptr(vmtp, VMT_ARGS), args);
342 #endif /* AFS_AIX_ENV */
345 #define MOUNTED_TABLE MNT_MNTTAB
348 #define MOUNTED_TABLE MNTTAB
350 #define MOUNTED_TABLE MOUNTED
355 HandleMTab(char *cacheMountDir)
357 #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)
361 struct mnttab tmntent;
363 memset(&tmntent, '\0', sizeof(struct mnttab));
364 if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
365 printf("Can't open %s\n", MOUNTED_TABLE);
369 tmntent.mnt_special = "AFS";
370 tmntent.mnt_mountp = cacheMountDir;
371 tmntent.mnt_fstype = "xx";
372 tmntent.mnt_mntopts = "rw";
373 sprintf(tbuf, "%ld", (long)time((time_t *) 0));
374 tmntent.mnt_time = tbuf;
375 putmntent(tfilep, &tmntent);
378 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
379 struct mntent tmntent;
381 tfilep = setmntent("/etc/mtab", "a+");
382 tmntent.mnt_fsname = "AFS";
383 tmntent.mnt_dir = cacheMountDir;
384 tmntent.mnt_type = "afs";
385 tmntent.mnt_opts = "rw";
386 tmntent.mnt_freq = 1;
387 tmntent.mnt_passno = 3;
388 addmntent(tfilep, &tmntent);
391 struct mntent tmntent;
393 memset(&tmntent, '\0', sizeof(struct mntent));
394 tfilep = setmntent(MOUNTED_TABLE, "a+");
396 printf("Can't open %s for write; Not adding afs entry to it\n",
400 tmntent.mnt_fsname = "AFS";
401 tmntent.mnt_dir = cacheMountDir;
402 tmntent.mnt_type = "xx";
403 tmntent.mnt_opts = "rw";
404 tmntent.mnt_freq = 1;
405 tmntent.mnt_passno = 3;
407 tmntent.mnt_type = "afs";
408 tmntent.mnt_time = time(0);
409 tmntent.mnt_cnode = 0;
411 addmntent(tfilep, &tmntent);
413 #endif /* AFS_SGI_ENV */
414 #endif /* AFS_SUN5_ENV */
415 #endif /* unreasonable systems */
416 #ifdef AFS_DARWIN_ENV
417 #ifndef AFS_DARWIN100_ENV
418 mach_port_t diskarb_port;
419 kern_return_t status;
421 status = DiskArbStart(&diskarb_port);
422 if (status == KERN_SUCCESS) {
424 DiskArbDiskAppearedWithMountpointPing_auto("AFS",
425 DISK_ARB_NETWORK_DISK_FLAG,
431 #endif /* AFS_DARWIN_ENV */
436 afsd_mount_afs(const char *rn, const char *cacheMountDir)
438 int mountFlags; /*Flags passed to mount() */
439 char *mountDir; /* For HandleMTab() */
441 mountFlags = 0; /* Read/write file system, can do setuid() */
442 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
444 mountFlags |= MS_DATA;
446 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... */
450 #if defined(AFS_HPUX100_ENV)
451 mountFlags |= MS_DATA;
455 printf("%s: Mounting the AFS root on '%s', flags: %d.\n", rn,
456 cacheMountDir, mountFlags);
457 #if defined(AFS_FBSD60_ENV)
458 /* data must be non-NULL but is otherwise ignored */
459 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, rn)) < 0) {
460 #elif defined(AFS_FBSD_ENV)
461 if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
462 #elif defined(AFS_AIX_ENV)
464 #elif defined(AFS_HPUX100_ENV)
465 if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
466 #elif defined(AFS_SUN5_ENV)
467 if ((mount("AFS", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
468 #elif defined(AFS_SGI_ENV)
470 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) MOUNT_AFS))
472 #elif defined(AFS_LINUX20_ENV)
473 if ((mount("AFS", cacheMountDir, MOUNT_AFS, 0, NULL)) < 0) {
475 /* This is the standard mount used by the suns and rts */
476 if ((mount(MOUNT_AFS, cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
478 printf("%s: Can't mount AFS on %s(%d)\n", rn, cacheMountDir,
483 mountDir = strdup(cacheMountDir);
484 HandleMTab(mountDir);
489 afsd_fork(int wait, afsd_callback_func cb, void *rock)
499 assert(waitpid(code, NULL, 0) != -1);
506 afsd_daemon(int nochdir, int noclose)
508 return daemon(nochdir, noclose);
512 main(int argc, char **argv)
518 code = afsd_parse(argc, argv);