diff options
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 @@ | |||
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 | |||
36 | static 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 */ | ||
56 | static 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 */ | ||
68 | static 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 | |||
45 | void print_error(char* msg) | 79 | void 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 | ||