Messages in this thread Patch in this message | | | Date | Thu, 17 Sep 1998 14:27:58 +0300 (EET DST) | From | Jukka Tapani Santala <> | Subject | Re: [PATCH] Speeding up FAT operations |
| |
On Wed, 16 Sep 1998, Gordon Chaffee wrote: > I tried applying your patch, and it is rather corrupted. It looks > like it is missing lines or something. For example, look at this > piece:
That's correct... checked out the patch on my disk, and it has same problems. It seems to have got corrupted at some point, since the code it's from actually compiles ;) I'm resending the patch with the aforementioned "obsolete" macro corrected, as well. Let's hope it gets thru correct this time...
-Donwulffdiff --unified --recursive linux.120/fs/fat/cache.c linux/fs/fat/cache.c --- linux.120/fs/fat/cache.c Thu Jan 22 03:46:56 1998 +++ linux/fs/fat/cache.c Wed Sep 16 19:35:56 1998 @@ -276,10 +276,10 @@ return 0; return sector+sb->dir_start; } - cluster = sector/sb->cluster_size; - offset = sector % sb->cluster_size; + cluster = sector>>sb->cluster_shift; + offset = sector & ~(-1<<sb->cluster_shift); if (!(cluster = fat_get_cluster(inode,cluster))) return 0; - return (cluster-2)*sb->cluster_size+sb->data_start+offset; + return ((cluster-2)<<sb->cluster_shift)+sb->data_start+offset; } @@ -319,7 +319,7 @@ fat_clusters_flush(inode->i_sb); } } - inode->i_blocks -= MSDOS_SB(inode->i_sb)->cluster_size; + inode->i_blocks -= 1<<MSDOS_SB(inode->i_sb)->cluster_shift; } unlock_fat(inode->i_sb); fat_cache_inval_inode(inode); diff --unified --recursive linux.120/fs/fat/file.c linux/fs/fat/file.c --- linux.120/fs/fat/file.c Mon Aug 24 23:02:44 1998 +++ linux/fs/fat/file.c Wed Sep 16 19:24:15 1998 @@ -450,7 +450,7 @@ /* Why no return value? Surely the disk could fail... */ if (IS_IMMUTABLE(inode)) return /* -EPERM */; - cluster = SECTOR_SIZE*MSDOS_SB(inode->i_sb)->cluster_size; + cluster = SECTOR_SIZE<<MSDOS_SB(inode->i_sb)->cluster_shift; (void) fat_free(inode,(inode->i_size+(cluster-1))/cluster); MSDOS_I(inode)->i_attrs |= ATTR_ARCH; mark_inode_dirty(inode); diff --unified --recursive linux.120/fs/fat/inode.c linux/fs/fat/inode.c --- linux.120/fs/fat/inode.c Sat Apr 4 20:45:15 1998 +++ linux/fs/fat/inode.c Wed Sep 16 20:08:33 1998 @@ -282,7 +282,7 @@ int fat32; struct fat_mount_options opts; char buf[50]; - int i; + int i,j; char cvf_format[21]; char cvf_options[101]; @@ -352,7 +352,11 @@ logical_sector_size = CF_LE_W(get_unaligned((unsigned short *) &b->sector_size)); sector_mult = logical_sector_size >> SECTOR_BITS; - MSDOS_SB(sb)->cluster_size = b->cluster_size*sector_mult; + i = b->cluster_size*sector_mult; + for(j=0;(i=i>>1)!=0;j++); + if((1<<j)!=b->cluster_size*sector_mult) + printk("fat_read_super: Cluster size was not power of two!\n"); + MSDOS_SB(sb)->cluster_shift = j; MSDOS_SB(sb)->fats = b->fats; MSDOS_SB(sb)->fat_start = CF_LE_W(b->reserved)*sector_mult; if (!b->fat_length && b->fat32_length) { @@ -430,7 +434,7 @@ MSDOS_CAN_BMAP(MSDOS_SB(sb)) ? ",bmap" : ""); printk("[me=0x%x,cs=%d,#f=%d,fs=%d,fl=%d,ds=%d,de=%d,data=%d," "se=%d,ts=%ld,ls=%d,rc=%ld,fc=%u]\n", - b->media,MSDOS_SB(sb)->cluster_size, + b->media,MSDOS_SB(sb)->cluster_shift, MSDOS_SB(sb)->fats,MSDOS_SB(sb)->fat_start, MSDOS_SB(sb)->fat_length, MSDOS_SB(sb)->dir_start,MSDOS_SB(sb)->dir_entries, @@ -534,7 +538,7 @@ } unlock_fat(sb); tmp.f_type = sb->s_magic; - tmp.f_bsize = MSDOS_SB(sb)->cluster_size*SECTOR_SIZE; + tmp.f_bsize = SECTOR_SIZE<<MSDOS_SB(sb)->cluster_shift; tmp.f_blocks = MSDOS_SB(sb)->clusters; tmp.f_bfree = free; tmp.f_bavail = free; @@ -557,10 +561,10 @@ if ((inode->i_ino == MSDOS_ROOT_INO) && (sb->fat_bits != 32)) { return sb->dir_start + block; } - cluster = block/sb->cluster_size; - offset = block % sb->cluster_size; + cluster = block>>sb->cluster_shift; + offset = block & ~(-1<<sb->cluster_shift); if (!(cluster = fat_get_cluster(inode,cluster))) return 0; - return (cluster-2)*sb->cluster_size+sb->data_start+offset; + return ((cluster-2)<<sb->cluster_shift)+sb->data_start+offset; } static int is_exec(char *extension) @@ -595,7 +599,7 @@ MSDOS_I(inode)->i_start = MSDOS_SB(sb)->root_cluster; if ((nr = MSDOS_I(inode)->i_start) != 0) { while (nr != -1) { - inode->i_size += SECTOR_SIZE*MSDOS_SB(sb)->cluster_size; + inode->i_size += SECTOR_SIZE<<MSDOS_SB(sb)->cluster_shift; if (!(nr = fat_access(sb,nr,-1))) { printk("Directory %ld: bad FAT\n", inode->i_ino); @@ -608,10 +612,9 @@ inode->i_size = MSDOS_SB(sb)->dir_entries* sizeof(struct msdos_dir_entry); } - inode->i_blksize = MSDOS_SB(sb)->cluster_size* - SECTOR_SIZE; + inode->i_blksize = SECTOR_SIZE<<MSDOS_SB(sb)->cluster_shift; inode->i_blocks = (inode->i_size+inode->i_blksize-1)/ - inode->i_blksize*MSDOS_SB(sb)->cluster_size; + inode->i_blksize<<MSDOS_SB(sb)->cluster_shift; MSDOS_I(inode)->i_logstart = 0; MSDOS_I(inode)->i_attrs = 0; @@ -650,8 +653,8 @@ inode->i_size = 0; if ((nr = MSDOS_I(inode)->i_start) != 0) while (nr != -1) { - inode->i_size += SECTOR_SIZE*MSDOS_SB(inode-> - i_sb)->cluster_size; + inode->i_size += SECTOR_SIZE<<MSDOS_SB(inode-> + i_sb)->cluster_shift; if (!(nr = fat_access(sb,nr,-1))) { printk("Directory %ld: bad FAT\n", inode->i_ino); @@ -689,9 +692,9 @@ raw_entry->ext); MSDOS_I(inode)->i_attrs = raw_entry->attr & ATTR_UNUSED; /* this is as close to the truth as we can get ... */ - inode->i_blksize = MSDOS_SB(sb)->cluster_size*SECTOR_SIZE; + inode->i_blksize = SECTOR_SIZE<<MSDOS_SB(sb)->cluster_shift; inode->i_blocks = (inode->i_size+inode->i_blksize-1)/ - inode->i_blksize*MSDOS_SB(sb)->cluster_size; + inode->i_blksize<<MSDOS_SB(sb)->cluster_shift; inode->i_mtime = inode->i_atime = date_dos2unix(CF_LE_W(raw_entry->time),CF_LE_W(raw_entry->date)); inode->i_ctime = diff --unified --recursive linux.120/fs/fat/misc.c linux/fs/fat/misc.c --- linux.120/fs/fat/misc.c Thu Jan 22 03:46:56 1998 +++ linux/fs/fat/misc.c Wed Sep 16 19:50:11 1998 @@ -149,7 +149,7 @@ struct super_block *sb = inode->i_sb; int count,nr,limit,last,curr,sector,last_sector,file_cluster; struct buffer_head *bh; - int cluster_size = MSDOS_SB(sb)->cluster_size; + int cluster_shift = MSDOS_SB(sb)->cluster_shift; if (MSDOS_SB(sb)->fat_bits != 32) { if (inode->i_ino == MSDOS_ROOT_INO) return -ENOSPC; @@ -219,8 +219,8 @@ #ifdef DEBUG if (last) printk("next set to %d\n",fat_access(sb,last,-1)); #endif - sector = MSDOS_SB(sb)->data_start+(nr-2)*cluster_size; - last_sector = sector + cluster_size; + sector = MSDOS_SB(sb)->data_start+((nr-2)<<cluster_shift); + last_sector = sector + (1<<cluster_shift); if (MSDOS_SB(sb)->cvf_format && MSDOS_SB(sb)->cvf_format->zero_out_cluster) MSDOS_SB(sb)->cvf_format->zero_out_cluster(inode,nr); @@ -238,20 +238,20 @@ fat_brelse(sb, bh); } } - if (file_cluster != inode->i_blocks/cluster_size){ + if (file_cluster != inode->i_blocks>>cluster_shift){ printk ("file_cluster badly computed!!! %d <> %ld\n" - ,file_cluster,inode->i_blocks/cluster_size); + ,file_cluster,inode->i_blocks>>cluster_shift); }else{ fat_cache_add(inode,file_cluster,nr); } - inode->i_blocks += cluster_size; + inode->i_blocks += 1<<cluster_shift; if (S_ISDIR(inode->i_mode)) { if (inode->i_size & (SECTOR_SIZE-1)) { fat_fs_panic(sb,"Odd directory size"); inode->i_size = (inode->i_size+SECTOR_SIZE) & ~(SECTOR_SIZE-1); } - inode->i_size += SECTOR_SIZE*cluster_size; + inode->i_size += SECTOR_SIZE<<cluster_shift; #ifdef DEBUG printk("size is %d now (%x)\n",inode->i_size,inode); #endif @@ -491,9 +491,9 @@ printk("raw_scan_nonroot: start=%d\n",start); #endif do { - for (count = 0; count < MSDOS_SB(sb)->cluster_size; count++) { - if ((cluster = raw_scan_sector(sb,(start-2)* - MSDOS_SB(sb)->cluster_size+MSDOS_SB(sb)->data_start+ + for (count = 0; count < (1<<MSDOS_SB(sb)->cluster_shift); count++) { + if ((cluster = raw_scan_sector(sb,((start-2)<< + MSDOS_SB(sb)->cluster_shift)+MSDOS_SB(sb)->data_start+ count,name,number,ino,res_bh,res_de,scantype)) >= 0) return cluster; } diff --unified --recursive linux.120/include/linux/msdos_fs.h linux/include/linux/msdos_fs.h --- linux.120/include/linux/msdos_fs.h Sat Sep 5 05:24:02 1998 +++ linux/include/linux/msdos_fs.h Thu Sep 17 17:05:41 1998 @@ -171,7 +171,7 @@ }; /* Determine whether this FS has kB-aligned data. */ -#define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \ +#define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_shift == 0) || \ ((mib)->data_start & 1))) /* Convert attribute bits and a mask to the UNIX mode. */ diff --unified --recursive linux.120/include/linux/msdos_fs_sb.h linux/include/linux/msdos_fs_sb.h --- linux.120/include/linux/msdos_fs_sb.h Fri Jan 9 00:02:41 1998 +++ linux/include/linux/msdos_fs_sb.h Thu Sep 17 17:06:58 1998 @@ -33,7 +33,7 @@ }; struct msdos_sb_info { - unsigned short cluster_size; /* sectors/cluster */ + unsigned short cluster_shift; /* power of 2 for cluster size */ unsigned char fats,fat_bits; /* number of FATs, FAT bits (12 or 16) */ unsigned short fat_start,fat_length; /* FAT start & length (sec.) */ unsigned short dir_start,dir_entries; /* root dir start & entries */ | |