Changeset b9060a83 in mainline


Ignore:
Timestamp:
2011-06-12T09:45:17Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
17fa0280
Parents:
010b52d8
Message:

Fix bug in fat_get_cluster_fat12 and fat_set_cluster_fat12:
offset should not be larger than size of sector

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/filegen/filegen.c

    r010b52d8 rb9060a83  
    7373        close(fd);
    7474        crc = ~crc;
    75         printf("%s: %x\n", argv[1], crc);
     75        printf("%s : %x\n", argv[1], crc);
    7676
    7777        return 0;
  • uspace/srv/fs/fat/fat_fat.c

    r010b52d8 rb9060a83  
    304304
    305305        offset = (clst + clst/2);
     306        if (offset / BPS(bs) >= SF(bs))
     307                return ERANGE;
     308
    306309        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
    307310            offset / BPS(bs), BLOCK_FLAGS_NONE);
     
    309312                return rc;
    310313
    311         byte1 = ((uint8_t*) b->data)[offset];
    312 
     314        byte1 = ((uint8_t*) b->data)[offset % BPS(bs)];
    313315        /* This cluster access spans a sector boundary. Check only for FAT12 */
    314         if ((offset % BPS(bs) + 1 == BPS(bs))) {
     316        if ((offset % BPS(bs)) + 1 == BPS(bs)) {
    315317                /* Is it last sector of FAT? */
    316318                if (offset / BPS(bs) < SF(bs)) {
     
    341343        }
    342344        else
    343                 byte2 = ((uint8_t*) b->data)[offset+1];
     345                byte2 = ((uint8_t*) b->data)[(offset % BPS(bs))+1];
    344346
    345347#ifdef __BE__   
     
    351353        *value = uint16_t_le2host(*value);
    352354        if (IS_ODD(clst))
    353                 *value = *value >> 4;
     355                *value = (*value) >> 4;
    354356        else
    355                 *value = *value & FAT12_MASK;
    356 
     357                *value = (*value) & FAT12_MASK;
     358       
    357359        rc = block_put(b);
    358 
    359360        return rc;
    360361}
     
    473474
    474475        offset = (clst + clst/2);
     476        if (offset / BPS(bs) >= SF(bs))
     477                return ERANGE;
     478       
    475479        rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +
    476480            offset / BPS(bs), BLOCK_FLAGS_NONE);
     
    478482                return rc;
    479483
    480         byte1 = ((uint8_t*) b->data)[offset];
     484        byte1 = ((uint8_t*) b->data)[offset % BPS(bs)];
    481485        bool border = false;
    482486        /* This cluster access spans a sector boundary. Check only for FAT12 */
    483         if (offset % BPS(bs)+1 == BPS(bs)) {
     487        if ((offset % BPS(bs))+1 == BPS(bs)) {
    484488                /* Is it last sector of FAT? */
    485489                if (offset / BPS(bs) < SF(bs)) {
     
    492496                        }
    493497                        /*
    494                         * Combining value with last byte of current sector and
    495                         * first byte of next sector
    496                         */
     498                         * Combining value with last byte of current sector and
     499                         * first byte of next sector
     500                         */
    497501                        byte2 = ((uint8_t*) b1->data)[0];
    498502                        border = true;
     
    505509        }
    506510        else
    507                 byte2 = ((uint8_t*) b->data)[offset+1];
     511                byte2 = ((uint8_t*) b->data)[(offset % BPS(bs))+1];
    508512
    509513        if (IS_ODD(clst)) {
     
    520524        byte2 = byte2 | (value >> 8);
    521525
    522         ((uint8_t*) b->data)[offset] = byte1;
     526        ((uint8_t*) b->data)[(offset % BPS(bs))] = byte1;
    523527        if (border) {
    524528                ((uint8_t*) b1->data)[0] = byte2;
     
    531535                }
    532536        } else
    533                 ((uint8_t*) b->data)[offset+1] = byte2;
     537                ((uint8_t*) b->data)[(offset % BPS(bs))+1] = byte2;
    534538
    535539        b->dirty = true;        /* need to sync block */
Note: See TracChangeset for help on using the changeset viewer.