Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Sep 2001 13:03:50 -0400
From:      The Anarcat <anarcat@anarcat.dyndns.org>
To:        freebsd-doc@freebsd.org
Cc:        freebsd-hackers@freebsd.org
Subject:   libh?disk doc (deficiencies?)
Message-ID:  <20010926130350.C40172@shall.anarcat.dyndns.org>

next in thread | raw e-mail | index | archive | help

--n2Pv11Ogg/Ox8ay5
Content-Type: multipart/mixed; boundary="oTHb8nViIGeoXxdp"
Content-Disposition: inline


--oTHb8nViIGeoXxdp
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

[crossposted to -hackers in a hope to have more information, sorry if
this is inappropriate]

Hi.

I'm currently working a bit on libh, which includes a libhdisk library
to interface libdisk(3), newfs, etc, in short, a interface to operate
disk partition/slice edition =E0 la sysinstall.

The thing is that I'm trying to figure out how all this stuff works.
libdisk(3) is not very informative, in fact, it doesn't document
anything below the "slice" level (FS_SWAP macro and structure of a
Disk/Chunk tree, for example).

I made a little graphic (ASCII!) to show how such a tree (Disk/Chunk) is
made, along with an algorithm from sysinstall's label.c that extract
relevant data out of it.

I will make documentation for the Disk/Chunk class hierarchy and
functions, and that will imply investigating libdisk's functions.=20

I think libdisk(3) should be split and rewrote. Anyways, isn't it policy
to have *functions* instead of *libraries* documented in manpages? :)

The thing is that I might not be the best person to do it, and I do not
understand everything clearly yet. If anyone has any other source of
information (apart from source code), please share. :) I will probably
end up posting prs about libdisk's doc...

One thing I haven't figured out yet is why there is an intermediate
"Chunk" between Disk and slices (see picture, the first chunk on the
right of the Disk box).

I think the graphic is quite good, and should be included somewhere, for
reference because it took me a while to figure it out.

A.

--oTHb8nViIGeoXxdp
Content-Type: text/plain; charset=us-ascii
Content-Description: libh/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;
    }
}
--oTHb8nViIGeoXxdp--

--n2Pv11Ogg/Ox8ay5
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

iEYEARECAAYFAjuyCnUACgkQttcWHAnWiGcIdwCeMGZ0JINGAJ9EAvP6reQdAuFb
eCIAni5QtKHblw51OKnEq8lQshr3+Uy7
=7B4T
-----END PGP SIGNATURE-----

--n2Pv11Ogg/Ox8ay5--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-doc" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010926130350.C40172>