9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] struct problems
@ 2003-05-07  4:36 Christopher Nielsen
  2003-05-07  5:34 ` Christopher Nielsen
                   ` (2 more replies)
  0 siblings, 3 replies; 52+ messages in thread
From: Christopher Nielsen @ 2003-05-07  4:36 UTC (permalink / raw)
  To: 9fans

I've been working on 48-bit LBA support for ATA, and
I've run into something peculiar. I decided to rewrite
the identify array as a struct of bit fields for better
readability. As it turns out, the struct is 16 bytes
bigger than expected, which is causing all sorts of
trouble with accessing the fields properly. I am pretty
sure I copied all the fields correctly; the struct
should be 512 bytes, but it's 528 bytes. Below is the
struct definition for folks to look at. I am in the
process of rooting out where the extra bytes are
coming from, but if someone can provide some insight,
it would save me some time.


typedef struct Params {
/*000*/	union {
		ushort	config;
		ushort	pktsz:2;	/* packet command size */
		ushort	incomplete:1;
		ushort	:2;
		ushort	drq:2;	/* DRQ type */
		ushort	removable:1;	/* device is removable */
    		ushort	type:5;	/* device type */
    		ushort	:2;
    		ushort	proto:1;	/* command protocol */
	};
/*001*/	ushort	lcyl;	/* logical cylinders */
	ushort	reserved2;
/*003*/	ushort	lhead;	/* logical heads */
	ushort	obsolete4;
	ushort	obsolete5;
/*006*/	ushort	lsec;	/* logical sectors */
	ushort	reserved7;
	ushort	reserved8;
	ushort	retired9;
/*010*/	uchar	serial[20];	/* serial number */
	ushort	retired20;
	ushort	retired21;
	ushort	obsolete22;
/*023*/	uchar	firmware[8];	/* firmware revision */
/*027*/	uchar	model[40];	/* model name */
/*047*/	ushort	maxrwm:8;	/* max. read/write multiple sectors */
	ushort	:8;
	ushort	reserved48;
/*049*/	union {
		ushort	capabilities;
		ushort	retired49:8;
		ushort	dma:1;	/* DMA supported */
		ushort	lba:1;	/* LBA supported */
		ushort	noiordy:1;	/* IORDY may be disabled */
		ushort	iordy:1;	/* IORDY supported */
		ushort	softrst:1;	/* needs soft reset when bsy */
		ushort	stdby:1;	/* standby supported */
		ushort	queueing:1;	/* queueing overlap supported */
		ushort	idma:1;	/* interleaved DMA supported */
	};
/*050*/	ushort	stdbymin:1;
	ushort	:13;
	ushort	cap1:1;
	ushort	cap0:1;
	ushort	retired51;
	ushort	retired52;
/*053*/	ushort	valid;
/*054*/	ushort	ccyl;
/*055*/	ushort	chead;
/*056*/	ushort	csec;
/*057*/	ushort	cap;
	ushort	obsolete58;
/*059*/	ushort	mstc:8;	/* number of sectors ready for transfer */
	ushort	mstvalid:1;	/* multi-sector transfer enabled */
	ushort	:7;
/*060-061*/	ushort	lba0;	/* LBA size */
	ushort	lba1;	/* LBA size */
	ushort	obsolete62;
/*063*/	ushort	mwdma;	/* multiword DMA mode */
/*064*/	ushort	apio;	/* advanced PIO mode */
/*065*/	ushort	minmwdma;	/* min. multiword DMA cycle time */
/*066*/	ushort	recmwdma;	/* rec. multiword DMA cycle time */
/*067*/	ushort	minpio;	/* min. PIO cycle w/o flow control */
/*068*/	ushort	miniordy;	/* min. PIO cycle with IORDY */
	ushort	reserved69;
	ushort	reserved70;
/*071*/	ushort	pktbr;	/* time from PACKET to bus release */
/*072*/	ushort	svcbsy;	/* time for SERVICE to !bsy */
	ushort	reserved73;
	ushort	reserved74;
/*075*/	ushort	qdepth:5;	/* max. queue depth */
	ushort	:11;
	ushort	reserved76;
	ushort	reserved77;
	ushort	reserved78;
	ushort	reserved79;
/*080*/	ushort	major;	/* major version number */
/*081*/	ushort	minor;	/* minor version number */
/*082-084/085-087*/	struct {
		ushort	smart:1;
		ushort	security:1;
		ushort	removable:1;
		ushort	pwrmgmt:1;
		ushort	pkt:1;
		ushort	wcache:1;
		ushort	lookahead:1;
		ushort	relirq:1;
		ushort	svcirq:1;
		ushort	reset:1;
		ushort	protected:1;
		ushort	:1;
		ushort	wbuf:1;
		ushort	rbuf:1;
		ushort	nop:1;
		ushort	:1;

		ushort	microcode:1;
		ushort	queued:1;
		ushort	cfa:1;
		ushort	apm:1;
		ushort	notify:1;
		ushort	standby:1;
		ushort	spinup:1;
		ushort	:1;
		ushort	maxsec:1;
		ushort	autoacoustic:1;
		ushort	addr48:1;
		ushort	devconfov:1;
		ushort	flush:1;
		ushort	flush48:1;
		ushort	support1:1;
		ushort	support0:1;

		ushort	smarterror:1;
		ushort	smartselftest:1;
		ushort	mserial:1;
		ushort	mpassthrough:1;
		ushort	:1;
		ushort	logging:1;
		ushort	:8;
		ushort	supportext1:1;
		ushort	supportext0:1;
	} supported, enabled;
/*088*/	ushort	udma;	/* ultra DMA mode */
/*089*/	ushort	erase;	/* time for security erase */
/*090*/	ushort	eerase;	/* time for enhanced security erase */
/*091*/	ushort	power;	/* current advanced power management */
/*092*/	ushort	mpwrev;	/* master password revision */
/*093*/	ushort	hwres;	/* hardware config test results */
/*094*/	ushort	acoustic;	/* current automatic acoustic management */
	ushort	reserved95;
	ushort	reserved96;
	ushort	reserved97;
	ushort	reserved98;
	ushort	reserved99;
/* 100-103 */	ushort	lbaext0;	/* 48-bit LBA size */
	ushort	lbaext1;	/* 48-bit LBA size */
	ushort	lbaext2;	/* 48-bit LBA size */
	ushort	lbaext3;	/* 48-bit LBA size */
	ushort	reserved104[23];
/*127*/	ushort	remstat;	/* removable media status */
/*128*/	ushort	secstat;	/* security status */
	ushort	reserved129[31];
/*160*/	ushort	cfapwr;	/* CFA power mode */
	ushort	reserved161[14];
/*176*/	ushort	mediaserial[30];	/* current media serial number */
	ushort	reserved206[49];
/*255*/	ushort	chksum;
} Params;


