uint32_t offset;
int lo, hi;
struct cache_struct *cs;
+ uint32_t sector_mask = SECTOR_SIZE(fs) - 1;
switch(FAT_SB(fs)->fat_type) {
case FAT12:
offset = clust_num + (clust_num >> 1);
- fat_sector = offset >> SECTOR_SHIFT;
- offset &= (1 << SECTOR_SHIFT) - 1;
+ fat_sector = offset >> SECTOR_SHIFT(fs);
+ offset &= sector_mask;
cs = get_fat_sector(fs, fat_sector);
- if (offset == (1 << SECTOR_SHIFT)-1) {
+ if (offset == sector_mask) {
/*
* we got the end of the one fat sector,
* but we have just one byte and we need two,
break;
case FAT16:
- fat_sector = clust_num >> (SECTOR_SHIFT - 1);
- offset = clust_num & ((1 << (SECTOR_SHIFT-1)) -1);
+ fat_sector = clust_num >> (SECTOR_SHIFT(fs) - 1);
+ offset = clust_num & sector_mask;
cs = get_fat_sector(fs, fat_sector);
next_cluster = ((uint16_t *)cs->data)[offset];
break;
case FAT32:
- fat_sector = clust_num >> (SECTOR_SHIFT - 2);
- offset = clust_num & ((1 << (SECTOR_SHIFT-2)) -1);
+ fat_sector = clust_num >> (SECTOR_SHIFT(fs) - 2);
+ offset = clust_num & sector_mask;
cs = get_fat_sector(fs, fat_sector);
next_cluster = ((uint32_t *)cs->data)[offset] & 0x0fffffff;
break;
static sector_t get_the_right_sector(struct file *file)
{
int i = 0;
- int sector_pos = file->offset >> SECTOR_SHIFT;
+ int sector_pos = file->offset >> SECTOR_SHIFT(file->fs);
sector_t sector = *file->inode->data;
for (; i < sector_pos; i++)
/* do read */
disk->rdwr_sectors(disk, buf, frag_start, con_sec_cnt, 0);
- buf += con_sec_cnt << SECTOR_SHIFT;/* adjust buffer pointer */
+ buf += con_sec_cnt << SECTOR_SHIFT(fs);/* adjust buffer pointer */
if (!sectors)
break;
cs = get_cache_block(fs->fs_dev, sector);
de = (struct fat_dir_entry *)(cs->data + sec_off);
entries_left = ((1 << fs->sector_shift) - sec_off) >> 5;
+
+ vfat_next = vfat_csum = 0xff;
while (1) {
while(entries_left--) {
sector_t total_sectors;
fs->sector_shift = fs->block_shift = disk->sector_shift;
+ fs->sector_size = 1 << fs->sector_shift;
+ fs->block_size = 1 << fs->block_shift;
+
disk->rdwr_sectors(disk, &fat, 0, 1, 0);
sbi = malloc(sizeof(*sbi));
sbi->fat = fat.bxResSectors;
sbi->root = sbi->fat + sectors_per_fat * fat.bxFATs;
- sbi->root_size = root_dir_size(&fat);
+ sbi->root_size = root_dir_size(fs, &fat);
sbi->data = sbi->root + sbi->root_size;
sbi->clust_shift = bsr(fat.bxSecPerClust);
#define FILENAME_MAX_LG2 8
#define FILENAME_MAX (1 << FILENAME_MAX_LG2)
-#define BLOCK_SIZE(fs) (1 << fs->block_shift)
-#define SECTOR_SIZE(fs) (1 << fs->sector_shift)
+#define BLOCK_SIZE(fs) ((fs)->block_size)
+#define BLOCK_SHIFT(fs) ((fs)->block_shift)
+#define SECTOR_SIZE(fs) ((fs)->sector_size)
+#define SECTOR_SHIFT(fs) ((fs)->sector_shift)
struct fs_info {
const struct fs_ops *fs_ops;
struct device *fs_dev;
void *fs_info; /* The fs-specific information */
- int sector_shift;
- int block_shift;
+ int sector_shift, sector_size;
+ int block_shift, block_size;
};
extern struct fs_info *this_fs;