1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
4 * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
5 * Copyright 2001-2006 Ian Kent <raven@themaw.net>
8 #include <linux/capability.h>
9 #include <linux/compat.h>
13 static int autofs_dir_symlink(struct inode
*, struct dentry
*, const char *);
14 static int autofs_dir_unlink(struct inode
*, struct dentry
*);
15 static int autofs_dir_rmdir(struct inode
*, struct dentry
*);
16 static int autofs_dir_mkdir(struct inode
*, struct dentry
*, umode_t
);
17 static long autofs_root_ioctl(struct file
*, unsigned int, unsigned long);
19 static long autofs_root_compat_ioctl(struct file
*,
20 unsigned int, unsigned long);
22 static int autofs_dir_open(struct inode
*inode
, struct file
*file
);
23 static struct dentry
*autofs_lookup(struct inode
*,
24 struct dentry
*, unsigned int);
25 static struct vfsmount
*autofs_d_automount(struct path
*);
26 static int autofs_d_manage(const struct path
*, bool);
27 static void autofs_dentry_release(struct dentry
*);
29 const struct file_operations autofs_root_operations
= {
30 .open
= dcache_dir_open
,
31 .release
= dcache_dir_close
,
32 .read
= generic_read_dir
,
33 .iterate_shared
= dcache_readdir
,
34 .llseek
= dcache_dir_lseek
,
35 .unlocked_ioctl
= autofs_root_ioctl
,
37 .compat_ioctl
= autofs_root_compat_ioctl
,
41 const struct file_operations autofs_dir_operations
= {
42 .open
= autofs_dir_open
,
43 .release
= dcache_dir_close
,
44 .read
= generic_read_dir
,
45 .iterate_shared
= dcache_readdir
,
46 .llseek
= dcache_dir_lseek
,
49 const struct inode_operations autofs_dir_inode_operations
= {
50 .lookup
= autofs_lookup
,
51 .unlink
= autofs_dir_unlink
,
52 .symlink
= autofs_dir_symlink
,
53 .mkdir
= autofs_dir_mkdir
,
54 .rmdir
= autofs_dir_rmdir
,
57 const struct dentry_operations autofs_dentry_operations
= {
58 .d_automount
= autofs_d_automount
,
59 .d_manage
= autofs_d_manage
,
60 .d_release
= autofs_dentry_release
,
63 static void autofs_del_active(struct dentry
*dentry
)
65 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
66 struct autofs_info
*ino
;
68 ino
= autofs_dentry_ino(dentry
);
69 spin_lock(&sbi
->lookup_lock
);
70 list_del_init(&ino
->active
);
71 spin_unlock(&sbi
->lookup_lock
);
74 static int autofs_dir_open(struct inode
*inode
, struct file
*file
)
76 struct dentry
*dentry
= file
->f_path
.dentry
;
77 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
79 pr_debug("file=%p dentry=%p %pd\n", file
, dentry
, dentry
);
81 if (autofs_oz_mode(sbi
))
85 * An empty directory in an autofs file system is always a
86 * mount point. The daemon must have failed to mount this
87 * during lookup so it doesn't exist. This can happen, for
88 * example, if user space returns an incorrect status for a
89 * mount request. Otherwise we're doing a readdir on the
90 * autofs file system so just let the libfs routines handle
93 spin_lock(&sbi
->lookup_lock
);
94 if (!path_is_mountpoint(&file
->f_path
) && simple_empty(dentry
)) {
95 spin_unlock(&sbi
->lookup_lock
);
98 spin_unlock(&sbi
->lookup_lock
);
101 return dcache_dir_open(inode
, file
);
104 static void autofs_dentry_release(struct dentry
*de
)
106 struct autofs_info
*ino
= autofs_dentry_ino(de
);
107 struct autofs_sb_info
*sbi
= autofs_sbi(de
->d_sb
);
109 pr_debug("releasing %p\n", de
);
115 spin_lock(&sbi
->lookup_lock
);
116 if (!list_empty(&ino
->active
))
117 list_del(&ino
->active
);
118 if (!list_empty(&ino
->expiring
))
119 list_del(&ino
->expiring
);
120 spin_unlock(&sbi
->lookup_lock
);
123 autofs_free_ino(ino
);
126 static struct dentry
*autofs_lookup_active(struct dentry
*dentry
)
128 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
129 struct dentry
*parent
= dentry
->d_parent
;
130 const struct qstr
*name
= &dentry
->d_name
;
131 unsigned int len
= name
->len
;
132 unsigned int hash
= name
->hash
;
133 const unsigned char *str
= name
->name
;
134 struct list_head
*p
, *head
;
136 head
= &sbi
->active_list
;
137 if (list_empty(head
))
139 spin_lock(&sbi
->lookup_lock
);
140 list_for_each(p
, head
) {
141 struct autofs_info
*ino
;
142 struct dentry
*active
;
143 const struct qstr
*qstr
;
145 ino
= list_entry(p
, struct autofs_info
, active
);
146 active
= ino
->dentry
;
148 spin_lock(&active
->d_lock
);
151 if ((int) d_count(active
) <= 0)
154 qstr
= &active
->d_name
;
156 if (active
->d_name
.hash
!= hash
)
158 if (active
->d_parent
!= parent
)
161 if (qstr
->len
!= len
)
163 if (memcmp(qstr
->name
, str
, len
))
166 if (d_unhashed(active
)) {
168 spin_unlock(&active
->d_lock
);
169 spin_unlock(&sbi
->lookup_lock
);
173 spin_unlock(&active
->d_lock
);
175 spin_unlock(&sbi
->lookup_lock
);
180 static struct dentry
*autofs_lookup_expiring(struct dentry
*dentry
,
183 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
184 struct dentry
*parent
= dentry
->d_parent
;
185 const struct qstr
*name
= &dentry
->d_name
;
186 unsigned int len
= name
->len
;
187 unsigned int hash
= name
->hash
;
188 const unsigned char *str
= name
->name
;
189 struct list_head
*p
, *head
;
191 head
= &sbi
->expiring_list
;
192 if (list_empty(head
))
194 spin_lock(&sbi
->lookup_lock
);
195 list_for_each(p
, head
) {
196 struct autofs_info
*ino
;
197 struct dentry
*expiring
;
198 const struct qstr
*qstr
;
201 spin_unlock(&sbi
->lookup_lock
);
202 return ERR_PTR(-ECHILD
);
205 ino
= list_entry(p
, struct autofs_info
, expiring
);
206 expiring
= ino
->dentry
;
208 spin_lock(&expiring
->d_lock
);
210 /* We've already been dentry_iput or unlinked */
211 if (d_really_is_negative(expiring
))
214 qstr
= &expiring
->d_name
;
216 if (expiring
->d_name
.hash
!= hash
)
218 if (expiring
->d_parent
!= parent
)
221 if (qstr
->len
!= len
)
223 if (memcmp(qstr
->name
, str
, len
))
226 if (d_unhashed(expiring
)) {
227 dget_dlock(expiring
);
228 spin_unlock(&expiring
->d_lock
);
229 spin_unlock(&sbi
->lookup_lock
);
233 spin_unlock(&expiring
->d_lock
);
235 spin_unlock(&sbi
->lookup_lock
);
240 static int autofs_mount_wait(const struct path
*path
, bool rcu_walk
)
242 struct autofs_sb_info
*sbi
= autofs_sbi(path
->dentry
->d_sb
);
243 struct autofs_info
*ino
= autofs_dentry_ino(path
->dentry
);
246 if (ino
->flags
& AUTOFS_INF_PENDING
) {
249 pr_debug("waiting for mount name=%pd\n", path
->dentry
);
250 status
= autofs_wait(sbi
, path
, NFY_MOUNT
);
251 pr_debug("mount wait done status=%d\n", status
);
252 ino
->last_used
= jiffies
;
255 if (!(sbi
->flags
& AUTOFS_SBI_STRICTEXPIRE
))
256 ino
->last_used
= jiffies
;
260 static int do_expire_wait(const struct path
*path
, bool rcu_walk
)
262 struct dentry
*dentry
= path
->dentry
;
263 struct dentry
*expiring
;
265 expiring
= autofs_lookup_expiring(dentry
, rcu_walk
);
266 if (IS_ERR(expiring
))
267 return PTR_ERR(expiring
);
269 return autofs_expire_wait(path
, rcu_walk
);
271 const struct path
this = { .mnt
= path
->mnt
, .dentry
= expiring
};
273 * If we are racing with expire the request might not
274 * be quite complete, but the directory has been removed
275 * so it must have been successful, just wait for it.
277 autofs_expire_wait(&this, 0);
278 autofs_del_expiring(expiring
);
284 static struct dentry
*autofs_mountpoint_changed(struct path
*path
)
286 struct dentry
*dentry
= path
->dentry
;
287 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
290 * If this is an indirect mount the dentry could have gone away
291 * as a result of an expire and a new one created.
293 if (autofs_type_indirect(sbi
->type
) && d_unhashed(dentry
)) {
294 struct dentry
*parent
= dentry
->d_parent
;
295 struct autofs_info
*ino
;
298 new = d_lookup(parent
, &dentry
->d_name
);
301 ino
= autofs_dentry_ino(new);
302 ino
->last_used
= jiffies
;
309 static struct vfsmount
*autofs_d_automount(struct path
*path
)
311 struct dentry
*dentry
= path
->dentry
;
312 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
313 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
316 pr_debug("dentry=%p %pd\n", dentry
, dentry
);
318 /* The daemon never triggers a mount. */
319 if (autofs_oz_mode(sbi
))
323 * If an expire request is pending everyone must wait.
324 * If the expire fails we're still mounted so continue
325 * the follow and return. A return of -EAGAIN (which only
326 * happens with indirect mounts) means the expire completed
327 * and the directory was removed, so just go ahead and try
330 status
= do_expire_wait(path
, 0);
331 if (status
&& status
!= -EAGAIN
)
334 /* Callback to the daemon to perform the mount or wait */
335 spin_lock(&sbi
->fs_lock
);
336 if (ino
->flags
& AUTOFS_INF_PENDING
) {
337 spin_unlock(&sbi
->fs_lock
);
338 status
= autofs_mount_wait(path
, 0);
340 return ERR_PTR(status
);
345 * If the dentry is a symlink it's equivalent to a directory
346 * having path_is_mountpoint() true, so there's no need to call
347 * back to the daemon.
349 if (d_really_is_positive(dentry
) && d_is_symlink(dentry
)) {
350 spin_unlock(&sbi
->fs_lock
);
354 if (!path_is_mountpoint(path
)) {
356 * It's possible that user space hasn't removed directories
357 * after umounting a rootless multi-mount, although it
358 * should. For v5 path_has_submounts() is sufficient to
359 * handle this because the leaves of the directory tree under
360 * the mount never trigger mounts themselves (they have an
361 * autofs trigger mount mounted on them). But v4 pseudo direct
362 * mounts do need the leaves to trigger mounts. In this case
363 * we have no choice but to use the list_empty() check and
364 * require user space behave.
366 if (sbi
->version
> 4) {
367 if (path_has_submounts(path
)) {
368 spin_unlock(&sbi
->fs_lock
);
372 if (!simple_empty(dentry
)) {
373 spin_unlock(&sbi
->fs_lock
);
377 ino
->flags
|= AUTOFS_INF_PENDING
;
378 spin_unlock(&sbi
->fs_lock
);
379 status
= autofs_mount_wait(path
, 0);
380 spin_lock(&sbi
->fs_lock
);
381 ino
->flags
&= ~AUTOFS_INF_PENDING
;
383 spin_unlock(&sbi
->fs_lock
);
384 return ERR_PTR(status
);
387 spin_unlock(&sbi
->fs_lock
);
389 /* Mount succeeded, check if we ended up with a new dentry */
390 dentry
= autofs_mountpoint_changed(path
);
392 return ERR_PTR(-ENOENT
);
397 static int autofs_d_manage(const struct path
*path
, bool rcu_walk
)
399 struct dentry
*dentry
= path
->dentry
;
400 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
401 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
404 pr_debug("dentry=%p %pd\n", dentry
, dentry
);
406 /* The daemon never waits. */
407 if (autofs_oz_mode(sbi
)) {
408 if (!path_is_mountpoint(path
))
413 /* Wait for pending expires */
414 if (do_expire_wait(path
, rcu_walk
) == -ECHILD
)
418 * This dentry may be under construction so wait on mount
421 status
= autofs_mount_wait(path
, rcu_walk
);
426 /* We don't need fs_lock in rcu_walk mode,
427 * just testing 'AUTOFS_INFO_NO_RCU' is enough.
428 * simple_empty() takes a spinlock, so leave it
430 * We only return -EISDIR when certain this isn't
435 if (ino
->flags
& AUTOFS_INF_WANT_EXPIRE
)
437 if (path_is_mountpoint(path
))
439 inode
= d_inode_rcu(dentry
);
440 if (inode
&& S_ISLNK(inode
->i_mode
))
442 if (list_empty(&dentry
->d_subdirs
))
444 if (!simple_empty(dentry
))
449 spin_lock(&sbi
->fs_lock
);
451 * If the dentry has been selected for expire while we slept
452 * on the lock then it might go away. We'll deal with that in
453 * ->d_automount() and wait on a new mount if the expire
454 * succeeds or return here if it doesn't (since there's no
455 * mount to follow with a rootless multi-mount).
457 if (!(ino
->flags
& AUTOFS_INF_EXPIRING
)) {
459 * Any needed mounting has been completed and the path
460 * updated so check if this is a rootless multi-mount so
461 * we can avoid needless calls ->d_automount() and avoid
462 * an incorrect ELOOP error return.
464 if ((!path_is_mountpoint(path
) && !simple_empty(dentry
)) ||
465 (d_really_is_positive(dentry
) && d_is_symlink(dentry
)))
468 spin_unlock(&sbi
->fs_lock
);
473 /* Lookups in the root directory */
474 static struct dentry
*autofs_lookup(struct inode
*dir
,
475 struct dentry
*dentry
, unsigned int flags
)
477 struct autofs_sb_info
*sbi
;
478 struct autofs_info
*ino
;
479 struct dentry
*active
;
481 pr_debug("name = %pd\n", dentry
);
483 /* File name too long to exist */
484 if (dentry
->d_name
.len
> NAME_MAX
)
485 return ERR_PTR(-ENAMETOOLONG
);
487 sbi
= autofs_sbi(dir
->i_sb
);
489 pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
490 current
->pid
, task_pgrp_nr(current
),
491 sbi
->flags
& AUTOFS_SBI_CATATONIC
,
492 autofs_oz_mode(sbi
));
494 active
= autofs_lookup_active(dentry
);
499 * A dentry that is not within the root can never trigger a
500 * mount operation, unless the directory already exists, so we
501 * can return fail immediately. The daemon however does need
502 * to create directories within the file system.
504 if (!autofs_oz_mode(sbi
) && !IS_ROOT(dentry
->d_parent
))
505 return ERR_PTR(-ENOENT
);
507 ino
= autofs_new_ino(sbi
);
509 return ERR_PTR(-ENOMEM
);
511 spin_lock(&sbi
->lookup_lock
);
512 spin_lock(&dentry
->d_lock
);
513 /* Mark entries in the root as mount triggers */
514 if (IS_ROOT(dentry
->d_parent
) &&
515 autofs_type_indirect(sbi
->type
))
516 __managed_dentry_set_managed(dentry
);
517 dentry
->d_fsdata
= ino
;
518 ino
->dentry
= dentry
;
520 list_add(&ino
->active
, &sbi
->active_list
);
521 spin_unlock(&sbi
->lookup_lock
);
522 spin_unlock(&dentry
->d_lock
);
527 static int autofs_dir_symlink(struct inode
*dir
,
528 struct dentry
*dentry
,
531 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
532 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
533 struct autofs_info
*p_ino
;
535 size_t size
= strlen(symname
);
538 pr_debug("%s <- %pd\n", symname
, dentry
);
540 if (!autofs_oz_mode(sbi
))
543 /* autofs_oz_mode() needs to allow path walks when the
544 * autofs mount is catatonic but the state of an autofs
545 * file system needs to be preserved over restarts.
547 if (sbi
->flags
& AUTOFS_SBI_CATATONIC
)
552 autofs_clean_ino(ino
);
554 autofs_del_active(dentry
);
556 cp
= kmalloc(size
+ 1, GFP_KERNEL
);
562 inode
= autofs_get_inode(dir
->i_sb
, S_IFLNK
| 0555);
567 inode
->i_private
= cp
;
568 inode
->i_size
= size
;
569 d_add(dentry
, inode
);
573 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
576 dir
->i_mtime
= current_time(dir
);
584 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
585 * that the file no longer exists. However, doing that means that the
586 * VFS layer can turn the dentry into a negative dentry. We don't want
587 * this, because the unlink is probably the result of an expire.
588 * We simply d_drop it and add it to a expiring list in the super block,
589 * which allows the dentry lookup to check for an incomplete expire.
591 * If a process is blocked on the dentry waiting for the expire to finish,
592 * it will invalidate the dentry and try to mount with a new one.
594 * Also see autofs_dir_rmdir()..
596 static int autofs_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
598 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
599 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
600 struct autofs_info
*p_ino
;
602 if (!autofs_oz_mode(sbi
))
605 /* autofs_oz_mode() needs to allow path walks when the
606 * autofs mount is catatonic but the state of an autofs
607 * file system needs to be preserved over restarts.
609 if (sbi
->flags
& AUTOFS_SBI_CATATONIC
)
613 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
617 d_inode(dentry
)->i_size
= 0;
618 clear_nlink(d_inode(dentry
));
620 dir
->i_mtime
= current_time(dir
);
622 spin_lock(&sbi
->lookup_lock
);
623 __autofs_add_expiring(dentry
);
625 spin_unlock(&sbi
->lookup_lock
);
631 * Version 4 of autofs provides a pseudo direct mount implementation
632 * that relies on directories at the leaves of a directory tree under
633 * an indirect mount to trigger mounts. To allow for this we need to
634 * set the DMANAGED_AUTOMOUNT and DMANAGED_TRANSIT flags on the leaves
635 * of the directory tree. There is no need to clear the automount flag
636 * following a mount or restore it after an expire because these mounts
637 * are always covered. However, it is necessary to ensure that these
638 * flags are clear on non-empty directories to avoid unnecessary calls
641 static void autofs_set_leaf_automount_flags(struct dentry
*dentry
)
643 struct dentry
*parent
;
645 /* root and dentrys in the root are already handled */
646 if (IS_ROOT(dentry
->d_parent
))
649 managed_dentry_set_managed(dentry
);
651 parent
= dentry
->d_parent
;
652 /* only consider parents below dentrys in the root */
653 if (IS_ROOT(parent
->d_parent
))
655 managed_dentry_clear_managed(parent
);
658 static void autofs_clear_leaf_automount_flags(struct dentry
*dentry
)
660 struct dentry
*parent
;
662 /* flags for dentrys in the root are handled elsewhere */
663 if (IS_ROOT(dentry
->d_parent
))
666 managed_dentry_clear_managed(dentry
);
668 parent
= dentry
->d_parent
;
669 /* only consider parents below dentrys in the root */
670 if (IS_ROOT(parent
->d_parent
))
672 if (autofs_dentry_ino(parent
)->count
== 2)
673 managed_dentry_set_managed(parent
);
676 static int autofs_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
678 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
679 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
680 struct autofs_info
*p_ino
;
682 pr_debug("dentry %p, removing %pd\n", dentry
, dentry
);
684 if (!autofs_oz_mode(sbi
))
687 /* autofs_oz_mode() needs to allow path walks when the
688 * autofs mount is catatonic but the state of an autofs
689 * file system needs to be preserved over restarts.
691 if (sbi
->flags
& AUTOFS_SBI_CATATONIC
)
697 spin_lock(&sbi
->lookup_lock
);
698 __autofs_add_expiring(dentry
);
700 spin_unlock(&sbi
->lookup_lock
);
702 if (sbi
->version
< 5)
703 autofs_clear_leaf_automount_flags(dentry
);
706 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
709 d_inode(dentry
)->i_size
= 0;
710 clear_nlink(d_inode(dentry
));
718 static int autofs_dir_mkdir(struct inode
*dir
,
719 struct dentry
*dentry
, umode_t mode
)
721 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
722 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
723 struct autofs_info
*p_ino
;
726 if (!autofs_oz_mode(sbi
))
729 /* autofs_oz_mode() needs to allow path walks when the
730 * autofs mount is catatonic but the state of an autofs
731 * file system needs to be preserved over restarts.
733 if (sbi
->flags
& AUTOFS_SBI_CATATONIC
)
736 pr_debug("dentry %p, creating %pd\n", dentry
, dentry
);
740 autofs_clean_ino(ino
);
742 autofs_del_active(dentry
);
744 inode
= autofs_get_inode(dir
->i_sb
, S_IFDIR
| mode
);
747 d_add(dentry
, inode
);
749 if (sbi
->version
< 5)
750 autofs_set_leaf_automount_flags(dentry
);
754 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
757 dir
->i_mtime
= current_time(dir
);
762 /* Get/set timeout ioctl() operation */
764 static inline int autofs_compat_get_set_timeout(struct autofs_sb_info
*sbi
,
765 compat_ulong_t __user
*p
)
767 unsigned long ntimeout
;
770 rv
= get_user(ntimeout
, p
);
774 rv
= put_user(sbi
->exp_timeout
/HZ
, p
);
778 if (ntimeout
> UINT_MAX
/HZ
)
779 sbi
->exp_timeout
= 0;
781 sbi
->exp_timeout
= ntimeout
* HZ
;
789 static inline int autofs_get_set_timeout(struct autofs_sb_info
*sbi
,
790 unsigned long __user
*p
)
792 unsigned long ntimeout
;
795 rv
= get_user(ntimeout
, p
);
799 rv
= put_user(sbi
->exp_timeout
/HZ
, p
);
803 if (ntimeout
> ULONG_MAX
/HZ
)
804 sbi
->exp_timeout
= 0;
806 sbi
->exp_timeout
= ntimeout
* HZ
;
813 /* Return protocol version */
814 static inline int autofs_get_protover(struct autofs_sb_info
*sbi
,
817 return put_user(sbi
->version
, p
);
820 /* Return protocol sub version */
821 static inline int autofs_get_protosubver(struct autofs_sb_info
*sbi
,
824 return put_user(sbi
->sub_version
, p
);
828 * Tells the daemon whether it can umount the autofs mount.
830 static inline int autofs_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
837 pr_debug("may umount %d\n", status
);
839 status
= put_user(status
, p
);
844 /* Identify autofs_dentries - this is so we can tell if there's
845 * an extra dentry refcount or not. We only hold a refcount on the
846 * dentry if its non-negative (ie, d_inode != NULL)
848 int is_autofs_dentry(struct dentry
*dentry
)
850 return dentry
&& d_really_is_positive(dentry
) &&
851 dentry
->d_op
== &autofs_dentry_operations
&&
852 dentry
->d_fsdata
!= NULL
;
856 * ioctl()'s on the root directory is the chief method for the daemon to
857 * generate kernel reactions
859 static int autofs_root_ioctl_unlocked(struct inode
*inode
, struct file
*filp
,
860 unsigned int cmd
, unsigned long arg
)
862 struct autofs_sb_info
*sbi
= autofs_sbi(inode
->i_sb
);
863 void __user
*p
= (void __user
*)arg
;
865 pr_debug("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
866 cmd
, arg
, sbi
, task_pgrp_nr(current
));
868 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
869 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
872 if (!autofs_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
876 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
877 return autofs_wait_release(sbi
, (autofs_wqt_t
) arg
, 0);
878 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
879 return autofs_wait_release(sbi
, (autofs_wqt_t
) arg
, -ENOENT
);
880 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
881 autofs_catatonic_mode(sbi
);
883 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
884 return autofs_get_protover(sbi
, p
);
885 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
886 return autofs_get_protosubver(sbi
, p
);
887 case AUTOFS_IOC_SETTIMEOUT
:
888 return autofs_get_set_timeout(sbi
, p
);
890 case AUTOFS_IOC_SETTIMEOUT32
:
891 return autofs_compat_get_set_timeout(sbi
, p
);
894 case AUTOFS_IOC_ASKUMOUNT
:
895 return autofs_ask_umount(filp
->f_path
.mnt
, p
);
897 /* return a single thing to expire */
898 case AUTOFS_IOC_EXPIRE
:
899 return autofs_expire_run(inode
->i_sb
, filp
->f_path
.mnt
, sbi
, p
);
900 /* same as above, but can send multiple expires through pipe */
901 case AUTOFS_IOC_EXPIRE_MULTI
:
902 return autofs_expire_multi(inode
->i_sb
,
903 filp
->f_path
.mnt
, sbi
, p
);
910 static long autofs_root_ioctl(struct file
*filp
,
911 unsigned int cmd
, unsigned long arg
)
913 struct inode
*inode
= file_inode(filp
);
915 return autofs_root_ioctl_unlocked(inode
, filp
, cmd
, arg
);
919 static long autofs_root_compat_ioctl(struct file
*filp
,
920 unsigned int cmd
, unsigned long arg
)
922 struct inode
*inode
= file_inode(filp
);
925 if (cmd
== AUTOFS_IOC_READY
|| cmd
== AUTOFS_IOC_FAIL
)
926 ret
= autofs_root_ioctl_unlocked(inode
, filp
, cmd
, arg
);
928 ret
= autofs_root_ioctl_unlocked(inode
, filp
, cmd
,
929 (unsigned long) compat_ptr(arg
));