ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / fs / autofs4 / autofs_i.h
1 /* -*- c -*- ------------------------------------------------------------- *
2  *   
3  * linux/fs/autofs/autofs_i.h
4  *
5  *   Copyright 1997-1998 Transmeta Corporation - All Rights Reserved
6  *
7  * This file is part of the Linux kernel and is made available under
8  * the terms of the GNU General Public License, version 2, or at your
9  * option, any later version, incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12
13 /* Internal header file for autofs */
14
15 #include <linux/auto_fs4.h>
16 #include <linux/list.h>
17
18 /* This is the range of ioctl() numbers we claim as ours */
19 #define AUTOFS_IOC_FIRST     AUTOFS_IOC_READY
20 #define AUTOFS_IOC_COUNT     32
21
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/time.h>
25 #include <linux/string.h>
26 #include <linux/wait.h>
27 #include <linux/sched.h>
28 #include <asm/current.h>
29 #include <asm/uaccess.h>
30
31 /* #define DEBUG */
32
33 #ifdef DEBUG
34 #define DPRINTK(D) do{ printk("pid %d: ", current->pid); printk D; } while(0)
35 #else
36 #define DPRINTK(D) do {} while(0)
37 #endif
38
39 #define AUTOFS_SUPER_MAGIC 0x0187
40
41 /*
42  * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
43  * kernel will keep the negative response cached for up to the time given
44  * here, although the time can be shorter if the kernel throws the dcache
45  * entry away.  This probably should be settable from user space.
46  */
47 #define AUTOFS_NEGATIVE_TIMEOUT (60*HZ) /* 1 minute */
48
49 /* Unified info structure.  This is pointed to by both the dentry and
50    inode structures.  Each file in the filesystem has an instance of this
51    structure.  It holds a reference to the dentry, so dentries are never
52    flushed while the file exists.  All name lookups are dealt with at the
53    dentry level, although the filesystem can interfere in the validation
54    process.  Readdir is implemented by traversing the dentry lists. */
55 struct autofs_info {
56         struct dentry   *dentry;
57         struct inode    *inode;
58
59         int             flags;
60
61         struct autofs_sb_info *sbi;
62         unsigned long last_used;
63
64         mode_t  mode;
65         size_t  size;
66
67         void (*free)(struct autofs_info *);
68         union {
69                 const char *symlink;
70         } u;
71 };
72
73 #define AUTOFS_INF_EXPIRING     (1<<0) /* dentry is in the process of expiring */
74
75 struct autofs_wait_queue {
76         wait_queue_head_t queue;
77         struct autofs_wait_queue *next;
78         autofs_wqt_t wait_queue_token;
79         /* We use the following to see what we are waiting for */
80         int hash;
81         int len;
82         char *name;
83         /* This is for status reporting upon return */
84         int status;
85         int wait_ctr;
86 };
87
88 #define AUTOFS_SBI_MAGIC 0x6d4a556d
89
90 struct autofs_sb_info {
91         u32 magic;
92         struct file *pipe;
93         pid_t oz_pgrp;
94         int catatonic;
95         int version;
96         unsigned long exp_timeout;
97         struct super_block *sb;
98         struct autofs_wait_queue *queues; /* Wait queue pointer */
99 };
100
101 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
102 {
103         return (struct autofs_sb_info *)(sb->s_fs_info);
104 }
105
106 static inline struct autofs_info *autofs4_dentry_ino(struct dentry *dentry)
107 {
108         return (struct autofs_info *)(dentry->d_fsdata);
109 }
110
111 /* autofs4_oz_mode(): do we see the man behind the curtain?  (The
112    processes which do manipulations for us in user space sees the raw
113    filesystem without "magic".) */
114
115 static inline int autofs4_oz_mode(struct autofs_sb_info *sbi) {
116         return sbi->catatonic || process_group(current) == sbi->oz_pgrp;
117 }
118
119 /* Does a dentry have some pending activity? */
120 static inline int autofs4_ispending(struct dentry *dentry)
121 {
122         struct autofs_info *inf = autofs4_dentry_ino(dentry);
123
124         return (dentry->d_flags & DCACHE_AUTOFS_PENDING) ||
125                 (inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
126 }
127
128 struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
129 struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
130 void autofs4_free_ino(struct autofs_info *);
131
132 /* Expiration */
133 int is_autofs4_dentry(struct dentry *);
134 int autofs4_expire_run(struct super_block *, struct vfsmount *,
135                         struct autofs_sb_info *, struct autofs_packet_expire *);
136 int autofs4_expire_multi(struct super_block *, struct vfsmount *,
137                         struct autofs_sb_info *, int *);
138
139 /* Operations structures */
140
141 extern struct inode_operations autofs4_symlink_inode_operations;
142 extern struct inode_operations autofs4_dir_inode_operations;
143 extern struct inode_operations autofs4_root_inode_operations;
144 extern struct file_operations autofs4_root_operations;
145
146 /* Initializing function */
147
148 int autofs4_fill_super(struct super_block *, void *, int);
149 struct autofs_info *autofs4_init_ino(struct autofs_info *, struct autofs_sb_info *sbi, mode_t mode);
150
151 /* Queue management functions */
152
153 enum autofs_notify
154 {
155         NFY_NONE,
156         NFY_MOUNT,
157         NFY_EXPIRE
158 };
159
160 int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
161 int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
162 void autofs4_catatonic_mode(struct autofs_sb_info *);