diff options
author | Dave Chapman <dave@dchapman.com> | 2007-06-16 22:32:57 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-06-16 22:32:57 +0000 |
commit | 56780e3e417cb1b9d1d453592d58c988c8029c16 (patch) | |
tree | 78cf5d5ebb36348932bc7f425a107d838b656fe9 /rbutil/ipodpatcher/ipodio-posix.c | |
parent | 9e0dfa1a533206200d2fcc87113417d8676e8fd7 (diff) | |
download | rockbox-56780e3e417cb1b9d1d453592d58c988c8029c16.tar.gz rockbox-56780e3e417cb1b9d1d453592d58c988c8029c16.zip |
Initial integration of a --format option, based on fat32format.exe. The main limitation is that it only works on disks with 512-byte sectors - it needs adapting to the 2048-byte sector ipods. It has only been tested on Linux and Mac OS X, with a 60GB ipod Color, but appears to work.... When this feature has been more widely tested, the intention is to add code to convert the information in an Apple Partition Map (which can currently be read by ipodpatcher) to a DOS partition table, and hence allow conversion of Macpods to Winpods.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13643 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-posix.c')
-rw-r--r-- | rbutil/ipodpatcher/ipodio-posix.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/rbutil/ipodpatcher/ipodio-posix.c b/rbutil/ipodpatcher/ipodio-posix.c index 365bc27291..78c2dbf852 100644 --- a/rbutil/ipodpatcher/ipodio-posix.c +++ b/rbutil/ipodpatcher/ipodio-posix.c @@ -26,22 +26,56 @@ #include <sys/stat.h> #include <sys/ioctl.h> +#include "ipodio.h" + #if defined(linux) || defined (__linux) #include <sys/mount.h> +#include <linux/hdreg.h> #define IPOD_SECTORSIZE_IOCTL BLKSSZGET + +static void get_geometry(struct ipod_t* ipod) +{ + struct hd_geometry geometry; + + if (!ioctl(ipod->dh, HDIO_GETGEO, &geometry)) { + /* never use geometry.cylinders - it is truncated */ + ipod->num_heads = geometry.heads; + ipod->sectors_per_track = geometry.sectors; + } else { + ipod->num_heads = 0; + ipod->sectors_per_track = 0; + } +} + #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ || defined(__bsdi__) || defined(__DragonFly__) #include <sys/disk.h> #define IPOD_SECTORSIZE_IOCTL DIOCGSECTORSIZE + +/* TODO: Implement this function for BSD */ +static void get_geometry(struct ipod_t* ipod) +{ + /* Are these universal for all ipods? */ + ipod->num_heads = 255; + ipod->sectors_per_track = 63; +} + #elif defined(__APPLE__) && defined(__MACH__) #include <sys/disk.h> #define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE + +/* TODO: Implement this function for Mac OS X */ +static void get_geometry(struct ipod_t* ipod) +{ + /* Are these universal for all ipods? */ + ipod->num_heads = 255; + ipod->sectors_per_track = 63; +} + #else #error No sector-size detection implemented for this platform #endif -#include "ipodio.h" - void print_error(char* msg) { perror(msg); @@ -55,6 +89,8 @@ int ipod_open(struct ipod_t* ipod, int silent) return -1; } + /* Read information about the disk */ + if(ioctl(ipod->dh,IPOD_SECTORSIZE_IOCTL,&ipod->sector_size) < 0) { ipod->sector_size=512; if (!silent) { @@ -62,6 +98,9 @@ int ipod_open(struct ipod_t* ipod, int silent) ,ipod->sector_size); } } + + get_geometry(ipod); + return 0; } |