summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher/ipodpatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher/ipodpatcher.c')
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index 395fd6953d..567c5b9cce 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -171,6 +171,8 @@ int read_partinfo(struct ipod_t* ipod, int silent)
171 return -1; 171 return -1;
172 } 172 }
173 173
174 memset(ipod->pinfo, 0, sizeof(ipod->pinfo));
175
174 if ((sectorbuf[510] == 0x55) && (sectorbuf[511] == 0xaa)) { 176 if ((sectorbuf[510] == 0x55) && (sectorbuf[511] == 0xaa)) {
175 /* DOS partition table */ 177 /* DOS partition table */
176 ipod->macpod = 0; 178 ipod->macpod = 0;
@@ -1289,3 +1291,60 @@ int ipod_scan(struct ipod_t* ipod)
1289 } 1291 }
1290 return n; 1292 return n;
1291} 1293}
1294
1295static void put_int32le(uint32_t x, unsigned char* p)
1296{
1297 p[0] = x & 0xff;
1298 p[1] = (x >> 8) & 0xff;
1299 p[2] = (x >> 16) & 0xff;
1300 p[3] = (x >> 24) & 0xff;
1301}
1302
1303int write_dos_partition_table(struct ipod_t* ipod)
1304{
1305 unsigned char* p;
1306 int i, n;
1307 uint32_t type;
1308
1309 /* Only support 512-byte sectors at the moment */
1310 if ( ipod->sector_size != 512 )
1311 {
1312 fprintf(stderr,"[ERR] Only ipods with 512 bytes per sector are supported.\n");
1313 return -1;
1314 }
1315
1316 /* Firstly zero the entire MBR */
1317 memset(sectorbuf, 0, ipod->sector_size);
1318
1319 /* Now add the partition info */
1320 for (i=0; i < 4 ; i++)
1321 {
1322 p = sectorbuf + 0x1be + i*16;
1323
1324 /* Ensure first partition is type 0, and second is 0xb */
1325 if (i==0) { type = 0; }
1326 else if (i==1) { type = 0xb; }
1327 else { type = ipod->pinfo[i].type; }
1328
1329 put_int32le(type, p + 4);
1330 put_int32le(ipod->pinfo[i].start, p + 8);
1331 put_int32le(ipod->pinfo[i].size, p + 12);
1332 }
1333
1334 /* Finally add the magic */
1335 sectorbuf[0x1fe] = 0x55;
1336 sectorbuf[0x1ff] = 0xaa;
1337
1338 if (ipod_seek(ipod, 0) < 0) {
1339 fprintf(stderr,"[ERR] Seek failed writing MBR\n");
1340 return -1;
1341 }
1342
1343 /* Write MBR */
1344 if ((n = ipod_write(ipod, sectorbuf, ipod->sector_size)) < 0) {
1345 perror("[ERR] Write failed\n");
1346 return -1;
1347 }
1348
1349 return 0;
1350}