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-2006 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>
22 static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
23 static int autofs4_dir_unlink(struct inode *,struct dentry *);
24 static int autofs4_dir_rmdir(struct inode *,struct dentry *);
25 static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
26 static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
27 static int autofs4_dir_open(struct inode *inode, struct file *file);
28 static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
29 static void *autofs4_follow_link(struct dentry *, struct nameidata *);
31 #define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
32 #define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
34 const struct file_operations autofs4_root_operations = {
35 .open = dcache_dir_open,
36 .release = dcache_dir_close,
37 .read = generic_read_dir,
38 .readdir = dcache_readdir,
39 .llseek = dcache_dir_lseek,
40 .ioctl = autofs4_root_ioctl,
43 const struct file_operations autofs4_dir_operations = {
44 .open = autofs4_dir_open,
45 .release = dcache_dir_close,
46 .read = generic_read_dir,
47 .readdir = dcache_readdir,
48 .llseek = dcache_dir_lseek,
51 const struct inode_operations autofs4_indirect_root_inode_operations = {
52 .lookup = autofs4_lookup,
53 .unlink = autofs4_dir_unlink,
54 .symlink = autofs4_dir_symlink,
55 .mkdir = autofs4_dir_mkdir,
56 .rmdir = autofs4_dir_rmdir,
59 const struct inode_operations autofs4_direct_root_inode_operations = {
60 .lookup = autofs4_lookup,
61 .unlink = autofs4_dir_unlink,
62 .mkdir = autofs4_dir_mkdir,
63 .rmdir = autofs4_dir_rmdir,
64 .follow_link = autofs4_follow_link,
67 const struct inode_operations autofs4_dir_inode_operations = {
68 .lookup = autofs4_lookup,
69 .unlink = autofs4_dir_unlink,
70 .symlink = autofs4_dir_symlink,
71 .mkdir = autofs4_dir_mkdir,
72 .rmdir = autofs4_dir_rmdir,
75 static void autofs4_add_active(struct dentry *dentry)
77 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
78 struct autofs_info *ino = autofs4_dentry_ino(dentry);
80 spin_lock(&sbi->lookup_lock);
81 if (!ino->active_count) {
82 if (list_empty(&ino->active))
83 list_add(&ino->active, &sbi->active_list);
86 spin_unlock(&sbi->lookup_lock);
91 static void autofs4_del_active(struct dentry *dentry)
93 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
94 struct autofs_info *ino = autofs4_dentry_ino(dentry);
96 spin_lock(&sbi->lookup_lock);
98 if (!ino->active_count) {
99 if (!list_empty(&ino->active))
100 list_del_init(&ino->active);
102 spin_unlock(&sbi->lookup_lock);
107 static int autofs4_dir_open(struct inode *inode, struct file *file)
109 struct dentry *dentry = file->f_path.dentry;
110 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
112 DPRINTK("file=%p dentry=%p %.*s",
113 file, dentry, dentry->d_name.len, dentry->d_name.name);
115 if (autofs4_oz_mode(sbi))
119 * An empty directory in an autofs file system is always a
120 * mount point. The daemon must have failed to mount this
121 * during lookup so it doesn't exist. This can happen, for
122 * example, if user space returns an incorrect status for a
123 * mount request. Otherwise we're doing a readdir on the
124 * autofs file system so just let the libfs routines handle
127 spin_lock(&dcache_lock);
128 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
129 spin_unlock(&dcache_lock);
132 spin_unlock(&dcache_lock);
135 return dcache_dir_open(inode, file);
138 static int try_to_fill_dentry(struct dentry *dentry, int flags)
140 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
141 struct autofs_info *ino = autofs4_dentry_ino(dentry);
144 DPRINTK("dentry=%p %.*s ino=%p",
145 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
148 * Wait for a pending mount, triggering one if there
151 if (dentry->d_inode == NULL) {
152 DPRINTK("waiting for mount name=%.*s",
153 dentry->d_name.len, dentry->d_name.name);
155 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
157 DPRINTK("mount done status=%d", status);
159 /* Turn this into a real negative dentry? */
160 if (status == -ENOENT) {
161 spin_lock(&dentry->d_lock);
162 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
163 spin_unlock(&dentry->d_lock);
166 /* Return a negative dentry, but leave it "pending" */
169 /* Trigger mount for path component or follow link */
170 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
171 flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
172 current->link_count) {
173 DPRINTK("waiting for mount name=%.*s",
174 dentry->d_name.len, dentry->d_name.name);
176 spin_lock(&dentry->d_lock);
177 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
178 spin_unlock(&dentry->d_lock);
179 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
181 DPRINTK("mount done status=%d", status);
184 spin_lock(&dentry->d_lock);
185 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
186 spin_unlock(&dentry->d_lock);
191 /* Initialize expiry counter after successful mount */
193 ino->last_used = jiffies;
195 spin_lock(&dentry->d_lock);
196 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
197 spin_unlock(&dentry->d_lock);
202 /* For autofs direct mounts the follow link triggers the mount */
203 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
205 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
206 struct autofs_info *ino = autofs4_dentry_ino(dentry);
207 int oz_mode = autofs4_oz_mode(sbi);
208 unsigned int lookup_type;
211 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
212 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
215 * For an expire of a covered direct or offset mount we need
216 * to break out of follow_down() at the autofs mount trigger
217 * (d_mounted--), so we can see the expiring flag, and manage
218 * the blocking and following here until the expire is completed.
221 spin_lock(&sbi->fs_lock);
222 if (ino->flags & AUTOFS_INF_EXPIRING) {
223 spin_unlock(&sbi->fs_lock);
224 /* Follow down to our covering mount. */
225 if (!follow_down(&nd->path))
229 spin_unlock(&sbi->fs_lock);
233 /* If an expire request is pending everyone must wait. */
234 autofs4_expire_wait(dentry);
236 /* We trigger a mount for almost all flags */
237 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
238 if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
242 * If the dentry contains directories then it is an autofs
243 * multi-mount with no root mount offset. So don't try to
246 spin_lock(&dcache_lock);
247 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
248 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
249 spin_unlock(&dcache_lock);
251 status = try_to_fill_dentry(dentry, 0);
257 spin_unlock(&dcache_lock);
260 * If there is no root mount it must be an autofs
261 * multi-mount with no root offset so we don't need
264 if (d_mountpoint(dentry)) {
265 if (!autofs4_follow_mount(&nd->path)) {
276 return ERR_PTR(status);
280 * Revalidate is called on every cache lookup. Some of those
281 * cache lookups may actually happen while the dentry is not
282 * yet completely filled in, and revalidate has to delay such
285 static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
287 struct inode *dir = dentry->d_parent->d_inode;
288 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
289 int oz_mode = autofs4_oz_mode(sbi);
290 int flags = nd ? nd->flags : 0;
294 spin_lock(&sbi->fs_lock);
295 if (autofs4_ispending(dentry)) {
296 /* The daemon never causes a mount to trigger */
297 spin_unlock(&sbi->fs_lock);
303 * If the directory has gone away due to an expire
304 * we have been called as ->d_revalidate() and so
305 * we need to return false and proceed to ->lookup().
307 if (autofs4_expire_wait(dentry) == -EAGAIN)
311 * A zero status is success otherwise we have a
312 * negative error code.
314 status = try_to_fill_dentry(dentry, flags);
320 spin_unlock(&sbi->fs_lock);
322 /* Negative dentry.. invalidate if "old" */
323 if (dentry->d_inode == NULL)
326 /* Check for a non-mountpoint directory with no contents */
327 spin_lock(&dcache_lock);
328 if (S_ISDIR(dentry->d_inode->i_mode) &&
329 !d_mountpoint(dentry) &&
330 __simple_empty(dentry)) {
331 DPRINTK("dentry=%p %.*s, emptydir",
332 dentry, dentry->d_name.len, dentry->d_name.name);
333 spin_unlock(&dcache_lock);
335 /* The daemon never causes a mount to trigger */
340 * A zero status is success otherwise we have a
341 * negative error code.
343 status = try_to_fill_dentry(dentry, flags);
349 spin_unlock(&dcache_lock);
354 void autofs4_dentry_release(struct dentry *de)
356 struct autofs_info *inf;
358 DPRINTK("releasing %p", de);
360 inf = autofs4_dentry_ino(de);
364 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
367 spin_lock(&sbi->lookup_lock);
368 if (!list_empty(&inf->active))
369 list_del(&inf->active);
370 if (!list_empty(&inf->expiring))
371 list_del(&inf->expiring);
372 spin_unlock(&sbi->lookup_lock);
378 autofs4_free_ino(inf);
382 /* For dentries of directories in the root dir */
383 static const struct dentry_operations autofs4_root_dentry_operations = {
384 .d_revalidate = autofs4_revalidate,
385 .d_release = autofs4_dentry_release,
388 /* For other dentries */
389 static const struct dentry_operations autofs4_dentry_operations = {
390 .d_revalidate = autofs4_revalidate,
391 .d_release = autofs4_dentry_release,
394 static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
396 unsigned int len = name->len;
397 unsigned int hash = name->hash;
398 const unsigned char *str = name->name;
399 struct list_head *p, *head;
401 spin_lock(&dcache_lock);
402 spin_lock(&sbi->lookup_lock);
403 head = &sbi->active_list;
404 list_for_each(p, head) {
405 struct autofs_info *ino;
406 struct dentry *dentry;
409 ino = list_entry(p, struct autofs_info, active);
410 dentry = ino->dentry;
412 spin_lock(&dentry->d_lock);
415 if (atomic_read(&dentry->d_count) == 0)
418 qstr = &dentry->d_name;
420 if (dentry->d_name.hash != hash)
422 if (dentry->d_parent != parent)
425 if (qstr->len != len)
427 if (memcmp(qstr->name, str, len))
430 if (d_unhashed(dentry)) {
432 spin_unlock(&dentry->d_lock);
433 spin_unlock(&sbi->lookup_lock);
434 spin_unlock(&dcache_lock);
438 spin_unlock(&dentry->d_lock);
440 spin_unlock(&sbi->lookup_lock);
441 spin_unlock(&dcache_lock);
446 static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
448 unsigned int len = name->len;
449 unsigned int hash = name->hash;
450 const unsigned char *str = name->name;
451 struct list_head *p, *head;
453 spin_lock(&dcache_lock);
454 spin_lock(&sbi->lookup_lock);
455 head = &sbi->expiring_list;
456 list_for_each(p, head) {
457 struct autofs_info *ino;
458 struct dentry *dentry;
461 ino = list_entry(p, struct autofs_info, expiring);
462 dentry = ino->dentry;
464 spin_lock(&dentry->d_lock);
466 /* Bad luck, we've already been dentry_iput */
467 if (!dentry->d_inode)
470 qstr = &dentry->d_name;
472 if (dentry->d_name.hash != hash)
474 if (dentry->d_parent != parent)
477 if (qstr->len != len)
479 if (memcmp(qstr->name, str, len))
482 if (d_unhashed(dentry)) {
484 spin_unlock(&dentry->d_lock);
485 spin_unlock(&sbi->lookup_lock);
486 spin_unlock(&dcache_lock);
490 spin_unlock(&dentry->d_lock);
492 spin_unlock(&sbi->lookup_lock);
493 spin_unlock(&dcache_lock);
498 /* Lookups in the root directory */
499 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
501 struct autofs_sb_info *sbi;
502 struct autofs_info *ino;
503 struct dentry *expiring, *unhashed;
506 DPRINTK("name = %.*s",
507 dentry->d_name.len, dentry->d_name.name);
509 /* File name too long to exist */
510 if (dentry->d_name.len > NAME_MAX)
511 return ERR_PTR(-ENAMETOOLONG);
513 sbi = autofs4_sbi(dir->i_sb);
514 oz_mode = autofs4_oz_mode(sbi);
516 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
517 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
519 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
524 * Mark the dentry incomplete but don't hash it. We do this
525 * to serialize our inode creation operations (symlink and
526 * mkdir) which prevents deadlock during the callback to
527 * the daemon. Subsequent user space lookups for the same
528 * dentry are placed on the wait queue while the daemon
529 * itself is allowed passage unresticted so the create
530 * operation itself can then hash the dentry. Finally,
531 * we check for the hashed dentry and return the newly
534 dentry->d_op = &autofs4_root_dentry_operations;
537 * And we need to ensure that the same dentry is used for
538 * all following lookup calls until it is hashed so that
539 * the dentry flags are persistent throughout the request.
541 ino = autofs4_init_ino(NULL, sbi, 0555);
543 return ERR_PTR(-ENOMEM);
545 dentry->d_fsdata = ino;
546 ino->dentry = dentry;
548 autofs4_add_active(dentry);
550 d_instantiate(dentry, NULL);
554 mutex_unlock(&dir->i_mutex);
555 expiring = autofs4_lookup_expiring(sbi,
560 * If we are racing with expire the request might not
561 * be quite complete but the directory has been removed
562 * so it must have been successful, so just wait for it.
564 ino = autofs4_dentry_ino(expiring);
565 autofs4_expire_wait(expiring);
566 autofs4_del_expiring(expiring);
570 spin_lock(&dentry->d_lock);
571 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
572 spin_unlock(&dentry->d_lock);
573 if (dentry->d_op && dentry->d_op->d_revalidate)
574 (dentry->d_op->d_revalidate)(dentry, nd);
575 mutex_lock(&dir->i_mutex);
579 * If we are still pending, check if we had to handle
580 * a signal. If so we can force a restart..
582 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
583 /* See if we were interrupted */
584 if (signal_pending(current)) {
585 sigset_t *sigset = ¤t->pending.signal;
586 if (sigismember (sigset, SIGKILL) ||
587 sigismember (sigset, SIGQUIT) ||
588 sigismember (sigset, SIGINT)) {
591 return ERR_PTR(-ERESTARTNOINTR);
595 spin_lock(&dentry->d_lock);
596 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
597 spin_unlock(&dentry->d_lock);
602 * If this dentry is unhashed, then we shouldn't honour this
603 * lookup. Returning ENOENT here doesn't do the right thing
604 * for all system calls, but it should be OK for the operations
605 * we permit from an autofs.
607 if (!oz_mode && d_unhashed(dentry)) {
609 * A user space application can (and has done in the past)
610 * remove and re-create this directory during the callback.
611 * This can leave us with an unhashed dentry, but a
612 * successful mount! So we need to perform another
613 * cached lookup in case the dentry now exists.
615 struct dentry *parent = dentry->d_parent;
616 struct dentry *new = d_lookup(parent, &dentry->d_name);
620 dentry = ERR_PTR(-ENOENT);
634 static int autofs4_dir_symlink(struct inode *dir,
635 struct dentry *dentry,
638 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
639 struct autofs_info *ino = autofs4_dentry_ino(dentry);
640 struct autofs_info *p_ino;
644 DPRINTK("%s <- %.*s", symname,
645 dentry->d_name.len, dentry->d_name.name);
647 if (!autofs4_oz_mode(sbi))
650 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
654 autofs4_del_active(dentry);
656 ino->size = strlen(symname);
657 cp = kmalloc(ino->size + 1, GFP_KERNEL);
659 if (!dentry->d_fsdata)
666 inode = autofs4_get_inode(dir->i_sb, ino);
669 if (!dentry->d_fsdata)
673 d_add(dentry, inode);
675 if (dir == dir->i_sb->s_root->d_inode)
676 dentry->d_op = &autofs4_root_dentry_operations;
678 dentry->d_op = &autofs4_dentry_operations;
680 dentry->d_fsdata = ino;
681 ino->dentry = dget(dentry);
682 atomic_inc(&ino->count);
683 p_ino = autofs4_dentry_ino(dentry->d_parent);
684 if (p_ino && dentry->d_parent != dentry)
685 atomic_inc(&p_ino->count);
689 dir->i_mtime = CURRENT_TIME;
697 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
698 * that the file no longer exists. However, doing that means that the
699 * VFS layer can turn the dentry into a negative dentry. We don't want
700 * this, because the unlink is probably the result of an expire.
701 * We simply d_drop it and add it to a expiring list in the super block,
702 * which allows the dentry lookup to check for an incomplete expire.
704 * If a process is blocked on the dentry waiting for the expire to finish,
705 * it will invalidate the dentry and try to mount with a new one.
707 * Also see autofs4_dir_rmdir()..
709 static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
711 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
712 struct autofs_info *ino = autofs4_dentry_ino(dentry);
713 struct autofs_info *p_ino;
715 /* This allows root to remove symlinks */
716 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
719 if (atomic_dec_and_test(&ino->count)) {
720 p_ino = autofs4_dentry_ino(dentry->d_parent);
721 if (p_ino && dentry->d_parent != dentry)
722 atomic_dec(&p_ino->count);
726 dentry->d_inode->i_size = 0;
727 clear_nlink(dentry->d_inode);
729 dir->i_mtime = CURRENT_TIME;
731 spin_lock(&dcache_lock);
732 autofs4_add_expiring(dentry);
733 spin_lock(&dentry->d_lock);
735 spin_unlock(&dentry->d_lock);
736 spin_unlock(&dcache_lock);
741 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
743 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
744 struct autofs_info *ino = autofs4_dentry_ino(dentry);
745 struct autofs_info *p_ino;
747 DPRINTK("dentry %p, removing %.*s",
748 dentry, dentry->d_name.len, dentry->d_name.name);
750 if (!autofs4_oz_mode(sbi))
753 spin_lock(&dcache_lock);
754 if (!list_empty(&dentry->d_subdirs)) {
755 spin_unlock(&dcache_lock);
758 autofs4_add_expiring(dentry);
759 spin_lock(&dentry->d_lock);
761 spin_unlock(&dentry->d_lock);
762 spin_unlock(&dcache_lock);
764 if (atomic_dec_and_test(&ino->count)) {
765 p_ino = autofs4_dentry_ino(dentry->d_parent);
766 if (p_ino && dentry->d_parent != dentry)
767 atomic_dec(&p_ino->count);
770 dentry->d_inode->i_size = 0;
771 clear_nlink(dentry->d_inode);
779 static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
781 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
782 struct autofs_info *ino = autofs4_dentry_ino(dentry);
783 struct autofs_info *p_ino;
786 if (!autofs4_oz_mode(sbi))
789 DPRINTK("dentry %p, creating %.*s",
790 dentry, dentry->d_name.len, dentry->d_name.name);
792 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
796 autofs4_del_active(dentry);
798 inode = autofs4_get_inode(dir->i_sb, ino);
800 if (!dentry->d_fsdata)
804 d_add(dentry, inode);
806 if (dir == dir->i_sb->s_root->d_inode)
807 dentry->d_op = &autofs4_root_dentry_operations;
809 dentry->d_op = &autofs4_dentry_operations;
811 dentry->d_fsdata = ino;
812 ino->dentry = dget(dentry);
813 atomic_inc(&ino->count);
814 p_ino = autofs4_dentry_ino(dentry->d_parent);
815 if (p_ino && dentry->d_parent != dentry)
816 atomic_inc(&p_ino->count);
819 dir->i_mtime = CURRENT_TIME;
824 /* Get/set timeout ioctl() operation */
825 static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
826 unsigned long __user *p)
829 unsigned long ntimeout;
831 if ((rv = get_user(ntimeout, p)) ||
832 (rv = put_user(sbi->exp_timeout/HZ, p)))
835 if (ntimeout > ULONG_MAX/HZ)
836 sbi->exp_timeout = 0;
838 sbi->exp_timeout = ntimeout * HZ;
843 /* Return protocol version */
844 static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
846 return put_user(sbi->version, p);
849 /* Return protocol sub version */
850 static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
852 return put_user(sbi->sub_version, p);
856 * Tells the daemon whether it can umount the autofs mount.
858 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
865 DPRINTK("returning %d", status);
867 status = put_user(status, p);
872 /* Identify autofs4_dentries - this is so we can tell if there's
873 an extra dentry refcount or not. We only hold a refcount on the
874 dentry if its non-negative (ie, d_inode != NULL)
876 int is_autofs4_dentry(struct dentry *dentry)
878 return dentry && dentry->d_inode &&
879 (dentry->d_op == &autofs4_root_dentry_operations ||
880 dentry->d_op == &autofs4_dentry_operations) &&
881 dentry->d_fsdata != NULL;
885 * ioctl()'s on the root directory is the chief method for the daemon to
886 * generate kernel reactions
888 static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
889 unsigned int cmd, unsigned long arg)
891 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
892 void __user *p = (void __user *)arg;
894 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
895 cmd,arg,sbi,task_pgrp_nr(current));
897 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
898 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
901 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
905 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
906 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
907 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
908 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
909 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
910 autofs4_catatonic_mode(sbi);
912 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
913 return autofs4_get_protover(sbi, p);
914 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
915 return autofs4_get_protosubver(sbi, p);
916 case AUTOFS_IOC_SETTIMEOUT:
917 return autofs4_get_set_timeout(sbi, p);
919 case AUTOFS_IOC_ASKUMOUNT:
920 return autofs4_ask_umount(filp->f_path.mnt, p);
922 /* return a single thing to expire */
923 case AUTOFS_IOC_EXPIRE:
924 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
925 /* same as above, but can send multiple expires through pipe */
926 case AUTOFS_IOC_EXPIRE_MULTI:
927 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);