[PATCH] autofs4 oops fix
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / autofs4 / root.c
blob62d8d4acb8bbbe75ba0965214808c259c4b1b292
1 /* -*- c -*- --------------------------------------------------------------- *
3 * linux/fs/autofs/root.c
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
7 * Copyright 2001-2003 Ian Kent <raven@themaw.net>
9 * This file is part of the Linux kernel and is made available under
10 * the terms of the GNU General Public License, version 2, or at your
11 * option, any later version, incorporated herein by reference.
13 * ------------------------------------------------------------------------- */
15 #include <linux/capability.h>
16 #include <linux/errno.h>
17 #include <linux/stat.h>
18 #include <linux/param.h>
19 #include <linux/time.h>
20 #include <linux/smp_lock.h>
21 #include "autofs_i.h"
23 static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
24 static int autofs4_dir_unlink(struct inode *,struct dentry *);
25 static int autofs4_dir_rmdir(struct inode *,struct dentry *);
26 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
27 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
28 static int autofs4_dir_open(struct inode *inode, struct file *file);
29 static int autofs4_dir_close(struct inode *inode, struct file *file);
30 static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir);
31 static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir);
32 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
33 static int autofs4_dcache_readdir(struct file *, void *, filldir_t);
35 struct file_operations autofs4_root_operations = {
36 .open = dcache_dir_open,
37 .release = dcache_dir_close,
38 .read = generic_read_dir,
39 .readdir = autofs4_root_readdir,
40 .ioctl = autofs4_root_ioctl,
43 struct file_operations autofs4_dir_operations = {
44 .open = autofs4_dir_open,
45 .release = autofs4_dir_close,
46 .read = generic_read_dir,
47 .readdir = autofs4_dir_readdir,
50 struct inode_operations autofs4_root_inode_operations = {
51 .lookup = autofs4_lookup,
52 .unlink = autofs4_dir_unlink,
53 .symlink = autofs4_dir_symlink,
54 .mkdir = autofs4_dir_mkdir,
55 .rmdir = autofs4_dir_rmdir,
58 struct inode_operations autofs4_dir_inode_operations = {
59 .lookup = autofs4_lookup,
60 .unlink = autofs4_dir_unlink,
61 .symlink = autofs4_dir_symlink,
62 .mkdir = autofs4_dir_mkdir,
63 .rmdir = autofs4_dir_rmdir,
66 static int autofs4_root_readdir(struct file *file, void *dirent,
67 filldir_t filldir)
69 struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb);
70 int oz_mode = autofs4_oz_mode(sbi);
72 DPRINTK("called, filp->f_pos = %lld", file->f_pos);
75 * Don't set reghost flag if:
76 * 1) f_pos is larger than zero -- we've already been here.
77 * 2) we haven't even enabled reghosting in the 1st place.
78 * 3) this is the daemon doing a readdir
80 if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled)
81 sbi->needs_reghost = 1;
83 DPRINTK("needs_reghost = %d", sbi->needs_reghost);
85 return autofs4_dcache_readdir(file, dirent, filldir);
88 /* Update usage from here to top of tree, so that scan of
89 top-level directories will give a useful result */
90 static void autofs4_update_usage(struct vfsmount *mnt, struct dentry *dentry)
92 struct dentry *top = dentry->d_sb->s_root;
94 spin_lock(&dcache_lock);
95 for(; dentry != top; dentry = dentry->d_parent) {
96 struct autofs_info *ino = autofs4_dentry_ino(dentry);
98 if (ino) {
99 touch_atime(mnt, dentry);
100 ino->last_used = jiffies;
103 spin_unlock(&dcache_lock);
107 * From 2.4 kernel readdir.c
109 static int autofs4_dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
111 int i;
112 struct dentry *dentry = filp->f_dentry;
114 i = filp->f_pos;
115 switch (i) {
116 case 0:
117 if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
118 break;
119 i++;
120 filp->f_pos++;
121 /* fallthrough */
122 case 1:
123 if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
124 break;
125 i++;
126 filp->f_pos++;
127 /* fallthrough */
128 default: {
129 struct list_head *list;
130 int j = i-2;
132 spin_lock(&dcache_lock);
133 list = dentry->d_subdirs.next;
135 for (;;) {
136 if (list == &dentry->d_subdirs) {
137 spin_unlock(&dcache_lock);
138 return 0;
140 if (!j)
141 break;
142 j--;
143 list = list->next;
146 while(1) {
147 struct dentry *de = list_entry(list,
148 struct dentry, d_u.d_child);
150 if (!d_unhashed(de) && de->d_inode) {
151 spin_unlock(&dcache_lock);
152 if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_UNKNOWN) < 0)
153 break;
154 spin_lock(&dcache_lock);
156 filp->f_pos++;
157 list = list->next;
158 if (list != &dentry->d_subdirs)
159 continue;
160 spin_unlock(&dcache_lock);
161 break;
165 return 0;
168 static int autofs4_dir_open(struct inode *inode, struct file *file)
170 struct dentry *dentry = file->f_dentry;
171 struct vfsmount *mnt = file->f_vfsmnt;
172 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
173 int status;
175 DPRINTK("file=%p dentry=%p %.*s",
176 file, dentry, dentry->d_name.len, dentry->d_name.name);
178 if (autofs4_oz_mode(sbi))
179 goto out;
181 if (autofs4_ispending(dentry)) {
182 DPRINTK("dentry busy");
183 return -EBUSY;
186 if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) {
187 struct nameidata nd;
188 int empty;
190 /* In case there are stale directory dentrys from a failed mount */
191 spin_lock(&dcache_lock);
192 empty = list_empty(&dentry->d_subdirs);
193 spin_unlock(&dcache_lock);
195 if (!empty)
196 d_invalidate(dentry);
198 nd.dentry = dentry;
199 nd.mnt = mnt;
200 nd.flags = LOOKUP_DIRECTORY;
201 status = (dentry->d_op->d_revalidate)(dentry, &nd);
203 if (!status)
204 return -ENOENT;
207 if (d_mountpoint(dentry)) {
208 struct file *fp = NULL;
209 struct vfsmount *fp_mnt = mntget(mnt);
210 struct dentry *fp_dentry = dget(dentry);
212 if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) {
213 dput(fp_dentry);
214 mntput(fp_mnt);
215 return -ENOENT;
218 fp = dentry_open(fp_dentry, fp_mnt, file->f_flags);
219 status = PTR_ERR(fp);
220 if (IS_ERR(fp)) {
221 file->private_data = NULL;
222 return status;
224 file->private_data = fp;
226 out:
227 return 0;
230 static int autofs4_dir_close(struct inode *inode, struct file *file)
232 struct dentry *dentry = file->f_dentry;
233 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
235 DPRINTK("file=%p dentry=%p %.*s",
236 file, dentry, dentry->d_name.len, dentry->d_name.name);
238 if (autofs4_oz_mode(sbi))
239 goto out;
241 if (autofs4_ispending(dentry)) {
242 DPRINTK("dentry busy");
243 return -EBUSY;
246 if (d_mountpoint(dentry)) {
247 struct file *fp = file->private_data;
249 if (!fp)
250 return -ENOENT;
252 filp_close(fp, current->files);
253 file->private_data = NULL;
255 out:
256 return 0;
259 static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
261 struct dentry *dentry = file->f_dentry;
262 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
263 int status;
265 DPRINTK("file=%p dentry=%p %.*s",
266 file, dentry, dentry->d_name.len, dentry->d_name.name);
268 if (autofs4_oz_mode(sbi))
269 goto out;
271 if (autofs4_ispending(dentry)) {
272 DPRINTK("dentry busy");
273 return -EBUSY;
276 if (d_mountpoint(dentry)) {
277 struct file *fp = file->private_data;
279 if (!fp)
280 return -ENOENT;
282 if (!fp->f_op || !fp->f_op->readdir)
283 goto out;
285 status = vfs_readdir(fp, filldir, dirent);
286 file->f_pos = fp->f_pos;
287 if (status)
288 autofs4_copy_atime(file, fp);
289 return status;
291 out:
292 return autofs4_dcache_readdir(file, dirent, filldir);
295 static int try_to_fill_dentry(struct vfsmount *mnt, struct dentry *dentry, int flags)
297 struct super_block *sb = mnt->mnt_sb;
298 struct autofs_sb_info *sbi = autofs4_sbi(sb);
299 struct autofs_info *de_info = autofs4_dentry_ino(dentry);
300 int status = 0;
302 /* Block on any pending expiry here; invalidate the dentry
303 when expiration is done to trigger mount request with a new
304 dentry */
305 if (de_info && (de_info->flags & AUTOFS_INF_EXPIRING)) {
306 DPRINTK("waiting for expire %p name=%.*s",
307 dentry, dentry->d_name.len, dentry->d_name.name);
309 status = autofs4_wait(sbi, dentry, NFY_NONE);
311 DPRINTK("expire done status=%d", status);
314 * If the directory still exists the mount request must
315 * continue otherwise it can't be followed at the right
316 * time during the walk.
318 status = d_invalidate(dentry);
319 if (status != -EBUSY)
320 return 0;
323 DPRINTK("dentry=%p %.*s ino=%p",
324 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
326 /* Wait for a pending mount, triggering one if there isn't one already */
327 if (dentry->d_inode == NULL) {
328 DPRINTK("waiting for mount name=%.*s",
329 dentry->d_name.len, dentry->d_name.name);
331 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
333 DPRINTK("mount done status=%d", status);
335 if (status && dentry->d_inode)
336 return 0; /* Try to get the kernel to invalidate this dentry */
338 /* Turn this into a real negative dentry? */
339 if (status == -ENOENT) {
340 dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
341 spin_lock(&dentry->d_lock);
342 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
343 spin_unlock(&dentry->d_lock);
344 return 1;
345 } else if (status) {
346 /* Return a negative dentry, but leave it "pending" */
347 return 1;
349 /* Trigger mount for path component or follow link */
350 } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
351 current->link_count) {
352 DPRINTK("waiting for mount name=%.*s",
353 dentry->d_name.len, dentry->d_name.name);
355 spin_lock(&dentry->d_lock);
356 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
357 spin_unlock(&dentry->d_lock);
358 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
360 DPRINTK("mount done status=%d", status);
362 if (status) {
363 spin_lock(&dentry->d_lock);
364 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
365 spin_unlock(&dentry->d_lock);
366 return 0;
370 /* We don't update the usages for the autofs daemon itself, this
371 is necessary for recursive autofs mounts */
372 if (!autofs4_oz_mode(sbi))
373 autofs4_update_usage(mnt, dentry);
375 spin_lock(&dentry->d_lock);
376 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
377 spin_unlock(&dentry->d_lock);
378 return 1;
382 * Revalidate is called on every cache lookup. Some of those
383 * cache lookups may actually happen while the dentry is not
384 * yet completely filled in, and revalidate has to delay such
385 * lookups..
387 static int autofs4_revalidate(struct dentry * dentry, struct nameidata *nd)
389 struct inode * dir = dentry->d_parent->d_inode;
390 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
391 int oz_mode = autofs4_oz_mode(sbi);
392 int flags = nd ? nd->flags : 0;
393 int status = 1;
395 /* Pending dentry */
396 if (autofs4_ispending(dentry)) {
397 if (!oz_mode)
398 status = try_to_fill_dentry(nd->mnt, dentry, flags);
399 return status;
402 /* Negative dentry.. invalidate if "old" */
403 if (dentry->d_inode == NULL)
404 return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
406 /* Check for a non-mountpoint directory with no contents */
407 spin_lock(&dcache_lock);
408 if (S_ISDIR(dentry->d_inode->i_mode) &&
409 !d_mountpoint(dentry) &&
410 list_empty(&dentry->d_subdirs)) {
411 DPRINTK("dentry=%p %.*s, emptydir",
412 dentry, dentry->d_name.len, dentry->d_name.name);
413 spin_unlock(&dcache_lock);
414 if (!oz_mode)
415 status = try_to_fill_dentry(nd->mnt, dentry, flags);
416 return status;
418 spin_unlock(&dcache_lock);
420 /* Update the usage list */
421 if (!oz_mode)
422 autofs4_update_usage(nd->mnt, dentry);
424 return 1;
427 static void autofs4_dentry_release(struct dentry *de)
429 struct autofs_info *inf;
431 DPRINTK("releasing %p", de);
433 inf = autofs4_dentry_ino(de);
434 de->d_fsdata = NULL;
436 if (inf) {
437 inf->dentry = NULL;
438 inf->inode = NULL;
440 autofs4_free_ino(inf);
444 /* For dentries of directories in the root dir */
445 static struct dentry_operations autofs4_root_dentry_operations = {
446 .d_revalidate = autofs4_revalidate,
447 .d_release = autofs4_dentry_release,
450 /* For other dentries */
451 static struct dentry_operations autofs4_dentry_operations = {
452 .d_revalidate = autofs4_revalidate,
453 .d_release = autofs4_dentry_release,
456 /* Lookups in the root directory */
457 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
459 struct autofs_sb_info *sbi;
460 int oz_mode;
462 DPRINTK("name = %.*s",
463 dentry->d_name.len, dentry->d_name.name);
465 if (dentry->d_name.len > NAME_MAX)
466 return ERR_PTR(-ENAMETOOLONG);/* File name too long to exist */
468 sbi = autofs4_sbi(dir->i_sb);
470 oz_mode = autofs4_oz_mode(sbi);
471 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
472 current->pid, process_group(current), sbi->catatonic, oz_mode);
475 * Mark the dentry incomplete, but add it. This is needed so
476 * that the VFS layer knows about the dentry, and we can count
477 * on catching any lookups through the revalidate.
479 * Let all the hard work be done by the revalidate function that
480 * needs to be able to do this anyway..
482 * We need to do this before we release the directory semaphore.
484 dentry->d_op = &autofs4_root_dentry_operations;
486 if (!oz_mode) {
487 spin_lock(&dentry->d_lock);
488 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
489 spin_unlock(&dentry->d_lock);
491 dentry->d_fsdata = NULL;
492 d_add(dentry, NULL);
494 if (dentry->d_op && dentry->d_op->d_revalidate) {
495 mutex_unlock(&dir->i_mutex);
496 (dentry->d_op->d_revalidate)(dentry, nd);
497 mutex_lock(&dir->i_mutex);
501 * If we are still pending, check if we had to handle
502 * a signal. If so we can force a restart..
504 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
505 /* See if we were interrupted */
506 if (signal_pending(current)) {
507 sigset_t *sigset = &current->pending.signal;
508 if (sigismember (sigset, SIGKILL) ||
509 sigismember (sigset, SIGQUIT) ||
510 sigismember (sigset, SIGINT)) {
511 return ERR_PTR(-ERESTARTNOINTR);
517 * If this dentry is unhashed, then we shouldn't honour this
518 * lookup even if the dentry is positive. Returning ENOENT here
519 * doesn't do the right thing for all system calls, but it should
520 * be OK for the operations we permit from an autofs.
522 if ( dentry->d_inode && d_unhashed(dentry) )
523 return ERR_PTR(-ENOENT);
525 return NULL;
528 static int autofs4_dir_symlink(struct inode *dir,
529 struct dentry *dentry,
530 const char *symname)
532 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
533 struct autofs_info *ino = autofs4_dentry_ino(dentry);
534 struct inode *inode;
535 char *cp;
537 DPRINTK("%s <- %.*s", symname,
538 dentry->d_name.len, dentry->d_name.name);
540 if (!autofs4_oz_mode(sbi))
541 return -EACCES;
543 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
544 if (ino == NULL)
545 return -ENOSPC;
547 ino->size = strlen(symname);
548 ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
550 if (cp == NULL) {
551 kfree(ino);
552 return -ENOSPC;
555 strcpy(cp, symname);
557 inode = autofs4_get_inode(dir->i_sb, ino);
558 d_instantiate(dentry, inode);
560 if (dir == dir->i_sb->s_root->d_inode)
561 dentry->d_op = &autofs4_root_dentry_operations;
562 else
563 dentry->d_op = &autofs4_dentry_operations;
565 dentry->d_fsdata = ino;
566 ino->dentry = dget(dentry);
567 ino->inode = inode;
569 dir->i_mtime = CURRENT_TIME;
571 return 0;
575 * NOTE!
577 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
578 * that the file no longer exists. However, doing that means that the
579 * VFS layer can turn the dentry into a negative dentry. We don't want
580 * this, because since the unlink is probably the result of an expire.
581 * We simply d_drop it, which allows the dentry lookup to remount it
582 * if necessary.
584 * If a process is blocked on the dentry waiting for the expire to finish,
585 * it will invalidate the dentry and try to mount with a new one.
587 * Also see autofs4_dir_rmdir()..
589 static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
591 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
592 struct autofs_info *ino = autofs4_dentry_ino(dentry);
594 /* This allows root to remove symlinks */
595 if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
596 return -EACCES;
598 dput(ino->dentry);
600 dentry->d_inode->i_size = 0;
601 dentry->d_inode->i_nlink = 0;
603 dir->i_mtime = CURRENT_TIME;
605 d_drop(dentry);
607 return 0;
610 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
612 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
613 struct autofs_info *ino = autofs4_dentry_ino(dentry);
615 if (!autofs4_oz_mode(sbi))
616 return -EACCES;
618 spin_lock(&dcache_lock);
619 if (!list_empty(&dentry->d_subdirs)) {
620 spin_unlock(&dcache_lock);
621 return -ENOTEMPTY;
623 spin_lock(&dentry->d_lock);
624 __d_drop(dentry);
625 spin_unlock(&dentry->d_lock);
626 spin_unlock(&dcache_lock);
628 dput(ino->dentry);
630 dentry->d_inode->i_size = 0;
631 dentry->d_inode->i_nlink = 0;
633 if (dir->i_nlink)
634 dir->i_nlink--;
636 return 0;
639 static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
641 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
642 struct autofs_info *ino = autofs4_dentry_ino(dentry);
643 struct inode *inode;
645 if ( !autofs4_oz_mode(sbi) )
646 return -EACCES;
648 DPRINTK("dentry %p, creating %.*s",
649 dentry, dentry->d_name.len, dentry->d_name.name);
651 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
652 if (ino == NULL)
653 return -ENOSPC;
655 inode = autofs4_get_inode(dir->i_sb, ino);
656 d_instantiate(dentry, inode);
658 if (dir == dir->i_sb->s_root->d_inode)
659 dentry->d_op = &autofs4_root_dentry_operations;
660 else
661 dentry->d_op = &autofs4_dentry_operations;
663 dentry->d_fsdata = ino;
664 ino->dentry = dget(dentry);
665 ino->inode = inode;
666 dir->i_nlink++;
667 dir->i_mtime = CURRENT_TIME;
669 return 0;
672 /* Get/set timeout ioctl() operation */
673 static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
674 unsigned long __user *p)
676 int rv;
677 unsigned long ntimeout;
679 if ( (rv = get_user(ntimeout, p)) ||
680 (rv = put_user(sbi->exp_timeout/HZ, p)) )
681 return rv;
683 if ( ntimeout > ULONG_MAX/HZ )
684 sbi->exp_timeout = 0;
685 else
686 sbi->exp_timeout = ntimeout * HZ;
688 return 0;
691 /* Return protocol version */
692 static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
694 return put_user(sbi->version, p);
697 /* Return protocol sub version */
698 static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
700 return put_user(sbi->sub_version, p);
704 * Tells the daemon whether we need to reghost or not. Also, clears
705 * the reghost_needed flag.
707 static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
709 int status;
711 DPRINTK("returning %d", sbi->needs_reghost);
713 status = put_user(sbi->needs_reghost, p);
714 if ( status )
715 return status;
717 sbi->needs_reghost = 0;
718 return 0;
722 * Enable / Disable reghosting ioctl() operation
724 static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
726 int status;
727 int val;
729 status = get_user(val, p);
731 DPRINTK("reghost = %d", val);
733 if (status)
734 return status;
736 /* turn on/off reghosting, with the val */
737 sbi->reghost_enabled = val;
738 return 0;
742 * Tells the daemon whether it can umount the autofs mount.
744 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
746 int status = 0;
748 if (may_umount(mnt) == 0)
749 status = 1;
751 DPRINTK("returning %d", status);
753 status = put_user(status, p);
755 return status;
758 /* Identify autofs4_dentries - this is so we can tell if there's
759 an extra dentry refcount or not. We only hold a refcount on the
760 dentry if its non-negative (ie, d_inode != NULL)
762 int is_autofs4_dentry(struct dentry *dentry)
764 return dentry && dentry->d_inode &&
765 (dentry->d_op == &autofs4_root_dentry_operations ||
766 dentry->d_op == &autofs4_dentry_operations) &&
767 dentry->d_fsdata != NULL;
771 * ioctl()'s on the root directory is the chief method for the daemon to
772 * generate kernel reactions
774 static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
775 unsigned int cmd, unsigned long arg)
777 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
778 void __user *p = (void __user *)arg;
780 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
781 cmd,arg,sbi,process_group(current));
783 if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
784 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT )
785 return -ENOTTY;
787 if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
788 return -EPERM;
790 switch(cmd) {
791 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
792 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
793 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
794 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
795 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
796 autofs4_catatonic_mode(sbi);
797 return 0;
798 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
799 return autofs4_get_protover(sbi, p);
800 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
801 return autofs4_get_protosubver(sbi, p);
802 case AUTOFS_IOC_SETTIMEOUT:
803 return autofs4_get_set_timeout(sbi, p);
805 case AUTOFS_IOC_TOGGLEREGHOST:
806 return autofs4_toggle_reghost(sbi, p);
807 case AUTOFS_IOC_ASKREGHOST:
808 return autofs4_ask_reghost(sbi, p);
810 case AUTOFS_IOC_ASKUMOUNT:
811 return autofs4_ask_umount(filp->f_vfsmnt, p);
813 /* return a single thing to expire */
814 case AUTOFS_IOC_EXPIRE:
815 return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi, p);
816 /* same as above, but can send multiple expires through pipe */
817 case AUTOFS_IOC_EXPIRE_MULTI:
818 return autofs4_expire_multi(inode->i_sb,filp->f_vfsmnt,sbi, p);
820 default:
821 return -ENOSYS;