diff options
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-posix.c')
-rw-r--r-- | rbutil/ipodpatcher/ipodio-posix.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/rbutil/ipodpatcher/ipodio-posix.c b/rbutil/ipodpatcher/ipodio-posix.c index 6dfb09ed33..be048fc986 100644 --- a/rbutil/ipodpatcher/ipodio-posix.c +++ b/rbutil/ipodpatcher/ipodio-posix.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #if defined(linux) || defined (__linux) | 34 | #if defined(linux) || defined (__linux) |
35 | #include <sys/mount.h> | 35 | #include <sys/mount.h> |
36 | #include <linux/hdreg.h> | 36 | #include <linux/hdreg.h> |
37 | #include <scsi/scsi_ioctl.h> | ||
38 | #include <scsi/sg.h> | ||
39 | |||
37 | #define IPOD_SECTORSIZE_IOCTL BLKSSZGET | 40 | #define IPOD_SECTORSIZE_IOCTL BLKSSZGET |
38 | 41 | ||
39 | static void get_geometry(struct ipod_t* ipod) | 42 | static void get_geometry(struct ipod_t* ipod) |
@@ -50,6 +53,51 @@ static void get_geometry(struct ipod_t* ipod) | |||
50 | } | 53 | } |
51 | } | 54 | } |
52 | 55 | ||
56 | /* Linux SCSI Inquiry code based on the documentation and example code from | ||
57 | http://www.ibm.com/developerworks/linux/library/l-scsi-api/index.html | ||
58 | */ | ||
59 | |||
60 | int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code, | ||
61 | unsigned char* buf, int bufsize) | ||
62 | { | ||
63 | unsigned char cdb[6]; | ||
64 | struct sg_io_hdr hdr; | ||
65 | unsigned char sense_buffer[255]; | ||
66 | |||
67 | memset(&hdr, 0, sizeof(hdr)); | ||
68 | |||
69 | hdr.interface_id = 'S'; /* this is the only choice we have! */ | ||
70 | hdr.flags = SG_FLAG_LUN_INHIBIT; /* this would put the LUN to 2nd byte of cdb*/ | ||
71 | |||
72 | /* Set xfer data */ | ||
73 | hdr.dxferp = buf; | ||
74 | hdr.dxfer_len = bufsize; | ||
75 | |||
76 | /* Set sense data */ | ||
77 | hdr.sbp = sense_buffer; | ||
78 | hdr.mx_sb_len = sizeof(sense_buffer); | ||
79 | |||
80 | /* Set the cdb format */ | ||
81 | cdb[0] = 0x12; | ||
82 | cdb[1] = 1; /* Enable Vital Product Data (EVPD) */ | ||
83 | cdb[2] = page_code & 0xff; | ||
84 | cdb[3] = 0; | ||
85 | cdb[4] = 0xff; | ||
86 | cdb[5] = 0; /* For control filed, just use 0 */ | ||
87 | |||
88 | hdr.dxfer_direction = SG_DXFER_FROM_DEV; | ||
89 | hdr.cmdp = cdb; | ||
90 | hdr.cmd_len = 6; | ||
91 | |||
92 | int ret = ioctl(ipod->dh, SG_IO, &hdr); | ||
93 | |||
94 | if (ret < 0) { | ||
95 | return -1; | ||
96 | } else { | ||
97 | return 0; | ||
98 | } | ||
99 | } | ||
100 | |||
53 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ | 101 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ |
54 | || defined(__bsdi__) || defined(__DragonFly__) | 102 | || defined(__bsdi__) || defined(__DragonFly__) |
55 | #include <sys/disk.h> | 103 | #include <sys/disk.h> |
@@ -63,6 +111,13 @@ static void get_geometry(struct ipod_t* ipod) | |||
63 | ipod->sectors_per_track = 63; | 111 | ipod->sectors_per_track = 63; |
64 | } | 112 | } |
65 | 113 | ||
114 | int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code, | ||
115 | unsigned char* buf, int bufsize) | ||
116 | { | ||
117 | /* TODO: Implement for BSD */ | ||
118 | return -1; | ||
119 | } | ||
120 | |||
66 | #elif defined(__APPLE__) && defined(__MACH__) | 121 | #elif defined(__APPLE__) && defined(__MACH__) |
67 | #include <sys/disk.h> | 122 | #include <sys/disk.h> |
68 | #define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE | 123 | #define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE |
@@ -75,6 +130,13 @@ static void get_geometry(struct ipod_t* ipod) | |||
75 | ipod->sectors_per_track = 63; | 130 | ipod->sectors_per_track = 63; |
76 | } | 131 | } |
77 | 132 | ||
133 | int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code, | ||
134 | unsigned char* buf, int bufsize) | ||
135 | { | ||
136 | /* TODO: Implement for OS X */ | ||
137 | return -1; | ||
138 | } | ||
139 | |||
78 | #else | 140 | #else |
79 | #error No sector-size detection implemented for this platform | 141 | #error No sector-size detection implemented for this platform |
80 | #endif | 142 | #endif |
@@ -180,3 +242,4 @@ ssize_t ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes) | |||
180 | { | 242 | { |
181 | return write(ipod->dh, buf, nbytes); | 243 | return write(ipod->dh, buf, nbytes); |
182 | } | 244 | } |
245 | |||