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_permission(struct mnt_idmap
*, struct inode
*, int);
14 static int autofs_dir_symlink(struct mnt_idmap
*, struct inode
*,
15 struct dentry
*, const char *);
16 static int autofs_dir_unlink(struct inode
*, struct dentry
*);
17 static int autofs_dir_rmdir(struct inode
*, struct dentry
*);
18 static int autofs_dir_mkdir(struct mnt_idmap
*, struct inode
*,
19 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 .permission
= autofs_dir_permission
,
55 .unlink
= autofs_dir_unlink
,
56 .symlink
= autofs_dir_symlink
,
57 .mkdir
= autofs_dir_mkdir
,
58 .rmdir
= autofs_dir_rmdir
,
61 const struct dentry_operations autofs_dentry_operations
= {
62 .d_automount
= autofs_d_automount
,
63 .d_manage
= autofs_d_manage
,
64 .d_release
= autofs_dentry_release
,
67 static void autofs_del_active(struct dentry
*dentry
)
69 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
70 struct autofs_info
*ino
;
72 ino
= autofs_dentry_ino(dentry
);
73 spin_lock(&sbi
->lookup_lock
);
74 list_del_init(&ino
->active
);
75 spin_unlock(&sbi
->lookup_lock
);
78 static int autofs_dir_open(struct inode
*inode
, struct file
*file
)
80 struct dentry
*dentry
= file
->f_path
.dentry
;
81 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
82 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
84 pr_debug("file=%p dentry=%p %pd\n", file
, dentry
, dentry
);
86 if (autofs_oz_mode(sbi
))
90 * An empty directory in an autofs file system is always a
91 * mount point. The daemon must have failed to mount this
92 * during lookup so it doesn't exist. This can happen, for
93 * example, if user space returns an incorrect status for a
94 * mount request. Otherwise we're doing a readdir on the
95 * autofs file system so just let the libfs routines handle
98 spin_lock(&sbi
->lookup_lock
);
99 if (!path_is_mountpoint(&file
->f_path
) && autofs_empty(ino
)) {
100 spin_unlock(&sbi
->lookup_lock
);
103 spin_unlock(&sbi
->lookup_lock
);
106 return dcache_dir_open(inode
, file
);
109 static void autofs_dentry_release(struct dentry
*de
)
111 struct autofs_info
*ino
= autofs_dentry_ino(de
);
112 struct autofs_sb_info
*sbi
= autofs_sbi(de
->d_sb
);
114 pr_debug("releasing %p\n", de
);
120 spin_lock(&sbi
->lookup_lock
);
121 if (!list_empty(&ino
->active
))
122 list_del(&ino
->active
);
123 if (!list_empty(&ino
->expiring
))
124 list_del(&ino
->expiring
);
125 spin_unlock(&sbi
->lookup_lock
);
128 autofs_free_ino(ino
);
131 static struct dentry
*autofs_lookup_active(struct dentry
*dentry
)
133 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
134 struct dentry
*parent
= dentry
->d_parent
;
135 const struct qstr
*name
= &dentry
->d_name
;
136 unsigned int len
= name
->len
;
137 unsigned int hash
= name
->hash
;
138 const unsigned char *str
= name
->name
;
139 struct list_head
*p
, *head
;
141 head
= &sbi
->active_list
;
142 if (list_empty(head
))
144 spin_lock(&sbi
->lookup_lock
);
145 list_for_each(p
, head
) {
146 struct autofs_info
*ino
;
147 struct dentry
*active
;
148 const struct qstr
*qstr
;
150 ino
= list_entry(p
, struct autofs_info
, active
);
151 active
= ino
->dentry
;
153 spin_lock(&active
->d_lock
);
156 if ((int) d_count(active
) <= 0)
159 qstr
= &active
->d_name
;
161 if (active
->d_name
.hash
!= hash
)
163 if (active
->d_parent
!= parent
)
166 if (qstr
->len
!= len
)
168 if (memcmp(qstr
->name
, str
, len
))
171 if (d_unhashed(active
)) {
173 spin_unlock(&active
->d_lock
);
174 spin_unlock(&sbi
->lookup_lock
);
178 spin_unlock(&active
->d_lock
);
180 spin_unlock(&sbi
->lookup_lock
);
185 static struct dentry
*autofs_lookup_expiring(struct dentry
*dentry
,
188 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
189 struct dentry
*parent
= dentry
->d_parent
;
190 const struct qstr
*name
= &dentry
->d_name
;
191 unsigned int len
= name
->len
;
192 unsigned int hash
= name
->hash
;
193 const unsigned char *str
= name
->name
;
194 struct list_head
*p
, *head
;
196 head
= &sbi
->expiring_list
;
197 if (list_empty(head
))
199 spin_lock(&sbi
->lookup_lock
);
200 list_for_each(p
, head
) {
201 struct autofs_info
*ino
;
202 struct dentry
*expiring
;
203 const struct qstr
*qstr
;
206 spin_unlock(&sbi
->lookup_lock
);
207 return ERR_PTR(-ECHILD
);
210 ino
= list_entry(p
, struct autofs_info
, expiring
);
211 expiring
= ino
->dentry
;
213 spin_lock(&expiring
->d_lock
);
215 /* We've already been dentry_iput or unlinked */
216 if (d_really_is_negative(expiring
))
219 qstr
= &expiring
->d_name
;
221 if (expiring
->d_name
.hash
!= hash
)
223 if (expiring
->d_parent
!= parent
)
226 if (qstr
->len
!= len
)
228 if (memcmp(qstr
->name
, str
, len
))
231 if (d_unhashed(expiring
)) {
232 dget_dlock(expiring
);
233 spin_unlock(&expiring
->d_lock
);
234 spin_unlock(&sbi
->lookup_lock
);
238 spin_unlock(&expiring
->d_lock
);
240 spin_unlock(&sbi
->lookup_lock
);
245 static int autofs_mount_wait(const struct path
*path
, bool rcu_walk
)
247 struct autofs_sb_info
*sbi
= autofs_sbi(path
->dentry
->d_sb
);
248 struct autofs_info
*ino
= autofs_dentry_ino(path
->dentry
);
251 if (ino
->flags
& AUTOFS_INF_PENDING
) {
254 pr_debug("waiting for mount name=%pd\n", path
->dentry
);
255 status
= autofs_wait(sbi
, path
, NFY_MOUNT
);
256 pr_debug("mount wait done status=%d\n", status
);
257 ino
->last_used
= jiffies
;
260 if (!(sbi
->flags
& AUTOFS_SBI_STRICTEXPIRE
))
261 ino
->last_used
= jiffies
;
265 static int do_expire_wait(const struct path
*path
, bool rcu_walk
)
267 struct dentry
*dentry
= path
->dentry
;
268 struct dentry
*expiring
;
270 expiring
= autofs_lookup_expiring(dentry
, rcu_walk
);
271 if (IS_ERR(expiring
))
272 return PTR_ERR(expiring
);
274 return autofs_expire_wait(path
, rcu_walk
);
276 const struct path
this = { .mnt
= path
->mnt
, .dentry
= expiring
};
278 * If we are racing with expire the request might not
279 * be quite complete, but the directory has been removed
280 * so it must have been successful, just wait for it.
282 autofs_expire_wait(&this, 0);
283 autofs_del_expiring(expiring
);
289 static struct dentry
*autofs_mountpoint_changed(struct path
*path
)
291 struct dentry
*dentry
= path
->dentry
;
292 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
294 /* If this is an indirect mount the dentry could have gone away
295 * and a new one created.
297 * This is unusual and I can't remember the case for which it
298 * was originally added now. But an example of how this can
299 * happen is an autofs indirect mount that has the "browse"
300 * option set and also has the "symlink" option in the autofs
301 * map entry. In this case the daemon will remove the browse
302 * directory and create a symlink as the mount leaving the
305 * Another not so obvious case is when a mount in an autofs
306 * indirect mount that uses the "nobrowse" option is being
307 * expired at the same time as a path walk. If the mount has
308 * been umounted but the mount point directory seen before
309 * becoming unhashed (during a lockless path walk) when a stat
310 * family system call is made the mount won't be re-mounted as
311 * it should. In this case the mount point that's been removed
312 * (by the daemon) will be stale and the a new mount point
315 if (autofs_type_indirect(sbi
->type
) && d_unhashed(dentry
)) {
316 struct dentry
*parent
= dentry
->d_parent
;
317 struct autofs_info
*ino
;
320 new = d_lookup(parent
, &dentry
->d_name
);
323 ino
= autofs_dentry_ino(new);
324 ino
->last_used
= jiffies
;
331 static struct vfsmount
*autofs_d_automount(struct path
*path
)
333 struct dentry
*dentry
= path
->dentry
;
334 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
335 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
338 pr_debug("dentry=%p %pd\n", dentry
, dentry
);
340 /* The daemon never triggers a mount. */
341 if (autofs_oz_mode(sbi
))
345 * If an expire request is pending everyone must wait.
346 * If the expire fails we're still mounted so continue
347 * the follow and return. A return of -EAGAIN (which only
348 * happens with indirect mounts) means the expire completed
349 * and the directory was removed, so just go ahead and try
352 status
= do_expire_wait(path
, 0);
353 if (status
&& status
!= -EAGAIN
)
356 /* Callback to the daemon to perform the mount or wait */
357 spin_lock(&sbi
->fs_lock
);
358 if (ino
->flags
& AUTOFS_INF_PENDING
) {
359 spin_unlock(&sbi
->fs_lock
);
360 status
= autofs_mount_wait(path
, 0);
362 return ERR_PTR(status
);
367 * If the dentry is a symlink it's equivalent to a directory
368 * having path_is_mountpoint() true, so there's no need to call
369 * back to the daemon.
371 if (d_really_is_positive(dentry
) && d_is_symlink(dentry
)) {
372 spin_unlock(&sbi
->fs_lock
);
376 if (!path_is_mountpoint(path
)) {
378 * It's possible that user space hasn't removed directories
379 * after umounting a rootless multi-mount, although it
380 * should. For v5 path_has_submounts() is sufficient to
381 * handle this because the leaves of the directory tree under
382 * the mount never trigger mounts themselves (they have an
383 * autofs trigger mount mounted on them). But v4 pseudo direct
384 * mounts do need the leaves to trigger mounts. In this case
385 * we have no choice but to use the autofs_empty() check and
386 * require user space behave.
388 if (sbi
->version
> 4) {
389 if (path_has_submounts(path
)) {
390 spin_unlock(&sbi
->fs_lock
);
394 if (!autofs_empty(ino
)) {
395 spin_unlock(&sbi
->fs_lock
);
399 ino
->flags
|= AUTOFS_INF_PENDING
;
400 spin_unlock(&sbi
->fs_lock
);
401 status
= autofs_mount_wait(path
, 0);
402 spin_lock(&sbi
->fs_lock
);
403 ino
->flags
&= ~AUTOFS_INF_PENDING
;
405 spin_unlock(&sbi
->fs_lock
);
406 return ERR_PTR(status
);
409 spin_unlock(&sbi
->fs_lock
);
411 /* Mount succeeded, check if we ended up with a new dentry */
412 dentry
= autofs_mountpoint_changed(path
);
414 return ERR_PTR(-ENOENT
);
419 static int autofs_d_manage(const struct path
*path
, bool rcu_walk
)
421 struct dentry
*dentry
= path
->dentry
;
422 struct autofs_sb_info
*sbi
= autofs_sbi(dentry
->d_sb
);
423 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
426 pr_debug("dentry=%p %pd\n", dentry
, dentry
);
428 /* The daemon never waits. */
429 if (autofs_oz_mode(sbi
)) {
430 if (!path_is_mountpoint(path
))
435 /* Wait for pending expires */
436 if (do_expire_wait(path
, rcu_walk
) == -ECHILD
)
440 * This dentry may be under construction so wait on mount
443 status
= autofs_mount_wait(path
, rcu_walk
);
448 /* We don't need fs_lock in rcu_walk mode,
449 * just testing 'AUTOFS_INF_WANT_EXPIRE' is enough.
451 * We only return -EISDIR when certain this isn't
456 if (ino
->flags
& AUTOFS_INF_WANT_EXPIRE
)
458 if (path_is_mountpoint(path
))
460 inode
= d_inode_rcu(dentry
);
461 if (inode
&& S_ISLNK(inode
->i_mode
))
463 if (!autofs_empty(ino
))
468 spin_lock(&sbi
->fs_lock
);
470 * If the dentry has been selected for expire while we slept
471 * on the lock then it might go away. We'll deal with that in
472 * ->d_automount() and wait on a new mount if the expire
473 * succeeds or return here if it doesn't (since there's no
474 * mount to follow with a rootless multi-mount).
476 if (!(ino
->flags
& AUTOFS_INF_EXPIRING
)) {
478 * Any needed mounting has been completed and the path
479 * updated so check if this is a rootless multi-mount so
480 * we can avoid needless calls ->d_automount() and avoid
481 * an incorrect ELOOP error return.
483 if ((!path_is_mountpoint(path
) && !autofs_empty(ino
)) ||
484 (d_really_is_positive(dentry
) && d_is_symlink(dentry
)))
487 spin_unlock(&sbi
->fs_lock
);
492 /* Lookups in the root directory */
493 static struct dentry
*autofs_lookup(struct inode
*dir
,
494 struct dentry
*dentry
, unsigned int flags
)
496 struct autofs_sb_info
*sbi
;
497 struct autofs_info
*ino
;
498 struct dentry
*active
;
500 pr_debug("name = %pd\n", dentry
);
502 /* File name too long to exist */
503 if (dentry
->d_name
.len
> NAME_MAX
)
504 return ERR_PTR(-ENAMETOOLONG
);
506 sbi
= autofs_sbi(dir
->i_sb
);
508 pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
509 current
->pid
, task_pgrp_nr(current
),
510 sbi
->flags
& AUTOFS_SBI_CATATONIC
,
511 autofs_oz_mode(sbi
));
513 active
= autofs_lookup_active(dentry
);
518 * A dentry that is not within the root can never trigger a
519 * mount operation, unless the directory already exists, so we
520 * can return fail immediately. The daemon however does need
521 * to create directories within the file system.
523 if (!autofs_oz_mode(sbi
) && !IS_ROOT(dentry
->d_parent
))
524 return ERR_PTR(-ENOENT
);
526 ino
= autofs_new_ino(sbi
);
528 return ERR_PTR(-ENOMEM
);
530 spin_lock(&sbi
->lookup_lock
);
531 spin_lock(&dentry
->d_lock
);
532 /* Mark entries in the root as mount triggers */
533 if (IS_ROOT(dentry
->d_parent
) &&
534 autofs_type_indirect(sbi
->type
))
535 __managed_dentry_set_managed(dentry
);
536 dentry
->d_fsdata
= ino
;
537 ino
->dentry
= dentry
;
539 list_add(&ino
->active
, &sbi
->active_list
);
540 spin_unlock(&sbi
->lookup_lock
);
541 spin_unlock(&dentry
->d_lock
);
546 static int autofs_dir_permission(struct mnt_idmap
*idmap
,
547 struct inode
*inode
, int mask
)
549 if (mask
& MAY_WRITE
) {
550 struct autofs_sb_info
*sbi
= autofs_sbi(inode
->i_sb
);
552 if (!autofs_oz_mode(sbi
))
555 /* autofs_oz_mode() needs to allow path walks when the
556 * autofs mount is catatonic but the state of an autofs
557 * file system needs to be preserved over restarts.
559 if (sbi
->flags
& AUTOFS_SBI_CATATONIC
)
563 return generic_permission(idmap
, inode
, mask
);
566 static int autofs_dir_symlink(struct mnt_idmap
*idmap
,
567 struct inode
*dir
, struct dentry
*dentry
,
570 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
571 struct autofs_info
*p_ino
;
573 size_t size
= strlen(symname
);
576 pr_debug("%s <- %pd\n", symname
, dentry
);
580 autofs_clean_ino(ino
);
582 autofs_del_active(dentry
);
584 cp
= kmalloc(size
+ 1, GFP_KERNEL
);
590 inode
= autofs_get_inode(dir
->i_sb
, S_IFLNK
| 0555);
595 inode
->i_private
= cp
;
596 inode
->i_size
= size
;
597 d_add(dentry
, inode
);
600 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
603 inode_set_mtime_to_ts(dir
, inode_set_ctime_current(dir
));
611 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
612 * that the file no longer exists. However, doing that means that the
613 * VFS layer can turn the dentry into a negative dentry. We don't want
614 * this, because the unlink is probably the result of an expire.
615 * We simply d_drop it and add it to a expiring list in the super block,
616 * which allows the dentry lookup to check for an incomplete expire.
618 * If a process is blocked on the dentry waiting for the expire to finish,
619 * it will invalidate the dentry and try to mount with a new one.
621 * Also see autofs_dir_rmdir()..
623 static int autofs_dir_unlink(struct inode
*dir
, struct dentry
*dentry
)
625 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
626 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
627 struct autofs_info
*p_ino
;
629 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
633 d_inode(dentry
)->i_size
= 0;
634 clear_nlink(d_inode(dentry
));
636 inode_set_mtime_to_ts(dir
, inode_set_ctime_current(dir
));
638 spin_lock(&sbi
->lookup_lock
);
639 __autofs_add_expiring(dentry
);
641 spin_unlock(&sbi
->lookup_lock
);
647 * Version 4 of autofs provides a pseudo direct mount implementation
648 * that relies on directories at the leaves of a directory tree under
649 * an indirect mount to trigger mounts. To allow for this we need to
650 * set the DMANAGED_AUTOMOUNT and DMANAGED_TRANSIT flags on the leaves
651 * of the directory tree. There is no need to clear the automount flag
652 * following a mount or restore it after an expire because these mounts
653 * are always covered. However, it is necessary to ensure that these
654 * flags are clear on non-empty directories to avoid unnecessary calls
657 static void autofs_set_leaf_automount_flags(struct dentry
*dentry
)
659 struct dentry
*parent
;
661 /* root and dentrys in the root are already handled */
662 if (IS_ROOT(dentry
->d_parent
))
665 managed_dentry_set_managed(dentry
);
667 parent
= dentry
->d_parent
;
668 /* only consider parents below dentrys in the root */
669 if (IS_ROOT(parent
->d_parent
))
671 managed_dentry_clear_managed(parent
);
674 static void autofs_clear_leaf_automount_flags(struct dentry
*dentry
)
676 struct dentry
*parent
;
678 /* flags for dentrys in the root are handled elsewhere */
679 if (IS_ROOT(dentry
->d_parent
))
682 managed_dentry_clear_managed(dentry
);
684 parent
= dentry
->d_parent
;
685 /* only consider parents below dentrys in the root */
686 if (IS_ROOT(parent
->d_parent
))
688 if (autofs_dentry_ino(parent
)->count
== 2)
689 managed_dentry_set_managed(parent
);
692 static int autofs_dir_rmdir(struct inode
*dir
, struct dentry
*dentry
)
694 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
695 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
696 struct autofs_info
*p_ino
;
698 pr_debug("dentry %p, removing %pd\n", dentry
, dentry
);
703 spin_lock(&sbi
->lookup_lock
);
704 __autofs_add_expiring(dentry
);
706 spin_unlock(&sbi
->lookup_lock
);
708 if (sbi
->version
< 5)
709 autofs_clear_leaf_automount_flags(dentry
);
711 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
714 d_inode(dentry
)->i_size
= 0;
715 clear_nlink(d_inode(dentry
));
723 static int autofs_dir_mkdir(struct mnt_idmap
*idmap
,
724 struct inode
*dir
, struct dentry
*dentry
,
727 struct autofs_sb_info
*sbi
= autofs_sbi(dir
->i_sb
);
728 struct autofs_info
*ino
= autofs_dentry_ino(dentry
);
729 struct autofs_info
*p_ino
;
732 pr_debug("dentry %p, creating %pd\n", dentry
, dentry
);
736 autofs_clean_ino(ino
);
738 autofs_del_active(dentry
);
740 inode
= autofs_get_inode(dir
->i_sb
, S_IFDIR
| mode
);
743 d_add(dentry
, inode
);
745 if (sbi
->version
< 5)
746 autofs_set_leaf_automount_flags(dentry
);
749 p_ino
= autofs_dentry_ino(dentry
->d_parent
);
752 inode_set_mtime_to_ts(dir
, inode_set_ctime_current(dir
));
757 /* Get/set timeout ioctl() operation */
759 static inline int autofs_compat_get_set_timeout(struct autofs_sb_info
*sbi
,
760 compat_ulong_t __user
*p
)
762 unsigned long ntimeout
;
765 rv
= get_user(ntimeout
, p
);
769 rv
= put_user(sbi
->exp_timeout
/HZ
, p
);
773 if (ntimeout
> UINT_MAX
/HZ
)
774 sbi
->exp_timeout
= 0;
776 sbi
->exp_timeout
= ntimeout
* HZ
;
784 static inline int autofs_get_set_timeout(struct autofs_sb_info
*sbi
,
785 unsigned long __user
*p
)
787 unsigned long ntimeout
;
790 rv
= get_user(ntimeout
, p
);
794 rv
= put_user(sbi
->exp_timeout
/HZ
, p
);
798 if (ntimeout
> ULONG_MAX
/HZ
)
799 sbi
->exp_timeout
= 0;
801 sbi
->exp_timeout
= ntimeout
* HZ
;
808 /* Return protocol version */
809 static inline int autofs_get_protover(struct autofs_sb_info
*sbi
,
812 return put_user(sbi
->version
, p
);
815 /* Return protocol sub version */
816 static inline int autofs_get_protosubver(struct autofs_sb_info
*sbi
,
819 return put_user(sbi
->sub_version
, p
);
823 * Tells the daemon whether it can umount the autofs mount.
825 static inline int autofs_ask_umount(struct vfsmount
*mnt
, int __user
*p
)
832 pr_debug("may umount %d\n", status
);
834 status
= put_user(status
, p
);
839 /* Identify autofs_dentries - this is so we can tell if there's
840 * an extra dentry refcount or not. We only hold a refcount on the
841 * dentry if its non-negative (ie, d_inode != NULL)
843 int is_autofs_dentry(struct dentry
*dentry
)
845 return dentry
&& d_really_is_positive(dentry
) &&
846 dentry
->d_op
== &autofs_dentry_operations
&&
847 dentry
->d_fsdata
!= NULL
;
851 * ioctl()'s on the root directory is the chief method for the daemon to
852 * generate kernel reactions
854 static int autofs_root_ioctl_unlocked(struct inode
*inode
, struct file
*filp
,
855 unsigned int cmd
, unsigned long arg
)
857 struct autofs_sb_info
*sbi
= autofs_sbi(inode
->i_sb
);
858 void __user
*p
= (void __user
*)arg
;
860 pr_debug("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
861 cmd
, arg
, sbi
, task_pgrp_nr(current
));
863 if (_IOC_TYPE(cmd
) != _IOC_TYPE(AUTOFS_IOC_FIRST
) ||
864 _IOC_NR(cmd
) - _IOC_NR(AUTOFS_IOC_FIRST
) >= AUTOFS_IOC_COUNT
)
867 if (!autofs_oz_mode(sbi
) && !capable(CAP_SYS_ADMIN
))
871 case AUTOFS_IOC_READY
: /* Wait queue: go ahead and retry */
872 return autofs_wait_release(sbi
, (autofs_wqt_t
) arg
, 0);
873 case AUTOFS_IOC_FAIL
: /* Wait queue: fail with ENOENT */
874 return autofs_wait_release(sbi
, (autofs_wqt_t
) arg
, -ENOENT
);
875 case AUTOFS_IOC_CATATONIC
: /* Enter catatonic mode (daemon shutdown) */
876 autofs_catatonic_mode(sbi
);
878 case AUTOFS_IOC_PROTOVER
: /* Get protocol version */
879 return autofs_get_protover(sbi
, p
);
880 case AUTOFS_IOC_PROTOSUBVER
: /* Get protocol sub version */
881 return autofs_get_protosubver(sbi
, p
);
882 case AUTOFS_IOC_SETTIMEOUT
:
883 return autofs_get_set_timeout(sbi
, p
);
885 case AUTOFS_IOC_SETTIMEOUT32
:
886 return autofs_compat_get_set_timeout(sbi
, p
);
889 case AUTOFS_IOC_ASKUMOUNT
:
890 return autofs_ask_umount(filp
->f_path
.mnt
, p
);
892 /* return a single thing to expire */
893 case AUTOFS_IOC_EXPIRE
:
894 return autofs_expire_run(inode
->i_sb
, filp
->f_path
.mnt
, sbi
, p
);
895 /* same as above, but can send multiple expires through pipe */
896 case AUTOFS_IOC_EXPIRE_MULTI
:
897 return autofs_expire_multi(inode
->i_sb
,
898 filp
->f_path
.mnt
, sbi
, p
);
905 static long autofs_root_ioctl(struct file
*filp
,
906 unsigned int cmd
, unsigned long arg
)
908 struct inode
*inode
= file_inode(filp
);
910 return autofs_root_ioctl_unlocked(inode
, filp
, cmd
, arg
);
914 static long autofs_root_compat_ioctl(struct file
*filp
,
915 unsigned int cmd
, unsigned long arg
)
917 struct inode
*inode
= file_inode(filp
);
920 if (cmd
== AUTOFS_IOC_READY
|| cmd
== AUTOFS_IOC_FAIL
)
921 ret
= autofs_root_ioctl_unlocked(inode
, filp
, cmd
, arg
);
923 ret
= autofs_root_ioctl_unlocked(inode
, filp
, cmd
,
924 (unsigned long) compat_ptr(arg
));