lkml.org 
[lkml]   [2005]   [Mar]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Subject[PATCH 7/29] FAT: Use "unsigned int" for ->free_clusters and ->prev_free
    From
    Date

    This changes ->free_clusters and ->prev_free from "int" to "unsigned int".
    These value should be never negative value (but it's using 0xffffffff(-1)
    as undefined state).

    With this changes, fatfs would handle the corruption of free_clusters
    more proper.

    Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
    ---

    fs/fat/fatent.c | 3 +--
    fs/fat/inode.c | 6 +++++-
    include/linux/msdos_fs.h | 4 ++--
    3 files changed, 8 insertions(+), 5 deletions(-)

    diff -puN fs/fat/fatent.c~sync05-fat_free-unsigned fs/fat/fatent.c
    --- linux-2.6.11/fs/fat/fatent.c~sync05-fat_free-unsigned 2005-03-06 02:36:19.000000000 +0900
    +++ linux-2.6.11-hirofumi/fs/fat/fatent.c 2005-03-06 02:36:19.000000000 +0900
    @@ -453,8 +453,7 @@ int fat_alloc_clusters(struct inode *ino
    fatent_init(&fatent);
    fatent_set_entry(&fatent, sbi->prev_free + 1);
    while (count < sbi->max_cluster) {
    - fatent.entry %= sbi->max_cluster;
    - if (fatent.entry < FAT_START_ENT)
    + if (fatent.entry >= sbi->max_cluster)
    fatent.entry = FAT_START_ENT;
    fatent_set_entry(&fatent, fatent.entry);
    err = fat_ent_read_block(sb, &fatent);
    diff -puN fs/fat/inode.c~sync05-fat_free-unsigned fs/fat/inode.c
    --- linux-2.6.11/fs/fat/inode.c~sync05-fat_free-unsigned 2005-03-06 02:36:19.000000000 +0900
    +++ linux-2.6.11-hirofumi/fs/fat/inode.c 2005-03-06 02:36:19.000000000 +0900
    @@ -1163,7 +1163,7 @@ int fat_fill_super(struct super_block *s
    sbi->fat_length = le16_to_cpu(b->fat_length);
    sbi->root_cluster = 0;
    sbi->free_clusters = -1; /* Don't know yet */
    - sbi->prev_free = -1;
    + sbi->prev_free = FAT_START_ENT;

    if (!sbi->fat_length && b->fat32_length) {
    struct fat_boot_fsinfo *fsinfo;
    @@ -1247,6 +1247,10 @@ int fat_fill_super(struct super_block *s
    /* check the free_clusters, it's not necessarily correct */
    if (sbi->free_clusters != -1 && sbi->free_clusters > total_clusters)
    sbi->free_clusters = -1;
    + /* check the prev_free, it's not necessarily correct */
    + sbi->prev_free %= sbi->max_cluster;
    + if (sbi->prev_free < FAT_START_ENT)
    + sbi->prev_free = FAT_START_ENT;

    brelse(bh);

    diff -puN include/linux/msdos_fs.h~sync05-fat_free-unsigned include/linux/msdos_fs.h
    --- linux-2.6.11/include/linux/msdos_fs.h~sync05-fat_free-unsigned 2005-03-06 02:36:19.000000000 +0900
    +++ linux-2.6.11-hirofumi/include/linux/msdos_fs.h 2005-03-06 02:36:19.000000000 +0900
    @@ -225,8 +225,8 @@ struct msdos_sb_info {
    unsigned long root_cluster; /* first cluster of the root directory */
    unsigned long fsinfo_sector; /* sector number of FAT32 fsinfo */
    struct semaphore fat_lock;
    - int prev_free; /* previously allocated cluster number */
    - int free_clusters; /* -1 if undefined */
    + unsigned int prev_free; /* previously allocated cluster number */
    + unsigned int free_clusters; /* -1 if undefined */
    struct fat_mount_options options;
    struct nls_table *nls_disk; /* Codepage used on disk */
    struct nls_table *nls_io; /* Charset used for input and display */
    _
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/
    \
     
     \ /
      Last update: 2005-03-22 14:10    [W:3.578 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site