2 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * This file is part of the Linux kernel and is made available under
7 * the terms of the GNU General Public License, version 2, or at your
8 * option, any later version, incorporated herein by reference.
11 #include <linux/capability.h>
12 #include <linux/compat.h>
16 static int autofs_dir_symlink(struct inode *, struct dentry *, const char *);
17 static int autofs_dir_unlink(struct inode *, struct dentry *);
18 static int autofs_dir_rmdir(struct inode *, struct dentry *);
19 static int autofs_dir_mkdir(struct inode *, struct dentry *, umode_t);
20 static long autofs_root_ioctl(struct file *, unsigned int, unsigned long);
22 static long autofs_root_compat_ioctl(struct file *,
23 unsigned int, unsigned long);
25 static int autofs_dir_open(struct inode *inode, struct file *file);
26 static struct dentry *autofs_lookup(struct inode *,
27 struct dentry *, unsigned int);
28 static struct vfsmount *autofs_d_automount(struct path *);
29 static int autofs_d_manage(const struct path *, bool);
30 static void autofs_dentry_release(struct dentry *);
32 const struct file_operations autofs_root_operations = {
33 .open = dcache_dir_open,
34 .release = dcache_dir_close,
35 .read = generic_read_dir,
36 .iterate_shared = dcache_readdir,
37 .llseek = dcache_dir_lseek,
38 .unlocked_ioctl = autofs_root_ioctl,
40 .compat_ioctl = autofs_root_compat_ioctl,
44 const struct file_operations autofs_dir_operations = {
45 .open = autofs_dir_open,
46 .release = dcache_dir_close,
47 .read = generic_read_dir,
48 .iterate_shared = dcache_readdir,
49 .llseek = dcache_dir_lseek,
52 const struct inode_operations autofs_dir_inode_operations = {
53 .lookup = autofs_lookup,
54 .unlink = autofs_dir_unlink,
55 .symlink = autofs_dir_symlink,
56 .mkdir = autofs_dir_mkdir,
57 .rmdir = autofs_dir_rmdir,
60 const struct dentry_operations autofs_dentry_operations = {
61 .d_automount = autofs_d_automount,
62 .d_manage = autofs_d_manage,
63 .d_release = autofs_dentry_release,
66 static void autofs_add_active(struct dentry *dentry)
68 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
69 struct autofs_info *ino;
71 ino = autofs_dentry_ino(dentry);
73 spin_lock(&sbi->lookup_lock);
74 if (!ino->active_count) {
75 if (list_empty(&ino->active))
76 list_add(&ino->active, &sbi->active_list);
79 spin_unlock(&sbi->lookup_lock);
83 static void autofs_del_active(struct dentry *dentry)
85 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
86 struct autofs_info *ino;
88 ino = autofs_dentry_ino(dentry);
90 spin_lock(&sbi->lookup_lock);
92 if (!ino->active_count) {
93 if (!list_empty(&ino->active))
94 list_del_init(&ino->active);
96 spin_unlock(&sbi->lookup_lock);
100 static int autofs_dir_open(struct inode *inode, struct file *file)
102 struct dentry *dentry = file->f_path.dentry;
103 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
105 pr_debug("file=%p dentry=%p %pd\n", file, dentry, dentry);
107 if (autofs_oz_mode(sbi))
111 * An empty directory in an autofs file system is always a
112 * mount point. The daemon must have failed to mount this
113 * during lookup so it doesn't exist. This can happen, for
114 * example, if user space returns an incorrect status for a
115 * mount request. Otherwise we're doing a readdir on the
116 * autofs file system so just let the libfs routines handle
119 spin_lock(&sbi->lookup_lock);
120 if (!path_is_mountpoint(&file->f_path) && simple_empty(dentry)) {
121 spin_unlock(&sbi->lookup_lock);
124 spin_unlock(&sbi->lookup_lock);
127 return dcache_dir_open(inode, file);
130 static void autofs_dentry_release(struct dentry *de)
132 struct autofs_info *ino = autofs_dentry_ino(de);
133 struct autofs_sb_info *sbi = autofs_sbi(de->d_sb);
135 pr_debug("releasing %p\n", de);
141 spin_lock(&sbi->lookup_lock);
142 if (!list_empty(&ino->active))
143 list_del(&ino->active);
144 if (!list_empty(&ino->expiring))
145 list_del(&ino->expiring);
146 spin_unlock(&sbi->lookup_lock);
149 autofs_free_ino(ino);
152 static struct dentry *autofs_lookup_active(struct dentry *dentry)
154 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
155 struct dentry *parent = dentry->d_parent;
156 const struct qstr *name = &dentry->d_name;
157 unsigned int len = name->len;
158 unsigned int hash = name->hash;
159 const unsigned char *str = name->name;
160 struct list_head *p, *head;
162 head = &sbi->active_list;
163 if (list_empty(head))
165 spin_lock(&sbi->lookup_lock);
166 list_for_each(p, head) {
167 struct autofs_info *ino;
168 struct dentry *active;
169 const struct qstr *qstr;
171 ino = list_entry(p, struct autofs_info, active);
172 active = ino->dentry;
174 spin_lock(&active->d_lock);
177 if ((int) d_count(active) <= 0)
180 qstr = &active->d_name;
182 if (active->d_name.hash != hash)
184 if (active->d_parent != parent)
187 if (qstr->len != len)
189 if (memcmp(qstr->name, str, len))
192 if (d_unhashed(active)) {
194 spin_unlock(&active->d_lock);
195 spin_unlock(&sbi->lookup_lock);
199 spin_unlock(&active->d_lock);
201 spin_unlock(&sbi->lookup_lock);
206 static struct dentry *autofs_lookup_expiring(struct dentry *dentry,
209 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
210 struct dentry *parent = dentry->d_parent;
211 const struct qstr *name = &dentry->d_name;
212 unsigned int len = name->len;
213 unsigned int hash = name->hash;
214 const unsigned char *str = name->name;
215 struct list_head *p, *head;
217 head = &sbi->expiring_list;
218 if (list_empty(head))
220 spin_lock(&sbi->lookup_lock);
221 list_for_each(p, head) {
222 struct autofs_info *ino;
223 struct dentry *expiring;
224 const struct qstr *qstr;
227 spin_unlock(&sbi->lookup_lock);
228 return ERR_PTR(-ECHILD);
231 ino = list_entry(p, struct autofs_info, expiring);
232 expiring = ino->dentry;
234 spin_lock(&expiring->d_lock);
236 /* We've already been dentry_iput or unlinked */
237 if (d_really_is_negative(expiring))
240 qstr = &expiring->d_name;
242 if (expiring->d_name.hash != hash)
244 if (expiring->d_parent != parent)
247 if (qstr->len != len)
249 if (memcmp(qstr->name, str, len))
252 if (d_unhashed(expiring)) {
253 dget_dlock(expiring);
254 spin_unlock(&expiring->d_lock);
255 spin_unlock(&sbi->lookup_lock);
259 spin_unlock(&expiring->d_lock);
261 spin_unlock(&sbi->lookup_lock);
266 static int autofs_mount_wait(const struct path *path, bool rcu_walk)
268 struct autofs_sb_info *sbi = autofs_sbi(path->dentry->d_sb);
269 struct autofs_info *ino = autofs_dentry_ino(path->dentry);
272 if (ino->flags & AUTOFS_INF_PENDING) {
275 pr_debug("waiting for mount name=%pd\n", path->dentry);
276 status = autofs_wait(sbi, path, NFY_MOUNT);
277 pr_debug("mount wait done status=%d\n", status);
278 ino->last_used = jiffies;
281 if (!(sbi->flags & AUTOFS_SBI_STRICTEXPIRE))
282 ino->last_used = jiffies;
286 static int do_expire_wait(const struct path *path, bool rcu_walk)
288 struct dentry *dentry = path->dentry;
289 struct dentry *expiring;
291 expiring = autofs_lookup_expiring(dentry, rcu_walk);
292 if (IS_ERR(expiring))
293 return PTR_ERR(expiring);
295 return autofs_expire_wait(path, rcu_walk);
297 const struct path this = { .mnt = path->mnt, .dentry = expiring };
299 * If we are racing with expire the request might not
300 * be quite complete, but the directory has been removed
301 * so it must have been successful, just wait for it.
303 autofs_expire_wait(&this, 0);
304 autofs_del_expiring(expiring);
310 static struct dentry *autofs_mountpoint_changed(struct path *path)
312 struct dentry *dentry = path->dentry;
313 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
316 * If this is an indirect mount the dentry could have gone away
317 * as a result of an expire and a new one created.
319 if (autofs_type_indirect(sbi->type) && d_unhashed(dentry)) {
320 struct dentry *parent = dentry->d_parent;
321 struct autofs_info *ino;
324 new = d_lookup(parent, &dentry->d_name);
327 ino = autofs_dentry_ino(new);
328 ino->last_used = jiffies;
335 static struct vfsmount *autofs_d_automount(struct path *path)
337 struct dentry *dentry = path->dentry;
338 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
339 struct autofs_info *ino = autofs_dentry_ino(dentry);
342 pr_debug("dentry=%p %pd\n", dentry, dentry);
344 /* The daemon never triggers a mount. */
345 if (autofs_oz_mode(sbi))
349 * If an expire request is pending everyone must wait.
350 * If the expire fails we're still mounted so continue
351 * the follow and return. A return of -EAGAIN (which only
352 * happens with indirect mounts) means the expire completed
353 * and the directory was removed, so just go ahead and try
356 status = do_expire_wait(path, 0);
357 if (status && status != -EAGAIN)
360 /* Callback to the daemon to perform the mount or wait */
361 spin_lock(&sbi->fs_lock);
362 if (ino->flags & AUTOFS_INF_PENDING) {
363 spin_unlock(&sbi->fs_lock);
364 status = autofs_mount_wait(path, 0);
366 return ERR_PTR(status);
371 * If the dentry is a symlink it's equivalent to a directory
372 * having path_is_mountpoint() true, so there's no need to call
373 * back to the daemon.
375 if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
376 spin_unlock(&sbi->fs_lock);
380 if (!path_is_mountpoint(path)) {
382 * It's possible that user space hasn't removed directories
383 * after umounting a rootless multi-mount, although it
384 * should. For v5 path_has_submounts() is sufficient to
385 * handle this because the leaves of the directory tree under
386 * the mount never trigger mounts themselves (they have an
387 * autofs trigger mount mounted on them). But v4 pseudo direct
388 * mounts do need the leaves to trigger mounts. In this case
389 * we have no choice but to use the list_empty() check and
390 * require user space behave.
392 if (sbi->version > 4) {
393 if (path_has_submounts(path)) {
394 spin_unlock(&sbi->fs_lock);
398 if (!simple_empty(dentry)) {
399 spin_unlock(&sbi->fs_lock);
403 ino->flags |= AUTOFS_INF_PENDING;
404 spin_unlock(&sbi->fs_lock);
405 status = autofs_mount_wait(path, 0);
406 spin_lock(&sbi->fs_lock);
407 ino->flags &= ~AUTOFS_INF_PENDING;
409 spin_unlock(&sbi->fs_lock);
410 return ERR_PTR(status);
413 spin_unlock(&sbi->fs_lock);
415 /* Mount succeeded, check if we ended up with a new dentry */
416 dentry = autofs_mountpoint_changed(path);
418 return ERR_PTR(-ENOENT);
423 static int autofs_d_manage(const struct path *path, bool rcu_walk)
425 struct dentry *dentry = path->dentry;
426 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
427 struct autofs_info *ino = autofs_dentry_ino(dentry);
430 pr_debug("dentry=%p %pd\n", dentry, dentry);
432 /* The daemon never waits. */
433 if (autofs_oz_mode(sbi)) {
434 if (!path_is_mountpoint(path))
439 /* Wait for pending expires */
440 if (do_expire_wait(path, rcu_walk) == -ECHILD)
444 * This dentry may be under construction so wait on mount
447 status = autofs_mount_wait(path, rcu_walk);
452 /* We don't need fs_lock in rcu_walk mode,
453 * just testing 'AUTOFS_INFO_NO_RCU' is enough.
454 * simple_empty() takes a spinlock, so leave it
456 * We only return -EISDIR when certain this isn't
461 if (ino->flags & AUTOFS_INF_WANT_EXPIRE)
463 if (path_is_mountpoint(path))
465 inode = d_inode_rcu(dentry);
466 if (inode && S_ISLNK(inode->i_mode))
468 if (list_empty(&dentry->d_subdirs))
470 if (!simple_empty(dentry))
475 spin_lock(&sbi->fs_lock);
477 * If the dentry has been selected for expire while we slept
478 * on the lock then it might go away. We'll deal with that in
479 * ->d_automount() and wait on a new mount if the expire
480 * succeeds or return here if it doesn't (since there's no
481 * mount to follow with a rootless multi-mount).
483 if (!(ino->flags & AUTOFS_INF_EXPIRING)) {
485 * Any needed mounting has been completed and the path
486 * updated so check if this is a rootless multi-mount so
487 * we can avoid needless calls ->d_automount() and avoid
488 * an incorrect ELOOP error return.
490 if ((!path_is_mountpoint(path) && !simple_empty(dentry)) ||
491 (d_really_is_positive(dentry) && d_is_symlink(dentry)))
494 spin_unlock(&sbi->fs_lock);
499 /* Lookups in the root directory */
500 static struct dentry *autofs_lookup(struct inode *dir,
501 struct dentry *dentry, unsigned int flags)
503 struct autofs_sb_info *sbi;
504 struct autofs_info *ino;
505 struct dentry *active;
507 pr_debug("name = %pd\n", dentry);
509 /* File name too long to exist */
510 if (dentry->d_name.len > NAME_MAX)
511 return ERR_PTR(-ENAMETOOLONG);
513 sbi = autofs_sbi(dir->i_sb);
515 pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
516 current->pid, task_pgrp_nr(current),
517 sbi->flags & AUTOFS_SBI_CATATONIC,
518 autofs_oz_mode(sbi));
520 active = autofs_lookup_active(dentry);
525 * A dentry that is not within the root can never trigger a
526 * mount operation, unless the directory already exists, so we
527 * can return fail immediately. The daemon however does need
528 * to create directories within the file system.
530 if (!autofs_oz_mode(sbi) && !IS_ROOT(dentry->d_parent))
531 return ERR_PTR(-ENOENT);
533 /* Mark entries in the root as mount triggers */
534 if (IS_ROOT(dentry->d_parent) &&
535 autofs_type_indirect(sbi->type))
536 __managed_dentry_set_managed(dentry);
538 ino = autofs_new_ino(sbi);
540 return ERR_PTR(-ENOMEM);
542 dentry->d_fsdata = ino;
543 ino->dentry = dentry;
545 autofs_add_active(dentry);
550 static int autofs_dir_symlink(struct inode *dir,
551 struct dentry *dentry,
554 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
555 struct autofs_info *ino = autofs_dentry_ino(dentry);
556 struct autofs_info *p_ino;
558 size_t size = strlen(symname);
561 pr_debug("%s <- %pd\n", symname, dentry);
563 if (!autofs_oz_mode(sbi))
566 /* autofs_oz_mode() needs to allow path walks when the
567 * autofs mount is catatonic but the state of an autofs
568 * file system needs to be preserved over restarts.
570 if (sbi->flags & AUTOFS_SBI_CATATONIC)
575 autofs_clean_ino(ino);
577 autofs_del_active(dentry);
579 cp = kmalloc(size + 1, GFP_KERNEL);
585 inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555);
590 inode->i_private = cp;
591 inode->i_size = size;
592 d_add(dentry, inode);
595 atomic_inc(&ino->count);
596 p_ino = autofs_dentry_ino(dentry->d_parent);
597 if (p_ino && !IS_ROOT(dentry))
598 atomic_inc(&p_ino->count);
600 dir->i_mtime = current_time(dir);
608 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
609 * that the file no longer exists. However, doing that means that the
610 * VFS layer can turn the dentry into a negative dentry. We don't want
611 * this, because the unlink is probably the result of an expire.
612 * We simply d_drop it and add it to a expiring list in the super block,
613 * which allows the dentry lookup to check for an incomplete expire.
615 * If a process is blocked on the dentry waiting for the expire to finish,
616 * it will invalidate the dentry and try to mount with a new one.
618 * Also see autofs_dir_rmdir()..
620 static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
622 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
623 struct autofs_info *ino = autofs_dentry_ino(dentry);
624 struct autofs_info *p_ino;
626 if (!autofs_oz_mode(sbi))
629 /* autofs_oz_mode() needs to allow path walks when the
630 * autofs mount is catatonic but the state of an autofs
631 * file system needs to be preserved over restarts.
633 if (sbi->flags & AUTOFS_SBI_CATATONIC)
636 if (atomic_dec_and_test(&ino->count)) {
637 p_ino = autofs_dentry_ino(dentry->d_parent);
638 if (p_ino && !IS_ROOT(dentry))
639 atomic_dec(&p_ino->count);
643 d_inode(dentry)->i_size = 0;
644 clear_nlink(d_inode(dentry));
646 dir->i_mtime = current_time(dir);
648 spin_lock(&sbi->lookup_lock);
649 __autofs_add_expiring(dentry);
651 spin_unlock(&sbi->lookup_lock);
657 * Version 4 of autofs provides a pseudo direct mount implementation
658 * that relies on directories at the leaves of a directory tree under
659 * an indirect mount to trigger mounts. To allow for this we need to
660 * set the DMANAGED_AUTOMOUNT and DMANAGED_TRANSIT flags on the leaves
661 * of the directory tree. There is no need to clear the automount flag
662 * following a mount or restore it after an expire because these mounts
663 * are always covered. However, it is necessary to ensure that these
664 * flags are clear on non-empty directories to avoid unnecessary calls
667 static void autofs_set_leaf_automount_flags(struct dentry *dentry)
669 struct dentry *parent;
671 /* root and dentrys in the root are already handled */
672 if (IS_ROOT(dentry->d_parent))
675 managed_dentry_set_managed(dentry);
677 parent = dentry->d_parent;
678 /* only consider parents below dentrys in the root */
679 if (IS_ROOT(parent->d_parent))
681 managed_dentry_clear_managed(parent);
684 static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
686 struct list_head *d_child;
687 struct dentry *parent;
689 /* flags for dentrys in the root are handled elsewhere */
690 if (IS_ROOT(dentry->d_parent))
693 managed_dentry_clear_managed(dentry);
695 parent = dentry->d_parent;
696 /* only consider parents below dentrys in the root */
697 if (IS_ROOT(parent->d_parent))
699 d_child = &dentry->d_child;
700 /* Set parent managed if it's becoming empty */
701 if (d_child->next == &parent->d_subdirs &&
702 d_child->prev == &parent->d_subdirs)
703 managed_dentry_set_managed(parent);
706 static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
708 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
709 struct autofs_info *ino = autofs_dentry_ino(dentry);
710 struct autofs_info *p_ino;
712 pr_debug("dentry %p, removing %pd\n", dentry, dentry);
714 if (!autofs_oz_mode(sbi))
717 /* autofs_oz_mode() needs to allow path walks when the
718 * autofs mount is catatonic but the state of an autofs
719 * file system needs to be preserved over restarts.
721 if (sbi->flags & AUTOFS_SBI_CATATONIC)
724 spin_lock(&sbi->lookup_lock);
725 if (!simple_empty(dentry)) {
726 spin_unlock(&sbi->lookup_lock);
729 __autofs_add_expiring(dentry);
731 spin_unlock(&sbi->lookup_lock);
733 if (sbi->version < 5)
734 autofs_clear_leaf_automount_flags(dentry);
736 if (atomic_dec_and_test(&ino->count)) {
737 p_ino = autofs_dentry_ino(dentry->d_parent);
738 if (p_ino && dentry->d_parent != dentry)
739 atomic_dec(&p_ino->count);
742 d_inode(dentry)->i_size = 0;
743 clear_nlink(d_inode(dentry));
751 static int autofs_dir_mkdir(struct inode *dir,
752 struct dentry *dentry, umode_t mode)
754 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
755 struct autofs_info *ino = autofs_dentry_ino(dentry);
756 struct autofs_info *p_ino;
759 if (!autofs_oz_mode(sbi))
762 /* autofs_oz_mode() needs to allow path walks when the
763 * autofs mount is catatonic but the state of an autofs
764 * file system needs to be preserved over restarts.
766 if (sbi->flags & AUTOFS_SBI_CATATONIC)
769 pr_debug("dentry %p, creating %pd\n", dentry, dentry);
773 autofs_clean_ino(ino);
775 autofs_del_active(dentry);
777 inode = autofs_get_inode(dir->i_sb, S_IFDIR | mode);
780 d_add(dentry, inode);
782 if (sbi->version < 5)
783 autofs_set_leaf_automount_flags(dentry);
786 atomic_inc(&ino->count);
787 p_ino = autofs_dentry_ino(dentry->d_parent);
788 if (p_ino && !IS_ROOT(dentry))
789 atomic_inc(&p_ino->count);
791 dir->i_mtime = current_time(dir);
796 /* Get/set timeout ioctl() operation */
798 static inline int autofs_compat_get_set_timeout(struct autofs_sb_info *sbi,
799 compat_ulong_t __user *p)
801 unsigned long ntimeout;
804 rv = get_user(ntimeout, p);
808 rv = put_user(sbi->exp_timeout/HZ, p);
812 if (ntimeout > UINT_MAX/HZ)
813 sbi->exp_timeout = 0;
815 sbi->exp_timeout = ntimeout * HZ;
823 static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
824 unsigned long __user *p)
826 unsigned long ntimeout;
829 rv = get_user(ntimeout, p);
833 rv = put_user(sbi->exp_timeout/HZ, p);
837 if (ntimeout > ULONG_MAX/HZ)
838 sbi->exp_timeout = 0;
840 sbi->exp_timeout = ntimeout * HZ;
847 /* Return protocol version */
848 static inline int autofs_get_protover(struct autofs_sb_info *sbi,
851 return put_user(sbi->version, p);
854 /* Return protocol sub version */
855 static inline int autofs_get_protosubver(struct autofs_sb_info *sbi,
858 return put_user(sbi->sub_version, p);
862 * Tells the daemon whether it can umount the autofs mount.
864 static inline int autofs_ask_umount(struct vfsmount *mnt, int __user *p)
871 pr_debug("may umount %d\n", status);
873 status = put_user(status, p);
878 /* Identify autofs_dentries - this is so we can tell if there's
879 * an extra dentry refcount or not. We only hold a refcount on the
880 * dentry if its non-negative (ie, d_inode != NULL)
882 int is_autofs_dentry(struct dentry *dentry)
884 return dentry && d_really_is_positive(dentry) &&
885 dentry->d_op == &autofs_dentry_operations &&
886 dentry->d_fsdata != NULL;
890 * ioctl()'s on the root directory is the chief method for the daemon to
891 * generate kernel reactions
893 static int autofs_root_ioctl_unlocked(struct inode *inode, struct file *filp,
894 unsigned int cmd, unsigned long arg)
896 struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
897 void __user *p = (void __user *)arg;
899 pr_debug("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
900 cmd, arg, sbi, task_pgrp_nr(current));
902 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
903 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
906 if (!autofs_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
910 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
911 return autofs_wait_release(sbi, (autofs_wqt_t) arg, 0);
912 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
913 return autofs_wait_release(sbi, (autofs_wqt_t) arg, -ENOENT);
914 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
915 autofs_catatonic_mode(sbi);
917 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
918 return autofs_get_protover(sbi, p);
919 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
920 return autofs_get_protosubver(sbi, p);
921 case AUTOFS_IOC_SETTIMEOUT:
922 return autofs_get_set_timeout(sbi, p);
924 case AUTOFS_IOC_SETTIMEOUT32:
925 return autofs_compat_get_set_timeout(sbi, p);
928 case AUTOFS_IOC_ASKUMOUNT:
929 return autofs_ask_umount(filp->f_path.mnt, p);
931 /* return a single thing to expire */
932 case AUTOFS_IOC_EXPIRE:
933 return autofs_expire_run(inode->i_sb, filp->f_path.mnt, sbi, p);
934 /* same as above, but can send multiple expires through pipe */
935 case AUTOFS_IOC_EXPIRE_MULTI:
936 return autofs_expire_multi(inode->i_sb,
937 filp->f_path.mnt, sbi, p);
944 static long autofs_root_ioctl(struct file *filp,
945 unsigned int cmd, unsigned long arg)
947 struct inode *inode = file_inode(filp);
949 return autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
953 static long autofs_root_compat_ioctl(struct file *filp,
954 unsigned int cmd, unsigned long arg)
956 struct inode *inode = file_inode(filp);
959 if (cmd == AUTOFS_IOC_READY || cmd == AUTOFS_IOC_FAIL)
960 ret = autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
962 ret = autofs_root_ioctl_unlocked(inode, filp, cmd,
963 (unsigned long) compat_ptr(arg));