Fixes bug 221501. In this bug, a valid msdosfs image was corrupted by changing the bytes per sector from 512 to 2048. This patch checks to see if the FAT is valid and in the correct sector based on the bytes per sector value.
Details
Details
Diff Detail
Diff Detail
- Lint
Lint Skipped - Unit
Tests Skipped
Event Timeline
Comment Actions
- You should put return argument into braces, as in return (EINVAL);.
- brelse() is not needed after failed bread(), bp is set to NULL consistently on error. But if bp was indeed read, it must be brelse()d. So I would structure the code differently:
error = bread(); if (error == 0 && bp->b_data[0] != bpbMedia) error = EINVAL; brelse(bp); if (error != 0) return (error);
- According to the FAT spec, not only the byte 0 should have the specific value bpbMedia, but the whole FAT cluster is specified, other bits must be all 1's. So it might be easier to start the loop in fillinusemap() from 0 and not from CLUST_FIRST, but then ensure that FAT[0] readcn is not added to usemap, but only checked for the right value. Then additional bread() is not needed at all.
Comment Actions
I will commit this shortly. That said, I do not believe that the change really fixes the panic reported in the PR 221501. If FAT 0 cluster is corrected in the corrupted image, the failure should still happen. This does not invalidate the change, just that it is somewhat different from what is described in the review.
Comment Actions
That makes sense, I will continue working on an actual solution to the panic. Thanks for the clarification.