0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/capability.h>
0009 #include <linux/compat.h>
0010
0011 #include "autofs_i.h"
0012
0013 static int autofs_dir_permission(struct user_namespace *, struct inode *, int);
0014 static int autofs_dir_symlink(struct user_namespace *, struct inode *,
0015 struct dentry *, const char *);
0016 static int autofs_dir_unlink(struct inode *, struct dentry *);
0017 static int autofs_dir_rmdir(struct inode *, struct dentry *);
0018 static int autofs_dir_mkdir(struct user_namespace *, struct inode *,
0019 struct dentry *, umode_t);
0020 static long autofs_root_ioctl(struct file *, unsigned int, unsigned long);
0021 #ifdef CONFIG_COMPAT
0022 static long autofs_root_compat_ioctl(struct file *,
0023 unsigned int, unsigned long);
0024 #endif
0025 static int autofs_dir_open(struct inode *inode, struct file *file);
0026 static struct dentry *autofs_lookup(struct inode *,
0027 struct dentry *, unsigned int);
0028 static struct vfsmount *autofs_d_automount(struct path *);
0029 static int autofs_d_manage(const struct path *, bool);
0030 static void autofs_dentry_release(struct dentry *);
0031
0032 const struct file_operations autofs_root_operations = {
0033 .open = dcache_dir_open,
0034 .release = dcache_dir_close,
0035 .read = generic_read_dir,
0036 .iterate_shared = dcache_readdir,
0037 .llseek = dcache_dir_lseek,
0038 .unlocked_ioctl = autofs_root_ioctl,
0039 #ifdef CONFIG_COMPAT
0040 .compat_ioctl = autofs_root_compat_ioctl,
0041 #endif
0042 };
0043
0044 const struct file_operations autofs_dir_operations = {
0045 .open = autofs_dir_open,
0046 .release = dcache_dir_close,
0047 .read = generic_read_dir,
0048 .iterate_shared = dcache_readdir,
0049 .llseek = dcache_dir_lseek,
0050 };
0051
0052 const struct inode_operations autofs_dir_inode_operations = {
0053 .lookup = autofs_lookup,
0054 .permission = autofs_dir_permission,
0055 .unlink = autofs_dir_unlink,
0056 .symlink = autofs_dir_symlink,
0057 .mkdir = autofs_dir_mkdir,
0058 .rmdir = autofs_dir_rmdir,
0059 };
0060
0061 const struct dentry_operations autofs_dentry_operations = {
0062 .d_automount = autofs_d_automount,
0063 .d_manage = autofs_d_manage,
0064 .d_release = autofs_dentry_release,
0065 };
0066
0067 static void autofs_del_active(struct dentry *dentry)
0068 {
0069 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0070 struct autofs_info *ino;
0071
0072 ino = autofs_dentry_ino(dentry);
0073 spin_lock(&sbi->lookup_lock);
0074 list_del_init(&ino->active);
0075 spin_unlock(&sbi->lookup_lock);
0076 }
0077
0078 static int autofs_dir_open(struct inode *inode, struct file *file)
0079 {
0080 struct dentry *dentry = file->f_path.dentry;
0081 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0082 struct autofs_info *ino = autofs_dentry_ino(dentry);
0083
0084 pr_debug("file=%p dentry=%p %pd\n", file, dentry, dentry);
0085
0086 if (autofs_oz_mode(sbi))
0087 goto out;
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 spin_lock(&sbi->lookup_lock);
0099 if (!path_is_mountpoint(&file->f_path) && autofs_empty(ino)) {
0100 spin_unlock(&sbi->lookup_lock);
0101 return -ENOENT;
0102 }
0103 spin_unlock(&sbi->lookup_lock);
0104
0105 out:
0106 return dcache_dir_open(inode, file);
0107 }
0108
0109 static void autofs_dentry_release(struct dentry *de)
0110 {
0111 struct autofs_info *ino = autofs_dentry_ino(de);
0112 struct autofs_sb_info *sbi = autofs_sbi(de->d_sb);
0113
0114 pr_debug("releasing %p\n", de);
0115
0116 if (!ino)
0117 return;
0118
0119 if (sbi) {
0120 spin_lock(&sbi->lookup_lock);
0121 if (!list_empty(&ino->active))
0122 list_del(&ino->active);
0123 if (!list_empty(&ino->expiring))
0124 list_del(&ino->expiring);
0125 spin_unlock(&sbi->lookup_lock);
0126 }
0127
0128 autofs_free_ino(ino);
0129 }
0130
0131 static struct dentry *autofs_lookup_active(struct dentry *dentry)
0132 {
0133 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0134 struct dentry *parent = dentry->d_parent;
0135 const struct qstr *name = &dentry->d_name;
0136 unsigned int len = name->len;
0137 unsigned int hash = name->hash;
0138 const unsigned char *str = name->name;
0139 struct list_head *p, *head;
0140
0141 head = &sbi->active_list;
0142 if (list_empty(head))
0143 return NULL;
0144 spin_lock(&sbi->lookup_lock);
0145 list_for_each(p, head) {
0146 struct autofs_info *ino;
0147 struct dentry *active;
0148 const struct qstr *qstr;
0149
0150 ino = list_entry(p, struct autofs_info, active);
0151 active = ino->dentry;
0152
0153 spin_lock(&active->d_lock);
0154
0155
0156 if ((int) d_count(active) <= 0)
0157 goto next;
0158
0159 qstr = &active->d_name;
0160
0161 if (active->d_name.hash != hash)
0162 goto next;
0163 if (active->d_parent != parent)
0164 goto next;
0165
0166 if (qstr->len != len)
0167 goto next;
0168 if (memcmp(qstr->name, str, len))
0169 goto next;
0170
0171 if (d_unhashed(active)) {
0172 dget_dlock(active);
0173 spin_unlock(&active->d_lock);
0174 spin_unlock(&sbi->lookup_lock);
0175 return active;
0176 }
0177 next:
0178 spin_unlock(&active->d_lock);
0179 }
0180 spin_unlock(&sbi->lookup_lock);
0181
0182 return NULL;
0183 }
0184
0185 static struct dentry *autofs_lookup_expiring(struct dentry *dentry,
0186 bool rcu_walk)
0187 {
0188 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0189 struct dentry *parent = dentry->d_parent;
0190 const struct qstr *name = &dentry->d_name;
0191 unsigned int len = name->len;
0192 unsigned int hash = name->hash;
0193 const unsigned char *str = name->name;
0194 struct list_head *p, *head;
0195
0196 head = &sbi->expiring_list;
0197 if (list_empty(head))
0198 return NULL;
0199 spin_lock(&sbi->lookup_lock);
0200 list_for_each(p, head) {
0201 struct autofs_info *ino;
0202 struct dentry *expiring;
0203 const struct qstr *qstr;
0204
0205 if (rcu_walk) {
0206 spin_unlock(&sbi->lookup_lock);
0207 return ERR_PTR(-ECHILD);
0208 }
0209
0210 ino = list_entry(p, struct autofs_info, expiring);
0211 expiring = ino->dentry;
0212
0213 spin_lock(&expiring->d_lock);
0214
0215
0216 if (d_really_is_negative(expiring))
0217 goto next;
0218
0219 qstr = &expiring->d_name;
0220
0221 if (expiring->d_name.hash != hash)
0222 goto next;
0223 if (expiring->d_parent != parent)
0224 goto next;
0225
0226 if (qstr->len != len)
0227 goto next;
0228 if (memcmp(qstr->name, str, len))
0229 goto next;
0230
0231 if (d_unhashed(expiring)) {
0232 dget_dlock(expiring);
0233 spin_unlock(&expiring->d_lock);
0234 spin_unlock(&sbi->lookup_lock);
0235 return expiring;
0236 }
0237 next:
0238 spin_unlock(&expiring->d_lock);
0239 }
0240 spin_unlock(&sbi->lookup_lock);
0241
0242 return NULL;
0243 }
0244
0245 static int autofs_mount_wait(const struct path *path, bool rcu_walk)
0246 {
0247 struct autofs_sb_info *sbi = autofs_sbi(path->dentry->d_sb);
0248 struct autofs_info *ino = autofs_dentry_ino(path->dentry);
0249 int status = 0;
0250
0251 if (ino->flags & AUTOFS_INF_PENDING) {
0252 if (rcu_walk)
0253 return -ECHILD;
0254 pr_debug("waiting for mount name=%pd\n", path->dentry);
0255 status = autofs_wait(sbi, path, NFY_MOUNT);
0256 pr_debug("mount wait done status=%d\n", status);
0257 ino->last_used = jiffies;
0258 return status;
0259 }
0260 if (!(sbi->flags & AUTOFS_SBI_STRICTEXPIRE))
0261 ino->last_used = jiffies;
0262 return status;
0263 }
0264
0265 static int do_expire_wait(const struct path *path, bool rcu_walk)
0266 {
0267 struct dentry *dentry = path->dentry;
0268 struct dentry *expiring;
0269
0270 expiring = autofs_lookup_expiring(dentry, rcu_walk);
0271 if (IS_ERR(expiring))
0272 return PTR_ERR(expiring);
0273 if (!expiring)
0274 return autofs_expire_wait(path, rcu_walk);
0275 else {
0276 const struct path this = { .mnt = path->mnt, .dentry = expiring };
0277
0278
0279
0280
0281
0282 autofs_expire_wait(&this, 0);
0283 autofs_del_expiring(expiring);
0284 dput(expiring);
0285 }
0286 return 0;
0287 }
0288
0289 static struct dentry *autofs_mountpoint_changed(struct path *path)
0290 {
0291 struct dentry *dentry = path->dentry;
0292 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 if (autofs_type_indirect(sbi->type) && d_unhashed(dentry)) {
0316 struct dentry *parent = dentry->d_parent;
0317 struct autofs_info *ino;
0318 struct dentry *new;
0319
0320 new = d_lookup(parent, &dentry->d_name);
0321 if (!new)
0322 return NULL;
0323 ino = autofs_dentry_ino(new);
0324 ino->last_used = jiffies;
0325 dput(path->dentry);
0326 path->dentry = new;
0327 }
0328 return path->dentry;
0329 }
0330
0331 static struct vfsmount *autofs_d_automount(struct path *path)
0332 {
0333 struct dentry *dentry = path->dentry;
0334 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0335 struct autofs_info *ino = autofs_dentry_ino(dentry);
0336 int status;
0337
0338 pr_debug("dentry=%p %pd\n", dentry, dentry);
0339
0340
0341 if (autofs_oz_mode(sbi))
0342 return NULL;
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352 status = do_expire_wait(path, 0);
0353 if (status && status != -EAGAIN)
0354 return NULL;
0355
0356
0357 spin_lock(&sbi->fs_lock);
0358 if (ino->flags & AUTOFS_INF_PENDING) {
0359 spin_unlock(&sbi->fs_lock);
0360 status = autofs_mount_wait(path, 0);
0361 if (status)
0362 return ERR_PTR(status);
0363 goto done;
0364 }
0365
0366
0367
0368
0369
0370
0371 if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
0372 spin_unlock(&sbi->fs_lock);
0373 goto done;
0374 }
0375
0376 if (!path_is_mountpoint(path)) {
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388 if (sbi->version > 4) {
0389 if (path_has_submounts(path)) {
0390 spin_unlock(&sbi->fs_lock);
0391 goto done;
0392 }
0393 } else {
0394 if (!autofs_empty(ino)) {
0395 spin_unlock(&sbi->fs_lock);
0396 goto done;
0397 }
0398 }
0399 ino->flags |= AUTOFS_INF_PENDING;
0400 spin_unlock(&sbi->fs_lock);
0401 status = autofs_mount_wait(path, 0);
0402 spin_lock(&sbi->fs_lock);
0403 ino->flags &= ~AUTOFS_INF_PENDING;
0404 if (status) {
0405 spin_unlock(&sbi->fs_lock);
0406 return ERR_PTR(status);
0407 }
0408 }
0409 spin_unlock(&sbi->fs_lock);
0410 done:
0411
0412 dentry = autofs_mountpoint_changed(path);
0413 if (!dentry)
0414 return ERR_PTR(-ENOENT);
0415
0416 return NULL;
0417 }
0418
0419 static int autofs_d_manage(const struct path *path, bool rcu_walk)
0420 {
0421 struct dentry *dentry = path->dentry;
0422 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
0423 struct autofs_info *ino = autofs_dentry_ino(dentry);
0424 int status;
0425
0426 pr_debug("dentry=%p %pd\n", dentry, dentry);
0427
0428
0429 if (autofs_oz_mode(sbi)) {
0430 if (!path_is_mountpoint(path))
0431 return -EISDIR;
0432 return 0;
0433 }
0434
0435
0436 if (do_expire_wait(path, rcu_walk) == -ECHILD)
0437 return -ECHILD;
0438
0439
0440
0441
0442
0443 status = autofs_mount_wait(path, rcu_walk);
0444 if (status)
0445 return status;
0446
0447 if (rcu_walk) {
0448
0449
0450
0451
0452
0453
0454 struct inode *inode;
0455
0456 if (ino->flags & AUTOFS_INF_WANT_EXPIRE)
0457 return 0;
0458 if (path_is_mountpoint(path))
0459 return 0;
0460 inode = d_inode_rcu(dentry);
0461 if (inode && S_ISLNK(inode->i_mode))
0462 return -EISDIR;
0463 if (!autofs_empty(ino))
0464 return -EISDIR;
0465 return 0;
0466 }
0467
0468 spin_lock(&sbi->fs_lock);
0469
0470
0471
0472
0473
0474
0475
0476 if (!(ino->flags & AUTOFS_INF_EXPIRING)) {
0477
0478
0479
0480
0481
0482
0483 if ((!path_is_mountpoint(path) && !autofs_empty(ino)) ||
0484 (d_really_is_positive(dentry) && d_is_symlink(dentry)))
0485 status = -EISDIR;
0486 }
0487 spin_unlock(&sbi->fs_lock);
0488
0489 return status;
0490 }
0491
0492
0493 static struct dentry *autofs_lookup(struct inode *dir,
0494 struct dentry *dentry, unsigned int flags)
0495 {
0496 struct autofs_sb_info *sbi;
0497 struct autofs_info *ino;
0498 struct dentry *active;
0499
0500 pr_debug("name = %pd\n", dentry);
0501
0502
0503 if (dentry->d_name.len > NAME_MAX)
0504 return ERR_PTR(-ENAMETOOLONG);
0505
0506 sbi = autofs_sbi(dir->i_sb);
0507
0508 pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
0509 current->pid, task_pgrp_nr(current),
0510 sbi->flags & AUTOFS_SBI_CATATONIC,
0511 autofs_oz_mode(sbi));
0512
0513 active = autofs_lookup_active(dentry);
0514 if (active)
0515 return active;
0516 else {
0517
0518
0519
0520
0521
0522
0523 if (!autofs_oz_mode(sbi) && !IS_ROOT(dentry->d_parent))
0524 return ERR_PTR(-ENOENT);
0525
0526 ino = autofs_new_ino(sbi);
0527 if (!ino)
0528 return ERR_PTR(-ENOMEM);
0529
0530 spin_lock(&sbi->lookup_lock);
0531 spin_lock(&dentry->d_lock);
0532
0533 if (IS_ROOT(dentry->d_parent) &&
0534 autofs_type_indirect(sbi->type))
0535 __managed_dentry_set_managed(dentry);
0536 dentry->d_fsdata = ino;
0537 ino->dentry = dentry;
0538
0539 list_add(&ino->active, &sbi->active_list);
0540 spin_unlock(&sbi->lookup_lock);
0541 spin_unlock(&dentry->d_lock);
0542 }
0543 return NULL;
0544 }
0545
0546 static int autofs_dir_permission(struct user_namespace *mnt_userns,
0547 struct inode *inode, int mask)
0548 {
0549 if (mask & MAY_WRITE) {
0550 struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
0551
0552 if (!autofs_oz_mode(sbi))
0553 return -EACCES;
0554
0555
0556
0557
0558
0559 if (sbi->flags & AUTOFS_SBI_CATATONIC)
0560 return -EACCES;
0561 }
0562
0563 return generic_permission(mnt_userns, inode, mask);
0564 }
0565
0566 static int autofs_dir_symlink(struct user_namespace *mnt_userns,
0567 struct inode *dir, struct dentry *dentry,
0568 const char *symname)
0569 {
0570 struct autofs_info *ino = autofs_dentry_ino(dentry);
0571 struct autofs_info *p_ino;
0572 struct inode *inode;
0573 size_t size = strlen(symname);
0574 char *cp;
0575
0576 pr_debug("%s <- %pd\n", symname, dentry);
0577
0578 BUG_ON(!ino);
0579
0580 autofs_clean_ino(ino);
0581
0582 autofs_del_active(dentry);
0583
0584 cp = kmalloc(size + 1, GFP_KERNEL);
0585 if (!cp)
0586 return -ENOMEM;
0587
0588 strcpy(cp, symname);
0589
0590 inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555);
0591 if (!inode) {
0592 kfree(cp);
0593 return -ENOMEM;
0594 }
0595 inode->i_private = cp;
0596 inode->i_size = size;
0597 d_add(dentry, inode);
0598
0599 dget(dentry);
0600 p_ino = autofs_dentry_ino(dentry->d_parent);
0601 p_ino->count++;
0602
0603 dir->i_mtime = current_time(dir);
0604
0605 return 0;
0606 }
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623 static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
0624 {
0625 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
0626 struct autofs_info *ino = autofs_dentry_ino(dentry);
0627 struct autofs_info *p_ino;
0628
0629 p_ino = autofs_dentry_ino(dentry->d_parent);
0630 p_ino->count--;
0631 dput(ino->dentry);
0632
0633 d_inode(dentry)->i_size = 0;
0634 clear_nlink(d_inode(dentry));
0635
0636 dir->i_mtime = current_time(dir);
0637
0638 spin_lock(&sbi->lookup_lock);
0639 __autofs_add_expiring(dentry);
0640 d_drop(dentry);
0641 spin_unlock(&sbi->lookup_lock);
0642
0643 return 0;
0644 }
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657 static void autofs_set_leaf_automount_flags(struct dentry *dentry)
0658 {
0659 struct dentry *parent;
0660
0661
0662 if (IS_ROOT(dentry->d_parent))
0663 return;
0664
0665 managed_dentry_set_managed(dentry);
0666
0667 parent = dentry->d_parent;
0668
0669 if (IS_ROOT(parent->d_parent))
0670 return;
0671 managed_dentry_clear_managed(parent);
0672 }
0673
0674 static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
0675 {
0676 struct dentry *parent;
0677
0678
0679 if (IS_ROOT(dentry->d_parent))
0680 return;
0681
0682 managed_dentry_clear_managed(dentry);
0683
0684 parent = dentry->d_parent;
0685
0686 if (IS_ROOT(parent->d_parent))
0687 return;
0688 if (autofs_dentry_ino(parent)->count == 2)
0689 managed_dentry_set_managed(parent);
0690 }
0691
0692 static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
0693 {
0694 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
0695 struct autofs_info *ino = autofs_dentry_ino(dentry);
0696 struct autofs_info *p_ino;
0697
0698 pr_debug("dentry %p, removing %pd\n", dentry, dentry);
0699
0700 if (ino->count != 1)
0701 return -ENOTEMPTY;
0702
0703 spin_lock(&sbi->lookup_lock);
0704 __autofs_add_expiring(dentry);
0705 d_drop(dentry);
0706 spin_unlock(&sbi->lookup_lock);
0707
0708 if (sbi->version < 5)
0709 autofs_clear_leaf_automount_flags(dentry);
0710
0711 p_ino = autofs_dentry_ino(dentry->d_parent);
0712 p_ino->count--;
0713 dput(ino->dentry);
0714 d_inode(dentry)->i_size = 0;
0715 clear_nlink(d_inode(dentry));
0716
0717 if (dir->i_nlink)
0718 drop_nlink(dir);
0719
0720 return 0;
0721 }
0722
0723 static int autofs_dir_mkdir(struct user_namespace *mnt_userns,
0724 struct inode *dir, struct dentry *dentry,
0725 umode_t mode)
0726 {
0727 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
0728 struct autofs_info *ino = autofs_dentry_ino(dentry);
0729 struct autofs_info *p_ino;
0730 struct inode *inode;
0731
0732 pr_debug("dentry %p, creating %pd\n", dentry, dentry);
0733
0734 BUG_ON(!ino);
0735
0736 autofs_clean_ino(ino);
0737
0738 autofs_del_active(dentry);
0739
0740 inode = autofs_get_inode(dir->i_sb, S_IFDIR | mode);
0741 if (!inode)
0742 return -ENOMEM;
0743 d_add(dentry, inode);
0744
0745 if (sbi->version < 5)
0746 autofs_set_leaf_automount_flags(dentry);
0747
0748 dget(dentry);
0749 p_ino = autofs_dentry_ino(dentry->d_parent);
0750 p_ino->count++;
0751 inc_nlink(dir);
0752 dir->i_mtime = current_time(dir);
0753
0754 return 0;
0755 }
0756
0757
0758 #ifdef CONFIG_COMPAT
0759 static inline int autofs_compat_get_set_timeout(struct autofs_sb_info *sbi,
0760 compat_ulong_t __user *p)
0761 {
0762 unsigned long ntimeout;
0763 int rv;
0764
0765 rv = get_user(ntimeout, p);
0766 if (rv)
0767 goto error;
0768
0769 rv = put_user(sbi->exp_timeout/HZ, p);
0770 if (rv)
0771 goto error;
0772
0773 if (ntimeout > UINT_MAX/HZ)
0774 sbi->exp_timeout = 0;
0775 else
0776 sbi->exp_timeout = ntimeout * HZ;
0777
0778 return 0;
0779 error:
0780 return rv;
0781 }
0782 #endif
0783
0784 static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
0785 unsigned long __user *p)
0786 {
0787 unsigned long ntimeout;
0788 int rv;
0789
0790 rv = get_user(ntimeout, p);
0791 if (rv)
0792 goto error;
0793
0794 rv = put_user(sbi->exp_timeout/HZ, p);
0795 if (rv)
0796 goto error;
0797
0798 if (ntimeout > ULONG_MAX/HZ)
0799 sbi->exp_timeout = 0;
0800 else
0801 sbi->exp_timeout = ntimeout * HZ;
0802
0803 return 0;
0804 error:
0805 return rv;
0806 }
0807
0808
0809 static inline int autofs_get_protover(struct autofs_sb_info *sbi,
0810 int __user *p)
0811 {
0812 return put_user(sbi->version, p);
0813 }
0814
0815
0816 static inline int autofs_get_protosubver(struct autofs_sb_info *sbi,
0817 int __user *p)
0818 {
0819 return put_user(sbi->sub_version, p);
0820 }
0821
0822
0823
0824
0825 static inline int autofs_ask_umount(struct vfsmount *mnt, int __user *p)
0826 {
0827 int status = 0;
0828
0829 if (may_umount(mnt))
0830 status = 1;
0831
0832 pr_debug("may umount %d\n", status);
0833
0834 status = put_user(status, p);
0835
0836 return status;
0837 }
0838
0839
0840
0841
0842
0843 int is_autofs_dentry(struct dentry *dentry)
0844 {
0845 return dentry && d_really_is_positive(dentry) &&
0846 dentry->d_op == &autofs_dentry_operations &&
0847 dentry->d_fsdata != NULL;
0848 }
0849
0850
0851
0852
0853
0854 static int autofs_root_ioctl_unlocked(struct inode *inode, struct file *filp,
0855 unsigned int cmd, unsigned long arg)
0856 {
0857 struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
0858 void __user *p = (void __user *)arg;
0859
0860 pr_debug("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
0861 cmd, arg, sbi, task_pgrp_nr(current));
0862
0863 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
0864 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
0865 return -ENOTTY;
0866
0867 if (!autofs_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
0868 return -EPERM;
0869
0870 switch (cmd) {
0871 case AUTOFS_IOC_READY:
0872 return autofs_wait_release(sbi, (autofs_wqt_t) arg, 0);
0873 case AUTOFS_IOC_FAIL:
0874 return autofs_wait_release(sbi, (autofs_wqt_t) arg, -ENOENT);
0875 case AUTOFS_IOC_CATATONIC:
0876 autofs_catatonic_mode(sbi);
0877 return 0;
0878 case AUTOFS_IOC_PROTOVER:
0879 return autofs_get_protover(sbi, p);
0880 case AUTOFS_IOC_PROTOSUBVER:
0881 return autofs_get_protosubver(sbi, p);
0882 case AUTOFS_IOC_SETTIMEOUT:
0883 return autofs_get_set_timeout(sbi, p);
0884 #ifdef CONFIG_COMPAT
0885 case AUTOFS_IOC_SETTIMEOUT32:
0886 return autofs_compat_get_set_timeout(sbi, p);
0887 #endif
0888
0889 case AUTOFS_IOC_ASKUMOUNT:
0890 return autofs_ask_umount(filp->f_path.mnt, p);
0891
0892
0893 case AUTOFS_IOC_EXPIRE:
0894 return autofs_expire_run(inode->i_sb, filp->f_path.mnt, sbi, p);
0895
0896 case AUTOFS_IOC_EXPIRE_MULTI:
0897 return autofs_expire_multi(inode->i_sb,
0898 filp->f_path.mnt, sbi, p);
0899
0900 default:
0901 return -EINVAL;
0902 }
0903 }
0904
0905 static long autofs_root_ioctl(struct file *filp,
0906 unsigned int cmd, unsigned long arg)
0907 {
0908 struct inode *inode = file_inode(filp);
0909
0910 return autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
0911 }
0912
0913 #ifdef CONFIG_COMPAT
0914 static long autofs_root_compat_ioctl(struct file *filp,
0915 unsigned int cmd, unsigned long arg)
0916 {
0917 struct inode *inode = file_inode(filp);
0918 int ret;
0919
0920 if (cmd == AUTOFS_IOC_READY || cmd == AUTOFS_IOC_FAIL)
0921 ret = autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
0922 else
0923 ret = autofs_root_ioctl_unlocked(inode, filp, cmd,
0924 (unsigned long) compat_ptr(arg));
0925
0926 return ret;
0927 }
0928 #endif