[PATCH] autofs4: lookup white space cleanup
[linux-2.6.22.y-op.git] / fs / autofs4 / root.c
blob2c676bd44acdcc910a721b2bf75154fd43b2c450
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 *ino = 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 (ino && (ino->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);
327 * Wait for a pending mount, triggering one if there
328 * isn't one already
330 if (dentry->d_inode == NULL) {
331 DPRINTK("waiting for mount name=%.*s",
332 dentry->d_name.len, dentry->d_name.name);
334 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
336 DPRINTK("mount done status=%d", status);
338 if (status && dentry->d_inode)
339 return 0; /* Try to get the kernel to invalidate this dentry */
341 /* Turn this into a real negative dentry? */
342 if (status == -ENOENT) {
343 dentry->d_time = jiffies + AUTOFS_NEGATIVE_TIMEOUT;
344 spin_lock(&dentry->d_lock);
345 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
346 spin_unlock(&dentry->d_lock);
347 return 1;
348 } else if (status) {
349 /* Return a negative dentry, but leave it "pending" */
350 return 1;
352 /* Trigger mount for path component or follow link */
353 } else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) ||
354 current->link_count) {
355 DPRINTK("waiting for mount name=%.*s",
356 dentry->d_name.len, dentry->d_name.name);
358 spin_lock(&dentry->d_lock);
359 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
360 spin_unlock(&dentry->d_lock);
361 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
363 DPRINTK("mount done status=%d", status);
365 if (status) {
366 spin_lock(&dentry->d_lock);
367 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
368 spin_unlock(&dentry->d_lock);
369 return 0;
374 * We don't update the usages for the autofs daemon itself, this
375 * is necessary for recursive autofs mounts
377 if (!autofs4_oz_mode(sbi))
378 autofs4_update_usage(mnt, dentry);
380 spin_lock(&dentry->d_lock);
381 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
382 spin_unlock(&dentry->d_lock);
383 return 1;
387 * Revalidate is called on every cache lookup. Some of those
388 * cache lookups may actually happen while the dentry is not
389 * yet completely filled in, and revalidate has to delay such
390 * lookups..
392 static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
394 struct inode *dir = dentry->d_parent->d_inode;
395 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
396 int oz_mode = autofs4_oz_mode(sbi);
397 int flags = nd ? nd->flags : 0;
398 int status = 1;
400 /* Pending dentry */
401 if (autofs4_ispending(dentry)) {
402 if (!oz_mode)
403 status = try_to_fill_dentry(nd->mnt, dentry, flags);
404 return status;
407 /* Negative dentry.. invalidate if "old" */
408 if (dentry->d_inode == NULL)
409 return (dentry->d_time - jiffies <= AUTOFS_NEGATIVE_TIMEOUT);
411 /* Check for a non-mountpoint directory with no contents */
412 spin_lock(&dcache_lock);
413 if (S_ISDIR(dentry->d_inode->i_mode) &&
414 !d_mountpoint(dentry) &&
415 list_empty(&dentry->d_subdirs)) {
416 DPRINTK("dentry=%p %.*s, emptydir",
417 dentry, dentry->d_name.len, dentry->d_name.name);
418 spin_unlock(&dcache_lock);
419 if (!oz_mode)
420 status = try_to_fill_dentry(nd->mnt, dentry, flags);
421 return status;
423 spin_unlock(&dcache_lock);
425 /* Update the usage list */
426 if (!oz_mode)
427 autofs4_update_usage(nd->mnt, dentry);
429 return 1;
432 static void autofs4_dentry_release(struct dentry *de)
434 struct autofs_info *inf;
436 DPRINTK("releasing %p", de);
438 inf = autofs4_dentry_ino(de);
439 de->d_fsdata = NULL;
441 if (inf) {
442 inf->dentry = NULL;
443 inf->inode = NULL;
445 autofs4_free_ino(inf);
449 /* For dentries of directories in the root dir */
450 static struct dentry_operations autofs4_root_dentry_operations = {
451 .d_revalidate = autofs4_revalidate,
452 .d_release = autofs4_dentry_release,
455 /* For other dentries */
456 static struct dentry_operations autofs4_dentry_operations = {
457 .d_revalidate = autofs4_revalidate,
458 .d_release = autofs4_dentry_release,
461 /* Lookups in the root directory */
462 static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
464 struct autofs_sb_info *sbi;
465 int oz_mode;
467 DPRINTK("name = %.*s",
468 dentry->d_name.len, dentry->d_name.name);
470 /* File name too long to exist */
471 if (dentry->d_name.len > NAME_MAX)
472 return ERR_PTR(-ENAMETOOLONG);
474 sbi = autofs4_sbi(dir->i_sb);
475 oz_mode = autofs4_oz_mode(sbi);
477 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
478 current->pid, process_group(current), sbi->catatonic, oz_mode);
481 * Mark the dentry incomplete, but add it. This is needed so
482 * that the VFS layer knows about the dentry, and we can count
483 * on catching any lookups through the revalidate.
485 * Let all the hard work be done by the revalidate function that
486 * needs to be able to do this anyway..
488 * We need to do this before we release the directory semaphore.
490 dentry->d_op = &autofs4_root_dentry_operations;
492 if (!oz_mode) {
493 spin_lock(&dentry->d_lock);
494 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
495 spin_unlock(&dentry->d_lock);
497 dentry->d_fsdata = NULL;
498 d_add(dentry, NULL);
500 if (dentry->d_op && dentry->d_op->d_revalidate) {
501 mutex_unlock(&dir->i_mutex);
502 (dentry->d_op->d_revalidate)(dentry, nd);
503 mutex_lock(&dir->i_mutex);
507 * If we are still pending, check if we had to handle
508 * a signal. If so we can force a restart..
510 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
511 /* See if we were interrupted */
512 if (signal_pending(current)) {
513 sigset_t *sigset = &current->pending.signal;
514 if (sigismember (sigset, SIGKILL) ||
515 sigismember (sigset, SIGQUIT) ||
516 sigismember (sigset, SIGINT)) {
517 return ERR_PTR(-ERESTARTNOINTR);
523 * If this dentry is unhashed, then we shouldn't honour this
524 * lookup even if the dentry is positive. Returning ENOENT here
525 * doesn't do the right thing for all system calls, but it should
526 * be OK for the operations we permit from an autofs.
528 if (dentry->d_inode && d_unhashed(dentry))
529 return ERR_PTR(-ENOENT);
531 return NULL;
534 static int autofs4_dir_symlink(struct inode *dir,
535 struct dentry *dentry,
536 const char *symname)
538 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
539 struct autofs_info *ino = autofs4_dentry_ino(dentry);
540 struct inode *inode;
541 char *cp;
543 DPRINTK("%s <- %.*s", symname,
544 dentry->d_name.len, dentry->d_name.name);
546 if (!autofs4_oz_mode(sbi))
547 return -EACCES;
549 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
550 if (ino == NULL)
551 return -ENOSPC;
553 ino->size = strlen(symname);
554 ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
556 if (cp == NULL) {
557 kfree(ino);
558 return -ENOSPC;
561 strcpy(cp, symname);
563 inode = autofs4_get_inode(dir->i_sb, ino);
564 d_instantiate(dentry, inode);
566 if (dir == dir->i_sb->s_root->d_inode)
567 dentry->d_op = &autofs4_root_dentry_operations;
568 else
569 dentry->d_op = &autofs4_dentry_operations;
571 dentry->d_fsdata = ino;
572 ino->dentry = dget(dentry);
573 ino->inode = inode;
575 dir->i_mtime = CURRENT_TIME;
577 return 0;
581 * NOTE!
583 * Normal filesystems would do a "d_delete()" to tell the VFS dcache
584 * that the file no longer exists. However, doing that means that the
585 * VFS layer can turn the dentry into a negative dentry. We don't want
586 * this, because since the unlink is probably the result of an expire.
587 * We simply d_drop it, which allows the dentry lookup to remount it
588 * if necessary.
590 * If a process is blocked on the dentry waiting for the expire to finish,
591 * it will invalidate the dentry and try to mount with a new one.
593 * Also see autofs4_dir_rmdir()..
595 static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
597 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
598 struct autofs_info *ino = autofs4_dentry_ino(dentry);
600 /* This allows root to remove symlinks */
601 if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
602 return -EACCES;
604 dput(ino->dentry);
606 dentry->d_inode->i_size = 0;
607 dentry->d_inode->i_nlink = 0;
609 dir->i_mtime = CURRENT_TIME;
611 d_drop(dentry);
613 return 0;
616 static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
618 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
619 struct autofs_info *ino = autofs4_dentry_ino(dentry);
621 if (!autofs4_oz_mode(sbi))
622 return -EACCES;
624 spin_lock(&dcache_lock);
625 if (!list_empty(&dentry->d_subdirs)) {
626 spin_unlock(&dcache_lock);
627 return -ENOTEMPTY;
629 spin_lock(&dentry->d_lock);
630 __d_drop(dentry);
631 spin_unlock(&dentry->d_lock);
632 spin_unlock(&dcache_lock);
634 dput(ino->dentry);
636 dentry->d_inode->i_size = 0;
637 dentry->d_inode->i_nlink = 0;
639 if (dir->i_nlink)
640 dir->i_nlink--;
642 return 0;
645 static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
647 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
648 struct autofs_info *ino = autofs4_dentry_ino(dentry);
649 struct inode *inode;
651 if ( !autofs4_oz_mode(sbi) )
652 return -EACCES;
654 DPRINTK("dentry %p, creating %.*s",
655 dentry, dentry->d_name.len, dentry->d_name.name);
657 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
658 if (ino == NULL)
659 return -ENOSPC;
661 inode = autofs4_get_inode(dir->i_sb, ino);
662 d_instantiate(dentry, inode);
664 if (dir == dir->i_sb->s_root->d_inode)
665 dentry->d_op = &autofs4_root_dentry_operations;
666 else
667 dentry->d_op = &autofs4_dentry_operations;
669 dentry->d_fsdata = ino;
670 ino->dentry = dget(dentry);
671 ino->inode = inode;
672 dir->i_nlink++;
673 dir->i_mtime = CURRENT_TIME;
675 return 0;
678 /* Get/set timeout ioctl() operation */
679 static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
680 unsigned long __user *p)
682 int rv;
683 unsigned long ntimeout;
685 if ( (rv = get_user(ntimeout, p)) ||
686 (rv = put_user(sbi->exp_timeout/HZ, p)) )
687 return rv;
689 if ( ntimeout > ULONG_MAX/HZ )
690 sbi->exp_timeout = 0;
691 else
692 sbi->exp_timeout = ntimeout * HZ;
694 return 0;
697 /* Return protocol version */
698 static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
700 return put_user(sbi->version, p);
703 /* Return protocol sub version */
704 static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
706 return put_user(sbi->sub_version, p);
710 * Tells the daemon whether we need to reghost or not. Also, clears
711 * the reghost_needed flag.
713 static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p)
715 int status;
717 DPRINTK("returning %d", sbi->needs_reghost);
719 status = put_user(sbi->needs_reghost, p);
720 if ( status )
721 return status;
723 sbi->needs_reghost = 0;
724 return 0;
728 * Enable / Disable reghosting ioctl() operation
730 static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p)
732 int status;
733 int val;
735 status = get_user(val, p);
737 DPRINTK("reghost = %d", val);
739 if (status)
740 return status;
742 /* turn on/off reghosting, with the val */
743 sbi->reghost_enabled = val;
744 return 0;
748 * Tells the daemon whether it can umount the autofs mount.
750 static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
752 int status = 0;
754 if (may_umount(mnt) == 0)
755 status = 1;
757 DPRINTK("returning %d", status);
759 status = put_user(status, p);
761 return status;
764 /* Identify autofs4_dentries - this is so we can tell if there's
765 an extra dentry refcount or not. We only hold a refcount on the
766 dentry if its non-negative (ie, d_inode != NULL)
768 int is_autofs4_dentry(struct dentry *dentry)
770 return dentry && dentry->d_inode &&
771 (dentry->d_op == &autofs4_root_dentry_operations ||
772 dentry->d_op == &autofs4_dentry_operations) &&
773 dentry->d_fsdata != NULL;
777 * ioctl()'s on the root directory is the chief method for the daemon to
778 * generate kernel reactions
780 static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
781 unsigned int cmd, unsigned long arg)
783 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
784 void __user *p = (void __user *)arg;
786 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
787 cmd,arg,sbi,process_group(current));
789 if ( _IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
790 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT )
791 return -ENOTTY;
793 if ( !autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN) )
794 return -EPERM;
796 switch(cmd) {
797 case AUTOFS_IOC_READY: /* Wait queue: go ahead and retry */
798 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
799 case AUTOFS_IOC_FAIL: /* Wait queue: fail with ENOENT */
800 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
801 case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
802 autofs4_catatonic_mode(sbi);
803 return 0;
804 case AUTOFS_IOC_PROTOVER: /* Get protocol version */
805 return autofs4_get_protover(sbi, p);
806 case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
807 return autofs4_get_protosubver(sbi, p);
808 case AUTOFS_IOC_SETTIMEOUT:
809 return autofs4_get_set_timeout(sbi, p);
811 case AUTOFS_IOC_TOGGLEREGHOST:
812 return autofs4_toggle_reghost(sbi, p);
813 case AUTOFS_IOC_ASKREGHOST:
814 return autofs4_ask_reghost(sbi, p);
816 case AUTOFS_IOC_ASKUMOUNT:
817 return autofs4_ask_umount(filp->f_vfsmnt, p);
819 /* return a single thing to expire */
820 case AUTOFS_IOC_EXPIRE:
821 return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi, p);
822 /* same as above, but can send multiple expires through pipe */
823 case AUTOFS_IOC_EXPIRE_MULTI:
824 return autofs4_expire_multi(inode->i_sb,filp->f_vfsmnt,sbi, p);
826 default:
827 return -ENOSYS;