Skip to contentSkip to conversation

fat: Editions to support fat_fallocate()

PATCH New Steven Cavanagh 1 participant 1 message Dec 12, 2007 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fat: Editions to support fat_fallocate()

From: Steven Cavanagh <[email protected]>

Added support for fallocate for a msdos fat driver. This allows preallocation of clusters to an inode before writes to reduce file fragmentation

---

 fs/fat/cache.c           |    9 ++
 fs/fat/file.c            |  167 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/fat/inode.c           |   21 ++++++
 include/linux/msdos_fs.h |    5 +
 4 files changed, 201 insertions(+), 1 deletions(-)
fs/fat/cache.c +9 -0
index 639b3b4..1a69ce4 100644
@@ -8,6 +8,8 @@
  *  May 1999. AV. Fixed the bogosity with FAT32 (read "FAT28"). Fscking lusers.
  */
 
+#undef DEBUG
+
 #include <linux/fs.h>
 #include <linux/msdos_fs.h>
 #include <linux/buffer_head.h>
@@ -316,6 +318,10 @@ int fat_bmap(struct inode *inode, sector
 
 	cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
 	offset  = sector & (sbi->sec_per_clus - 1);
+
+	pr_debug("fat_bmap():cluster:%d, offset:%d, last_block:%llu\n",
+		cluster, offset, last_block);
+
 	cluster = fat_bmap_cluster(inode, cluster);
 	if (cluster < 0)
 		return cluster;
@@ -324,6 +330,9 @@ int fat_bmap(struct inode *inode, sector
 		*mapped_blocks = sbi->sec_per_clus - offset;
 		if (*mapped_blocks > last_block - sector)
 			*mapped_blocks = last_block - sector;
+
+			pr_debug("fat_bmap():cluster:%d, phys:%llu\n",
+				cluster, *phys);
 	}
 	return 0;
 }
fs/fat/file.c +167 -0

187 lines not on this page · raw message

fs/fat/inode.c +20 -1
index 920a576..463ead5 100644
@@ -10,6 +10,8 @@
  *	Max Cohan: Fixed invalid FSINFO offset when info_sector is 0
  */
 
+#undef DEBUG
+
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/time.h>
@@ -38,7 +40,7 @@ static int fat_default_codepage = CONFIG
 static char fat_default_iocharset[] = CONFIG_FAT_DEFAULT_IOCHARSET;
 
 
-static int fat_add_cluster(struct inode *inode)
+int fat_add_cluster(struct inode *inode)
 {
 	int err, cluster;
 
@@ -64,6 +66,11 @@ static inline int __fat_get_block(struct
 	int err, offset;
 
 	err = fat_bmap(inode, iblock, &phys, &mapped_blocks);
+
+	pr_debug(
+	"__fat_get_block():phys: %llu, mapped_blocks:%lu,sector: %llu\n",
+		phys, mapped_blocks, iblock);
+
 	if (err)
 		return err;
 	if (phys) {
@@ -90,10 +97,18 @@ static inline int __fat_get_block(struct
 	/* available blocks on this cluster */
 	mapped_blocks = sbi->sec_per_clus - offset;
 
+	pr_debug(
+	"__fat_get_block(): max_blocks: %lu, mapped_blocks:%lu\n",
+		*max_blocks, mapped_blocks);
+
 	*max_blocks = min(mapped_blocks, *max_blocks);
 	MSDOS_I(inode)->mmu_private += *max_blocks << sb->s_blocksize_bits;
 
 	err = fat_bmap(inode, iblock, &phys, &mapped_blocks);
+	pr_debug(
+	"__fat_get_block():phys: %llu, mapped_blocks:%lu,sector: %llu\n",
+		phys, mapped_blocks, iblock);
+
 	if (err)
 		return err;
 
@@ -116,6 +131,10 @@ static int fat_get_block(struct inode *i
 	if (err)
 		return err;
 	bh_result->b_size = max_blocks << sb->s_blocksize_bits;
+
+	printk(KERN_INFO "fat_get_block():bh_result->b_size:%d\n",
+	       bh_result->b_size);
+
 	return 0;
 }
 
include/linux/msdos_fs.h +5 -0
index f950921..034a2a4 100644
@@ -109,6 +109,8 @@ #define VFAT_SFN_DISPLAY_WINNT	0x0004 /*
 #define VFAT_SFN_CREATE_WIN95	0x0100 /* emulate win95 rule for create */
 #define VFAT_SFN_CREATE_WINNT	0x0200 /* emulate winnt rule for create */
 
+#define MSDOS_BLOCK_ALIGN(size, blkbits)	ALIGN((size), (1 << (blkbits)))
+
 struct fat_boot_sector {
 	__u8	ignored[3];	/* Boot strap short or near jump */
 	__u8	system_id[8];	/* Name - can be used to special case
@@ -350,6 +352,9 @@ extern int fat_add_entries(struct inode 
 			   struct fat_slot_info *sinfo);
 extern int fat_remove_entries(struct inode *dir, struct fat_slot_info *sinfo);
 
+/* fat/inode.c */
+extern int fat_add_cluster(struct inode *inode);
+
 /* fat/fatent.c */
 struct fat_entry {
 	int entry;