156 |
data = (struct pupa_fat_data *) pupa_malloc (sizeof (*data)); |
data = (struct pupa_fat_data *) pupa_malloc (sizeof (*data)); |
157 |
if (! data) |
if (! data) |
158 |
goto fail; |
goto fail; |
159 |
|
|
160 |
/* Read the BPB. */ |
/* Read the BPB. */ |
161 |
if (pupa_disk_read (disk, 0, 0, sizeof (bpb), (char *) &bpb)) |
if (pupa_disk_read (disk, 0, 0, sizeof (bpb), (char *) &bpb)) |
162 |
goto fail; |
goto fail; |
437 |
break; |
break; |
438 |
case 12: |
case 12: |
439 |
if (data->cur_cluster & 1) |
if (data->cur_cluster & 1) |
440 |
next_cluster >>= 12; |
next_cluster >>= 4; |
441 |
|
|
442 |
next_cluster &= 0x0FFF; |
next_cluster &= 0x0FFF; |
443 |
break; |
break; |
444 |
} |
} |
445 |
|
|
446 |
|
#if 0 |
447 |
|
pupa_printf ("%s:%d: fat_size=%d, next_cluster=%u\n", |
448 |
|
__FILE__, __LINE__, data->fat_size, next_cluster); |
449 |
|
#endif |
450 |
|
|
451 |
/* Check the end. */ |
/* Check the end. */ |
452 |
if (next_cluster >= data->cluster_eof_mark) |
if (next_cluster >= data->cluster_eof_mark) |
453 |
return ret; |
return ret; |
454 |
|
|
455 |
if (next_cluster < 2 || next_cluster >= data->num_clusters) |
if (next_cluster < 2 || next_cluster >= data->num_clusters) |
456 |
{ |
{ |
457 |
pupa_error (PUPA_ERR_BAD_FS, "invalid cluster"); |
pupa_error (PUPA_ERR_BAD_FS, "invalid cluster %u", |
458 |
|
next_cluster); |
459 |
return -1; |
return -1; |
460 |
} |
} |
461 |
|
|