8 #include <linux/module.h>
9 #include <linux/slab.h>
11 #include <linux/errno.h>
12 #include <linux/stat.h>
18 #include <linux/sched.h>
32 #define VFS_BLOCK_SIZE 512
35 static int befs_get_block(
struct inode *,
sector_t,
struct buffer_head *,
int);
41 static void befs_destroy_inode(
struct inode *
inode);
42 static int befs_init_inodecache(
void);
43 static void befs_destroy_inodecache(
void);
51 static int befs_remount(
struct super_block *,
int *,
char *);
56 .alloc_inode = befs_alloc_inode,
57 .destroy_inode = befs_destroy_inode,
58 .put_super = befs_put_super,
59 .statfs = befs_statfs,
60 .remount_fs = befs_remount,
69 .readdir = befs_readdir,
74 .lookup = befs_lookup,
78 .readpage = befs_readpage,
84 .follow_link = befs_follow_link,
85 .put_link = befs_put_link,
120 struct buffer_head *bh_result,
int create)
123 befs_data_stream *
ds = &BEFS_I(inode)->i_data.ds;
128 befs_debug(sb,
"---> befs_get_block() for inode %lu, block %ld",
129 inode->
i_ino, block);
132 befs_error(sb,
"befs_get_block() was asked for a block "
133 "number less than zero: block %ld in inode %lu",
134 block, inode->
i_ino);
139 befs_error(sb,
"befs_get_block() was asked to write to "
140 "block %ld in inode %lu", block, inode->
i_ino);
147 "<--- befs_get_block() for inode %lu, block "
148 "%ld ERROR", inode->
i_ino, block);
152 disk_off = (
ulong) iaddr2blockno(sb, &run);
154 map_bh(bh_result, inode->
i_sb, disk_off);
156 befs_debug(sb,
"<--- befs_get_block() for inode %lu, block %ld, "
157 "disk address %lu", inode->
i_ino, block, disk_off);
165 struct inode *inode =
NULL;
167 befs_data_stream *ds = &BEFS_I(dir)->i_data.ds;
175 "name %s inode %ld", dentry->
d_name.name, dir->
i_ino);
178 if (BEFS_SB(sb)->nls) {
180 befs_nls2utf(sb, name,
strlen(name), &utfname, &utfnamelen);
193 befs_debug(sb,
"<--- befs_lookup() %s not found",
197 }
else if (ret !=
BEFS_OK || offset == 0) {
202 inode = befs_iget(dir->
i_sb, (
ino_t) offset);
204 return ERR_CAST(inode);
206 d_add(dentry, inode);
216 struct inode *inode = filp->
f_path.dentry->d_inode;
218 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds;
222 unsigned char d_type;
226 const char *dirname = filp->
f_path.dentry->d_name.name;
229 "name %s, inode %ld, filp->f_pos %Ld",
233 keybuf, &keysize, &value);
237 befs_error(sb,
"IO error reading %s (inode %lu)",
238 dirname, inode->
i_ino);
246 befs_debug(sb,
"<--- befs_readdir() Empty directory");
253 if (BEFS_SB(sb)->nls) {
255 befs_utf2nls(sb, keybuf, keysize, &nlsname, &nlsnamelen);
260 result = filldir(dirent, nlsname, nlsnamelen, filp->
f_pos,
261 (
ino_t) value, d_type);
265 result = filldir(dirent, keybuf, keysize, filp->
f_pos,
266 (
ino_t) value, d_type);
276 static struct inode *
293 static void befs_destroy_inode(
struct inode *inode)
298 static void init_once(
void *
foo)
305 static struct inode *befs_iget(
struct super_block *sb,
unsigned long ino)
307 struct buffer_head *bh =
NULL;
308 befs_inode *raw_inode =
NULL;
315 befs_debug(sb,
"---> befs_read_inode() " "inode = %lu", ino);
323 befs_ino = BEFS_I(inode);
328 befs_debug(sb,
" real inode number [%u, %hu, %hu]",
334 befs_error(sb,
"unable to read inode block - "
335 "inode = %lu", inode->
i_ino);
339 raw_inode = (befs_inode *) bh->b_data;
374 fs64_to_cpu(sb, raw_inode->last_modified_time) >> 16;
379 befs_ino->
i_inode_num = fsrun_to_cpu(sb, raw_inode->inode_num);
380 befs_ino->
i_parent = fsrun_to_cpu(sb, raw_inode->parent);
381 befs_ino->
i_attribute = fsrun_to_cpu(sb, raw_inode->attributes);
382 befs_ino->
i_flags = fs32_to_cpu(sb, raw_inode->flags);
394 fsds_to_cpu(sb, &raw_inode->data.datastream);
407 inode->
i_op = &befs_dir_inode_operations;
408 inode->
i_fop = &befs_dir_operations;
410 inode->
i_op = &befs_symlink_inode_operations;
412 befs_error(sb,
"Inode %lu is not a regular file, "
413 "directory or symlink. THAT IS WRONG! BeFS has no "
414 "on disk special files", inode->
i_ino);
428 befs_debug(sb,
"<--- befs_read_inode() - Bad inode");
437 befs_init_inodecache(
void)
444 if (befs_inode_cachep ==
NULL) {
446 "Couldn't initialize inode slabcache\n");
458 befs_destroy_inodecache(
void)
474 befs_follow_link(
struct dentry *dentry,
struct nameidata *nd)
485 befs_error(sb,
"Long symlink with illegal length");
486 link = ERR_PTR(-
EIO);
495 befs_error(sb,
"Failed to read entire long symlink");
496 link = ERR_PTR(-
EIO);
498 link[len - 1] =
'\0';
505 nd_set_link(nd, link);
509 static void befs_put_link(
struct dentry *dentry,
struct nameidata *nd,
void *
p)
513 char *link = nd_get_link(nd);
531 struct nls_table *nls = BEFS_SB(sb)->nls;
540 int maxlen = in_len + 1;
545 befs_error(sb,
"befs_utf2nls called with no NLS table loaded");
551 befs_error(sb,
"befs_utf2nls() cannot allocate memory");
556 for (i = o = 0; i <
in_len; i += utflen, o += unilen) {
566 unilen = nls->
uni2char(uni, &result[o], in_len - o);
578 befs_error(sb,
"Name using character set %s contains a character that "
579 "cannot be converted to unicode.", nls->
charset);
608 befs_nls2utf(
struct super_block *sb,
const char *in,
609 int in_len,
char **out,
int *out_len)
611 struct nls_table *nls = BEFS_SB(sb)->nls;
619 int maxlen = (3 *
in_len) + 1;
624 befs_error(sb,
"befs_nls2utf called with no NLS table loaded.");
630 befs_error(sb,
"befs_nls2utf() cannot allocate memory");
635 for (i = o = 0; i <
in_len; i += unilen, o += utflen) {
638 unilen = nls->
char2uni(&in[i], in_len - i, &uni);
656 befs_error(sb,
"Name using charecter set %s contains a charecter that "
657 "cannot be converted to unicode.", nls->
charset);
712 if (!uid_valid(uid)) {
714 "using default\n", option);
726 if (!gid_valid(gid)) {
728 "using default\n", option);
739 "iocharset string\n");
748 "or missing value\n", p);
763 kfree(BEFS_SB(sb)->mount_opts.iocharset);
764 BEFS_SB(sb)->mount_opts.iocharset =
NULL;
777 befs_fill_super(
struct super_block *sb,
void *data,
int silent)
779 struct buffer_head *bh;
781 befs_super_block *disk_sb;
784 const unsigned long sb_block = 0;
785 const off_t x86_sb_off = 512;
792 "BeFS(%s): Unable to allocate memory for private "
793 "portion of superblock. Bailing.\n", sb->
s_id);
796 befs_sb = BEFS_SB(sb);
799 if (!parse_options((
char *) data, &befs_sb->
mount_opts)) {
801 goto unacquire_priv_sbp;
806 #ifndef CONFIG_BEFS_RW
809 "No write support. Marking filesystem read-only");
825 if (!(bh = sb_bread(sb, sb_block))) {
827 goto unacquire_priv_sbp;
831 disk_sb = (befs_super_block *) bh->b_data;
834 befs_debug(sb,
"Using PPC superblock location");
836 befs_debug(sb,
"Using x86 superblock location");
838 (befs_super_block *) ((
void *) bh->b_data + x86_sb_off);
849 goto unacquire_priv_sbp;
853 "is larger than the host can use",
855 goto unacquire_priv_sbp;
865 sb->
s_op = &befs_sops;
866 root = befs_iget(sb, iaddr2blockno(sb, &(befs_sb->
root_dir)));
869 goto unacquire_priv_sbp;
874 goto unacquire_priv_sbp;
884 " loading default nls",
909 befs_remount(
struct super_block *sb,
int *flags,
char *data)
917 befs_statfs(
struct dentry *dentry,
struct kstatfs *
buf)
920 u64 id = huge_encode_dev(sb->
s_bdev->bd_dev);
926 buf->
f_blocks = BEFS_SB(sb)->num_blocks;
927 buf->
f_bfree = BEFS_SB(sb)->num_blocks - BEFS_SB(sb)->used_blocks;
940 static struct dentry *
941 befs_mount(
struct file_system_type *fs_type,
int flags,
const char *dev_name,
944 return mount_bdev(fs_type, flags, dev_name, data, befs_fill_super);
962 err = befs_init_inodecache();
968 goto unacquire_inodecache;
972 unacquire_inodecache:
973 befs_destroy_inodecache();
982 befs_destroy_inodecache();