@@ -281,15 +281,42 @@ static inline unsigned long fat_hash(loff_t i_pos)
281281 return hash_32 (i_pos , FAT_HASH_BITS );
282282}
283283
284+ static void dir_hash_init (struct super_block * sb )
285+ {
286+ struct msdos_sb_info * sbi = MSDOS_SB (sb );
287+ int i ;
288+
289+ spin_lock_init (& sbi -> dir_hash_lock );
290+ for (i = 0 ; i < FAT_HASH_SIZE ; i ++ )
291+ INIT_HLIST_HEAD (& sbi -> dir_hashtable [i ]);
292+ }
293+
284294void fat_attach (struct inode * inode , loff_t i_pos )
285295{
286296 struct msdos_sb_info * sbi = MSDOS_SB (inode -> i_sb );
287- struct hlist_head * head = sbi -> inode_hashtable + fat_hash (i_pos );
288297
289- spin_lock (& sbi -> inode_hash_lock );
290- MSDOS_I (inode )-> i_pos = i_pos ;
291- hlist_add_head (& MSDOS_I (inode )-> i_fat_hash , head );
292- spin_unlock (& sbi -> inode_hash_lock );
298+ if (inode -> i_ino != MSDOS_ROOT_INO ) {
299+ struct hlist_head * head = sbi -> inode_hashtable
300+ + fat_hash (i_pos );
301+
302+ spin_lock (& sbi -> inode_hash_lock );
303+ MSDOS_I (inode )-> i_pos = i_pos ;
304+ hlist_add_head (& MSDOS_I (inode )-> i_fat_hash , head );
305+ spin_unlock (& sbi -> inode_hash_lock );
306+ }
307+
308+ /* If NFS support is enabled, cache the mapping of start cluster
309+ * to directory inode. This is used during reconnection of
310+ * dentries to the filesystem root.
311+ */
312+ if (S_ISDIR (inode -> i_mode ) && sbi -> options .nfs ) {
313+ struct hlist_head * d_head = sbi -> dir_hashtable ;
314+ d_head += fat_dir_hash (MSDOS_I (inode )-> i_logstart );
315+
316+ spin_lock (& sbi -> dir_hash_lock );
317+ hlist_add_head (& MSDOS_I (inode )-> i_dir_hash , d_head );
318+ spin_unlock (& sbi -> dir_hash_lock );
319+ }
293320}
294321EXPORT_SYMBOL_GPL (fat_attach );
295322
@@ -300,6 +327,12 @@ void fat_detach(struct inode *inode)
300327 MSDOS_I (inode )-> i_pos = 0 ;
301328 hlist_del_init (& MSDOS_I (inode )-> i_fat_hash );
302329 spin_unlock (& sbi -> inode_hash_lock );
330+
331+ if (S_ISDIR (inode -> i_mode ) && sbi -> options .nfs ) {
332+ spin_lock (& sbi -> dir_hash_lock );
333+ hlist_del_init (& MSDOS_I (inode )-> i_dir_hash );
334+ spin_unlock (& sbi -> dir_hash_lock );
335+ }
303336}
304337EXPORT_SYMBOL_GPL (fat_detach );
305338
@@ -504,6 +537,7 @@ static void init_once(void *foo)
504537 ei -> cache_valid_id = FAT_CACHE_VALID + 1 ;
505538 INIT_LIST_HEAD (& ei -> cache_lru );
506539 INIT_HLIST_NODE (& ei -> i_fat_hash );
540+ INIT_HLIST_NODE (& ei -> i_dir_hash );
507541 inode_init_once (& ei -> vfs_inode );
508542}
509543
@@ -562,6 +596,20 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
562596 return 0 ;
563597}
564598
599+ static inline loff_t fat_i_pos_read (struct msdos_sb_info * sbi ,
600+ struct inode * inode )
601+ {
602+ loff_t i_pos ;
603+ #if BITS_PER_LONG == 32
604+ spin_lock (& sbi -> inode_hash_lock );
605+ #endif
606+ i_pos = MSDOS_I (inode )-> i_pos ;
607+ #if BITS_PER_LONG == 32
608+ spin_unlock (& sbi -> inode_hash_lock );
609+ #endif
610+ return i_pos ;
611+ }
612+
565613static int __fat_write_inode (struct inode * inode , int wait )
566614{
567615 struct super_block * sb = inode -> i_sb ;
@@ -655,8 +703,8 @@ static const struct super_operations fat_sops = {
655703};
656704
657705static const struct export_operations fat_export_ops = {
658- .encode_fh = fat_encode_fh ,
659706 .fh_to_dentry = fat_fh_to_dentry ,
707+ .fh_to_parent = fat_fh_to_parent ,
660708 .get_parent = fat_get_parent ,
661709};
662710
@@ -706,6 +754,8 @@ static int fat_show_options(struct seq_file *m, struct dentry *root)
706754 seq_puts (m , ",usefree" );
707755 if (opts -> quiet )
708756 seq_puts (m , ",quiet" );
757+ if (opts -> nfs )
758+ seq_puts (m , ",nfs" );
709759 if (opts -> showexec )
710760 seq_puts (m , ",showexec" );
711761 if (opts -> sys_immutable )
@@ -750,7 +800,7 @@ enum {
750800 Opt_shortname_winnt , Opt_shortname_mixed , Opt_utf8_no , Opt_utf8_yes ,
751801 Opt_uni_xl_no , Opt_uni_xl_yes , Opt_nonumtail_no , Opt_nonumtail_yes ,
752802 Opt_obsolete , Opt_flush , Opt_tz_utc , Opt_rodir , Opt_err_cont ,
753- Opt_err_panic , Opt_err_ro , Opt_discard , Opt_err ,
803+ Opt_err_panic , Opt_err_ro , Opt_discard , Opt_nfs , Opt_err ,
754804};
755805
756806static const match_table_t fat_tokens = {
@@ -779,6 +829,7 @@ static const match_table_t fat_tokens = {
779829 {Opt_err_panic , "errors=panic" },
780830 {Opt_err_ro , "errors=remount-ro" },
781831 {Opt_discard , "discard" },
832+ {Opt_nfs , "nfs" },
782833 {Opt_obsolete , "conv=binary" },
783834 {Opt_obsolete , "conv=text" },
784835 {Opt_obsolete , "conv=auto" },
@@ -859,6 +910,7 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
859910 opts -> numtail = 1 ;
860911 opts -> usefree = opts -> nocase = 0 ;
861912 opts -> tz_utc = 0 ;
913+ opts -> nfs = 0 ;
862914 opts -> errors = FAT_ERRORS_RO ;
863915 * debug = 0 ;
864916
@@ -1023,6 +1075,9 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
10231075 case Opt_discard :
10241076 opts -> discard = 1 ;
10251077 break ;
1078+ case Opt_nfs :
1079+ opts -> nfs = 1 ;
1080+ break ;
10261081
10271082 /* obsolete mount options */
10281083 case Opt_obsolete :
@@ -1313,6 +1368,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
13131368
13141369 /* set up enough so that it can read an inode */
13151370 fat_hash_init (sb );
1371+ dir_hash_init (sb );
13161372 fat_ent_access_init (sb );
13171373
13181374 /*
@@ -1367,6 +1423,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
13671423 }
13681424 error = - ENOMEM ;
13691425 insert_inode_hash (root_inode );
1426+ fat_attach (root_inode , 0 );
13701427 sb -> s_root = d_make_root (root_inode );
13711428 if (!sb -> s_root ) {
13721429 fat_msg (sb , KERN_ERR , "get root inode failed" );
0 commit comments