Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/lofi.h
+++ new/usr/src/uts/common/sys/lofi.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25
26 26 #ifndef _SYS_LOFI_H
27 27 #define _SYS_LOFI_H
28 28
29 29 #include <sys/types.h>
30 30 #include <sys/time.h>
31 31 #include <sys/taskq.h>
32 32 #include <sys/vtoc.h>
33 33 #include <sys/dkio.h>
34 34 #include <sys/vnode.h>
35 35 #include <sys/list.h>
36 36 #include <sys/crypto/api.h>
37 37 #include <sys/zone.h>
38 38
39 39 #ifdef __cplusplus
40 40 extern "C" {
41 41 #endif
42 42
43 43 /*
44 44 * /dev names:
45 45 * /dev/lofictl - master control device
46 46 * /dev/lofi - block devices, named by minor number
47 47 * /dev/rlofi - character devices, named by minor number
48 48 */
49 49 #define LOFI_DRIVER_NAME "lofi"
50 50 #define LOFI_CTL_NODE "ctl"
51 51 #define LOFI_CTL_NAME LOFI_DRIVER_NAME LOFI_CTL_NODE
52 52 #define LOFI_BLOCK_NAME LOFI_DRIVER_NAME
53 53 #define LOFI_CHAR_NAME "r" LOFI_DRIVER_NAME
54 54
55 55 #define SEGHDR 1
56 56 #define COMPRESSED 1
57 57 #define UNCOMPRESSED 0
58 58 #define MAXALGLEN 36
59 59
60 60 /*
61 61 *
62 62 * Use is:
63 63 * ld = open("/dev/lofictl", O_RDWR | O_EXCL);
64 64 *
65 65 * lofi must be opened exclusively. Access is controlled by permissions on
66 66 * the device, which is 644 by default. Write-access is required for ioctls
67 67 * that change state, but only read-access is required for the ioctls that
68 68 * return information. Basically, only root can add and remove files, but
69 69 * non-root can look at the current lists.
70 70 *
71 71 * ioctl usage:
72 72 *
73 73 * kernel ioctls
74 74 *
75 75 * strcpy(li.li_filename, "somefilename");
76 76 * ioctl(ld, LOFI_MAP_FILE, &li);
77 77 * newminor = li.li_minor;
78 78 *
79 79 * strcpy(li.li_filename, "somefilename");
80 80 * ioctl(ld, LOFI_UNMAP_FILE, &li);
81 81 *
82 82 * strcpy(li.li_filename, "somefilename");
83 83 * li.li_minor = minor_number;
84 84 * ioctl(ld, LOFI_MAP_FILE_MINOR, &li);
85 85 *
86 86 * li.li_minor = minor_number;
87 87 * ioctl(ld, LOFI_UNMAP_FILE_MINOR, &li);
88 88 *
89 89 * li.li_minor = minor_number;
90 90 * ioctl(ld, LOFI_GET_FILENAME, &li);
91 91 * filename = li.li_filename;
92 92 * encrypted = li.li_crypto_enabled;
93 93 *
94 94 * strcpy(li.li_filename, "somefilename");
95 95 * ioctl(ld, LOFI_GET_MINOR, &li);
96 96 * minor = li.li_minor;
97 97 *
98 98 * li.li_minor = 0;
99 99 * ioctl(ld, LOFI_GET_MAXMINOR, &li);
100 100 * maxminor = li.li_minor;
101 101 *
102 102 * strcpy(li.li_filename, "somefilename");
103 103 * li.li_minor = 0;
104 104 * ioctl(ld, LOFI_CHECK_COMPRESSED, &li);
105 105 *
106 106 * If the 'li_force' flag is set for any of the LOFI_UNMAP_* commands, then if
107 107 * the device is busy, the underlying vnode will be closed, and any subsequent
108 108 * operations will fail. It will behave as if the device had been forcibly
109 109 * removed, so the DKIOCSTATE ioctl will return DKIO_DEV_GONE. When the device
110 110 * is last closed, it will be torn down.
111 111 *
112 112 * If the 'li_cleanup' flag is set for any of the LOFI_UNMAP_* commands, then
113 113 * if the device is busy, it is marked for removal at the next time it is
114 114 * no longer held open by anybody. When the device is last closed, it will be
115 115 * torn down.
116 116 *
117 117 * Oh, and last but not least: these ioctls are totally private and only
118 118 * for use by lofiadm(1M).
119 119 *
120 120 */
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
121 121
122 122 typedef enum iv_method {
123 123 IVM_NONE, /* no iv needed, iv is null */
124 124 IVM_ENC_BLKNO /* iv is logical block no. encrypted */
125 125 } iv_method_t;
126 126
127 127 struct lofi_ioctl {
128 128 uint32_t li_minor;
129 129 boolean_t li_force;
130 130 boolean_t li_cleanup;
131 + boolean_t li_readonly;
131 132 char li_filename[MAXPATHLEN];
132 133
133 134 /* the following fields are required for compression support */
134 135 char li_algorithm[MAXALGLEN];
135 136
136 137 /* the following fields are required for encryption support */
137 138 boolean_t li_crypto_enabled;
138 139 crypto_mech_name_t li_cipher; /* for data */
139 140 uint32_t li_key_len; /* for data */
140 141 char li_key[56]; /* for data: max 448-bit Blowfish key */
141 142 crypto_mech_name_t li_iv_cipher; /* for iv derivation */
142 143 uint32_t li_iv_len; /* for iv derivation */
143 144 iv_method_t li_iv_type; /* for iv derivation */
144 145 };
145 146
146 147 #define LOFI_IOC_BASE (('L' << 16) | ('F' << 8))
147 148
148 149 #define LOFI_MAP_FILE (LOFI_IOC_BASE | 0x01)
149 150 #define LOFI_MAP_FILE_MINOR (LOFI_IOC_BASE | 0x02)
150 151 #define LOFI_UNMAP_FILE (LOFI_IOC_BASE | 0x03)
151 152 #define LOFI_UNMAP_FILE_MINOR (LOFI_IOC_BASE | 0x04)
152 153 #define LOFI_GET_FILENAME (LOFI_IOC_BASE | 0x05)
153 154 #define LOFI_GET_MINOR (LOFI_IOC_BASE | 0x06)
154 155 #define LOFI_GET_MAXMINOR (LOFI_IOC_BASE | 0x07)
155 156 #define LOFI_CHECK_COMPRESSED (LOFI_IOC_BASE | 0x08)
156 157
157 158 /*
158 159 * file types that might be usable with lofi, maybe. Only regular
159 160 * files are documented though.
160 161 */
161 162 #define S_ISLOFIABLE(mode) \
162 163 (S_ISREG(mode) || S_ISBLK(mode) || S_ISCHR(mode))
163 164
164 165 #if defined(_KERNEL)
165 166
166 167
167 168 /*
168 169 * Cache decompressed data segments for the compressed lofi images.
169 170 *
170 171 * To avoid that we have to decompress data of a compressed
171 172 * segment multiple times when accessing parts of the segment's
172 173 * data we cache the uncompressed data, using a simple linked list.
173 174 */
174 175 struct lofi_comp_cache {
175 176 list_node_t lc_list; /* linked list */
176 177 uchar_t *lc_data; /* decompressed segment data */
177 178 uint64_t lc_index; /* segment index */
178 179 };
179 180
180 181 #define V_ISLOFIABLE(vtype) \
181 182 ((vtype == VREG) || (vtype == VBLK) || (vtype == VCHR))
182 183
183 184 /*
184 185 * Pre-allocated memory buffers for the purpose of compression
185 186 */
186 187 struct compbuf {
187 188 void *buf;
188 189 uint32_t bufsize;
189 190 int inuse;
190 191 };
191 192
192 193 /*
193 194 * Need exactly 6 bytes to identify encrypted lofi image
194 195 */
195 196 extern const char lofi_crypto_magic[6];
196 197 #define LOFI_CRYPTO_MAGIC { 'C', 'F', 'L', 'O', 'F', 'I' }
197 198 #define LOFI_CRYPTO_VERSION ((uint16_t)0)
198 199 #define LOFI_CRYPTO_DATA_SECTOR ((uint32_t)16) /* for version 0 */
199 200
200 201 /*
201 202 * Crypto metadata for encrypted lofi images
202 203 * The fields here only satisfy initial implementation requirements.
203 204 */
204 205 struct crypto_meta {
205 206 char magic[6]; /* LOFI_CRYPTO_MAGIC */
206 207 uint16_t version; /* version of encrypted lofi */
207 208 char reserved1[96]; /* future use */
208 209 uint32_t data_sector; /* start of data area */
209 210 char pad[404]; /* end on DEV_BSIZE bdry */
210 211 /* second header block is not defined at this time */
211 212 };
212 213
213 214 struct lofi_state {
214 215 vnode_t *ls_vp; /* open real vnode */
215 216 vnode_t *ls_stacked_vp; /* open vnode */
↓ open down ↓ |
75 lines elided |
↑ open up ↑ |
216 217 kmutex_t ls_vp_lock; /* protects ls_vp */
217 218 kcondvar_t ls_vp_cv; /* signal changes to ls_vp */
218 219 uint32_t ls_vp_iocount; /* # pending I/O requests */
219 220 boolean_t ls_vp_closereq; /* force close requested */
220 221 u_offset_t ls_vp_size;
221 222 uint32_t ls_blk_open;
222 223 uint32_t ls_chr_open;
223 224 uint32_t ls_lyr_open_count;
224 225 int ls_openflag;
225 226 boolean_t ls_cleanup; /* cleanup on close */
227 + boolean_t ls_readonly;
226 228 taskq_t *ls_taskq;
227 229 kstat_t *ls_kstat;
228 230 kmutex_t ls_kstat_lock;
229 231 struct dk_geom ls_dkg;
230 232 struct vtoc ls_vtoc;
231 233 struct dk_cinfo ls_ci;
232 234 zone_ref_t ls_zone;
233 235 list_node_t ls_list; /* all lofis */
234 236 dev_t ls_dev; /* this node's dev_t */
235 237
236 238 /* the following fields are required for compression support */
237 239 int ls_comp_algorithm_index; /* idx into compress_table */
238 240 char ls_comp_algorithm[MAXALGLEN];
239 241 uint32_t ls_uncomp_seg_sz; /* sz of uncompressed segment */
240 242 uint32_t ls_comp_index_sz; /* number of index entries */
241 243 uint32_t ls_comp_seg_shift; /* exponent for byte shift */
242 244 uint32_t ls_uncomp_last_seg_sz; /* sz of last uncomp segment */
243 245 uint64_t ls_comp_offbase; /* offset of actual compressed data */
244 246 uint64_t *ls_comp_seg_index; /* array of index entries */
245 247 caddr_t ls_comp_index_data; /* index pages loaded from file */
246 248 uint32_t ls_comp_index_data_sz;
247 249 u_offset_t ls_vp_comp_size; /* actual compressed file size */
248 250
249 251 /* pre-allocated list of buffers for compressed segment data */
250 252 kmutex_t ls_comp_bufs_lock;
251 253 struct compbuf *ls_comp_bufs;
252 254
253 255 /* lock and anchor for compressed segment caching */
254 256 kmutex_t ls_comp_cache_lock; /* protects ls_comp_cache */
255 257 list_t ls_comp_cache; /* cached decompressed segs */
256 258 uint32_t ls_comp_cache_count;
257 259
258 260 /* the following fields are required for encryption support */
259 261 boolean_t ls_crypto_enabled;
260 262 u_offset_t ls_crypto_offset; /* crypto meta size */
261 263 struct crypto_meta ls_crypto;
262 264 crypto_mechanism_t ls_mech; /* for data encr/decr */
263 265 crypto_key_t ls_key; /* for data encr/decr */
264 266 crypto_mechanism_t ls_iv_mech; /* for iv derivation */
265 267 size_t ls_iv_len; /* for iv derivation */
266 268 iv_method_t ls_iv_type; /* for iv derivation */
267 269 kmutex_t ls_crypto_lock;
268 270 crypto_ctx_template_t ls_ctx_tmpl;
269 271
270 272 };
271 273
272 274 #endif /* _KERNEL */
273 275
274 276 /*
275 277 * Common signature for all lofi compress functions
276 278 */
277 279 typedef int lofi_compress_func_t(void *src, size_t srclen, void *dst,
278 280 size_t *destlen, int level);
279 281
280 282 /*
281 283 * Information about each compression function
282 284 */
283 285 typedef struct lofi_compress_info {
284 286 lofi_compress_func_t *l_decompress;
285 287 lofi_compress_func_t *l_compress;
286 288 int l_level;
287 289 char *l_name; /* algorithm name */
288 290 } lofi_compress_info_t;
289 291
290 292 enum lofi_compress {
291 293 LOFI_COMPRESS_GZIP = 0,
292 294 LOFI_COMPRESS_GZIP_6 = 1,
293 295 LOFI_COMPRESS_GZIP_9 = 2,
294 296 LOFI_COMPRESS_LZMA = 3,
295 297 LOFI_COMPRESS_FUNCTIONS
296 298 };
297 299
298 300 #ifdef __cplusplus
299 301 }
300 302 #endif
301 303
302 304 #endif /* _SYS_LOFI_H */
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX