aboutsummaryrefslogtreecommitdiffstats
path: root/fs/befs/linuxvfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/befs/linuxvfs.c')
-rw-r--r--fs/befs/linuxvfs.c113
1 files changed, 57 insertions, 56 deletions
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 845d2d690ce2..d626756ff721 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -5,6 +5,8 @@
5 * 5 *
6 */ 6 */
7 7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
8#include <linux/module.h> 10#include <linux/module.h>
9#include <linux/slab.h> 11#include <linux/slab.h>
10#include <linux/fs.h> 12#include <linux/fs.h>
@@ -39,7 +41,6 @@ static struct dentry *befs_lookup(struct inode *, struct dentry *, unsigned int)
39static struct inode *befs_iget(struct super_block *, unsigned long); 41static struct inode *befs_iget(struct super_block *, unsigned long);
40static struct inode *befs_alloc_inode(struct super_block *sb); 42static struct inode *befs_alloc_inode(struct super_block *sb);
41static void befs_destroy_inode(struct inode *inode); 43static void befs_destroy_inode(struct inode *inode);
42static int befs_init_inodecache(void);
43static void befs_destroy_inodecache(void); 44static void befs_destroy_inodecache(void);
44static void *befs_follow_link(struct dentry *, struct nameidata *); 45static void *befs_follow_link(struct dentry *, struct nameidata *);
45static void *befs_fast_follow_link(struct dentry *, struct nameidata *); 46static void *befs_fast_follow_link(struct dentry *, struct nameidata *);
@@ -131,26 +132,28 @@ befs_get_block(struct inode *inode, sector_t block,
131 ulong disk_off; 132 ulong disk_off;
132 133
133 befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld", 134 befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld",
134 inode->i_ino, block); 135 (unsigned long)inode->i_ino, (long)block);
135 136
136 if (block < 0) { 137 if (block < 0) {
137 befs_error(sb, "befs_get_block() was asked for a block " 138 befs_error(sb, "befs_get_block() was asked for a block "
138 "number less than zero: block %ld in inode %lu", 139 "number less than zero: block %ld in inode %lu",
139 block, inode->i_ino); 140 (long)block, (unsigned long)inode->i_ino);
140 return -EIO; 141 return -EIO;
141 } 142 }
142 143
143 if (create) { 144 if (create) {
144 befs_error(sb, "befs_get_block() was asked to write to " 145 befs_error(sb, "befs_get_block() was asked to write to "
145 "block %ld in inode %lu", block, inode->i_ino); 146 "block %ld in inode %lu", (long)block,
147 (unsigned long)inode->i_ino);
146 return -EPERM; 148 return -EPERM;
147 } 149 }
148 150
149 res = befs_fblock2brun(sb, ds, block, &run); 151 res = befs_fblock2brun(sb, ds, block, &run);
150 if (res != BEFS_OK) { 152 if (res != BEFS_OK) {
151 befs_error(sb, 153 befs_error(sb,
152 "<--- befs_get_block() for inode %lu, block " 154 "<--- %s for inode %lu, block %ld ERROR",
153 "%ld ERROR", inode->i_ino, block); 155 __func__, (unsigned long)inode->i_ino,
156 (long)block);
154 return -EFBIG; 157 return -EFBIG;
155 } 158 }
156 159
@@ -158,8 +161,9 @@ befs_get_block(struct inode *inode, sector_t block,
158 161
159 map_bh(bh_result, inode->i_sb, disk_off); 162 map_bh(bh_result, inode->i_sb, disk_off);
160 163
161 befs_debug(sb, "<--- befs_get_block() for inode %lu, block %ld, " 164 befs_debug(sb, "<--- %s for inode %lu, block %ld, disk address %lu",
162 "disk address %lu", inode->i_ino, block, disk_off); 165 __func__, (unsigned long)inode->i_ino, (long)block,
166 (unsigned long)disk_off);
163 167
164 return 0; 168 return 0;
165} 169}
@@ -176,15 +180,15 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
176 char *utfname; 180 char *utfname;
177 const char *name = dentry->d_name.name; 181 const char *name = dentry->d_name.name;
178 182
179 befs_debug(sb, "---> befs_lookup() " 183 befs_debug(sb, "---> %s name %s inode %ld", __func__,
180 "name %s inode %ld", dentry->d_name.name, dir->i_ino); 184 dentry->d_name.name, dir->i_ino);
181 185
182 /* Convert to UTF-8 */ 186 /* Convert to UTF-8 */
183 if (BEFS_SB(sb)->nls) { 187 if (BEFS_SB(sb)->nls) {
184 ret = 188 ret =
185 befs_nls2utf(sb, name, strlen(name), &utfname, &utfnamelen); 189 befs_nls2utf(sb, name, strlen(name), &utfname, &utfnamelen);
186 if (ret < 0) { 190 if (ret < 0) {
187 befs_debug(sb, "<--- befs_lookup() ERROR"); 191 befs_debug(sb, "<--- %s ERROR", __func__);
188 return ERR_PTR(ret); 192 return ERR_PTR(ret);
189 } 193 }
190 ret = befs_btree_find(sb, ds, utfname, &offset); 194 ret = befs_btree_find(sb, ds, utfname, &offset);
@@ -195,12 +199,12 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
195 } 199 }
196 200
197 if (ret == BEFS_BT_NOT_FOUND) { 201 if (ret == BEFS_BT_NOT_FOUND) {
198 befs_debug(sb, "<--- befs_lookup() %s not found", 202 befs_debug(sb, "<--- %s %s not found", __func__,
199 dentry->d_name.name); 203 dentry->d_name.name);
200 return ERR_PTR(-ENOENT); 204 return ERR_PTR(-ENOENT);
201 205
202 } else if (ret != BEFS_OK || offset == 0) { 206 } else if (ret != BEFS_OK || offset == 0) {
203 befs_warning(sb, "<--- befs_lookup() Error"); 207 befs_warning(sb, "<--- %s Error", __func__);
204 return ERR_PTR(-ENODATA); 208 return ERR_PTR(-ENODATA);
205 } 209 }
206 210
@@ -210,7 +214,7 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
210 214
211 d_add(dentry, inode); 215 d_add(dentry, inode);
212 216
213 befs_debug(sb, "<--- befs_lookup()"); 217 befs_debug(sb, "<--- %s", __func__);
214 218
215 return NULL; 219 return NULL;
216} 220}
@@ -228,26 +232,25 @@ befs_readdir(struct file *file, struct dir_context *ctx)
228 char keybuf[BEFS_NAME_LEN + 1]; 232 char keybuf[BEFS_NAME_LEN + 1];
229 const char *dirname = file->f_path.dentry->d_name.name; 233 const char *dirname = file->f_path.dentry->d_name.name;
230 234
231 befs_debug(sb, "---> befs_readdir() " 235 befs_debug(sb, "---> %s name %s, inode %ld, ctx->pos %lld",
232 "name %s, inode %ld, ctx->pos %Ld", 236 __func__, dirname, inode->i_ino, ctx->pos);
233 dirname, inode->i_ino, ctx->pos);
234 237
235more: 238more:
236 result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1, 239 result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
237 keybuf, &keysize, &value); 240 keybuf, &keysize, &value);
238 241
239 if (result == BEFS_ERR) { 242 if (result == BEFS_ERR) {
240 befs_debug(sb, "<--- befs_readdir() ERROR"); 243 befs_debug(sb, "<--- %s ERROR", __func__);
241 befs_error(sb, "IO error reading %s (inode %lu)", 244 befs_error(sb, "IO error reading %s (inode %lu)",
242 dirname, inode->i_ino); 245 dirname, inode->i_ino);
243 return -EIO; 246 return -EIO;
244 247
245 } else if (result == BEFS_BT_END) { 248 } else if (result == BEFS_BT_END) {
246 befs_debug(sb, "<--- befs_readdir() END"); 249 befs_debug(sb, "<--- %s END", __func__);
247 return 0; 250 return 0;
248 251
249 } else if (result == BEFS_BT_EMPTY) { 252 } else if (result == BEFS_BT_EMPTY) {
250 befs_debug(sb, "<--- befs_readdir() Empty directory"); 253 befs_debug(sb, "<--- %s Empty directory", __func__);
251 return 0; 254 return 0;
252 } 255 }
253 256
@@ -260,7 +263,7 @@ more:
260 result = 263 result =
261 befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen); 264 befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen);
262 if (result < 0) { 265 if (result < 0) {
263 befs_debug(sb, "<--- befs_readdir() ERROR"); 266 befs_debug(sb, "<--- %s ERROR", __func__);
264 return result; 267 return result;
265 } 268 }
266 if (!dir_emit(ctx, nlsname, nlsnamelen, 269 if (!dir_emit(ctx, nlsname, nlsnamelen,
@@ -277,7 +280,7 @@ more:
277 ctx->pos++; 280 ctx->pos++;
278 goto more; 281 goto more;
279 282
280 befs_debug(sb, "<--- befs_readdir() pos %Ld", ctx->pos); 283 befs_debug(sb, "<--- %s pos %lld", __func__, ctx->pos);
281 284
282 return 0; 285 return 0;
283} 286}
@@ -321,7 +324,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
321 struct inode *inode; 324 struct inode *inode;
322 long ret = -EIO; 325 long ret = -EIO;
323 326
324 befs_debug(sb, "---> befs_read_inode() " "inode = %lu", ino); 327 befs_debug(sb, "---> %s inode = %lu", __func__, ino);
325 328
326 inode = iget_locked(sb, ino); 329 inode = iget_locked(sb, ino);
327 if (!inode) 330 if (!inode)
@@ -428,7 +431,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
428 } 431 }
429 432
430 brelse(bh); 433 brelse(bh);
431 befs_debug(sb, "<--- befs_read_inode()"); 434 befs_debug(sb, "<--- %s", __func__);
432 unlock_new_inode(inode); 435 unlock_new_inode(inode);
433 return inode; 436 return inode;
434 437
@@ -437,7 +440,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
437 440
438 unacquire_none: 441 unacquire_none:
439 iget_failed(inode); 442 iget_failed(inode);
440 befs_debug(sb, "<--- befs_read_inode() - Bad inode"); 443 befs_debug(sb, "<--- %s - Bad inode", __func__);
441 return ERR_PTR(ret); 444 return ERR_PTR(ret);
442} 445}
443 446
@@ -445,7 +448,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
445 * 448 *
446 * Taken from NFS implementation by Al Viro. 449 * Taken from NFS implementation by Al Viro.
447 */ 450 */
448static int 451static int __init
449befs_init_inodecache(void) 452befs_init_inodecache(void)
450{ 453{
451 befs_inode_cachep = kmem_cache_create("befs_inode_cache", 454 befs_inode_cachep = kmem_cache_create("befs_inode_cache",
@@ -454,11 +457,9 @@ befs_init_inodecache(void)
454 SLAB_MEM_SPREAD), 457 SLAB_MEM_SPREAD),
455 init_once); 458 init_once);
456 if (befs_inode_cachep == NULL) { 459 if (befs_inode_cachep == NULL) {
457 printk(KERN_ERR "befs_init_inodecache: " 460 pr_err("%s: Couldn't initialize inode slabcache\n", __func__);
458 "Couldn't initialize inode slabcache\n");
459 return -ENOMEM; 461 return -ENOMEM;
460 } 462 }
461
462 return 0; 463 return 0;
463} 464}
464 465
@@ -544,16 +545,16 @@ befs_utf2nls(struct super_block *sb, const char *in,
544 */ 545 */
545 int maxlen = in_len + 1; 546 int maxlen = in_len + 1;
546 547
547 befs_debug(sb, "---> utf2nls()"); 548 befs_debug(sb, "---> %s", __func__);
548 549
549 if (!nls) { 550 if (!nls) {
550 befs_error(sb, "befs_utf2nls called with no NLS table loaded"); 551 befs_error(sb, "%s called with no NLS table loaded", __func__);
551 return -EINVAL; 552 return -EINVAL;
552 } 553 }
553 554
554 *out = result = kmalloc(maxlen, GFP_NOFS); 555 *out = result = kmalloc(maxlen, GFP_NOFS);
555 if (!*out) { 556 if (!*out) {
556 befs_error(sb, "befs_utf2nls() cannot allocate memory"); 557 befs_error(sb, "%s cannot allocate memory", __func__);
557 *out_len = 0; 558 *out_len = 0;
558 return -ENOMEM; 559 return -ENOMEM;
559 } 560 }
@@ -575,14 +576,14 @@ befs_utf2nls(struct super_block *sb, const char *in,
575 result[o] = '\0'; 576 result[o] = '\0';
576 *out_len = o; 577 *out_len = o;
577 578
578 befs_debug(sb, "<--- utf2nls()"); 579 befs_debug(sb, "<--- %s", __func__);
579 580
580 return o; 581 return o;
581 582
582 conv_err: 583 conv_err:
583 befs_error(sb, "Name using character set %s contains a character that " 584 befs_error(sb, "Name using character set %s contains a character that "
584 "cannot be converted to unicode.", nls->charset); 585 "cannot be converted to unicode.", nls->charset);
585 befs_debug(sb, "<--- utf2nls()"); 586 befs_debug(sb, "<--- %s", __func__);
586 kfree(result); 587 kfree(result);
587 return -EILSEQ; 588 return -EILSEQ;
588} 589}
@@ -623,16 +624,17 @@ befs_nls2utf(struct super_block *sb, const char *in,
623 * in special cases */ 624 * in special cases */
624 int maxlen = (3 * in_len) + 1; 625 int maxlen = (3 * in_len) + 1;
625 626
626 befs_debug(sb, "---> nls2utf()\n"); 627 befs_debug(sb, "---> %s\n", __func__);
627 628
628 if (!nls) { 629 if (!nls) {
629 befs_error(sb, "befs_nls2utf called with no NLS table loaded."); 630 befs_error(sb, "%s called with no NLS table loaded.",
631 __func__);
630 return -EINVAL; 632 return -EINVAL;
631 } 633 }
632 634
633 *out = result = kmalloc(maxlen, GFP_NOFS); 635 *out = result = kmalloc(maxlen, GFP_NOFS);
634 if (!*out) { 636 if (!*out) {
635 befs_error(sb, "befs_nls2utf() cannot allocate memory"); 637 befs_error(sb, "%s cannot allocate memory", __func__);
636 *out_len = 0; 638 *out_len = 0;
637 return -ENOMEM; 639 return -ENOMEM;
638 } 640 }
@@ -653,14 +655,14 @@ befs_nls2utf(struct super_block *sb, const char *in,
653 result[o] = '\0'; 655 result[o] = '\0';
654 *out_len = o; 656 *out_len = o;
655 657
656 befs_debug(sb, "<--- nls2utf()"); 658 befs_debug(sb, "<--- %s", __func__);
657 659
658 return i; 660 return i;
659 661
660 conv_err: 662 conv_err:
661 befs_error(sb, "Name using charecter set %s contains a charecter that " 663 befs_error(sb, "Name using charecter set %s contains a charecter that "
662 "cannot be converted to unicode.", nls->charset); 664 "cannot be converted to unicode.", nls->charset);
663 befs_debug(sb, "<--- nls2utf()"); 665 befs_debug(sb, "<--- %s", __func__);
664 kfree(result); 666 kfree(result);
665 return -EILSEQ; 667 return -EILSEQ;
666} 668}
@@ -715,8 +717,8 @@ parse_options(char *options, befs_mount_options * opts)
715 if (option >= 0) 717 if (option >= 0)
716 uid = make_kuid(current_user_ns(), option); 718 uid = make_kuid(current_user_ns(), option);
717 if (!uid_valid(uid)) { 719 if (!uid_valid(uid)) {
718 printk(KERN_ERR "BeFS: Invalid uid %d, " 720 pr_err("Invalid uid %d, "
719 "using default\n", option); 721 "using default\n", option);
720 break; 722 break;
721 } 723 }
722 opts->uid = uid; 724 opts->uid = uid;
@@ -729,8 +731,8 @@ parse_options(char *options, befs_mount_options * opts)
729 if (option >= 0) 731 if (option >= 0)
730 gid = make_kgid(current_user_ns(), option); 732 gid = make_kgid(current_user_ns(), option);
731 if (!gid_valid(gid)) { 733 if (!gid_valid(gid)) {
732 printk(KERN_ERR "BeFS: Invalid gid %d, " 734 pr_err("Invalid gid %d, "
733 "using default\n", option); 735 "using default\n", option);
734 break; 736 break;
735 } 737 }
736 opts->gid = gid; 738 opts->gid = gid;
@@ -740,8 +742,8 @@ parse_options(char *options, befs_mount_options * opts)
740 kfree(opts->iocharset); 742 kfree(opts->iocharset);
741 opts->iocharset = match_strdup(&args[0]); 743 opts->iocharset = match_strdup(&args[0]);
742 if (!opts->iocharset) { 744 if (!opts->iocharset) {
743 printk(KERN_ERR "BeFS: allocation failure for " 745 pr_err("allocation failure for "
744 "iocharset string\n"); 746 "iocharset string\n");
745 return 0; 747 return 0;
746 } 748 }
747 break; 749 break;
@@ -749,8 +751,8 @@ parse_options(char *options, befs_mount_options * opts)
749 opts->debug = 1; 751 opts->debug = 1;
750 break; 752 break;
751 default: 753 default:
752 printk(KERN_ERR "BeFS: Unrecognized mount option \"%s\" " 754 pr_err("Unrecognized mount option \"%s\" "
753 "or missing value\n", p); 755 "or missing value\n", p);
754 return 0; 756 return 0;
755 } 757 }
756 } 758 }
@@ -791,22 +793,20 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
791 793
792 save_mount_options(sb, data); 794 save_mount_options(sb, data);
793 795
794 sb->s_fs_info = kmalloc(sizeof (*befs_sb), GFP_KERNEL); 796 sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL);
795 if (sb->s_fs_info == NULL) { 797 if (sb->s_fs_info == NULL) {
796 printk(KERN_ERR 798 pr_err("(%s): Unable to allocate memory for private "
797 "BeFS(%s): Unable to allocate memory for private "
798 "portion of superblock. Bailing.\n", sb->s_id); 799 "portion of superblock. Bailing.\n", sb->s_id);
799 goto unacquire_none; 800 goto unacquire_none;
800 } 801 }
801 befs_sb = BEFS_SB(sb); 802 befs_sb = BEFS_SB(sb);
802 memset(befs_sb, 0, sizeof(befs_sb_info));
803 803
804 if (!parse_options((char *) data, &befs_sb->mount_opts)) { 804 if (!parse_options((char *) data, &befs_sb->mount_opts)) {
805 befs_error(sb, "cannot parse mount options"); 805 befs_error(sb, "cannot parse mount options");
806 goto unacquire_priv_sbp; 806 goto unacquire_priv_sbp;
807 } 807 }
808 808
809 befs_debug(sb, "---> befs_fill_super()"); 809 befs_debug(sb, "---> %s", __func__);
810 810
811#ifndef CONFIG_BEFS_RW 811#ifndef CONFIG_BEFS_RW
812 if (!(sb->s_flags & MS_RDONLY)) { 812 if (!(sb->s_flags & MS_RDONLY)) {
@@ -854,7 +854,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
854 goto unacquire_priv_sbp; 854 goto unacquire_priv_sbp;
855 855
856 if( befs_sb->num_blocks > ~((sector_t)0) ) { 856 if( befs_sb->num_blocks > ~((sector_t)0) ) {
857 befs_error(sb, "blocks count: %Lu " 857 befs_error(sb, "blocks count: %llu "
858 "is larger than the host can use", 858 "is larger than the host can use",
859 befs_sb->num_blocks); 859 befs_sb->num_blocks);
860 goto unacquire_priv_sbp; 860 goto unacquire_priv_sbp;
@@ -913,6 +913,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
913static int 913static int
914befs_remount(struct super_block *sb, int *flags, char *data) 914befs_remount(struct super_block *sb, int *flags, char *data)
915{ 915{
916 sync_filesystem(sb);
916 if (!(*flags & MS_RDONLY)) 917 if (!(*flags & MS_RDONLY))
917 return -EINVAL; 918 return -EINVAL;
918 return 0; 919 return 0;
@@ -924,7 +925,7 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)
924 struct super_block *sb = dentry->d_sb; 925 struct super_block *sb = dentry->d_sb;
925 u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 926 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
926 927
927 befs_debug(sb, "---> befs_statfs()"); 928 befs_debug(sb, "---> %s", __func__);
928 929
929 buf->f_type = BEFS_SUPER_MAGIC; 930 buf->f_type = BEFS_SUPER_MAGIC;
930 buf->f_bsize = sb->s_blocksize; 931 buf->f_bsize = sb->s_blocksize;
@@ -937,7 +938,7 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)
937 buf->f_fsid.val[1] = (u32)(id >> 32); 938 buf->f_fsid.val[1] = (u32)(id >> 32);
938 buf->f_namelen = BEFS_NAME_LEN; 939 buf->f_namelen = BEFS_NAME_LEN;
939 940
940 befs_debug(sb, "<--- befs_statfs()"); 941 befs_debug(sb, "<--- %s", __func__);
941 942
942 return 0; 943 return 0;
943} 944}
@@ -963,7 +964,7 @@ init_befs_fs(void)
963{ 964{
964 int err; 965 int err;
965 966
966 printk(KERN_INFO "BeFS version: %s\n", BEFS_VERSION); 967 pr_info("version: %s\n", BEFS_VERSION);
967 968
968 err = befs_init_inodecache(); 969 err = befs_init_inodecache();
969 if (err) 970 if (err)