This is not 'Nam. This is C. There are rules.

Nov 29, 2006 16:42

I was going about my day earlier, when spot sent me an IM asking for help with one of my favorite programs. Apparently, it was failing quite spectacularly on sparc, and he was having some trouble making the machine give useful debug data.

After a bit of hacking on it, I found this wonderful nugget:

int label_read(struct device *dev, struct label **result)
{
char buf[LABEL_SIZE];
struct labeller *l;
...
if (!(l = _find_labeller(dev, buf, §or)))
goto_out;
...
}
...
static struct labeller *_find_labeller(struct device *dev, char *buf,
uint64_t *label_sector)
{
...
struct label_header *lh;
...
uint64_t sector;
int found = 0;
char readbuf[LABEL_SCAN_SIZE];

if (!dev_read(dev, UINT64_C(0), LABEL_SCAN_SIZE, readbuf)) {
log_debug("%s: Failed to read label area", dev_name(dev));
goto out;
}

/* Scan first few sectors for a valid label */
for (sector = 0; sector < LABEL_SCAN_SECTORS;
sector += LABEL_SIZE >> SECTOR_SHIFT) {
lh = (struct label_header *) (readbuf +
(sector << SECTOR_SHIFT));
...
list_iterate_items(li, &_labellers) {
if (li->l->ops->can_handle(li->l, (char *) lh, sector)) {
...
}
Where li->l->ops->can_handle() winds up being...
static int _pool_read(struct labeller *l, struct device *dev, char *buf,
struct label **label)
{
struct pool_list pl;

return read_pool_label(&pl, l, dev, buf, label);
}
...
int read_pool_label(struct pool_list *pl, struct labeller *l,
struct device *dev, char *buf, struct label **label)
{
...
struct pool_disk *pd = &pl->pd;

pool_label_in(pd, buf);
...
}
And elsewhere we find:
struct pool_disk {
uint64_t pl_magic; /* Pool magic number */
uint64_t pl_pool_id; /* Unique pool identifier */
char pl_pool_name[POOL_NAME_SIZE]; /* Name of pool */
...
}
...
#define CPIN_64(x, y) {(x) = xlate64_be((y));}
...
void pool_label_in(struct pool_disk *pl, char *buf)
{
struct pool_disk *bufpl = (struct pool_disk *) buf;

CPIN_64(pl->pl_magic, bufpl->pl_magic);
CPIN_64(pl->pl_pool_id, bufpl->pl_pool_id);
CPIN_8(pl->pl_pool_name, bufpl->pl_pool_name, POOL_NAME_SIZE);
CPIN_32(pl->pl_version, bufpl->pl_version);
...
}

Who wants to play "hunt the SIGBUS"?

Just think. Somebody was paid real money to write this. The mind boggles.
Previous post Next post
Up