Re: [Xbox-linux-user] Writing to XPad memory unit
"Chris Rorvick" <[email protected]>
| Newsgroups | gmane.linux.ports.xbox.devel |
|---|---|
| Message-ID | <[email protected]> |
--- Lunpa <[email protected]> wrote: > nifty. > how is it used? > > Like this: $ uudecode email.txt $ gzip -d xpad-write.gz $ chmod +x xpad-write $ ./xpad-write usage: xpad-write image_file $ MCARD=/dev/sdb ./xpad-write image.bin MCARD defaults to '/dev/sda'. ============== Why this works ============== It looks like the memory unit must be written to in 8k blocks, or multiples thereof. Even so, the following code does not work: for (i = 0; i < 1008; i++) write(fd, buf, 8192); The SCSI driver seems to buffer writes, and send off write commands to the lower-level driver with buffer sizes it sees fit. For example, the above code produces 127k writes to the USB storage driver on my laptop. Below are the first nine ranges of un-corrupted 1k blocks for the above code: 0 - 120 127 - 248 254 - 376 381 - 504 508 - 632 635 - 760 762 - 888 889 - 1136 * 1143 - 1264 ... Notice that the eighth block written had no corrupted blocks at the end since it ended on an 8k boundry. So, if instead of the above code I run the following: for (i = 0; i < 1008; i++) { fd = open("/dev/sda", O_RDWR); lseek(fd, i*8192, SEEK_SET); write(fd, buf, 8192); close(fd); } I now get un-corrupted writes out to the memory unit. Opening/closing the file each time forces individual SCSI commands to be sent to the USB device for each 8k write. Presumably, this would work for a buffer size of 16k, 32k, etc. So, now it is more obvious why my script using dd to write one 8k block at a time worked! I'm not familiar enough with the SCSI or USB kernel code to know immediately how to fix this, but I would think this should be an easy fix. Any ideas? Thanks, Chris Rorvick ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl