diff options
-rw-r--r-- | rbutil/ipodpatcher/fat32format.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/rbutil/ipodpatcher/fat32format.c b/rbutil/ipodpatcher/fat32format.c index 0cbfb00754..3dced355b6 100644 --- a/rbutil/ipodpatcher/fat32format.c +++ b/rbutil/ipodpatcher/fat32format.c | |||
@@ -54,9 +54,13 @@ static inline uint32_t swap32(uint32_t value) | |||
54 | /* The following functions are not the most efficient, but are | 54 | /* The following functions are not the most efficient, but are |
55 | self-contained and don't require needing to know endianness of CPU | 55 | self-contained and don't require needing to know endianness of CPU |
56 | at compile-time. | 56 | at compile-time. |
57 | |||
58 | Note that htole16/htole32 exist on some platforms, so for | ||
59 | simplicity we use different names. | ||
60 | |||
57 | */ | 61 | */ |
58 | 62 | ||
59 | uint16_t htole16(uint16_t x) | 63 | static uint16_t rb_htole16(uint16_t x) |
60 | { | 64 | { |
61 | uint16_t test = 0x1234; | 65 | uint16_t test = 0x1234; |
62 | unsigned char* p = (unsigned char*)&test; | 66 | unsigned char* p = (unsigned char*)&test; |
@@ -69,7 +73,7 @@ uint16_t htole16(uint16_t x) | |||
69 | } | 73 | } |
70 | } | 74 | } |
71 | 75 | ||
72 | uint32_t htole32(uint32_t x) | 76 | static uint32_t rb_htole32(uint32_t x) |
73 | { | 77 | { |
74 | uint32_t test = 0x12345678; | 78 | uint32_t test = 0x12345678; |
75 | unsigned char* p = (unsigned char*)&test; | 79 | unsigned char* p = (unsigned char*)&test; |
@@ -306,28 +310,28 @@ static void create_boot_sector(unsigned char* buf, | |||
306 | pFAT32BootSect->sJmpBoot[1]=0x5A; | 310 | pFAT32BootSect->sJmpBoot[1]=0x5A; |
307 | pFAT32BootSect->sJmpBoot[2]=0x90; | 311 | pFAT32BootSect->sJmpBoot[2]=0x90; |
308 | strcpy( pFAT32BootSect->sOEMName, "MSWIN4.1" ); | 312 | strcpy( pFAT32BootSect->sOEMName, "MSWIN4.1" ); |
309 | pFAT32BootSect->wBytsPerSec = htole16(BytesPerSect); | 313 | pFAT32BootSect->wBytsPerSec = rb_htole16(BytesPerSect); |
310 | pFAT32BootSect->bSecPerClus = SectorsPerCluster ; | 314 | pFAT32BootSect->bSecPerClus = SectorsPerCluster ; |
311 | pFAT32BootSect->wRsvdSecCnt = htole16(ReservedSectCount); | 315 | pFAT32BootSect->wRsvdSecCnt = rb_htole16(ReservedSectCount); |
312 | pFAT32BootSect->bNumFATs = NumFATs; | 316 | pFAT32BootSect->bNumFATs = NumFATs; |
313 | pFAT32BootSect->wRootEntCnt = htole16(0); | 317 | pFAT32BootSect->wRootEntCnt = rb_htole16(0); |
314 | pFAT32BootSect->wTotSec16 = htole16(0); | 318 | pFAT32BootSect->wTotSec16 = rb_htole16(0); |
315 | pFAT32BootSect->bMedia = 0xF8; | 319 | pFAT32BootSect->bMedia = 0xF8; |
316 | pFAT32BootSect->wFATSz16 = htole16(0); | 320 | pFAT32BootSect->wFATSz16 = rb_htole16(0); |
317 | pFAT32BootSect->wSecPerTrk = htole16(ipod->sectors_per_track); | 321 | pFAT32BootSect->wSecPerTrk = rb_htole16(ipod->sectors_per_track); |
318 | pFAT32BootSect->wNumHeads = htole16(ipod->num_heads); | 322 | pFAT32BootSect->wNumHeads = rb_htole16(ipod->num_heads); |
319 | pFAT32BootSect->dHiddSec = htole16(ipod->pinfo[partition].start); | 323 | pFAT32BootSect->dHiddSec = rb_htole16(ipod->pinfo[partition].start); |
320 | pFAT32BootSect->dTotSec32 = htole32(TotalSectors); | 324 | pFAT32BootSect->dTotSec32 = rb_htole32(TotalSectors); |
321 | pFAT32BootSect->dFATSz32 = htole32(FatSize); | 325 | pFAT32BootSect->dFATSz32 = rb_htole32(FatSize); |
322 | pFAT32BootSect->wExtFlags = htole16(0); | 326 | pFAT32BootSect->wExtFlags = rb_htole16(0); |
323 | pFAT32BootSect->wFSVer = htole16(0); | 327 | pFAT32BootSect->wFSVer = rb_htole16(0); |
324 | pFAT32BootSect->dRootClus = htole32(2); | 328 | pFAT32BootSect->dRootClus = rb_htole32(2); |
325 | pFAT32BootSect->wFSInfo = htole16(1); | 329 | pFAT32BootSect->wFSInfo = rb_htole16(1); |
326 | pFAT32BootSect->wBkBootSec = htole16(BackupBootSect); | 330 | pFAT32BootSect->wBkBootSec = rb_htole16(BackupBootSect); |
327 | pFAT32BootSect->bDrvNum = 0x80; | 331 | pFAT32BootSect->bDrvNum = 0x80; |
328 | pFAT32BootSect->Reserved1 = 0; | 332 | pFAT32BootSect->Reserved1 = 0; |
329 | pFAT32BootSect->bBootSig = 0x29; | 333 | pFAT32BootSect->bBootSig = 0x29; |
330 | pFAT32BootSect->dBS_VolID = htole32(VolumeId); | 334 | pFAT32BootSect->dBS_VolID = rb_htole32(VolumeId); |
331 | memcpy(pFAT32BootSect->sVolLab, VolId, 11); | 335 | memcpy(pFAT32BootSect->sVolLab, VolId, 11); |
332 | memcpy(pFAT32BootSect->sBS_FilSysType, "FAT32 ", 8 ); | 336 | memcpy(pFAT32BootSect->sBS_FilSysType, "FAT32 ", 8 ); |
333 | 337 | ||
@@ -340,15 +344,15 @@ static void create_fsinfo(unsigned char* buf) | |||
340 | struct FAT_FSINFO* pFAT32FsInfo = (struct FAT_FSINFO*)buf; | 344 | struct FAT_FSINFO* pFAT32FsInfo = (struct FAT_FSINFO*)buf; |
341 | 345 | ||
342 | /* FSInfo sect */ | 346 | /* FSInfo sect */ |
343 | pFAT32FsInfo->dLeadSig = htole32(0x41615252); | 347 | pFAT32FsInfo->dLeadSig = rb_htole32(0x41615252); |
344 | pFAT32FsInfo->dStrucSig = htole32(0x61417272); | 348 | pFAT32FsInfo->dStrucSig = rb_htole32(0x61417272); |
345 | pFAT32FsInfo->dFree_Count = htole32((uint32_t) -1); | 349 | pFAT32FsInfo->dFree_Count = rb_htole32((uint32_t) -1); |
346 | pFAT32FsInfo->dNxt_Free = htole32((uint32_t) -1); | 350 | pFAT32FsInfo->dNxt_Free = rb_htole32((uint32_t) -1); |
347 | pFAT32FsInfo->dTrailSig = htole32(0xaa550000); | 351 | pFAT32FsInfo->dTrailSig = rb_htole32(0xaa550000); |
348 | pFAT32FsInfo->dFree_Count = htole32((UserAreaSize/SectorsPerCluster)-1); | 352 | pFAT32FsInfo->dFree_Count = rb_htole32((UserAreaSize/SectorsPerCluster)-1); |
349 | 353 | ||
350 | /* clusters 0-1 reserved, we used cluster 2 for the root dir */ | 354 | /* clusters 0-1 reserved, we used cluster 2 for the root dir */ |
351 | pFAT32FsInfo->dNxt_Free = htole32(3); | 355 | pFAT32FsInfo->dNxt_Free = rb_htole32(3); |
352 | } | 356 | } |
353 | 357 | ||
354 | static void create_firstfatsector(unsigned char* buf) | 358 | static void create_firstfatsector(unsigned char* buf) |
@@ -356,9 +360,9 @@ static void create_firstfatsector(unsigned char* buf) | |||
356 | uint32_t* p = (uint32_t*)buf; /* We know the buffer is aligned */ | 360 | uint32_t* p = (uint32_t*)buf; /* We know the buffer is aligned */ |
357 | 361 | ||
358 | /* First FAT Sector */ | 362 | /* First FAT Sector */ |
359 | p[0] = htole32(0x0ffffff8); /* Reserved cluster 1 media id in low byte */ | 363 | p[0] = rb_htole32(0x0ffffff8); /* Reserved cluster 1 media id in low byte */ |
360 | p[1] = htole32(0x0fffffff); /* Reserved cluster 2 EOC */ | 364 | p[1] = rb_htole32(0x0fffffff); /* Reserved cluster 2 EOC */ |
361 | p[2] = htole32(0x0fffffff); /* end of cluster chain for root dir */ | 365 | p[2] = rb_htole32(0x0fffffff); /* end of cluster chain for root dir */ |
362 | } | 366 | } |
363 | 367 | ||
364 | int format_partition(struct ipod_t* ipod, int partition) | 368 | int format_partition(struct ipod_t* ipod, int partition) |