2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if !defined(_KERNEL) && !defined(_KERNEL_STRUCTURES)
38 #error "This file should not be included by userland programs."
42 #include <sys/queue.h>
50 #ifndef _SYS_MSGPORT2_H_
51 //#include <sys/msgport2.h>
53 #ifndef _SYS_MSGPORT_H_
54 #include <sys/msgport.h>
56 #ifndef _SYS_DIRENT_H_
57 #include <sys/dirent.h>
59 #ifndef _SYS_DEVICE_H_
60 #include <sys/device.h>
63 #include <sys/ucred.h>
68 Proot, /* the filesystem root */
81 //XXX: do I need a use count so I know when it is safe to
82 // unload the module or detach or whatever?
83 TAILQ_ENTRY(devfs_dev) link;
88 cdev_t d_dev; /* device assoicated with this node */
90 struct mount *mp; /* mount point of this node */
91 struct dirent d_dir; /* dirent data (name, inode, ...) */
92 struct vnode *v_node; /* assoicated vnode */
93 struct devfs_node *parent; /* parent of this node */
94 devfs_nodetype node_type; /* devfs node type */
96 u_int64_t refs; /* number of open references */
97 size_t nchildren; /* number of children of a parent */
98 u_int64_t cookie_jar; /* cookie pool for children */
99 u_int64_t cookie; /* directory entry cookie for readdir */
101 struct devfs_node *link_target; /* target of this autolink-type node */
102 size_t nlinks; /* number of links that point to this node */
104 char *symlink_name; /* symlink name for readlink */
105 size_t symlink_namelen; /* symlink name length for readlink */
107 u_short mode; /* files access mode and type */
108 uid_t uid; /* owner user id */
109 gid_t gid; /* owner group id */
112 struct timespec atime; /* time of last access */
113 struct timespec mtime; /* time of last modification */
114 struct timespec ctime; /* time file changed */
119 TAILQ_ENTRY(devfs_node) link;
120 TAILQ_HEAD(, devfs_node) list; /* linked list of children */
123 struct devfs_orphan {
124 struct devfs_node *node;
126 TAILQ_ENTRY(devfs_orphan) link;
129 struct devfs_mnt_data {
130 TAILQ_HEAD(, devfs_orphan) orphan_list;
132 struct devfs_node *root_node;
140 TAILQ_ENTRY(devfs_mnt_data) link;
143 struct devfs_clone_handler {
148 TAILQ_ENTRY(devfs_clone_handler) link;
153 char name[PATH_MAX + 1];
156 TAILQ_ENTRY(devfs_alias) link;
160 typedef struct devfs_msg {
172 struct devfs_mnt_data *mnt;
199 struct devfs_node *node;
212 #define m_chandler __m_u.__m_chandler
213 #define m_mnt __m_u.__m_mnt.mnt
214 #define m_load __m_u.__m_gen.load
215 #define m_response __m_u.__m_resp.resp
216 #define m_dev __m_u.__m_dev
217 #define m_link __m_u.__m_link
218 #define m_udev __m_u.__m_udev.udev
219 #define m_cdev __m_u.__m_cdev.cdev
220 #define m_name __m_u.__m_name.name
221 #define m_clone __m_u.__m_clone
222 #define m_node __m_u.__m_node.node
223 #define m_ops __m_u.__m_ops
227 typedef struct devfs_core_args {
229 } *devfs_core_args_t;
232 TAILQ_HEAD(devfs_node_head, devfs_node);
233 TAILQ_HEAD(devfs_dev_head, cdev);
234 TAILQ_HEAD(devfs_mnt_head, devfs_mnt_data);
235 TAILQ_HEAD(devfs_chandler_head, devfs_clone_handler);
236 TAILQ_HEAD(devfs_alias_head, devfs_alias);
238 typedef void (devfs_scan_t)(cdev_t);
241 #define DEVFS_NODE(x) ((struct devfs_node *)((x)->v_data))
242 #define DEVFS_MNTDATA(x) ((struct devfs_mnt_data *)((x)->mnt_data))
243 #define DEVFS_ORPHANLIST(x) (&(DEVFS_MNTDATA(x)->orphan_list))
244 #define DEVFS_DENODE_HEAD(x) (&((x)->list))
245 #define DEVFS_ISDIGIT(x) ((x >= '0') && (x <= '9'))
247 #define DEVFS_DEFAULT_MODE ((VREAD|VWRITE|VEXEC) | ((VREAD|VEXEC)>>3) | ((VREAD|VEXEC)>>6)); /* -rwxr-xr-x */
248 #define DEVFS_DEFAULT_UID 0 /* root */
249 #define DEVFS_DEFAULT_GID 5 /* operator */
251 //#define DEVFS_DEFAULT_FLAGS 0
256 #define DEVFS_DEBUG_SHOW 0x00
257 #define DEVFS_DEBUG_WARNING 0x01
258 #define DEVFS_DEBUG_INFO 0x02
259 #define DEVFS_DEBUG_DEBUG 0x03
264 #define DEVFS_TERMINATE_CORE 0x01
265 #define DEVFS_DEVICE_CREATE 0x02
266 #define DEVFS_DEVICE_DESTROY 0x03
267 #define DEVFS_MOUNT_ADD 0x04
268 #define DEVFS_MOUNT_DEL 0x05
269 #define DEVFS_CREATE_ALL_DEV 0x06
270 #define DEVFS_DESTROY_SUBNAMES 0x07
271 #define DEVFS_DESTROY_DEV_BY_OPS 0x08
272 #define DEVFS_CHANDLER_ADD 0x09
273 #define DEVFS_CHANDLER_DEL 0x0A
274 #define DEVFS_FIND_DEVICE_BY_UDEV 0x0B
275 #define DEVFS_FIND_DEVICE_BY_NAME 0x0C
276 #define DEVFS_MAKE_ALIAS 0x0D
277 #define DEVFS_APPLY_RULES 0x0F
278 #define DEVFS_RESET_RULES 0x10
279 #define DEVFS_SCAN_CALLBACK 0x11
280 #define DEVFS_SYNC 0x99
285 #define DEVFS_NODE_LINKED 0x01 /* Node is linked into topology */
286 #define DEVFS_USER_CREATED 0x02 /* Node was user-created */
287 #define DEVFS_NO_TRACE 0x04 /* Don't trace orphanage */
288 #define DEVFS_CLONED 0x08 /* Node was created by the clone code */
289 #define DEVFS_HIDDEN 0x10 /* Makes node inaccessible, apart from already allocated vnodes*/
290 #define DEVFS_INVISIBLE 0x20 /* Makes node invisible in a readdir() */
291 #define DEVFS_PTY 0x40 /* Node is linked to a PTY device */
292 //#define DEVFS_LINK 0x20
298 #define DEVFS_UNIT_HSIZE 64 /* power of 2 */
299 #define DEVFS_UNIT_HMASK (DEVFS_UNIT_HSIZE - 1)
300 #define DEVFS_CLONE_HASHLIST(name) devfs_ ## name ## _clone_hashlist
301 #define DEVFS_DECLARE_CLONE_HASHLIST(name) struct devfs_unit_hash* DEVFS_CLONE_HASHLIST(name) [DEVFS_UNIT_HSIZE]
304 #define DEVFS_BITMAP_INITIAL_SIZE 1
305 #define DEVFS_CLONE_BITMAP(name) devfs_ ## name ## _clone_bitmap
306 #define DEVFS_DECLARE_CLONE_BITMAP(name) struct devfs_bitmap DEVFS_CLONE_BITMAP(name)
307 #define devfs_clone_bitmap_put devfs_clone_bitmap_rst
309 struct devfs_bitmap {
311 unsigned long *bitmap;
314 struct devfs_unit_hash {
315 struct devfs_unit_hash *next;
321 struct devfs_clone_helper {
322 DEVFS_DECLARE_CLONE_HASHLIST(generic);
323 DEVFS_DECLARE_CLONE_BITMAP(generic);
326 #define DEVFS_CLONE_HELPER(name) devfs_ ## name ## _clone_helper
327 #define DEVFS_DECLARE_CLONE_HELPER(name) static struct devfs_clone_helper DEVFS_CLONE_HELPER(name)
330 void devfs_clone_bitmap_init(struct devfs_bitmap *);
331 void devfs_clone_bitmap_uninit(struct devfs_bitmap *);
332 void devfs_clone_bitmap_resize(struct devfs_bitmap *, int);
333 int devfs_clone_bitmap_fff(struct devfs_bitmap *);
334 void devfs_clone_bitmap_set(struct devfs_bitmap *, int);
335 void devfs_clone_bitmap_rst(struct devfs_bitmap *, int);
336 int devfs_clone_bitmap_get(struct devfs_bitmap *, int);
337 int devfs_clone_bitmap_chk(struct devfs_bitmap *, int);
339 void devfs_clone_helper_init(struct devfs_clone_helper *);
340 void devfs_clone_helper_uninit(struct devfs_clone_helper *);
341 int devfs_clone_helper_insert(struct devfs_clone_helper *, cdev_t);
342 int devfs_clone_helper_remove(struct devfs_clone_helper *, int);
348 int devfs_debug(int level, char *fmt, ...);
349 int devfs_allocv(struct vnode **, struct devfs_node *);
350 struct devfs_node *devfs_allocp(devfs_nodetype, char *, struct devfs_node *, struct mount *, cdev_t);
351 int devfs_allocvp(struct mount *, struct vnode **, devfs_nodetype, char *, struct devfs_node *, cdev_t);
353 int devfs_freep(struct devfs_node *);
354 int devfs_reaperp(struct devfs_node *);
356 int devfs_unlinkp(struct devfs_node *);
358 void devfs_tracer_add_orphan(struct devfs_node *);
359 void devfs_tracer_del_orphan(struct devfs_node *);
360 size_t devfs_tracer_orphan_count(struct mount *, int);
362 int devfs_set_perms(struct devfs_node *, uid_t, gid_t, u_short, u_long);
363 int devfs_gc(struct devfs_node *);
365 int devfs_create_dev(cdev_t, uid_t, gid_t, int);
366 int devfs_destroy_dev(cdev_t);
368 devfs_msg_t devfs_msg_send_sync(uint32_t, devfs_msg_t);
369 __uint32_t devfs_msg_send(uint32_t, devfs_msg_t);
370 __uint32_t devfs_msg_send_dev(uint32_t, cdev_t dev, uid_t, gid_t, int);
371 __uint32_t devfs_msg_send_mount(uint32_t, struct devfs_mnt_data *);
372 __uint32_t devfs_msg_send_ops(uint32_t, struct dev_ops *, int);
373 __uint32_t devfs_msg_send_chandler(uint32_t, char *, d_clone_t);
374 __uint32_t devfs_msg_send_generic(uint32_t, void *);
375 __uint32_t devfs_msg_send_name(uint32_t, char *);
376 __uint32_t devfs_msg_send_link(uint32_t, char *, char *, struct mount *);
378 devfs_msg_t devfs_msg_get(void);
379 int devfs_msg_put(devfs_msg_t);
381 int devfs_mount_add(struct devfs_mnt_data *);
382 int devfs_mount_del(struct devfs_mnt_data *);
384 int devfs_create_all_dev(struct devfs_node *);
386 struct devfs_node *devfs_resolve_or_create_path(struct devfs_node *, char *, int);
387 int devfs_resolve_name_path(char *, char *, char **, char **);
388 struct devfs_node *devfs_create_device_node(struct devfs_node *, cdev_t, char *, char *, ...);
390 int devfs_destroy_device_node(struct devfs_node *, cdev_t);
391 int devfs_destroy_subnames(char *);
392 int devfs_destroy_dev_by_ops(struct dev_ops *, int);
393 struct devfs_node *devfs_find_device_node(struct devfs_node *, cdev_t);
394 struct devfs_node *devfs_find_device_node_by_name(struct devfs_node *, char *);
396 cdev_t devfs_new_cdev(struct dev_ops *, int);
397 int devfs_destroy_cdev(cdev_t);
399 cdev_t devfs_find_device_by_name(const char *, ...);
400 cdev_t devfs_find_device_by_udev(udev_t);
402 int devfs_clone_handler_add(char *, d_clone_t *);
403 int devfs_clone_handler_del(char *);
404 int devfs_clone(char *, size_t *, cdev_t *, int, struct ucred *);
406 int devfs_link_dev(cdev_t);
407 int devfs_unlink_dev(cdev_t);
409 int devfs_make_alias(char *, cdev_t);
411 int devfs_alias_create(char *name_orig, struct devfs_node *target);
413 int devfs_apply_rules(char *);
414 int devfs_reset_rules(char *);
416 int devfs_scan_callback(devfs_scan_t *);
417 int devfs_node_to_path(struct devfs_node *, char *);
419 void devfs_config(void *);
420 #endif /* _VFS_DEVFS_H_ */