--
Christopher Nielsen
"They who can give up essential liberty for temporary
safety, deserve neither liberty nor safety." --Benjamin Franklin


^ permalink raw reply	[flat|nested] 52+ messages in thread
[parent not found: <presotto@closedmind.org>]

end of thread, other threads:[~2003-05-12  9:29 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-05-07  4:36 [9fans] struct problems Christopher Nielsen
2003-05-07  5:34 ` Christopher Nielsen
2003-05-07  5:36   ` Nigel Roles
2003-05-07  5:41     ` Christopher Nielsen
2003-05-08  7:30       ` boyd, rounin
2003-05-09 20:22         ` ron minnich
2003-05-09 21:09           ` Geoff Collyer
2003-05-09 23:29             ` Scott Schwartz
2003-05-10  2:54           ` boyd, rounin
2003-05-10  5:04             ` northern snowfall
2003-05-10  4:11               ` boyd, rounin
2003-05-12  8:56           ` Douglas A. Gwyn
2003-05-12  9:29             ` boyd, rounin
2003-05-07  7:32 ` northern snowfall
2003-05-07 11:05   ` Bruce Ellis
2003-05-07 13:06     ` northern snowfall
2003-05-07 12:47       ` Bruce Ellis
2003-05-07 13:50         ` northern snowfall
2003-05-07 17:01         ` [9fans] snapshots -> archives rog
2003-05-07 17:02           ` Russ Cox
2003-05-07 15:47 ` [9fans] acme/sam problem ron minnich
2003-05-07 15:59   ` Russ Cox
2003-05-07 16:32     ` ron minnich
2003-05-07 16:00   ` andrey mirtchovski
     [not found] <presotto@closedmind.org>
2003-05-10  0:13 ` [9fans] struct problems David Presotto
2003-05-10  0:22   ` Scott Schwartz
2003-05-10  4:49   ` Skip Tavakkolian
2003-05-10  4:52     ` boyd, rounin
2003-05-10  5:20       ` Skip Tavakkolian
2003-05-10  5:19         ` boyd, rounin
2003-05-10  7:11       ` Dennis Ritchie
2003-05-10 16:53         ` matt
2003-05-10 16:58           ` boyd, rounin
2003-05-10 16:58           ` boyd, rounin
2003-05-10 18:08             ` northern snowfall
2003-05-10 17:12               ` boyd, rounin
2003-05-10 22:34               ` boyd, rounin
2003-05-10 23:09         ` jmk
2003-05-10 23:16           ` boyd, rounin
2003-05-11  2:07             ` rob pike, esq.
2003-05-11  2:26               ` boyd, rounin
2003-05-11  3:48             ` Dennis Ritchie
2003-05-11  3:54               ` boyd, rounin
2003-05-10 23:26           ` boyd, rounin
2003-05-11  2:06           ` rob pike, esq.
2003-05-10 23:54         ` Skip Tavakkolian
2003-05-11  2:08           ` rob pike, esq.
2003-05-11  2:31             ` boyd, rounin
2003-05-11  6:04               ` rob pike, esq.
2003-05-11  7:03                 ` boyd, rounin
2003-05-12  8:56       ` Anthony Mandic
2003-05-12  9:27         ` boyd, rounin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).