device-mapper.c revision 1.11 1 1.11 haad /* $NetBSD: device-mapper.c,v 1.11 2009/12/29 23:37:47 haad Exp $ */
2 1.2 haad
3 1.2 haad /*
4 1.2 haad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.2 haad * All rights reserved.
6 1.2 haad *
7 1.2 haad * This code is derived from software contributed to The NetBSD Foundation
8 1.2 haad * by Adam Hamsik.
9 1.2 haad *
10 1.2 haad * Redistribution and use in source and binary forms, with or without
11 1.2 haad * modification, are permitted provided that the following conditions
12 1.2 haad * are met:
13 1.2 haad * 1. Redistributions of source code must retain the above copyright
14 1.2 haad * notice, this list of conditions and the following disclaimer.
15 1.2 haad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 haad * notice, this list of conditions and the following disclaimer in the
17 1.2 haad * documentation and/or other materials provided with the distribution.
18 1.2 haad *
19 1.2 haad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 haad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 haad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 haad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 haad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 haad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 haad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 haad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 haad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 haad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 haad * POSSIBILITY OF SUCH DAMAGE.
30 1.2 haad */
31 1.2 haad
32 1.2 haad /*
33 1.2 haad * I want to say thank you to all people who helped me with this project.
34 1.2 haad */
35 1.2 haad
36 1.2 haad #include <sys/types.h>
37 1.2 haad #include <sys/param.h>
38 1.2 haad
39 1.2 haad #include <sys/buf.h>
40 1.2 haad #include <sys/conf.h>
41 1.2 haad #include <sys/dkio.h>
42 1.2 haad #include <sys/disk.h>
43 1.2 haad #include <sys/disklabel.h>
44 1.2 haad #include <sys/ioctl.h>
45 1.2 haad #include <sys/ioccom.h>
46 1.2 haad #include <sys/kmem.h>
47 1.2 haad #include <sys/module.h>
48 1.2 haad
49 1.2 haad #include "netbsd-dm.h"
50 1.2 haad #include "dm.h"
51 1.2 haad
52 1.2 haad static dev_type_open(dmopen);
53 1.2 haad static dev_type_close(dmclose);
54 1.2 haad static dev_type_read(dmread);
55 1.2 haad static dev_type_write(dmwrite);
56 1.2 haad static dev_type_ioctl(dmioctl);
57 1.2 haad static dev_type_strategy(dmstrategy);
58 1.2 haad static dev_type_size(dmsize);
59 1.2 haad
60 1.2 haad /* attach and detach routines */
61 1.2 haad int dmattach(void);
62 1.2 haad int dmdestroy(void);
63 1.2 haad
64 1.2 haad static int dm_cmd_to_fun(prop_dictionary_t);
65 1.2 haad static int disk_ioctl_switch(dev_t, u_long, void *);
66 1.2 haad static int dm_ioctl_switch(u_long);
67 1.2 haad static void dmminphys(struct buf *);
68 1.2 haad
69 1.2 haad /* ***Variable-definitions*** */
70 1.2 haad const struct bdevsw dm_bdevsw = {
71 1.6 haad .d_open = dmopen,
72 1.6 haad .d_close = dmclose,
73 1.6 haad .d_strategy = dmstrategy,
74 1.6 haad .d_ioctl = dmioctl,
75 1.6 haad .d_dump = nodump,
76 1.6 haad .d_psize = dmsize,
77 1.6 haad .d_flag = D_DISK | D_MPSAFE
78 1.2 haad };
79 1.2 haad
80 1.2 haad const struct cdevsw dm_cdevsw = {
81 1.6 haad .d_open = dmopen,
82 1.6 haad .d_close = dmclose,
83 1.6 haad .d_read = dmread,
84 1.6 haad .d_write = dmwrite,
85 1.6 haad .d_ioctl = dmioctl,
86 1.6 haad .d_stop = nostop,
87 1.6 haad .d_tty = notty,
88 1.6 haad .d_poll = nopoll,
89 1.6 haad .d_mmap = nommap,
90 1.6 haad .d_kqfilter = nokqfilter,
91 1.6 haad .d_flag = D_DISK | D_MPSAFE
92 1.6 haad };
93 1.6 haad
94 1.6 haad const struct dkdriver dmdkdriver = {
95 1.6 haad .d_strategy = dmstrategy
96 1.2 haad };
97 1.2 haad
98 1.4 haad extern uint64_t dev_counter;
99 1.2 haad
100 1.2 haad /*
101 1.2 haad * This array is used to translate cmd to function pointer.
102 1.2 haad *
103 1.2 haad * Interface between libdevmapper and lvm2tools uses different
104 1.2 haad * names for one IOCTL call because libdevmapper do another thing
105 1.2 haad * then. When I run "info" or "mknodes" libdevmapper will send same
106 1.2 haad * ioctl to kernel but will do another things in userspace.
107 1.2 haad *
108 1.2 haad */
109 1.2 haad struct cmd_function cmd_fn[] = {
110 1.6 haad { .cmd = "version", .fn = dm_get_version_ioctl},
111 1.6 haad { .cmd = "targets", .fn = dm_list_versions_ioctl},
112 1.6 haad { .cmd = "create", .fn = dm_dev_create_ioctl},
113 1.6 haad { .cmd = "info", .fn = dm_dev_status_ioctl},
114 1.6 haad { .cmd = "mknodes", .fn = dm_dev_status_ioctl},
115 1.6 haad { .cmd = "names", .fn = dm_dev_list_ioctl},
116 1.6 haad { .cmd = "suspend", .fn = dm_dev_suspend_ioctl},
117 1.6 haad { .cmd = "remove", .fn = dm_dev_remove_ioctl},
118 1.6 haad { .cmd = "rename", .fn = dm_dev_rename_ioctl},
119 1.6 haad { .cmd = "resume", .fn = dm_dev_resume_ioctl},
120 1.6 haad { .cmd = "clear", .fn = dm_table_clear_ioctl},
121 1.6 haad { .cmd = "deps", .fn = dm_table_deps_ioctl},
122 1.6 haad { .cmd = "reload", .fn = dm_table_load_ioctl},
123 1.6 haad { .cmd = "status", .fn = dm_table_status_ioctl},
124 1.6 haad { .cmd = "table", .fn = dm_table_status_ioctl},
125 1.2 haad {NULL, NULL}
126 1.2 haad };
127 1.2 haad
128 1.2 haad
129 1.4 haad MODULE(MODULE_CLASS_DRIVER, dm, NULL);
130 1.2 haad
131 1.2 haad /* New module handle routine */
132 1.2 haad static int
133 1.2 haad dm_modcmd(modcmd_t cmd, void *arg)
134 1.2 haad {
135 1.2 haad #ifdef _MODULE
136 1.2 haad int bmajor = -1, cmajor = -1;
137 1.2 haad
138 1.2 haad switch (cmd) {
139 1.2 haad case MODULE_CMD_INIT:
140 1.2 haad dmattach();
141 1.2 haad return devsw_attach("dm", &dm_bdevsw, &bmajor,
142 1.2 haad &dm_cdevsw, &cmajor);
143 1.2 haad break;
144 1.2 haad
145 1.2 haad case MODULE_CMD_FINI:
146 1.4 haad /*
147 1.4 haad * Disable unloading of dm module if there are any devices
148 1.4 haad * defined in driver. This is probably too strong we need
149 1.4 haad * to disable auto-unload only if there is mounted dm device
150 1.4 haad * present.
151 1.4 haad */
152 1.4 haad if (dev_counter > 0)
153 1.4 haad return EBUSY;
154 1.2 haad dmdestroy();
155 1.2 haad return devsw_detach(&dm_bdevsw, &dm_cdevsw);
156 1.2 haad break;
157 1.2 haad case MODULE_CMD_STAT:
158 1.2 haad return ENOTTY;
159 1.2 haad
160 1.2 haad default:
161 1.2 haad return ENOTTY;
162 1.2 haad }
163 1.2 haad
164 1.2 haad return 0;
165 1.2 haad #else
166 1.2 haad
167 1.2 haad if (cmd == MODULE_CMD_INIT)
168 1.2 haad return 0;
169 1.2 haad return ENOTTY;
170 1.2 haad
171 1.2 haad #endif /* _MODULE */
172 1.2 haad }
173 1.2 haad
174 1.2 haad
175 1.2 haad /* attach routine */
176 1.2 haad int
177 1.2 haad dmattach(void)
178 1.2 haad {
179 1.2 haad dm_target_init();
180 1.2 haad dm_dev_init();
181 1.2 haad dm_pdev_init();
182 1.2 haad
183 1.2 haad return 0;
184 1.2 haad }
185 1.2 haad
186 1.2 haad /* Destroy routine */
187 1.2 haad int
188 1.2 haad dmdestroy(void)
189 1.2 haad {
190 1.2 haad dm_dev_destroy();
191 1.2 haad dm_pdev_destroy();
192 1.2 haad dm_target_destroy();
193 1.2 haad
194 1.2 haad return 0;
195 1.2 haad }
196 1.2 haad
197 1.2 haad static int
198 1.2 haad dmopen(dev_t dev, int flags, int mode, struct lwp *l)
199 1.2 haad {
200 1.5 agc aprint_debug("open routine called %" PRIu32 "\n", minor(dev));
201 1.2 haad return 0;
202 1.2 haad }
203 1.2 haad
204 1.2 haad static int
205 1.2 haad dmclose(dev_t dev, int flags, int mode, struct lwp *l)
206 1.2 haad {
207 1.2 haad aprint_debug("CLOSE routine called\n");
208 1.2 haad
209 1.2 haad return 0;
210 1.2 haad }
211 1.2 haad
212 1.2 haad
213 1.2 haad static int
214 1.2 haad dmioctl(dev_t dev, const u_long cmd, void *data, int flag, struct lwp *l)
215 1.2 haad {
216 1.2 haad int r;
217 1.2 haad prop_dictionary_t dm_dict_in;
218 1.2 haad
219 1.2 haad r = 0;
220 1.2 haad
221 1.2 haad aprint_debug("dmioctl called\n");
222 1.2 haad
223 1.2 haad KASSERT(data != NULL);
224 1.2 haad
225 1.2 haad if (disk_ioctl_switch(dev, cmd, data) != 0) {
226 1.2 haad struct plistref *pref = (struct plistref *) data;
227 1.2 haad
228 1.2 haad if((r = prop_dictionary_copyin_ioctl(pref, cmd, &dm_dict_in)) != 0)
229 1.2 haad return r;
230 1.2 haad
231 1.10 haad if ((r = dm_check_version(dm_dict_in)) != 0) {
232 1.10 haad prop_object_release(dm_dict_in);
233 1.10 haad return r;
234 1.10 haad }
235 1.2 haad
236 1.2 haad /* call cmd selected function */
237 1.2 haad if ((r = dm_ioctl_switch(cmd)) != 0) {
238 1.2 haad prop_object_release(dm_dict_in);
239 1.2 haad return r;
240 1.2 haad }
241 1.10 haad
242 1.2 haad /* run ioctl routine */
243 1.2 haad if ((r = dm_cmd_to_fun(dm_dict_in)) != 0) {
244 1.2 haad prop_object_release(dm_dict_in);
245 1.2 haad return r;
246 1.2 haad }
247 1.2 haad
248 1.2 haad r = prop_dictionary_copyout_ioctl(pref, cmd, dm_dict_in);
249 1.2 haad
250 1.2 haad prop_object_release(dm_dict_in);
251 1.2 haad }
252 1.2 haad
253 1.2 haad return r;
254 1.2 haad }
255 1.2 haad
256 1.2 haad /*
257 1.2 haad * Translate command sent from libdevmapper to func.
258 1.2 haad */
259 1.2 haad static int
260 1.2 haad dm_cmd_to_fun(prop_dictionary_t dm_dict){
261 1.2 haad int i, r;
262 1.2 haad prop_string_t command;
263 1.2 haad
264 1.2 haad r = 0;
265 1.2 haad
266 1.2 haad if ((command = prop_dictionary_get(dm_dict, DM_IOCTL_COMMAND)) == NULL)
267 1.2 haad return EINVAL;
268 1.2 haad
269 1.2 haad for(i = 0; cmd_fn[i].cmd != NULL; i++)
270 1.2 haad if (prop_string_equals_cstring(command, cmd_fn[i].cmd))
271 1.2 haad break;
272 1.2 haad
273 1.2 haad if (cmd_fn[i].cmd == NULL)
274 1.2 haad return EINVAL;
275 1.2 haad
276 1.2 haad aprint_debug("ioctl %s called\n", cmd_fn[i].cmd);
277 1.2 haad r = cmd_fn[i].fn(dm_dict);
278 1.2 haad
279 1.2 haad return r;
280 1.2 haad }
281 1.2 haad
282 1.2 haad /* Call apropriate ioctl handler function. */
283 1.2 haad static int
284 1.2 haad dm_ioctl_switch(u_long cmd)
285 1.2 haad {
286 1.2 haad int r;
287 1.2 haad
288 1.2 haad r = 0;
289 1.2 haad
290 1.2 haad switch(cmd) {
291 1.2 haad
292 1.2 haad case NETBSD_DM_IOCTL:
293 1.2 haad aprint_debug("NetBSD_DM_IOCTL called\n");
294 1.2 haad break;
295 1.2 haad
296 1.2 haad default:
297 1.2 haad aprint_debug("unknown ioctl called\n");
298 1.2 haad return ENOTTY;
299 1.2 haad break; /* NOT REACHED */
300 1.2 haad }
301 1.2 haad
302 1.2 haad return r;
303 1.2 haad }
304 1.2 haad
305 1.2 haad /*
306 1.2 haad * Check for disk specific ioctls.
307 1.2 haad */
308 1.2 haad
309 1.2 haad static int
310 1.2 haad disk_ioctl_switch(dev_t dev, u_long cmd, void *data)
311 1.2 haad {
312 1.2 haad dm_dev_t *dmv;
313 1.2 haad
314 1.2 haad switch(cmd) {
315 1.2 haad case DIOCGWEDGEINFO:
316 1.2 haad {
317 1.2 haad struct dkwedge_info *dkw = (void *) data;
318 1.2 haad
319 1.2 haad if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
320 1.2 haad return ENOENT;
321 1.2 haad
322 1.9 joerg aprint_debug("DIOCGWEDGEINFO ioctl called\n");
323 1.2 haad
324 1.2 haad strlcpy(dkw->dkw_devname, dmv->name, 16);
325 1.2 haad strlcpy(dkw->dkw_wname, dmv->name, DM_NAME_LEN);
326 1.2 haad strlcpy(dkw->dkw_parent, dmv->name, 16);
327 1.2 haad
328 1.2 haad dkw->dkw_offset = 0;
329 1.2 haad dkw->dkw_size = dm_table_size(&dmv->table_head);
330 1.2 haad strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS);
331 1.2 haad
332 1.2 haad dm_dev_unbusy(dmv);
333 1.2 haad break;
334 1.2 haad }
335 1.7 haad
336 1.7 haad case DIOCGDISKINFO:
337 1.2 haad {
338 1.7 haad struct plistref *pref = (struct plistref *) data;
339 1.2 haad
340 1.2 haad if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
341 1.2 haad return ENOENT;
342 1.7 haad
343 1.7 haad if (dmv->diskp->dk_info == NULL) {
344 1.7 haad dm_dev_unbusy(dmv);
345 1.7 haad return ENOTSUP;
346 1.7 haad } else
347 1.7 haad prop_dictionary_copyout_ioctl(pref, cmd,
348 1.7 haad dmv->diskp->dk_info);
349 1.2 haad
350 1.2 haad dm_dev_unbusy(dmv);
351 1.7 haad
352 1.2 haad break;
353 1.2 haad }
354 1.7 haad
355 1.2 haad default:
356 1.2 haad aprint_debug("unknown disk_ioctl called\n");
357 1.2 haad return 1;
358 1.2 haad break; /* NOT REACHED */
359 1.2 haad }
360 1.2 haad
361 1.2 haad return 0;
362 1.2 haad }
363 1.2 haad
364 1.2 haad /*
365 1.2 haad * Do all IO operations on dm logical devices.
366 1.2 haad */
367 1.2 haad static void
368 1.2 haad dmstrategy(struct buf *bp)
369 1.2 haad {
370 1.2 haad dm_dev_t *dmv;
371 1.2 haad dm_table_t *tbl;
372 1.2 haad dm_table_entry_t *table_en;
373 1.2 haad struct buf *nestbuf;
374 1.2 haad
375 1.2 haad uint32_t dev_type;
376 1.2 haad
377 1.2 haad uint64_t buf_start, buf_len, issued_len;
378 1.2 haad uint64_t table_start, table_end;
379 1.2 haad uint64_t start, end;
380 1.2 haad
381 1.2 haad buf_start = bp->b_blkno * DEV_BSIZE;
382 1.2 haad buf_len = bp->b_bcount;
383 1.2 haad
384 1.2 haad tbl = NULL;
385 1.2 haad
386 1.2 haad table_end = 0;
387 1.2 haad dev_type = 0;
388 1.2 haad issued_len = 0;
389 1.2 haad
390 1.2 haad if ((dmv = dm_dev_lookup(NULL, NULL, minor(bp->b_dev))) == NULL) {
391 1.2 haad bp->b_error = EIO;
392 1.2 haad bp->b_resid = bp->b_bcount;
393 1.2 haad biodone(bp);
394 1.2 haad return;
395 1.2 haad }
396 1.6 haad
397 1.8 jakllsch if (bounds_check_with_mediasize(bp, DEV_BSIZE,
398 1.8 jakllsch dm_table_size(&dmv->table_head)) <= 0) {
399 1.8 jakllsch dm_dev_unbusy(dmv);
400 1.8 jakllsch bp->b_resid = bp->b_bcount;
401 1.8 jakllsch biodone(bp);
402 1.8 jakllsch return;
403 1.8 jakllsch }
404 1.8 jakllsch
405 1.11 haad /*
406 1.11 haad * disk(9) is part of device structure and it can't be used without
407 1.11 haad * mutual exclusion, use diskp_mtx until it will be fixed.
408 1.11 haad */
409 1.11 haad mutex_enter(&dmv->diskp_mtx);
410 1.6 haad disk_busy(dmv->diskp);
411 1.11 haad mutex_exit(&dmv->diskp_mtx);
412 1.2 haad
413 1.2 haad /* Select active table */
414 1.2 haad tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_ACTIVE);
415 1.2 haad
416 1.2 haad /* Nested buffers count down to zero therefore I have
417 1.2 haad to set bp->b_resid to maximal value. */
418 1.2 haad bp->b_resid = bp->b_bcount;
419 1.2 haad
420 1.2 haad /*
421 1.2 haad * Find out what tables I want to select.
422 1.2 haad */
423 1.2 haad SLIST_FOREACH(table_en, tbl, next)
424 1.2 haad {
425 1.2 haad /* I need need number of bytes not blocks. */
426 1.2 haad table_start = table_en->start * DEV_BSIZE;
427 1.2 haad /*
428 1.2 haad * I have to sub 1 from table_en->length to prevent
429 1.2 haad * off by one error
430 1.2 haad */
431 1.2 haad table_end = table_start + (table_en->length)* DEV_BSIZE;
432 1.2 haad
433 1.2 haad start = MAX(table_start, buf_start);
434 1.2 haad
435 1.2 haad end = MIN(table_end, buf_start + buf_len);
436 1.2 haad
437 1.2 haad aprint_debug("----------------------------------------\n");
438 1.2 haad aprint_debug("table_start %010" PRIu64", table_end %010"
439 1.2 haad PRIu64 "\n", table_start, table_end);
440 1.2 haad aprint_debug("buf_start %010" PRIu64", buf_len %010"
441 1.2 haad PRIu64"\n", buf_start, buf_len);
442 1.2 haad aprint_debug("start-buf_start %010"PRIu64", end %010"
443 1.2 haad PRIu64"\n", start - buf_start, end);
444 1.2 haad aprint_debug("start %010" PRIu64" , end %010"
445 1.2 haad PRIu64"\n", start, end);
446 1.2 haad aprint_debug("\n----------------------------------------\n");
447 1.2 haad
448 1.2 haad if (start < end) {
449 1.2 haad /* create nested buffer */
450 1.2 haad nestbuf = getiobuf(NULL, true);
451 1.2 haad
452 1.2 haad nestiobuf_setup(bp, nestbuf, start - buf_start,
453 1.2 haad (end - start));
454 1.2 haad
455 1.2 haad issued_len += end - start;
456 1.2 haad
457 1.2 haad /* I need number of blocks. */
458 1.2 haad nestbuf->b_blkno = (start - table_start) / DEV_BSIZE;
459 1.2 haad
460 1.2 haad table_en->target->strategy(table_en, nestbuf);
461 1.2 haad }
462 1.8 jakllsch }
463 1.2 haad
464 1.2 haad if (issued_len < buf_len)
465 1.2 haad nestiobuf_done(bp, buf_len - issued_len, EINVAL);
466 1.2 haad
467 1.11 haad mutex_enter(&dmv->diskp_mtx);
468 1.6 haad disk_unbusy(dmv->diskp, buf_len, bp != NULL ? bp->b_flags & B_READ : 0);
469 1.11 haad mutex_exit(&dmv->diskp_mtx);
470 1.11 haad
471 1.2 haad dm_table_release(&dmv->table_head, DM_TABLE_ACTIVE);
472 1.2 haad dm_dev_unbusy(dmv);
473 1.2 haad
474 1.2 haad return;
475 1.2 haad }
476 1.2 haad
477 1.2 haad
478 1.2 haad static int
479 1.2 haad dmread(dev_t dev, struct uio *uio, int flag)
480 1.2 haad {
481 1.2 haad return (physio(dmstrategy, NULL, dev, B_READ, dmminphys, uio));
482 1.2 haad }
483 1.2 haad
484 1.2 haad static int
485 1.2 haad dmwrite(dev_t dev, struct uio *uio, int flag)
486 1.2 haad {
487 1.2 haad return (physio(dmstrategy, NULL, dev, B_WRITE, dmminphys, uio));
488 1.2 haad }
489 1.2 haad
490 1.2 haad static int
491 1.2 haad dmsize(dev_t dev)
492 1.2 haad {
493 1.2 haad dm_dev_t *dmv;
494 1.2 haad uint64_t size;
495 1.2 haad
496 1.2 haad size = 0;
497 1.2 haad
498 1.2 haad if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
499 1.2 haad return -ENOENT;
500 1.2 haad
501 1.2 haad size = dm_table_size(&dmv->table_head);
502 1.2 haad dm_dev_unbusy(dmv);
503 1.2 haad
504 1.2 haad return size;
505 1.2 haad }
506 1.2 haad
507 1.2 haad static void
508 1.2 haad dmminphys(struct buf *bp)
509 1.2 haad {
510 1.2 haad bp->b_bcount = MIN(bp->b_bcount, MAXPHYS);
511 1.2 haad }
512 1.2 haad
513 1.2 haad void
514 1.7 haad dmgetproperties(struct disk *disk, dm_table_head_t *head)
515 1.2 haad {
516 1.7 haad prop_dictionary_t disk_info, odisk_info, geom;
517 1.2 haad int dmp_size;
518 1.7 haad
519 1.7 haad dmp_size = dm_table_size(head);
520 1.7 haad
521 1.7 haad disk_info = prop_dictionary_create();
522 1.7 haad
523 1.7 haad prop_dictionary_set_cstring_nocopy(disk_info, "type", "ESDI");
524 1.7 haad
525 1.7 haad geom = prop_dictionary_create();
526 1.7 haad
527 1.7 haad prop_dictionary_set_uint64(geom, "sectors-per-unit", dmp_size);
528 1.2 haad
529 1.7 haad prop_dictionary_set_uint32(geom, "sector-size",
530 1.7 haad DEV_BSIZE /* XXX 512? */);
531 1.7 haad
532 1.7 haad prop_dictionary_set_uint32(geom, "sectors-per-track", 32);
533 1.7 haad
534 1.7 haad prop_dictionary_set_uint32(geom, "tracks-per-cylinder", 64);
535 1.7 haad
536 1.7 haad prop_dictionary_set_uint32(geom, "cylinders-per-unit", dmp_size / 2048);
537 1.2 haad
538 1.7 haad prop_dictionary_set(disk_info, "geometry", geom);
539 1.7 haad prop_object_release(geom);
540 1.2 haad
541 1.7 haad odisk_info = disk->dk_info;
542 1.2 haad
543 1.7 haad disk->dk_info = disk_info;
544 1.7 haad
545 1.7 haad if (odisk_info != NULL)
546 1.7 haad prop_object_release(odisk_info);
547 1.7 haad }
548