From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Nielsen To: 9fans@cse.psu.edu Message-ID: <20030507043633.GX36080@cassie.foobarbaz.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.3i Subject: [9fans] struct problems Date: Tue, 6 May 2003 21:36:33 -0700 Topicbox-Message-UUID: a0e407b8-eacb-11e9-9e20-41e7f4b1d025 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