summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher/ipodio-posix.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-06-16 22:32:57 +0000
committerDave Chapman <dave@dchapman.com>2007-06-16 22:32:57 +0000
commit56780e3e417cb1b9d1d453592d58c988c8029c16 (patch)
tree78cf5d5ebb36348932bc7f425a107d838b656fe9 /rbutil/ipodpatcher/ipodio-posix.c
parent9e0dfa1a533206200d2fcc87113417d8676e8fd7 (diff)
downloadrockbox-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.c43
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 @@
26#include <sys/stat.h> 26#include <sys/stat.h>
27#include <sys/ioctl.h> 27#include <sys/ioctl.h>
28 28
29#include "ipodio.h"
30
29#if defined(linux) || defined (__linux) 31#if defined(linux) || defined (__linux)
30#include <sys/mount.h> 32#include <sys/mount.h>
33#include <linux/hdreg.h>
31#define IPOD_SECTORSIZE_IOCTL BLKSSZGET 34#define IPOD_SECTORSIZE_IOCTL BLKSSZGET
35
36static void get_geometry(struct ipod_t* ipod)
37{
38 struct hd_geometry geometry;
39
40 if (!ioctl(ipod->dh, HDIO_GETGEO, &geometry)) {
41 /* never use geometry.cylinders - it is truncated */
42 ipod->num_heads = geometry.heads;
43 ipod->sectors_per_track = geometry.sectors;
44 } else {
45 ipod->num_heads = 0;
46 ipod->sectors_per_track = 0;
47 }
48}
49
32#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ 50#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \
33 || defined(__bsdi__) || defined(__DragonFly__) 51 || defined(__bsdi__) || defined(__DragonFly__)
34#include <sys/disk.h> 52#include <sys/disk.h>
35#define IPOD_SECTORSIZE_IOCTL DIOCGSECTORSIZE 53#define IPOD_SECTORSIZE_IOCTL DIOCGSECTORSIZE
54
55/* TODO: Implement this function for BSD */
56static void get_geometry(struct ipod_t* ipod)
57{
58 /* Are these universal for all ipods? */
59 ipod->num_heads = 255;
60 ipod->sectors_per_track = 63;
61}
62
36#elif defined(__APPLE__) && defined(__MACH__) 63#elif defined(__APPLE__) && defined(__MACH__)
37#include <sys/disk.h> 64#include <sys/disk.h>
38#define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE 65#define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE
66
67/* TODO: Implement this function for Mac OS X */
68static void get_geometry(struct ipod_t* ipod)
69{
70 /* Are these universal for all ipods? */
71 ipod->num_heads = 255;
72 ipod->sectors_per_track = 63;
73}
74
39#else 75#else
40 #error No sector-size detection implemented for this platform 76 #error No sector-size detection implemented for this platform
41#endif 77#endif
42 78
43#include "ipodio.h"
44
45void print_error(char* msg) 79void print_error(char* msg)
46{ 80{
47 perror(msg); 81 perror(msg);
@@ -55,6 +89,8 @@ int ipod_open(struct ipod_t* ipod, int silent)
55 return -1; 89 return -1;
56 } 90 }
57 91
92 /* Read information about the disk */
93
58 if(ioctl(ipod->dh,IPOD_SECTORSIZE_IOCTL,&ipod->sector_size) < 0) { 94 if(ioctl(ipod->dh,IPOD_SECTORSIZE_IOCTL,&ipod->sector_size) < 0) {
59 ipod->sector_size=512; 95 ipod->sector_size=512;
60 if (!silent) { 96 if (!silent) {
@@ -62,6 +98,9 @@ int ipod_open(struct ipod_t* ipod, int silent)
62 ,ipod->sector_size); 98 ,ipod->sector_size);
63 } 99 }
64 } 100 }
101
102 get_geometry(ipod);
103
65 return 0; 104 return 0;
66} 105}
67 106