1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 "autofs_i.h"
21
22static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *);
23static int autofs4_dir_unlink(struct inode *,struct dentry *);
24static int autofs4_dir_rmdir(struct inode *,struct dentry *);
25static int autofs4_dir_mkdir(struct inode *,struct dentry *,int);
26static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long);
27static int autofs4_dir_open(struct inode *inode, struct file *file);
28static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
29static void *autofs4_follow_link(struct dentry *, struct nameidata *);
30
31#define TRIGGER_FLAGS (LOOKUP_CONTINUE | LOOKUP_DIRECTORY)
32#define TRIGGER_INTENTS (LOOKUP_OPEN | LOOKUP_CREATE)
33
34const 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,
41};
42
43const 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,
49};
50
51const 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,
57};
58
59const 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,
65};
66
67const 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,
73};
74
75static int autofs4_dir_open(struct inode *inode, struct file *file)
76{
77 struct dentry *dentry = file->f_path.dentry;
78 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
79
80 DPRINTK("file=%p dentry=%p %.*s",
81 file, dentry, dentry->d_name.len, dentry->d_name.name);
82
83 if (autofs4_oz_mode(sbi))
84 goto out;
85
86
87
88
89
90
91
92
93
94
95 spin_lock(&dcache_lock);
96 if (!d_mountpoint(dentry) && __simple_empty(dentry)) {
97 spin_unlock(&dcache_lock);
98 return -ENOENT;
99 }
100 spin_unlock(&dcache_lock);
101
102out:
103 return dcache_dir_open(inode, file);
104}
105
106static int try_to_fill_dentry(struct dentry *dentry, int flags)
107{
108 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
109 struct autofs_info *ino = autofs4_dentry_ino(dentry);
110 int status;
111
112 DPRINTK("dentry=%p %.*s ino=%p",
113 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
114
115
116
117
118
119 if (dentry->d_inode == NULL) {
120 DPRINTK("waiting for mount name=%.*s",
121 dentry->d_name.len, dentry->d_name.name);
122
123 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
124
125 DPRINTK("mount done status=%d", status);
126
127
128 if (status == -ENOENT) {
129 spin_lock(&dentry->d_lock);
130 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
131 spin_unlock(&dentry->d_lock);
132 return status;
133 } else if (status) {
134
135 return status;
136 }
137
138 } else if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
139 flags & (TRIGGER_FLAGS | TRIGGER_INTENTS) ||
140 current->link_count) {
141 DPRINTK("waiting for mount name=%.*s",
142 dentry->d_name.len, dentry->d_name.name);
143
144 spin_lock(&dentry->d_lock);
145 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
146 spin_unlock(&dentry->d_lock);
147 status = autofs4_wait(sbi, dentry, NFY_MOUNT);
148
149 DPRINTK("mount done status=%d", status);
150
151 if (status) {
152 spin_lock(&dentry->d_lock);
153 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
154 spin_unlock(&dentry->d_lock);
155 return status;
156 }
157 }
158
159
160 if (ino)
161 ino->last_used = jiffies;
162
163 spin_lock(&dentry->d_lock);
164 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
165 spin_unlock(&dentry->d_lock);
166
167 return 0;
168}
169
170
171static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
172{
173 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
174 struct autofs_info *ino = autofs4_dentry_ino(dentry);
175 int oz_mode = autofs4_oz_mode(sbi);
176 unsigned int lookup_type;
177 int status;
178
179 DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d",
180 dentry, dentry->d_name.len, dentry->d_name.name, oz_mode,
181 nd->flags);
182
183
184
185
186
187
188 if (oz_mode) {
189 spin_lock(&sbi->fs_lock);
190 if (ino->flags & AUTOFS_INF_EXPIRING) {
191 spin_unlock(&sbi->fs_lock);
192
193 if (!follow_down(&nd->path))
194 goto done;
195 goto follow;
196 }
197 spin_unlock(&sbi->fs_lock);
198 goto done;
199 }
200
201
202 autofs4_expire_wait(dentry);
203
204
205 lookup_type = nd->flags & (TRIGGER_FLAGS | TRIGGER_INTENTS);
206 if (!(lookup_type || dentry->d_flags & DCACHE_AUTOFS_PENDING))
207 goto follow;
208
209
210
211
212
213
214 spin_lock(&dcache_lock);
215 if (dentry->d_flags & DCACHE_AUTOFS_PENDING ||
216 (!d_mountpoint(dentry) && __simple_empty(dentry))) {
217 spin_unlock(&dcache_lock);
218
219 status = try_to_fill_dentry(dentry, 0);
220 if (status)
221 goto out_error;
222
223 goto follow;
224 }
225 spin_unlock(&dcache_lock);
226follow:
227
228
229
230
231
232 if (d_mountpoint(dentry)) {
233 if (!autofs4_follow_mount(&nd->path)) {
234 status = -ENOENT;
235 goto out_error;
236 }
237 }
238
239done:
240 return NULL;
241
242out_error:
243 path_put(&nd->path);
244 return ERR_PTR(status);
245}
246
247
248
249
250
251
252
253static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd)
254{
255 struct inode *dir = dentry->d_parent->d_inode;
256 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
257 int oz_mode = autofs4_oz_mode(sbi);
258 int flags = nd ? nd->flags : 0;
259 int status = 1;
260
261
262 spin_lock(&sbi->fs_lock);
263 if (autofs4_ispending(dentry)) {
264
265 spin_unlock(&sbi->fs_lock);
266
267 if (oz_mode)
268 return 1;
269
270
271
272
273
274
275 if (autofs4_expire_wait(dentry) == -EAGAIN)
276 return 0;
277
278
279
280
281
282 status = try_to_fill_dentry(dentry, flags);
283 if (status == 0)
284 return 1;
285
286 return status;
287 }
288 spin_unlock(&sbi->fs_lock);
289
290
291 if (dentry->d_inode == NULL)
292 return 0;
293
294
295 spin_lock(&dcache_lock);
296 if (S_ISDIR(dentry->d_inode->i_mode) &&
297 !d_mountpoint(dentry) &&
298 __simple_empty(dentry)) {
299 DPRINTK("dentry=%p %.*s, emptydir",
300 dentry, dentry->d_name.len, dentry->d_name.name);
301 spin_unlock(&dcache_lock);
302
303
304 if (oz_mode)
305 return 1;
306
307
308
309
310
311 status = try_to_fill_dentry(dentry, flags);
312 if (status == 0)
313 return 1;
314
315 return status;
316 }
317 spin_unlock(&dcache_lock);
318
319 return 1;
320}
321
322void autofs4_dentry_release(struct dentry *de)
323{
324 struct autofs_info *inf;
325
326 DPRINTK("releasing %p", de);
327
328 inf = autofs4_dentry_ino(de);
329 de->d_fsdata = NULL;
330
331 if (inf) {
332 struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
333
334 if (sbi) {
335 spin_lock(&sbi->lookup_lock);
336 if (!list_empty(&inf->active))
337 list_del(&inf->active);
338 if (!list_empty(&inf->expiring))
339 list_del(&inf->expiring);
340 spin_unlock(&sbi->lookup_lock);
341 }
342
343 inf->dentry = NULL;
344 inf->inode = NULL;
345
346 autofs4_free_ino(inf);
347 }
348}
349
350
351static const struct dentry_operations autofs4_root_dentry_operations = {
352 .d_revalidate = autofs4_revalidate,
353 .d_release = autofs4_dentry_release,
354};
355
356
357static const struct dentry_operations autofs4_dentry_operations = {
358 .d_revalidate = autofs4_revalidate,
359 .d_release = autofs4_dentry_release,
360};
361
362static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
363{
364 unsigned int len = name->len;
365 unsigned int hash = name->hash;
366 const unsigned char *str = name->name;
367 struct list_head *p, *head;
368
369 spin_lock(&dcache_lock);
370 spin_lock(&sbi->lookup_lock);
371 head = &sbi->active_list;
372 list_for_each(p, head) {
373 struct autofs_info *ino;
374 struct dentry *dentry;
375 struct qstr *qstr;
376
377 ino = list_entry(p, struct autofs_info, active);
378 dentry = ino->dentry;
379
380 spin_lock(&dentry->d_lock);
381
382
383 if (atomic_read(&dentry->d_count) == 0)
384 goto next;
385
386 qstr = &dentry->d_name;
387
388 if (dentry->d_name.hash != hash)
389 goto next;
390 if (dentry->d_parent != parent)
391 goto next;
392
393 if (qstr->len != len)
394 goto next;
395 if (memcmp(qstr->name, str, len))
396 goto next;
397
398 if (d_unhashed(dentry)) {
399 dget(dentry);
400 spin_unlock(&dentry->d_lock);
401 spin_unlock(&sbi->lookup_lock);
402 spin_unlock(&dcache_lock);
403 return dentry;
404 }
405next:
406 spin_unlock(&dentry->d_lock);
407 }
408 spin_unlock(&sbi->lookup_lock);
409 spin_unlock(&dcache_lock);
410
411 return NULL;
412}
413
414static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
415{
416 unsigned int len = name->len;
417 unsigned int hash = name->hash;
418 const unsigned char *str = name->name;
419 struct list_head *p, *head;
420
421 spin_lock(&dcache_lock);
422 spin_lock(&sbi->lookup_lock);
423 head = &sbi->expiring_list;
424 list_for_each(p, head) {
425 struct autofs_info *ino;
426 struct dentry *dentry;
427 struct qstr *qstr;
428
429 ino = list_entry(p, struct autofs_info, expiring);
430 dentry = ino->dentry;
431
432 spin_lock(&dentry->d_lock);
433
434
435 if (!dentry->d_inode)
436 goto next;
437
438 qstr = &dentry->d_name;
439
440 if (dentry->d_name.hash != hash)
441 goto next;
442 if (dentry->d_parent != parent)
443 goto next;
444
445 if (qstr->len != len)
446 goto next;
447 if (memcmp(qstr->name, str, len))
448 goto next;
449
450 if (d_unhashed(dentry)) {
451 dget(dentry);
452 spin_unlock(&dentry->d_lock);
453 spin_unlock(&sbi->lookup_lock);
454 spin_unlock(&dcache_lock);
455 return dentry;
456 }
457next:
458 spin_unlock(&dentry->d_lock);
459 }
460 spin_unlock(&sbi->lookup_lock);
461 spin_unlock(&dcache_lock);
462
463 return NULL;
464}
465
466
467static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
468{
469 struct autofs_sb_info *sbi;
470 struct autofs_info *ino;
471 struct dentry *expiring, *unhashed;
472 int oz_mode;
473
474 DPRINTK("name = %.*s",
475 dentry->d_name.len, dentry->d_name.name);
476
477
478 if (dentry->d_name.len > NAME_MAX)
479 return ERR_PTR(-ENAMETOOLONG);
480
481 sbi = autofs4_sbi(dir->i_sb);
482 oz_mode = autofs4_oz_mode(sbi);
483
484 DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
485 current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
486
487 unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
488 if (unhashed)
489 dentry = unhashed;
490 else {
491
492
493
494
495
496
497
498
499
500
501
502 dentry->d_op = &autofs4_root_dentry_operations;
503
504
505
506
507
508
509 ino = autofs4_init_ino(NULL, sbi, 0555);
510 if (!ino)
511 return ERR_PTR(-ENOMEM);
512
513 dentry->d_fsdata = ino;
514 ino->dentry = dentry;
515
516 spin_lock(&sbi->lookup_lock);
517 list_add(&ino->active, &sbi->active_list);
518 spin_unlock(&sbi->lookup_lock);
519
520 d_instantiate(dentry, NULL);
521 }
522
523 if (!oz_mode) {
524 mutex_unlock(&dir->i_mutex);
525 expiring = autofs4_lookup_expiring(sbi,
526 dentry->d_parent,
527 &dentry->d_name);
528 if (expiring) {
529
530
531
532
533
534 ino = autofs4_dentry_ino(expiring);
535 autofs4_expire_wait(expiring);
536 spin_lock(&sbi->lookup_lock);
537 if (!list_empty(&ino->expiring))
538 list_del_init(&ino->expiring);
539 spin_unlock(&sbi->lookup_lock);
540 dput(expiring);
541 }
542
543 spin_lock(&dentry->d_lock);
544 dentry->d_flags |= DCACHE_AUTOFS_PENDING;
545 spin_unlock(&dentry->d_lock);
546 if (dentry->d_op && dentry->d_op->d_revalidate)
547 (dentry->d_op->d_revalidate)(dentry, nd);
548 mutex_lock(&dir->i_mutex);
549 }
550
551
552
553
554
555 if (dentry->d_flags & DCACHE_AUTOFS_PENDING) {
556
557 if (signal_pending(current)) {
558 sigset_t *sigset = ¤t->pending.signal;
559 if (sigismember (sigset, SIGKILL) ||
560 sigismember (sigset, SIGQUIT) ||
561 sigismember (sigset, SIGINT)) {
562 if (unhashed)
563 dput(unhashed);
564 return ERR_PTR(-ERESTARTNOINTR);
565 }
566 }
567 if (!oz_mode) {
568 spin_lock(&dentry->d_lock);
569 dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
570 spin_unlock(&dentry->d_lock);
571 }
572 }
573
574
575
576
577
578
579
580 if (!oz_mode && d_unhashed(dentry)) {
581
582
583
584
585
586
587
588 struct dentry *parent = dentry->d_parent;
589 struct dentry *new = d_lookup(parent, &dentry->d_name);
590 if (new != NULL)
591 dentry = new;
592 else
593 dentry = ERR_PTR(-ENOENT);
594
595 if (unhashed)
596 dput(unhashed);
597
598 return dentry;
599 }
600
601 if (unhashed)
602 return unhashed;
603
604 return NULL;
605}
606
607static int autofs4_dir_symlink(struct inode *dir,
608 struct dentry *dentry,
609 const char *symname)
610{
611 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
612 struct autofs_info *ino = autofs4_dentry_ino(dentry);
613 struct autofs_info *p_ino;
614 struct inode *inode;
615 char *cp;
616
617 DPRINTK("%s <- %.*s", symname,
618 dentry->d_name.len, dentry->d_name.name);
619
620 if (!autofs4_oz_mode(sbi))
621 return -EACCES;
622
623 ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
624 if (!ino)
625 return -ENOMEM;
626
627 spin_lock(&sbi->lookup_lock);
628 if (!list_empty(&ino->active))
629 list_del_init(&ino->active);
630 spin_unlock(&sbi->lookup_lock);
631
632 ino->size = strlen(symname);
633 cp = kmalloc(ino->size + 1, GFP_KERNEL);
634 if (!cp) {
635 if (!dentry->d_fsdata)
636 kfree(ino);
637 return -ENOMEM;
638 }
639
640 strcpy(cp, symname);
641
642 inode = autofs4_get_inode(dir->i_sb, ino);
643 if (!inode) {
644 kfree(cp);
645 if (!dentry->d_fsdata)
646 kfree(ino);
647 return -ENOMEM;
648 }
649 d_add(dentry, inode);
650
651 if (dir == dir->i_sb->s_root->d_inode)
652 dentry->d_op = &autofs4_root_dentry_operations;
653 else
654 dentry->d_op = &autofs4_dentry_operations;
655
656 dentry->d_fsdata = ino;
657 ino->dentry = dget(dentry);
658 atomic_inc(&ino->count);
659 p_ino = autofs4_dentry_ino(dentry->d_parent);
660 if (p_ino && dentry->d_parent != dentry)
661 atomic_inc(&p_ino->count);
662 ino->inode = inode;
663
664 ino->u.symlink = cp;
665 dir->i_mtime = CURRENT_TIME;
666
667 return 0;
668}
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)
686{
687 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
688 struct autofs_info *ino = autofs4_dentry_ino(dentry);
689 struct autofs_info *p_ino;
690
691
692 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
693 return -EACCES;
694
695 if (atomic_dec_and_test(&ino->count)) {
696 p_ino = autofs4_dentry_ino(dentry->d_parent);
697 if (p_ino && dentry->d_parent != dentry)
698 atomic_dec(&p_ino->count);
699 }
700 dput(ino->dentry);
701
702 dentry->d_inode->i_size = 0;
703 clear_nlink(dentry->d_inode);
704
705 dir->i_mtime = CURRENT_TIME;
706
707 spin_lock(&dcache_lock);
708 spin_lock(&sbi->lookup_lock);
709 if (list_empty(&ino->expiring))
710 list_add(&ino->expiring, &sbi->expiring_list);
711 spin_unlock(&sbi->lookup_lock);
712 spin_lock(&dentry->d_lock);
713 __d_drop(dentry);
714 spin_unlock(&dentry->d_lock);
715 spin_unlock(&dcache_lock);
716
717 return 0;
718}
719
720static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
721{
722 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
723 struct autofs_info *ino = autofs4_dentry_ino(dentry);
724 struct autofs_info *p_ino;
725
726 DPRINTK("dentry %p, removing %.*s",
727 dentry, dentry->d_name.len, dentry->d_name.name);
728
729 if (!autofs4_oz_mode(sbi))
730 return -EACCES;
731
732 spin_lock(&dcache_lock);
733 if (!list_empty(&dentry->d_subdirs)) {
734 spin_unlock(&dcache_lock);
735 return -ENOTEMPTY;
736 }
737 spin_lock(&sbi->lookup_lock);
738 if (list_empty(&ino->expiring))
739 list_add(&ino->expiring, &sbi->expiring_list);
740 spin_unlock(&sbi->lookup_lock);
741 spin_lock(&dentry->d_lock);
742 __d_drop(dentry);
743 spin_unlock(&dentry->d_lock);
744 spin_unlock(&dcache_lock);
745
746 if (atomic_dec_and_test(&ino->count)) {
747 p_ino = autofs4_dentry_ino(dentry->d_parent);
748 if (p_ino && dentry->d_parent != dentry)
749 atomic_dec(&p_ino->count);
750 }
751 dput(ino->dentry);
752 dentry->d_inode->i_size = 0;
753 clear_nlink(dentry->d_inode);
754
755 if (dir->i_nlink)
756 drop_nlink(dir);
757
758 return 0;
759}
760
761static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
762{
763 struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb);
764 struct autofs_info *ino = autofs4_dentry_ino(dentry);
765 struct autofs_info *p_ino;
766 struct inode *inode;
767
768 if (!autofs4_oz_mode(sbi))
769 return -EACCES;
770
771 DPRINTK("dentry %p, creating %.*s",
772 dentry, dentry->d_name.len, dentry->d_name.name);
773
774 ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
775 if (!ino)
776 return -ENOMEM;
777
778 spin_lock(&sbi->lookup_lock);
779 if (!list_empty(&ino->active))
780 list_del_init(&ino->active);
781 spin_unlock(&sbi->lookup_lock);
782
783 inode = autofs4_get_inode(dir->i_sb, ino);
784 if (!inode) {
785 if (!dentry->d_fsdata)
786 kfree(ino);
787 return -ENOMEM;
788 }
789 d_add(dentry, inode);
790
791 if (dir == dir->i_sb->s_root->d_inode)
792 dentry->d_op = &autofs4_root_dentry_operations;
793 else
794 dentry->d_op = &autofs4_dentry_operations;
795
796 dentry->d_fsdata = ino;
797 ino->dentry = dget(dentry);
798 atomic_inc(&ino->count);
799 p_ino = autofs4_dentry_ino(dentry->d_parent);
800 if (p_ino && dentry->d_parent != dentry)
801 atomic_inc(&p_ino->count);
802 ino->inode = inode;
803 inc_nlink(dir);
804 dir->i_mtime = CURRENT_TIME;
805
806 return 0;
807}
808
809
810static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi,
811 unsigned long __user *p)
812{
813 int rv;
814 unsigned long ntimeout;
815
816 if ((rv = get_user(ntimeout, p)) ||
817 (rv = put_user(sbi->exp_timeout/HZ, p)))
818 return rv;
819
820 if (ntimeout > ULONG_MAX/HZ)
821 sbi->exp_timeout = 0;
822 else
823 sbi->exp_timeout = ntimeout * HZ;
824
825 return 0;
826}
827
828
829static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p)
830{
831 return put_user(sbi->version, p);
832}
833
834
835static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p)
836{
837 return put_user(sbi->sub_version, p);
838}
839
840
841
842
843static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p)
844{
845 int status = 0;
846
847 if (may_umount(mnt))
848 status = 1;
849
850 DPRINTK("returning %d", status);
851
852 status = put_user(status, p);
853
854 return status;
855}
856
857
858
859
860
861int is_autofs4_dentry(struct dentry *dentry)
862{
863 return dentry && dentry->d_inode &&
864 (dentry->d_op == &autofs4_root_dentry_operations ||
865 dentry->d_op == &autofs4_dentry_operations) &&
866 dentry->d_fsdata != NULL;
867}
868
869
870
871
872
873static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
874 unsigned int cmd, unsigned long arg)
875{
876 struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb);
877 void __user *p = (void __user *)arg;
878
879 DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
880 cmd,arg,sbi,task_pgrp_nr(current));
881
882 if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
883 _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
884 return -ENOTTY;
885
886 if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
887 return -EPERM;
888
889 switch(cmd) {
890 case AUTOFS_IOC_READY:
891 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0);
892 case AUTOFS_IOC_FAIL:
893 return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT);
894 case AUTOFS_IOC_CATATONIC:
895 autofs4_catatonic_mode(sbi);
896 return 0;
897 case AUTOFS_IOC_PROTOVER:
898 return autofs4_get_protover(sbi, p);
899 case AUTOFS_IOC_PROTOSUBVER:
900 return autofs4_get_protosubver(sbi, p);
901 case AUTOFS_IOC_SETTIMEOUT:
902 return autofs4_get_set_timeout(sbi, p);
903
904 case AUTOFS_IOC_ASKUMOUNT:
905 return autofs4_ask_umount(filp->f_path.mnt, p);
906
907
908 case AUTOFS_IOC_EXPIRE:
909 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
910
911 case AUTOFS_IOC_EXPIRE_MULTI:
912 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);
913
914 default:
915 return -ENOSYS;
916 }
917}
918