Unleashed v1.4
[unleashed.git] / include / sys / devcache_impl.h
blob925da85c2831ac7f04235aaddc5e0dfb93e07eee
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_DEVCACHE_IMPL_H
27 #define _SYS_DEVCACHE_IMPL_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 #include <sys/list.h>
38 * /etc/devices cache files format
39 * Leave some padding for easy extension in the future
42 #define NVPF_HDR_MAGIC 0xdeb1dcac
43 #define NVPF_HDR_VERSION 1
44 #define NVPF_HDR_SIZE 128
46 typedef struct nvpacked_file_hdr {
47 union {
48 struct nvfp_hdr {
49 uint32_t magic;
50 int32_t version;
51 int64_t size;
52 uint16_t hdr_chksum;
53 uint16_t chksum;
54 } nvpf;
55 uchar_t nvpf_pad[NVPF_HDR_SIZE];
56 } un;
57 } nvpf_hdr_t;
59 #define nvpf_magic un.nvpf.magic
60 #define nvpf_version un.nvpf.version
61 #define nvpf_size un.nvpf.size
62 #define nvpf_hdr_chksum un.nvpf.hdr_chksum
63 #define nvpf_chksum un.nvpf.chksum
66 #ifdef _KERNEL
69 * Descriptor used for kernel-level file i/o
71 typedef struct kfile {
72 struct vnode *kf_vp;
73 int kf_vnflags;
74 char *kf_fname;
75 offset_t kf_fpos;
76 int kf_state;
77 } kfile_t;
80 * File descriptor for files in the nvlist format
82 typedef struct nvfiledesc nvfd_t;
85 * Descriptor for a file managed as a backing store for some
86 * kernel-generated device state such as device devids,
87 * vhci-to-phci mapping, etc.
88 * Each client can manage the data in any form convenient.
89 * providing functions to unpack (read) and pack (write)
90 * the data as an nvlist.
92 * Clients should not reference this structure directly
93 * but through the handle returned when registering.
95 struct nvfiledesc {
96 nvf_ops_t *nvf_ops; /* client ops vectors */
97 int nvf_flags; /* flags */
98 list_t nvf_data_list; /* data list */
99 krwlock_t nvf_lock; /* lock for data list */
100 list_node_t nvf_link; /* link to next file desc */
104 * nvf_flags
106 #define NVF_F_DIRTY 0x01 /* needs to be flushed */
107 #define NVF_F_FLUSHING 0x02 /* in process of being flushed */
108 #define NVF_F_ERROR 0x04 /* most recent flush failed */
109 #define NVF_F_READONLY 0x10 /* file is read-only */
110 #define NVF_F_CREATE_MSG 0x20 /* file not found on boot, emit msg */
111 #define NVF_F_REBUILD_MSG 0x40 /* file was found corrupted, emit msg */
113 #define NVF_IS_DIRTY(nvfd) ((nvfd)->nvf_flags & NVF_F_DIRTY)
114 #define NVF_MARK_DIRTY(nvfd) ((nvfd)->nvf_flags |= NVF_F_DIRTY)
115 #define NVF_CLEAR_DIRTY(nvfd) ((nvfd)->nvf_flags &= ~NVF_F_DIRTY)
117 #define NVF_IS_READONLY(nvfd) ((nvfd)->nvf_flags & NVF_F_READONLY)
118 #define NVF_MARK_READONLY(nvfd) ((nvfd)->nvf_flags |= NVF_F_READONLY)
120 /* shorthand to client ops */
121 #define nvf_cache_path nvf_ops->nvfr_cache_path
122 #define nvf_unpack_nvlist nvf_ops->nvfr_unpack_nvlist
123 #define nvf_pack_list nvf_ops->nvfr_pack_list
124 #define nvf_list_free nvf_ops->nvfr_list_free
125 #define nvf_write_complete nvf_ops->nvfr_write_complete
129 * More thorough error reporting available both debug &
130 * non-debug kernels, but turned off by default.
132 extern int kfio_report_error; /* kernel file i/o operations */
135 * Suffix of temporary file for updates
137 #define MAX_SUFFIX_LEN 4
138 #define NEW_FILENAME_SUFFIX "new"
141 #ifdef DEBUG
143 #define NVPDAEMON_DEBUG(args) { if (nvpdaemon_debug) cmn_err args; }
144 #define KFDEBUG(args) { if (kfio_debug) cmn_err args; }
145 #define KFDEBUG1(args) { if (kfio_debug > 1) cmn_err args; }
146 #define KFDEBUG2(args) { if (kfio_debug > 2) cmn_err args; }
147 #define KFDUMP(args) { if (kfio_debug > 2) args; }
149 #else
151 #define NVPDAEMON_DEBUG(args)
152 #define KFDEBUG(args)
153 #define KFDEBUG1(args)
154 #define KFDEBUG2(args)
155 #define KFDUMP(args)
157 #endif /* DEBUG */
160 #endif /* _KERNEL */
162 #ifdef __cplusplus
164 #endif
166 #endif /* _SYS_DEVCACHE_IMPL_H */