Skip to contentSkip to conversation

fat (exportfs): rebuild inode if ilookup() fails

PATCH In review Namjae Jeon 1 participant 1 message Aug 18, 2012 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 fat (exportfs): rebuild inode if ilookup() fails

From: Namjae Jeon <[email protected]>

Since the previous patch in this patch-set uses i_pos as the inode number, we can use it to find the directory entry of the inode and subsequently rebuild the inode if the cache lookups fail.

Since this involves accessing the FAT media,it is better to do this only if the 'nfs' mount option is enabled.

---
 fs/fat/nfs.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
fs/fat/nfs.c +18 -0
index ef4b5fa..44678e4 100644
@@ -52,6 +52,24 @@ static struct inode *fat_nfs_get_inode(struct super_block *sb,
 		iput(inode);
 		inode = NULL;
 	}
+	if (inode == NULL && MSDOS_SB(sb)->options.nfs) {
+		struct buffer_head *bh = NULL;
+		struct msdos_dir_entry *de ;
+		loff_t i_pos = (loff_t)ino;
+		int bits = MSDOS_SB(sb)->dir_per_block_bits;
+		loff_t blocknr = i_pos >> bits;
+		bh = sb_bread(sb, blocknr);
+		if (!bh) {
+			fat_msg(sb, KERN_ERR,
+				"unable to read block(%llu) for building NFS inode",
+				(llu)blocknr);
+			return inode;
+		}
+		de = (struct msdos_dir_entry *)bh->b_data;
+		inode = fat_build_inode(sb, &de[i_pos&((1<<bits)-1)],
+					i_pos);
+		brelse(bh);
+	}
 
 	return inode;
 }
Signature · 1 line
1.7.9.5