From owner-freebsd-libh Tue Sep 25 21:37: 8 2001 Delivered-To: freebsd-libh@freebsd.org Received: from tomts9-srv.bellnexxia.net (tomts9.bellnexxia.net [209.226.175.53]) by hub.freebsd.org (Postfix) with ESMTP id 7FDB337B40F for ; Tue, 25 Sep 2001 21:37:01 -0700 (PDT) Received: from khan.anarcat.dyndns.org ([65.92.169.79]) by tomts9-srv.bellnexxia.net (InterMail vM.4.01.03.16 201-229-121-116-20010115) with ESMTP id <20010926043659.HLXD25005.tomts9-srv.bellnexxia.net@khan.anarcat.dyndns.org> for ; Wed, 26 Sep 2001 00:36:59 -0400 Received: from shall.anarcat.dyndns.org (shall.anarcat.dyndns.org [192.168.0.1]) by khan.anarcat.dyndns.org (Postfix) with ESMTP id A31311AC5 for ; Wed, 26 Sep 2001 00:36:54 -0400 (EDT) Received: by shall.anarcat.dyndns.org (Postfix, from userid 1000) id 523FF20AD5; Wed, 26 Sep 2001 00:36:39 -0400 (EDT) Date: Wed, 26 Sep 2001 00:36:37 -0400 From: The Anarcat To: Libh Subject: libdisk doc Message-ID: <20010926003636.B499@shall.anarcat.dyndns.org> Mail-Followup-To: The Anarcat , Libh Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="BwCQnh7xodEAoBMC" Content-Disposition: inline User-Agent: Mutt/1.3.22.1i Sender: owner-freebsd-libh@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --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