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_MSGPORT_H_
51 #include <sys/msgport.h>
53 #ifndef _SYS_DIRENT_H_
54 #include <sys/dirent.h>
56 #ifndef _SYS_DEVICE_H_
57 #include <sys/device.h>
60 #include <sys/ucred.h>
65 Proot, /* the filesystem root */
73 ino_t d_ino; /* file number of entry */
74 uint16_t d_namlen; /* strlen(d_name) */
75 uint8_t d_type; /* file type */
80 uint16_t fid_len; /* Length of structure. */
81 uint16_t fid_pad; /* Force 32-bit alignment. */
83 ino_t fid_ino; /* File number (ino). */
87 cdev_t d_dev; /* device assoicated with this node */
89 struct mount *mp; /* mount point of this node */
90 struct devfs_dirent d_dir; /* dirent data (name, inode, ...) */
91 struct vnode *v_node; /* assoicated vnode */
92 struct devfs_node *parent; /* parent of this node */
93 devfs_nodetype node_type; /* devfs node type */
95 u_int64_t refs; /* number of open references */
96 size_t nchildren; /* number of children of a parent */
97 u_int64_t cookie_jar; /* cookie pool for children */
98 u_int64_t cookie; /* directory entry cookie for readdir */
100 struct devfs_node *link_target; /* target of this autolink-type node */
101 size_t nlinks; /* hard links */
103 char *symlink_name; /* symlink name for readlink */
104 size_t symlink_namelen; /* symlink name length for readlink */
106 u_short mode; /* files access mode and type */
107 uid_t uid; /* owner user id */
108 gid_t gid; /* owner group id */
111 struct timespec atime; /* time of last access */
112 struct timespec mtime; /* time of last modification */
113 struct timespec ctime; /* time file changed */
115 TAILQ_ENTRY(devfs_node) link;
116 TAILQ_HEAD(, devfs_node) list; /* linked list of children */
119 struct devfs_orphan {
120 struct devfs_node *node;
121 TAILQ_ENTRY(devfs_orphan) link;
124 struct devfs_mnt_data {
125 TAILQ_HEAD(, devfs_orphan) orphan_list;
126 TAILQ_ENTRY(devfs_mnt_data) link;
128 struct devfs_node *root_node;
136 struct devfs_clone_handler {
140 TAILQ_ENTRY(devfs_clone_handler) link;
148 TAILQ_ENTRY(devfs_alias) link;
152 typedef struct devfs_msg {
163 struct devfs_mnt_data *mnt;
190 struct devfs_node *node;
213 #define mdv_chandler __m_u.__m_chandler
214 #define mdv_mnt __m_u.__m_mnt.mnt
215 #define mdv_load __m_u.__m_gen.load
216 #define mdv_response __m_u.__m_resp.resp
217 #define mdv_dev __m_u.__m_dev
218 #define mdv_link __m_u.__m_link
219 #define mdv_udev __m_u.__m_udev.udev
220 #define mdv_cdev __m_u.__m_cdev.cdev
221 #define mdv_name __m_u.__m_name.name
222 #define mdv_clone __m_u.__m_clone
223 #define mdv_node __m_u.__m_node.node
224 #define mdv_ops __m_u.__m_ops
225 #define mdv_flags __m_u.__m_flags
226 #define mdv_ino __m_u.__m_ino
229 typedef struct devfs_core_args {
231 } *devfs_core_args_t;
233 TAILQ_HEAD(devfs_node_head, devfs_node);
234 TAILQ_HEAD(devfs_dev_head, cdev);
235 TAILQ_HEAD(devfs_mnt_head, devfs_mnt_data);
236 TAILQ_HEAD(devfs_chandler_head, devfs_clone_handler);
237 TAILQ_HEAD(devfs_alias_head, devfs_alias);
239 typedef void (devfs_scan_t)(cdev_t);
240 typedef void* (devfs_iterate_callback_t)(struct devfs_node *, void *);
242 #define DEVFS_NODE(x) ((struct devfs_node *)((x)->v_data))
243 #define DEVFS_MNTDATA(x) ((struct devfs_mnt_data *)((x)->mnt_data))
244 #define DEVFS_ORPHANLIST(x) (&(DEVFS_MNTDATA(x)->orphan_list))
245 #define DEVFS_DENODE_HEAD(x) (&((x)->list))
246 #define DEVFS_ISDIGIT(x) ((x >= '0') && (x <= '9'))
251 #define DEVFS_DEFAULT_MODE ((VREAD|VWRITE|VEXEC) | ((VREAD|VEXEC)>>3) | \
254 #define DEVFS_DEFAULT_UID 0 /* root */
255 #define DEVFS_DEFAULT_GID 5 /* operator */
260 #define DEVFS_DEBUG_SHOW 0x00
261 #define DEVFS_DEBUG_WARNING 0x01
262 #define DEVFS_DEBUG_INFO 0x02
263 #define DEVFS_DEBUG_DEBUG 0x03
268 #define DEVFS_TERMINATE_CORE 0x01
269 #define DEVFS_DEVICE_CREATE 0x02
270 #define DEVFS_DEVICE_DESTROY 0x03
271 #define DEVFS_MOUNT_ADD 0x04
272 #define DEVFS_MOUNT_DEL 0x05
273 #define DEVFS_CREATE_ALL_DEV 0x06
274 #define DEVFS_DESTROY_SUBNAMES 0x07
275 #define DEVFS_DESTROY_DEV_BY_OPS 0x08
276 #define DEVFS_CHANDLER_ADD 0x09
277 #define DEVFS_CHANDLER_DEL 0x0A
278 #define DEVFS_FIND_DEVICE_BY_UDEV 0x0B
279 #define DEVFS_FIND_DEVICE_BY_NAME 0x0C
280 #define DEVFS_MAKE_ALIAS 0x0D
281 #define DEVFS_APPLY_RULES 0x0F
282 #define DEVFS_RESET_RULES 0x10
283 #define DEVFS_SCAN_CALLBACK 0x11
284 #define DEVFS_CLR_SUBNAMES_FLAG 0x12
285 #define DEVFS_DESTROY_SUBNAMES_WO_FLAG 0x13
286 #define DEVFS_INODE_TO_VNODE 0x14
287 #define DEVFS_SYNC 0x99
292 * HIDDEN Makes node inaccessible, apart from already allocated vnodes
293 * INVISIBLE Makes node invisible in a readdir()
295 #define DEVFS_NODE_LINKED 0x001 /* Linked into topology */
296 #define DEVFS_USER_CREATED 0x002 /* Node was user-created */
297 #define DEVFS_ORPHANED 0x004 /* on orphan list */
298 #define DEVFS_CLONED 0x008 /* Created by cloning code */
299 #define DEVFS_HIDDEN 0x010 /* Makes node inaccessible */
300 #define DEVFS_INVISIBLE 0x020 /* Makes node invisible */
301 #define DEVFS_PTY 0x040 /* PTY device */
302 #define DEVFS_DESTROYED 0x080 /* Sanity check */
303 #define DEVFS_RULE_CREATED 0x100 /* Node was rule-created */
309 #define DEVFS_BITMAP_INITIAL_SIZE 1
310 #define DEVFS_CLONE_BITMAP(name) devfs_ ## name ## _clone_bitmap
311 #define DEVFS_DECLARE_CLONE_BITMAP(name) \
312 struct devfs_bitmap DEVFS_CLONE_BITMAP(name)
313 #define devfs_clone_bitmap_put devfs_clone_bitmap_rst
315 struct devfs_bitmap {
317 unsigned long *bitmap;
320 struct devfs_unit_hash {
321 struct devfs_unit_hash *next;
326 void devfs_clone_bitmap_init(struct devfs_bitmap *);
327 void devfs_clone_bitmap_uninit(struct devfs_bitmap *);
328 void devfs_clone_bitmap_resize(struct devfs_bitmap *, int);
329 int devfs_clone_bitmap_fff(struct devfs_bitmap *);
330 void devfs_clone_bitmap_set(struct devfs_bitmap *, int);
331 void devfs_clone_bitmap_rst(struct devfs_bitmap *, int);
332 int devfs_clone_bitmap_get(struct devfs_bitmap *, int);
333 int devfs_clone_bitmap_chk(struct devfs_bitmap *, int);
338 int devfs_debug(int level, char *fmt, ...);
339 int devfs_allocv(struct vnode **, struct devfs_node *);
340 struct devfs_node *devfs_allocp(devfs_nodetype, char *, struct devfs_node *,
341 struct mount *, cdev_t);
342 int devfs_allocvp(struct mount *, struct vnode **, devfs_nodetype, char *,
343 struct devfs_node *, cdev_t);
345 int devfs_freep(struct devfs_node *);
347 int devfs_unlinkp(struct devfs_node *);
349 void devfs_tracer_add_orphan(struct devfs_node *);
350 void devfs_tracer_del_orphan(struct devfs_node *);
351 size_t devfs_tracer_orphan_count(struct mount *, int);
353 int devfs_set_perms(struct devfs_node *, uid_t, gid_t, u_short, u_long);
354 int devfs_gc(struct devfs_node *);
356 int devfs_create_dev(cdev_t, uid_t, gid_t, int);
357 int devfs_destroy_dev(cdev_t);
359 devfs_msg_t devfs_msg_send_sync(uint32_t, devfs_msg_t);
360 void devfs_msg_send(uint32_t, devfs_msg_t);
361 void devfs_msg_send_dev(uint32_t, cdev_t dev, uid_t, gid_t, int);
362 void devfs_msg_send_mount(uint32_t, struct devfs_mnt_data *);
363 void devfs_msg_send_ops(uint32_t, struct dev_ops *, int);
364 void devfs_msg_send_chandler(uint32_t, char *, d_clone_t);
365 void devfs_msg_send_generic(uint32_t, void *);
366 void devfs_msg_send_name(uint32_t, char *);
367 void devfs_msg_send_link(uint32_t, char *, char *, struct mount *);
369 devfs_msg_t devfs_msg_get(void);
370 int devfs_msg_put(devfs_msg_t);
372 int devfs_mount_add(struct devfs_mnt_data *);
373 int devfs_mount_del(struct devfs_mnt_data *);
375 int devfs_create_all_dev(struct devfs_node *);
377 struct devfs_node *devfs_resolve_or_create_path(
378 struct devfs_node *, char *, int);
379 int devfs_resolve_name_path(char *, char *, char **, char **);
380 struct devfs_node *devfs_create_device_node(struct devfs_node *, cdev_t,
381 char *, char *, ...);
383 int devfs_destroy_device_node(struct devfs_node *, cdev_t);
384 int devfs_destroy_subnames(char *);
385 int devfs_destroy_dev_by_ops(struct dev_ops *, int);
386 struct devfs_node *devfs_find_device_node_by_name(struct devfs_node *, char *);
388 cdev_t devfs_new_cdev(struct dev_ops *, int);
390 cdev_t devfs_find_device_by_name(const char *, ...);
391 cdev_t devfs_find_device_by_udev(udev_t);
393 struct vnode *devfs_inode_to_vnode(struct mount *, ino_t);
395 int devfs_clone_handler_add(const char *, d_clone_t *);
396 int devfs_clone_handler_del(const char *);
397 cdev_t devfs_clone(cdev_t, const char *, size_t, int, struct ucred *);
399 int devfs_link_dev(cdev_t);
401 int devfs_make_alias(const char *, cdev_t);
403 int devfs_alias_create(char *, struct devfs_node *, int);
405 int devfs_apply_rules(char *);
406 int devfs_reset_rules(char *);
408 int devfs_scan_callback(devfs_scan_t *);
409 int devfs_node_to_path(struct devfs_node *, char *);
411 int devfs_clr_subnames_flag(char *, uint32_t);
412 int devfs_destroy_subnames_without_flag(char *, uint32_t);
413 int devfs_node_is_accessible(struct devfs_node *);
415 int devfs_reference_ops(struct dev_ops *);
416 void devfs_release_ops(struct dev_ops *);
418 void devfs_config(void);
420 void *devfs_iterate_topology(struct devfs_node *node,
421 devfs_iterate_callback_t *callback, void *arg1);
423 void *devfs_find_device_node_callback(struct devfs_node *, cdev_t);
425 #endif /* _VFS_DEVFS_H_ */