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.c130
1 files changed, 64 insertions, 66 deletions
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index bfe9f9994935..647a276eba56 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -120,7 +120,7 @@ befs_get_block(struct inode *inode, sector_t block,
120 struct super_block *sb = inode->i_sb; 120 struct super_block *sb = inode->i_sb;
121 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds; 121 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds;
122 befs_block_run run = BAD_IADDR; 122 befs_block_run run = BAD_IADDR;
123 int res = 0; 123 int res;
124 ulong disk_off; 124 ulong disk_off;
125 125
126 befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld", 126 befs_debug(sb, "---> befs_get_block() for inode %lu, block %ld",
@@ -179,15 +179,16 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
179 kfree(utfname); 179 kfree(utfname);
180 180
181 } else { 181 } else {
182 ret = befs_btree_find(sb, ds, dentry->d_name.name, &offset); 182 ret = befs_btree_find(sb, ds, name, &offset);
183 } 183 }
184 184
185 if (ret == BEFS_BT_NOT_FOUND) { 185 if (ret == BEFS_BT_NOT_FOUND) {
186 befs_debug(sb, "<--- %s %pd not found", __func__, dentry); 186 befs_debug(sb, "<--- %s %pd not found", __func__, dentry);
187 d_add(dentry, NULL);
187 return ERR_PTR(-ENOENT); 188 return ERR_PTR(-ENOENT);
188 189
189 } else if (ret != BEFS_OK || offset == 0) { 190 } else if (ret != BEFS_OK || offset == 0) {
190 befs_warning(sb, "<--- %s Error", __func__); 191 befs_error(sb, "<--- %s Error", __func__);
191 return ERR_PTR(-ENODATA); 192 return ERR_PTR(-ENODATA);
192 } 193 }
193 194
@@ -211,56 +212,55 @@ befs_readdir(struct file *file, struct dir_context *ctx)
211 befs_off_t value; 212 befs_off_t value;
212 int result; 213 int result;
213 size_t keysize; 214 size_t keysize;
214 unsigned char d_type;
215 char keybuf[BEFS_NAME_LEN + 1]; 215 char keybuf[BEFS_NAME_LEN + 1];
216 216
217 befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld", 217 befs_debug(sb, "---> %s name %pD, inode %ld, ctx->pos %lld",
218 __func__, file, inode->i_ino, ctx->pos); 218 __func__, file, inode->i_ino, ctx->pos);
219 219
220more: 220 while (1) {
221 result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1, 221 result = befs_btree_read(sb, ds, ctx->pos, BEFS_NAME_LEN + 1,
222 keybuf, &keysize, &value); 222 keybuf, &keysize, &value);
223 223
224 if (result == BEFS_ERR) { 224 if (result == BEFS_ERR) {
225 befs_debug(sb, "<--- %s ERROR", __func__); 225 befs_debug(sb, "<--- %s ERROR", __func__);
226 befs_error(sb, "IO error reading %pD (inode %lu)", 226 befs_error(sb, "IO error reading %pD (inode %lu)",
227 file, inode->i_ino); 227 file, inode->i_ino);
228 return -EIO; 228 return -EIO;
229
230 } else if (result == BEFS_BT_END) {
231 befs_debug(sb, "<--- %s END", __func__);
232 return 0;
233
234 } else if (result == BEFS_BT_EMPTY) {
235 befs_debug(sb, "<--- %s Empty directory", __func__);
236 return 0;
237 }
238 229
239 d_type = DT_UNKNOWN; 230 } else if (result == BEFS_BT_END) {
231 befs_debug(sb, "<--- %s END", __func__);
232 return 0;
240 233
241 /* Convert to NLS */ 234 } else if (result == BEFS_BT_EMPTY) {
242 if (BEFS_SB(sb)->nls) { 235 befs_debug(sb, "<--- %s Empty directory", __func__);
243 char *nlsname; 236 return 0;
244 int nlsnamelen;
245 result =
246 befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen);
247 if (result < 0) {
248 befs_debug(sb, "<--- %s ERROR", __func__);
249 return result;
250 } 237 }
251 if (!dir_emit(ctx, nlsname, nlsnamelen, 238
252 (ino_t) value, d_type)) { 239 /* Convert to NLS */
240 if (BEFS_SB(sb)->nls) {
241 char *nlsname;
242 int nlsnamelen;
243
244 result =
245 befs_utf2nls(sb, keybuf, keysize, &nlsname,
246 &nlsnamelen);
247 if (result < 0) {
248 befs_debug(sb, "<--- %s ERROR", __func__);
249 return result;
250 }
251 if (!dir_emit(ctx, nlsname, nlsnamelen,
252 (ino_t) value, DT_UNKNOWN)) {
253 kfree(nlsname);
254 return 0;
255 }
253 kfree(nlsname); 256 kfree(nlsname);
254 return 0; 257 } else {
258 if (!dir_emit(ctx, keybuf, keysize,
259 (ino_t) value, DT_UNKNOWN))
260 return 0;
255 } 261 }
256 kfree(nlsname); 262 ctx->pos++;
257 } else {
258 if (!dir_emit(ctx, keybuf, keysize,
259 (ino_t) value, d_type))
260 return 0;
261 } 263 }
262 ctx->pos++;
263 goto more;
264} 264}
265 265
266static struct inode * 266static struct inode *
@@ -299,7 +299,6 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
299 struct befs_sb_info *befs_sb = BEFS_SB(sb); 299 struct befs_sb_info *befs_sb = BEFS_SB(sb);
300 struct befs_inode_info *befs_ino; 300 struct befs_inode_info *befs_ino;
301 struct inode *inode; 301 struct inode *inode;
302 long ret = -EIO;
303 302
304 befs_debug(sb, "---> %s inode = %lu", __func__, ino); 303 befs_debug(sb, "---> %s inode = %lu", __func__, ino);
305 304
@@ -318,7 +317,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
318 befs_ino->i_inode_num.allocation_group, 317 befs_ino->i_inode_num.allocation_group,
319 befs_ino->i_inode_num.start, befs_ino->i_inode_num.len); 318 befs_ino->i_inode_num.start, befs_ino->i_inode_num.len);
320 319
321 bh = befs_bread(sb, inode->i_ino); 320 bh = sb_bread(sb, inode->i_ino);
322 if (!bh) { 321 if (!bh) {
323 befs_error(sb, "unable to read inode block - " 322 befs_error(sb, "unable to read inode block - "
324 "inode = %lu", inode->i_ino); 323 "inode = %lu", inode->i_ino);
@@ -421,7 +420,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
421 unacquire_none: 420 unacquire_none:
422 iget_failed(inode); 421 iget_failed(inode);
423 befs_debug(sb, "<--- %s - Bad inode", __func__); 422 befs_debug(sb, "<--- %s - Bad inode", __func__);
424 return ERR_PTR(ret); 423 return ERR_PTR(-EIO);
425} 424}
426 425
427/* Initialize the inode cache. Called at fs setup. 426/* Initialize the inode cache. Called at fs setup.
@@ -436,10 +435,9 @@ befs_init_inodecache(void)
436 0, (SLAB_RECLAIM_ACCOUNT| 435 0, (SLAB_RECLAIM_ACCOUNT|
437 SLAB_MEM_SPREAD|SLAB_ACCOUNT), 436 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
438 init_once); 437 init_once);
439 if (befs_inode_cachep == NULL) { 438 if (befs_inode_cachep == NULL)
440 pr_err("%s: Couldn't initialize inode slabcache\n", __func__);
441 return -ENOMEM; 439 return -ENOMEM;
442 } 440
443 return 0; 441 return 0;
444} 442}
445 443
@@ -524,8 +522,6 @@ befs_utf2nls(struct super_block *sb, const char *in,
524 522
525 *out = result = kmalloc(maxlen, GFP_NOFS); 523 *out = result = kmalloc(maxlen, GFP_NOFS);
526 if (!*out) { 524 if (!*out) {
527 befs_error(sb, "%s cannot allocate memory", __func__);
528 *out_len = 0;
529 return -ENOMEM; 525 return -ENOMEM;
530 } 526 }
531 527
@@ -604,7 +600,6 @@ befs_nls2utf(struct super_block *sb, const char *in,
604 600
605 *out = result = kmalloc(maxlen, GFP_NOFS); 601 *out = result = kmalloc(maxlen, GFP_NOFS);
606 if (!*out) { 602 if (!*out) {
607 befs_error(sb, "%s cannot allocate memory", __func__);
608 *out_len = 0; 603 *out_len = 0;
609 return -ENOMEM; 604 return -ENOMEM;
610 } 605 }
@@ -637,10 +632,6 @@ befs_nls2utf(struct super_block *sb, const char *in,
637 return -EILSEQ; 632 return -EILSEQ;
638} 633}
639 634
640/**
641 * Use the
642 *
643 */
644enum { 635enum {
645 Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err, 636 Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err,
646}; 637};
@@ -760,19 +751,19 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
760 long ret = -EINVAL; 751 long ret = -EINVAL;
761 const unsigned long sb_block = 0; 752 const unsigned long sb_block = 0;
762 const off_t x86_sb_off = 512; 753 const off_t x86_sb_off = 512;
754 int blocksize;
763 755
764 save_mount_options(sb, data); 756 save_mount_options(sb, data);
765 757
766 sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL); 758 sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL);
767 if (sb->s_fs_info == NULL) { 759 if (sb->s_fs_info == NULL)
768 pr_err("(%s): Unable to allocate memory for private "
769 "portion of superblock. Bailing.\n", sb->s_id);
770 goto unacquire_none; 760 goto unacquire_none;
771 } 761
772 befs_sb = BEFS_SB(sb); 762 befs_sb = BEFS_SB(sb);
773 763
774 if (!parse_options((char *) data, &befs_sb->mount_opts)) { 764 if (!parse_options((char *) data, &befs_sb->mount_opts)) {
775 befs_error(sb, "cannot parse mount options"); 765 if (!silent)
766 befs_error(sb, "cannot parse mount options");
776 goto unacquire_priv_sbp; 767 goto unacquire_priv_sbp;
777 } 768 }
778 769
@@ -793,10 +784,16 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
793 * least 1k to get the second 512 bytes of the volume. 784 * least 1k to get the second 512 bytes of the volume.
794 * -WD 10-26-01 785 * -WD 10-26-01
795 */ 786 */
796 sb_min_blocksize(sb, 1024); 787 blocksize = sb_min_blocksize(sb, 1024);
788 if (!blocksize) {
789 if (!silent)
790 befs_error(sb, "unable to set blocksize");
791 goto unacquire_priv_sbp;
792 }
797 793
798 if (!(bh = sb_bread(sb, sb_block))) { 794 if (!(bh = sb_bread(sb, sb_block))) {
799 befs_error(sb, "unable to read superblock"); 795 if (!silent)
796 befs_error(sb, "unable to read superblock");
800 goto unacquire_priv_sbp; 797 goto unacquire_priv_sbp;
801 } 798 }
802 799
@@ -820,9 +817,9 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
820 brelse(bh); 817 brelse(bh);
821 818
822 if( befs_sb->num_blocks > ~((sector_t)0) ) { 819 if( befs_sb->num_blocks > ~((sector_t)0) ) {
823 befs_error(sb, "blocks count: %llu " 820 if (!silent)
824 "is larger than the host can use", 821 befs_error(sb, "blocks count: %llu is larger than the host can use",
825 befs_sb->num_blocks); 822 befs_sb->num_blocks);
826 goto unacquire_priv_sbp; 823 goto unacquire_priv_sbp;
827 } 824 }
828 825
@@ -841,7 +838,8 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
841 } 838 }
842 sb->s_root = d_make_root(root); 839 sb->s_root = d_make_root(root);
843 if (!sb->s_root) { 840 if (!sb->s_root) {
844 befs_error(sb, "get root inode failed"); 841 if (!silent)
842 befs_error(sb, "get root inode failed");
845 goto unacquire_priv_sbp; 843 goto unacquire_priv_sbp;
846 } 844 }
847 845
@@ -870,9 +868,9 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
870 unacquire_priv_sbp: 868 unacquire_priv_sbp:
871 kfree(befs_sb->mount_opts.iocharset); 869 kfree(befs_sb->mount_opts.iocharset);
872 kfree(sb->s_fs_info); 870 kfree(sb->s_fs_info);
871 sb->s_fs_info = NULL;
873 872
874 unacquire_none: 873 unacquire_none:
875 sb->s_fs_info = NULL;
876 return ret; 874 return ret;
877} 875}
878 876