Date: Wed, 26 Sep 2001 00:36:37 -0400 From: The Anarcat <anarcat@anarcat.dyndns.org> To: Libh <freebsd-libh@freebsd.org> Subject: libdisk doc Message-ID: <20010926003636.B499@shall.anarcat.dyndns.org>
next in thread | raw e-mail | index | archive | help
--BwCQnh7xodEAoBMC Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi. I'm writing this here because I don't know where else it wouldn't be noise. :) I'm digging around libdisk because (correct me if I'm wrong) libhdisk is not really documented and pretty much only a wrapper for libdisk. Now, the only doc I could find on libdisk is the man page, and it's kinda short on details. :) By looking at /usr/src/release/sysinstall/label.c, I've been able to make up a nice ascii graphic of a a Disk and Chunk hierarchy (attached). The file also contains an procedure used in label.c to extract the info from such a tree. I think this grandiose work of art should be put somewhere. ;) Seriously, I spent a while trying to figure out how this thing was setup. In particular, I am still wondering why there is an "intermediary" struct Chunk between the struct Disk and the head of the slice list (see picture). All this and more (disklabel.h FS_* macros), should be documented somewhere (is it?). Anyways, don't want to hit on anyones head here, and I'm probably just too unused to libh?disk... :) I hope the nice drawing will be useful, if not entertaining, at least. A. --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Description: release/labeledit/algo.txt Content-Disposition: attachment; filename="algo.txt" Content-Transfer-Encoding: quoted-printable We have the structures: +--------+ +-------+ | Disk | | Chunk |=20 | | | | This chunk represents the disk in itself | chunks--->| part |=20 +--------+ +--|----+=20 | =20 +--------------|---------------------------+ |Slices (e.g. | freebsd, linux, dos) | | V | | +-----------+ +-----------+ | | | Chunk | | Chunk | | | | | | | | | | type=3Dfbsd | | type=3Dfat | | | | | | | | | | part next----->| part next----> ... | | | | | | | | | | +--|--------+ +---|-------+ | | | ? | +------|-----------------------------------+ | +------|-----------------------------------+ |Partitions (eg. fs, swap) | | V | | +--------------+ +--------+ | | | Chunk | | Chunk | | | | | | | | | | type=3Dpart | | ... | | | | | | | | | | next----->| next----> ... | | | | | | | | | subtype=3Dswap | | ... | | | | | | | | | +--------------+ +--------+ | | | +------------------------------------------+ /* All the chunks currently displayed on the screen */ static struct { struct chunk *c; PartType type; } label_chunk_info[MAX_CHUNKS + 1]; /* this function flattens such a tree in a single array */ static void record_label_chunks(Device **devs, Device *dev) { int i, j, p; struct chunk *c1, *c2; Disk *d; j =3D p =3D 0; /* First buzz through and pick up the FreeBSD slices */ for (i =3D 0; devs[i]; i++) { if ((dev && devs[i] !=3D dev) || !devs[i]->enabled) continue; d =3D (Disk *)devs[i]->private; if (!d->chunks) msgFatal("No chunk list found for %s!", d->name); /* Put the slice entries first */ for (c1 =3D d->chunks->part; c1; c1 =3D c1->next) { if (c1->type =3D=3D freebsd) { label_chunk_info[j].type =3D PART_SLICE; label_chunk_info[j].c =3D c1; ++j; } } } /* Now run through again and get the FreeBSD partition entries */ for (i =3D 0; devs[i]; i++) { if (!devs[i]->enabled) continue; d =3D (Disk *)devs[i]->private; /* Then buzz through and pick up the partitions */ for (c1 =3D d->chunks->part; c1; c1 =3D c1->next) { if (c1->type =3D=3D freebsd) { for (c2 =3D c1->part; c2; c2 =3D c2->next) { if (c2->type =3D=3D part) { if (c2->subtype =3D=3D FS_SWAP) label_chunk_info[j].type =3D PART_SWAP; else label_chunk_info[j].type =3D PART_FILESYSTEM; label_chunk_info[j].c =3D c2; ++j; } } } else if (c1->type =3D=3D fat) { label_chunk_info[j].type =3D PART_FAT; label_chunk_info[j].c =3D c1; ++j; } } } label_chunk_info[j].c =3D NULL; if (here >=3D j) { here =3D j ? j - 1 : 0; } } --LQksG6bCIzRHxTLp-- --BwCQnh7xodEAoBMC Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (FreeBSD) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjuxW08ACgkQttcWHAnWiGd+6ACfaZShBUcG5bB9MLdk2l8ATmVV 1D8AnjEt3Kp3mYE9I31MuW/r4xoCXGd3 =J+MY -----END PGP SIGNATURE----- --BwCQnh7xodEAoBMC-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-libh" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010926003636.B499>