linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] adds fat_get_cluster (7/11)
@ 2003-07-21 15:55 OGAWA Hirofumi
  0 siblings, 0 replies; only message in thread
From: OGAWA Hirofumi @ 2003-07-21 15:55 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

This adds the fat_get_cluster() for generic reads of FAT
cluster-chains, and old fat_get_cluster() is renamed to
fat_bmap_cluster().


 fs/fat/cache.c           |   46 ++++++++++++++++++++++++++++++++++++++++++++--
 include/linux/msdos_fs.h |    2 ++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff -puN fs/fat/cache.c~fat_add-get_cluster fs/fat/cache.c
--- linux-2.6.0-test1/fs/fat/cache.c~fat_add-get_cluster	2003-07-21 02:48:24.000000000 +0900
+++ linux-2.6.0-test1-hirofumi/fs/fat/cache.c	2003-07-21 02:48:24.000000000 +0900
@@ -287,7 +287,49 @@ out:
 	spin_unlock(&sbi->cache_lock);
 }
 
-static int fat_get_cluster(struct inode *inode, int cluster)
+int fat_get_cluster(struct inode *inode, int cluster, int *fclus, int *dclus)
+{
+	struct super_block *sb = inode->i_sb;
+	const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits;
+	int nr;
+
+	BUG_ON(MSDOS_I(inode)->i_start == 0);
+	
+	*fclus = 0;
+	*dclus = MSDOS_I(inode)->i_start;
+	if (cluster == 0)
+		return 0;
+
+	fat_cache_lookup(inode, cluster, fclus, dclus);
+	while (*fclus < cluster) {
+		/* prevent the infinite loop of cluster chain */
+		if (*fclus > limit) {
+			fat_fs_panic(sb, "%s: detected the cluster chain loop"
+				     " (i_pos %llu)", __FUNCTION__,
+				     MSDOS_I(inode)->i_pos);
+			return -EIO;
+		}
+
+		nr = fat_access(sb, *dclus, -1);
+		if (nr < 0)
+ 			return nr;
+		else if (nr == FAT_ENT_FREE) {
+			fat_fs_panic(sb, "%s: invalid cluster chain"
+				     " (i_pos %llu)", __FUNCTION__,
+				     MSDOS_I(inode)->i_pos);
+			return -EIO;
+		} else if (nr == FAT_ENT_EOF) {
+			fat_cache_add(inode, *fclus, *dclus);
+			return FAT_ENT_EOF;
+		}
+		(*fclus)++;
+		*dclus = nr;
+	}
+	fat_cache_add(inode, *fclus, *dclus);
+	return 0;
+}
+
+static int fat_bmap_cluster(struct inode *inode, int cluster)
 {
 	struct super_block *sb = inode->i_sb;
 	int nr,count;
@@ -336,7 +378,7 @@ int fat_bmap(struct inode *inode, sector
 
 	cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
 	offset  = sector & (sbi->cluster_size - 1);
-	cluster = fat_get_cluster(inode, cluster);
+	cluster = fat_bmap_cluster(inode, cluster);
 	if (cluster < 0)
 		return cluster;
 	else if (cluster) {
diff -puN include/linux/msdos_fs.h~fat_add-get_cluster include/linux/msdos_fs.h
--- linux-2.6.0-test1/include/linux/msdos_fs.h~fat_add-get_cluster	2003-07-21 02:48:24.000000000 +0900
+++ linux-2.6.0-test1-hirofumi/include/linux/msdos_fs.h	2003-07-21 02:48:24.000000000 +0900
@@ -237,6 +237,8 @@ extern void fat_cache_lookup(struct inod
 			     int *d_clu);
 extern void fat_cache_add(struct inode *inode, int f_clu, int d_clu);
 extern void fat_cache_inval_inode(struct inode *inode);
+extern int fat_get_cluster(struct inode *inode, int cluster,
+			   int *fclus, int *dclus);
 extern int fat_free(struct inode *inode, int skip);
 
 /* fat/dir.c */

_

-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-21 15:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-21 15:55 [PATCH] adds fat_get_cluster (7/11) OGAWA Hirofumi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).