@@ -42,7 +42,7 @@ static void befs_destroy_inode(struct inode *inode);
4242static int befs_init_inodecache (void );
4343static void befs_destroy_inodecache (void );
4444static void * befs_follow_link (struct dentry * , struct nameidata * );
45- static void befs_put_link (struct dentry * , struct nameidata * , void * );
45+ static void * befs_fast_follow_link (struct dentry * , struct nameidata * );
4646static int befs_utf2nls (struct super_block * sb , const char * in , int in_len ,
4747 char * * out , int * out_len );
4848static int befs_nls2utf (struct super_block * sb , const char * in , int in_len ,
@@ -79,10 +79,15 @@ static const struct address_space_operations befs_aops = {
7979 .bmap = befs_bmap ,
8080};
8181
82+ static const struct inode_operations befs_fast_symlink_inode_operations = {
83+ .readlink = generic_readlink ,
84+ .follow_link = befs_fast_follow_link ,
85+ };
86+
8287static const struct inode_operations befs_symlink_inode_operations = {
8388 .readlink = generic_readlink ,
8489 .follow_link = befs_follow_link ,
85- .put_link = befs_put_link ,
90+ .put_link = kfree_put_link ,
8691};
8792
8893/*
@@ -411,7 +416,10 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
411416 inode -> i_op = & befs_dir_inode_operations ;
412417 inode -> i_fop = & befs_dir_operations ;
413418 } else if (S_ISLNK (inode -> i_mode )) {
414- inode -> i_op = & befs_symlink_inode_operations ;
419+ if (befs_ino -> i_flags & BEFS_LONG_SYMLINK )
420+ inode -> i_op = & befs_symlink_inode_operations ;
421+ else
422+ inode -> i_op = & befs_fast_symlink_inode_operations ;
415423 } else {
416424 befs_error (sb , "Inode %lu is not a regular file, "
417425 "directory or symlink. THAT IS WRONG! BeFS has no "
@@ -477,47 +485,40 @@ befs_destroy_inodecache(void)
477485static void *
478486befs_follow_link (struct dentry * dentry , struct nameidata * nd )
479487{
488+ struct super_block * sb = dentry -> d_sb ;
480489 befs_inode_info * befs_ino = BEFS_I (dentry -> d_inode );
490+ befs_data_stream * data = & befs_ino -> i_data .ds ;
491+ befs_off_t len = data -> size ;
481492 char * link ;
482493
483- if (befs_ino -> i_flags & BEFS_LONG_SYMLINK ) {
484- struct super_block * sb = dentry -> d_sb ;
485- befs_data_stream * data = & befs_ino -> i_data .ds ;
486- befs_off_t len = data -> size ;
494+ if (len == 0 ) {
495+ befs_error (sb , "Long symlink with illegal length" );
496+ link = ERR_PTR (- EIO );
497+ } else {
498+ befs_debug (sb , "Follow long symlink" );
487499
488- if (len == 0 ) {
489- befs_error (sb , "Long symlink with illegal length" );
500+ link = kmalloc (len , GFP_NOFS );
501+ if (!link ) {
502+ link = ERR_PTR (- ENOMEM );
503+ } else if (befs_read_lsymlink (sb , data , link , len ) != len ) {
504+ kfree (link );
505+ befs_error (sb , "Failed to read entire long symlink" );
490506 link = ERR_PTR (- EIO );
491507 } else {
492- befs_debug (sb , "Follow long symlink" );
493-
494- link = kmalloc (len , GFP_NOFS );
495- if (!link ) {
496- link = ERR_PTR (- ENOMEM );
497- } else if (befs_read_lsymlink (sb , data , link , len ) != len ) {
498- kfree (link );
499- befs_error (sb , "Failed to read entire long symlink" );
500- link = ERR_PTR (- EIO );
501- } else {
502- link [len - 1 ] = '\0' ;
503- }
508+ link [len - 1 ] = '\0' ;
504509 }
505- } else {
506- link = befs_ino -> i_data .symlink ;
507510 }
508-
509511 nd_set_link (nd , link );
510512 return NULL ;
511513}
512514
513- static void befs_put_link (struct dentry * dentry , struct nameidata * nd , void * p )
515+
516+ static void *
517+ befs_fast_follow_link (struct dentry * dentry , struct nameidata * nd )
514518{
515519 befs_inode_info * befs_ino = BEFS_I (dentry -> d_inode );
516- if (befs_ino -> i_flags & BEFS_LONG_SYMLINK ) {
517- char * link = nd_get_link (nd );
518- if (!IS_ERR (link ))
519- kfree (link );
520- }
520+ nd_set_link (nd , befs_ino -> i_data .symlink );
521+ return NULL ;
521522}
522523
523524/*
0 commit comments