src/fs/fat/fat16.c
//Get the correct cluster to use based on the starting cluster and the offset
Get the correct cluster to use based on the starting cluster and the offset
Get the correct cluster to use based on the starting cluster and the offset
static int fat16_get_cluster_for_offset(struct disk* disk, int starting_cluster, int offset){
    int res = 0;
    struct fat_private* private = disk -> fs_private;
    int size_of_cluster_bytes = private -> header.primary_header.SectorsPerCluster * disk -> sector_size;
    int cluster_to_use = starting_cluster;
    int clusters_ahead = offset / size_of_cluster_bytes;
    for (int i = 0; i < clusters_ahead; i++){
        int entry = fat16_get_fat_entry(disk, cluster_to_use);
        if (entry == 0xFF8 || entry == 0xFFF){
            res = -EIO;
            goto out;
        }
        if (entry == MYSTOS_FAT16_BAD_SECTOR){
            res = -EIO;
            goto out;
        }
        if (entry == 0xFF0 || entry == 0xFF6){
            res = -EIO;
            goto out;
        }
        if (entry == 0x00){
            res = -EIO;
            goto out;
        }
        cluster_to_use = entry;
    }
    res = cluster_to_use;
out:
    return res;
}
static int fat16_get_cluster_for_offset ( struct disk * disk , int starting_cluster , int offset ) { int res = 0 ; struct fat_private * private = disk -> fs_private ; int size_of_cluster_bytes = private -> header . primary_header . SectorsPerCluster * disk -> sector_size ; int cluster_to_use = starting_cluster ; int clusters_ahead = offset / size_of_cluster_bytes ; for ( int i = 0 ; i < clusters_ahead ; i ++ ) { int entry = fat16_get_fat_entry ( disk , cluster_to_use ) ; if ( entry == 0xFF8 || entry == 0xFFF ) { res = - EIO ; goto out ; } if ( entry == MYSTOS_FAT16_BAD_SECTOR ) { res = - EIO ; goto out ; } if ( entry == 0xFF0 || entry == 0xFF6 ) { res = - EIO ; goto out ; } if ( entry == 0x00 ) { res = - EIO ; goto out ; } cluster_to_use = entry ; } res = cluster_to_use ; out : return res ; }
Get the correct cluster to use based on the starting cluster and the offset
Get the correct cluster to use based on the starting cluster and the offset
//Last entry in the file/subdirectory //Bad sector //Reserved sector