1 #ifndef _LINUX_DEVFS_FS_KERNEL_H
2 #define _LINUX_DEVFS_FS_KERNEL_H
3 
4 #include <linux/fs.h>
5 #include <linux/config.h>
6 #include <linux/spinlock.h>
7 #include <linux/kdev_t.h>
8 #include <linux/types.h>
9 
10 #include <asm/semaphore.h>
11 
12 #define DEVFS_SUPER_MAGIC                0x1373
13 
14 #define IS_DEVFS_INODE(inode) (DEVFS_SUPER_MAGIC == (inode)->i_sb->s_magic)
15 
16 #define DEVFS_MINOR(inode) \
17     ({unsigned int m; /* evil GCC trickery */ \
18       ((inode)->i_sb && \
19        ((inode)->i_sb->s_magic==DEVFS_SUPER_MAGIC) && \
20        (devfs_get_maj_min(devfs_get_handle_from_inode((inode)),NULL,&m)==0) \
21       ) ? m : MINOR((inode)->r_dev); })
22 
23 
24 #define DEVFS_FL_NONE           0x000 /* This helps to make code more readable
25 				       */
26 #define DEVFS_FL_AUTO_OWNER     0x001 /* When a closed inode is opened the
27 					 ownerships are set to the opening
28 					 process and the protection is set to
29 					 that given in <<mode>>. When the inode
30 					 is closed, ownership reverts back to
31 					 <<uid>> and <<gid>> and the protection
32 					 is set to read-write for all        */
33 #define DEVFS_FL_HIDE           0x002 /* Do not show entry in directory list */
34 #define DEVFS_FL_AUTO_DEVNUM    0x004 /* Automatically generate device number
35 				       */
36 #define DEVFS_FL_AOPEN_NOTIFY   0x008 /* Asynchronously notify devfsd on open
37 				       */
38 #define DEVFS_FL_REMOVABLE      0x010 /* This is a removable media device    */
39 #define DEVFS_FL_WAIT           0x020 /* Wait for devfsd to finish           */
40 #define DEVFS_FL_CURRENT_OWNER  0x040 /* Set initial ownership to current    */
41 #define DEVFS_FL_DEFAULT        DEVFS_FL_NONE
42 
43 
44 #define DEVFS_SPECIAL_CHR     0
45 #define DEVFS_SPECIAL_BLK     1
46 
47 typedef struct devfs_entry * devfs_handle_t;
48 
49 #ifdef CONFIG_DEVFS_FS
50 
51 struct unique_numspace
52 {
53     spinlock_t init_lock;
54     unsigned char sem_initialised;
55     unsigned int num_free;          /*  Num free in bits       */
56     unsigned int length;            /*  Array length in bytes  */
57     unsigned long *bits;
58     struct semaphore semaphore;
59 };
60 
61 #define UNIQUE_NUMBERSPACE_INITIALISER {SPIN_LOCK_UNLOCKED, 0, 0, 0, NULL}
62 
63 extern void devfs_put (devfs_handle_t de);
64 extern devfs_handle_t devfs_register (devfs_handle_t dir, const char *name,
65 				      unsigned int flags,
66 				      unsigned int major, unsigned int minor,
67 				      umode_t mode, void *ops, void *info);
68 extern void devfs_unregister (devfs_handle_t de);
69 extern int devfs_mk_symlink (devfs_handle_t dir, const char *name,
70 			     unsigned int flags, const char *link,
71 			     devfs_handle_t *handle, void *info);
72 extern devfs_handle_t devfs_mk_dir (devfs_handle_t dir, const char *name,
73 				    void *info);
74 extern devfs_handle_t devfs_get_handle (devfs_handle_t dir, const char *name,
75 					unsigned int major,unsigned int minor,
76 					char type, int traverse_symlinks);
77 extern devfs_handle_t devfs_find_handle (devfs_handle_t dir, const char *name,
78 					 unsigned int major,unsigned int minor,
79 					 char type, int traverse_symlinks);
80 extern int devfs_get_flags (devfs_handle_t de, unsigned int *flags);
81 extern int devfs_set_flags (devfs_handle_t de, unsigned int flags);
82 extern int devfs_get_maj_min (devfs_handle_t de,
83 			      unsigned int *major, unsigned int *minor);
84 extern devfs_handle_t devfs_get_handle_from_inode (struct inode *inode);
85 extern int devfs_generate_path (devfs_handle_t de, char *path, int buflen);
86 extern void *devfs_get_ops (devfs_handle_t de);
87 extern void devfs_put_ops (devfs_handle_t de);
88 extern int devfs_set_file_size (devfs_handle_t de, unsigned long size);
89 extern void *devfs_get_info (devfs_handle_t de);
90 extern int devfs_set_info (devfs_handle_t de, void *info);
91 extern devfs_handle_t devfs_get_parent (devfs_handle_t de);
92 extern devfs_handle_t devfs_get_first_child (devfs_handle_t de);
93 extern devfs_handle_t devfs_get_next_sibling (devfs_handle_t de);
94 extern void devfs_auto_unregister (devfs_handle_t master,devfs_handle_t slave);
95 extern devfs_handle_t devfs_get_unregister_slave (devfs_handle_t master);
96 extern const char *devfs_get_name (devfs_handle_t de, unsigned int *namelen);
97 extern int devfs_register_chrdev (unsigned int major, const char *name,
98 				  struct file_operations *fops);
99 extern int devfs_register_blkdev (unsigned int major, const char *name,
100 				  struct block_device_operations *bdops);
101 extern int devfs_unregister_chrdev (unsigned int major, const char *name);
102 extern int devfs_unregister_blkdev (unsigned int major, const char *name);
103 
104 extern void devfs_register_tape (devfs_handle_t de);
105 extern void devfs_register_series (devfs_handle_t dir, const char *format,
106 				   unsigned int num_entries,
107 				   unsigned int flags, unsigned int major,
108 				   unsigned int minor_start,
109 				   umode_t mode, void *ops, void *info);
110 extern int devfs_alloc_major (char type);
111 extern void devfs_dealloc_major (char type, int major);
112 extern kdev_t devfs_alloc_devnum (char type);
113 extern void devfs_dealloc_devnum (char type, kdev_t devnum);
114 extern int devfs_alloc_unique_number (struct unique_numspace *space);
115 extern void devfs_dealloc_unique_number (struct unique_numspace *space,
116 					 int number);
117 
118 extern void mount_devfs_fs (void);
119 
120 #else  /*  CONFIG_DEVFS_FS  */
121 
122 struct unique_numspace
123 {
124     char dummy;
125 };
126 
127 #define UNIQUE_NUMBERSPACE_INITIALISER {0}
128 
devfs_put(devfs_handle_t de)129 static inline void devfs_put (devfs_handle_t de)
130 {
131     return;
132 }
devfs_register(devfs_handle_t dir,const char * name,unsigned int flags,unsigned int major,unsigned int minor,umode_t mode,void * ops,void * info)133 static inline devfs_handle_t devfs_register (devfs_handle_t dir,
134 					     const char *name,
135 					     unsigned int flags,
136 					     unsigned int major,
137 					     unsigned int minor,
138 					     umode_t mode,
139 					     void *ops, void *info)
140 {
141     return NULL;
142 }
devfs_unregister(devfs_handle_t de)143 static inline void devfs_unregister (devfs_handle_t de)
144 {
145     return;
146 }
devfs_mk_symlink(devfs_handle_t dir,const char * name,unsigned int flags,const char * link,devfs_handle_t * handle,void * info)147 static inline int devfs_mk_symlink (devfs_handle_t dir, const char *name,
148 				    unsigned int flags, const char *link,
149 				    devfs_handle_t *handle, void *info)
150 {
151     return 0;
152 }
devfs_mk_dir(devfs_handle_t dir,const char * name,void * info)153 static inline devfs_handle_t devfs_mk_dir (devfs_handle_t dir,
154 					   const char *name, void *info)
155 {
156     return NULL;
157 }
devfs_get_handle(devfs_handle_t dir,const char * name,unsigned int major,unsigned int minor,char type,int traverse_symlinks)158 static inline devfs_handle_t devfs_get_handle (devfs_handle_t dir,
159 					       const char *name,
160 					       unsigned int major,
161 					       unsigned int minor,
162 					       char type,
163 					       int traverse_symlinks)
164 {
165     return NULL;
166 }
devfs_find_handle(devfs_handle_t dir,const char * name,unsigned int major,unsigned int minor,char type,int traverse_symlinks)167 static inline devfs_handle_t devfs_find_handle (devfs_handle_t dir,
168 						const char *name,
169 						unsigned int major,
170 						unsigned int minor,
171 						char type,
172 						int traverse_symlinks)
173 {
174     return NULL;
175 }
devfs_get_flags(devfs_handle_t de,unsigned int * flags)176 static inline int devfs_get_flags (devfs_handle_t de, unsigned int *flags)
177 {
178     return 0;
179 }
devfs_set_flags(devfs_handle_t de,unsigned int flags)180 static inline int devfs_set_flags (devfs_handle_t de, unsigned int flags)
181 {
182     return 0;
183 }
devfs_get_maj_min(devfs_handle_t de,unsigned int * major,unsigned int * minor)184 static inline int devfs_get_maj_min (devfs_handle_t de,
185 				     unsigned int *major, unsigned int *minor)
186 {
187     return 0;
188 }
devfs_get_handle_from_inode(struct inode * inode)189 static inline devfs_handle_t devfs_get_handle_from_inode (struct inode *inode)
190 {
191     return NULL;
192 }
devfs_generate_path(devfs_handle_t de,char * path,int buflen)193 static inline int devfs_generate_path (devfs_handle_t de, char *path,
194 				       int buflen)
195 {
196     return -ENOSYS;
197 }
devfs_get_ops(devfs_handle_t de)198 static inline void *devfs_get_ops (devfs_handle_t de)
199 {
200     return NULL;
201 }
devfs_put_ops(devfs_handle_t de)202 static inline void devfs_put_ops (devfs_handle_t de)
203 {
204     return;
205 }
devfs_set_file_size(devfs_handle_t de,unsigned long size)206 static inline int devfs_set_file_size (devfs_handle_t de, unsigned long size)
207 {
208     return -ENOSYS;
209 }
devfs_get_info(devfs_handle_t de)210 static inline void *devfs_get_info (devfs_handle_t de)
211 {
212     return NULL;
213 }
devfs_set_info(devfs_handle_t de,void * info)214 static inline int devfs_set_info (devfs_handle_t de, void *info)
215 {
216     return 0;
217 }
devfs_get_parent(devfs_handle_t de)218 static inline devfs_handle_t devfs_get_parent (devfs_handle_t de)
219 {
220     return NULL;
221 }
devfs_get_first_child(devfs_handle_t de)222 static inline devfs_handle_t devfs_get_first_child (devfs_handle_t de)
223 {
224     return NULL;
225 }
devfs_get_next_sibling(devfs_handle_t de)226 static inline devfs_handle_t devfs_get_next_sibling (devfs_handle_t de)
227 {
228     return NULL;
229 }
devfs_auto_unregister(devfs_handle_t master,devfs_handle_t slave)230 static inline void devfs_auto_unregister (devfs_handle_t master,
231 					  devfs_handle_t slave)
232 {
233     return;
234 }
devfs_get_unregister_slave(devfs_handle_t master)235 static inline devfs_handle_t devfs_get_unregister_slave (devfs_handle_t master)
236 {
237     return NULL;
238 }
devfs_get_name(devfs_handle_t de,unsigned int * namelen)239 static inline const char *devfs_get_name (devfs_handle_t de,
240 					  unsigned int *namelen)
241 {
242     return NULL;
243 }
devfs_register_chrdev(unsigned int major,const char * name,struct file_operations * fops)244 static inline int devfs_register_chrdev (unsigned int major, const char *name,
245 					 struct file_operations *fops)
246 {
247     return register_chrdev (major, name, fops);
248 }
devfs_register_blkdev(unsigned int major,const char * name,struct block_device_operations * bdops)249 static inline int devfs_register_blkdev (unsigned int major, const char *name,
250 					 struct block_device_operations *bdops)
251 {
252     return register_blkdev (major, name, bdops);
253 }
devfs_unregister_chrdev(unsigned int major,const char * name)254 static inline int devfs_unregister_chrdev (unsigned int major,const char *name)
255 {
256     return unregister_chrdev (major, name);
257 }
devfs_unregister_blkdev(unsigned int major,const char * name)258 static inline int devfs_unregister_blkdev (unsigned int major,const char *name)
259 {
260     return unregister_blkdev (major, name);
261 }
262 
devfs_register_tape(devfs_handle_t de)263 static inline void devfs_register_tape (devfs_handle_t de)
264 {
265     return;
266 }
267 
devfs_register_series(devfs_handle_t dir,const char * format,unsigned int num_entries,unsigned int flags,unsigned int major,unsigned int minor_start,umode_t mode,void * ops,void * info)268 static inline void devfs_register_series (devfs_handle_t dir,
269 					  const char *format,
270 					  unsigned int num_entries,
271 					  unsigned int flags,
272 					  unsigned int major,
273 					  unsigned int minor_start,
274 					  umode_t mode, void *ops, void *info)
275 {
276     return;
277 }
278 
devfs_alloc_major(char type)279 static inline int devfs_alloc_major (char type)
280 {
281     return -1;
282 }
283 
devfs_dealloc_major(char type,int major)284 static inline void devfs_dealloc_major (char type, int major)
285 {
286     return;
287 }
288 
devfs_alloc_devnum(char type)289 static inline kdev_t devfs_alloc_devnum (char type)
290 {
291     return NODEV;
292 }
293 
devfs_dealloc_devnum(char type,kdev_t devnum)294 static inline void devfs_dealloc_devnum (char type, kdev_t devnum)
295 {
296     return;
297 }
298 
devfs_alloc_unique_number(struct unique_numspace * space)299 static inline int devfs_alloc_unique_number (struct unique_numspace *space)
300 {
301     return -1;
302 }
303 
devfs_dealloc_unique_number(struct unique_numspace * space,int number)304 static inline void devfs_dealloc_unique_number (struct unique_numspace *space,
305 						int number)
306 {
307     return;
308 }
309 
mount_devfs_fs(void)310 static inline void mount_devfs_fs (void)
311 {
312     return;
313 }
314 #endif  /*  CONFIG_DEVFS_FS  */
315 
316 #endif  /*  _LINUX_DEVFS_FS_KERNEL_H  */
317