Commit a2adb173ec1551ce8a2081085d20d82162f7900d

Authored by Alexander Graf
Committed by Tom Rini
1 parent 2579c67478

iso: Allow 512 byte sector size

Real CD-ROMs are pretty obsolete these days. Usually people still keep
iso files around, but just put them on USB sticks or SD cards and expect
them to "just work".

To support this use case with El Torito images, add support for 512 byte
sector size to the iso parsing code.

Signed-off-by: Alexander Graf <agraf@suse.de>

Showing 1 changed file with 31 additions and 5 deletions Side-by-side Diff

... ... @@ -26,6 +26,25 @@
26 26  
27 27 static unsigned char tmpbuf[CD_SECTSIZE];
28 28  
  29 +unsigned long iso_dread(struct blk_desc *block_dev, lbaint_t start,
  30 + lbaint_t blkcnt, void *buffer)
  31 +{
  32 + unsigned long ret;
  33 +
  34 + if (block_dev->blksz == 512) {
  35 + /* Convert from 2048 to 512 sector size */
  36 + start *= 4;
  37 + blkcnt *= 4;
  38 + }
  39 +
  40 + ret = blk_dread(block_dev, start, blkcnt, buffer);
  41 +
  42 + if (block_dev->blksz == 512)
  43 + ret /= 4;
  44 +
  45 + return ret;
  46 +}
  47 +
29 48 /* only boot records will be listed as valid partitions */
30 49 int part_get_info_iso_verb(struct blk_desc *dev_desc, int part_num,
31 50 disk_partition_t *info, int verb)
32 51  
... ... @@ -39,12 +58,12 @@
39 58 iso_val_entry_t *pve = (iso_val_entry_t *)tmpbuf;
40 59 iso_init_def_entry_t *pide;
41 60  
42   - if (dev_desc->blksz != CD_SECTSIZE)
  61 + if ((dev_desc->blksz != CD_SECTSIZE) && (dev_desc->blksz != 512))
43 62 return -1;
44 63  
45 64 /* the first sector (sector 0x10) must be a primary volume desc */
46 65 blkaddr=PVD_OFFSET;
47   - if (blk_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
  66 + if (iso_dread(dev_desc, PVD_OFFSET, 1, (ulong *)tmpbuf) != 1)
48 67 return -1;
49 68 if(ppr->desctype!=0x01) {
50 69 if(verb)
... ... @@ -64,7 +83,7 @@
64 83 PRINTF(" Lastsect:%08lx\n",lastsect);
65 84 for(i=blkaddr;i<lastsect;i++) {
66 85 PRINTF("Reading block %d\n", i);
67   - if (blk_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
  86 + if (iso_dread(dev_desc, i, 1, (ulong *)tmpbuf) != 1)
68 87 return -1;
69 88 if(ppr->desctype==0x00)
70 89 break; /* boot entry found */
... ... @@ -84,7 +103,7 @@
84 103 }
85 104 bootaddr = get_unaligned_le32(pbr->pointer);
86 105 PRINTF(" Boot Entry at: %08lX\n",bootaddr);
87   - if (blk_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
  106 + if (iso_dread(dev_desc, bootaddr, 1, (ulong *)tmpbuf) != 1) {
88 107 if(verb)
89 108 printf ("** Can't read Boot Entry at %lX on %d:%d **\n",
90 109 bootaddr, dev_desc->devnum, part_num);
... ... @@ -192,7 +211,14 @@
192 211 }
193 212 newblkaddr = get_unaligned_le32(pide->rel_block_addr);
194 213 info->start=newblkaddr;
195   - PRINTF(" part %d found @ %lx size %lx\n",part_num,newblkaddr,info->size);
  214 +
  215 + if (dev_desc->blksz == 512) {
  216 + info->size *= 4;
  217 + info->start *= 4;
  218 + info->blksz = 512;
  219 + }
  220 +
  221 + PRINTF(" part %d found @ %lx size %lx\n",part_num,info->start,info->size);
196 222 return 0;
197 223 }
198 224