• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- linux-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_fs.h>
16 
17 /* This is the range of ioctl() numbers we claim as ours */
18 #define AUTOFS_IOC_FIRST     AUTOFS_IOC_READY
19 #define AUTOFS_IOC_COUNT     32
20 
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/time.h>
24 #include <linux/string.h>
25 #include <linux/wait.h>
26 #include <linux/dcache.h>
27 #include <linux/namei.h>
28 #include <linux/mount.h>
29 #include <linux/sched.h>
30 
31 #include <asm/current.h>
32 #include <asm/uaccess.h>
33 
34 #ifdef DEBUG
35 #define DPRINTK(D) (printk D)
36 #else
37 #define DPRINTK(D) ((void)0)
38 #endif
39 
40 /*
41  * If the daemon returns a negative response (AUTOFS_IOC_FAIL) then the
42  * kernel will keep the negative response cached for up to the time given
43  * here, although the time can be shorter if the kernel throws the dcache
44  * entry away.  This probably should be settable from user space.
45  */
46 #define AUTOFS_NEGATIVE_TIMEOUT (60*HZ)	/* 1 minute */
47 
48 /* Structures associated with the root directory hash table */
49 
50 #define AUTOFS_HASH_SIZE 67
51 
52 struct autofs_dir_ent {
53 	int hash;
54 	char *name;
55 	int len;
56 	ino_t ino;
57 	struct dentry *dentry;
58 	/* Linked list of entries */
59 	struct autofs_dir_ent *next;
60 	struct autofs_dir_ent **back;
61 	/* The following entries are for the expiry system */
62 	unsigned long last_usage;
63 	struct list_head exp;
64 };
65 
66 struct autofs_dirhash {
67 	struct autofs_dir_ent *h[AUTOFS_HASH_SIZE];
68 	struct list_head expiry_head;
69 };
70 
71 struct autofs_wait_queue {
72 	wait_queue_head_t queue;
73 	struct autofs_wait_queue *next;
74 	autofs_wqt_t wait_queue_token;
75 	/* We use the following to see what we are waiting for */
76 	int hash;
77 	int len;
78 	char *name;
79 	/* This is for status reporting upon return */
80 	int status;
81 	int wait_ctr;
82 };
83 
84 struct autofs_symlink {
85 	char *data;
86 	int len;
87 	time_t mtime;
88 };
89 
90 #define AUTOFS_MAX_SYMLINKS 256
91 
92 #define AUTOFS_ROOT_INO      1
93 #define AUTOFS_FIRST_SYMLINK 2
94 #define AUTOFS_FIRST_DIR_INO (AUTOFS_FIRST_SYMLINK+AUTOFS_MAX_SYMLINKS)
95 
96 #define AUTOFS_SYMLINK_BITMAP_LEN \
97 	((AUTOFS_MAX_SYMLINKS+((sizeof(long)*1)-1))/(sizeof(long)*8))
98 
99 #define AUTOFS_SBI_MAGIC 0x6d4a556d
100 
101 struct autofs_sb_info {
102 	u32 magic;
103 	struct file *pipe;
104 	struct pid *oz_pgrp;
105 	int catatonic;
106 	struct super_block *sb;
107 	unsigned long exp_timeout;
108 	ino_t next_dir_ino;
109 	struct autofs_wait_queue *queues; /* Wait queue pointer */
110 	struct autofs_dirhash dirhash; /* Root directory hash */
111 	struct autofs_symlink symlink[AUTOFS_MAX_SYMLINKS];
112 	unsigned long symlink_bitmap[AUTOFS_SYMLINK_BITMAP_LEN];
113 };
114 
autofs_sbi(struct super_block * sb)115 static inline struct autofs_sb_info *autofs_sbi(struct super_block *sb)
116 {
117 	return (struct autofs_sb_info *)(sb->s_fs_info);
118 }
119 
120 /* autofs_oz_mode(): do we see the man behind the curtain?  (The
121    processes which do manipulations for us in user space sees the raw
122    filesystem without "magic".) */
123 
autofs_oz_mode(struct autofs_sb_info * sbi)124 static inline int autofs_oz_mode(struct autofs_sb_info *sbi) {
125 	return sbi->catatonic || task_pgrp(current) == sbi->oz_pgrp;
126 }
127 
128 /* Hash operations */
129 
130 void autofs_initialize_hash(struct autofs_dirhash *);
131 struct autofs_dir_ent *autofs_hash_lookup(const struct autofs_dirhash *,struct qstr *);
132 void autofs_hash_insert(struct autofs_dirhash *,struct autofs_dir_ent *);
133 void autofs_hash_delete(struct autofs_dir_ent *);
134 struct autofs_dir_ent *autofs_hash_enum(const struct autofs_dirhash *,off_t *,struct autofs_dir_ent *);
135 void autofs_hash_dputall(struct autofs_dirhash *);
136 void autofs_hash_nuke(struct autofs_sb_info *);
137 
138 /* Expiration-handling functions */
139 
140 void autofs_update_usage(struct autofs_dirhash *,struct autofs_dir_ent *);
141 struct autofs_dir_ent *autofs_expire(struct super_block *,struct autofs_sb_info *, struct vfsmount *mnt);
142 
143 /* Operations structures */
144 
145 extern const struct inode_operations autofs_root_inode_operations;
146 extern const struct inode_operations autofs_symlink_inode_operations;
147 extern const struct file_operations autofs_root_operations;
148 
149 /* Initializing function */
150 
151 int autofs_fill_super(struct super_block *, void *, int);
152 void autofs_kill_sb(struct super_block *sb);
153 struct inode *autofs_iget(struct super_block *, unsigned long);
154 
155 /* Queue management functions */
156 
157 int autofs_wait(struct autofs_sb_info *,struct qstr *);
158 int autofs_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
159 void autofs_catatonic_mode(struct autofs_sb_info *);
160 
161 #ifdef DEBUG
162 void autofs_say(const char *name, int len);
163 #else
164 #define autofs_say(n,l) ((void)0)
165 #endif
166