8 #include <linux/time.h>
9 #include <linux/string.h>
12 #include <linux/sched.h>
18 #define dprintf(x...) printf(x)
23 static int bfs_add_entry(
struct inode *dir,
const unsigned char *
name,
25 static struct buffer_head *bfs_find_entry(
struct inode *dir,
32 struct buffer_head *bh;
41 printf(
"Bad f_pos=%08lx for %s:%08lx\n",
42 (
unsigned long)f->
f_pos,
51 bh = sb_bread(dir->
i_sb, block);
57 de = (
struct bfs_dirent *)(bh->b_data + offset);
60 if (filldir(dirent, de->
name, size, f->
f_pos,
80 .readdir = bfs_readdir,
115 BFS_I(inode)->i_dsk_ino =
ino;
116 BFS_I(inode)->i_sblock = 0;
117 BFS_I(inode)->i_eblock = 0;
118 insert_inode_hash(inode);
119 mark_inode_dirty(inode);
122 err = bfs_add_entry(dir, dentry->
d_name.name, dentry->
d_name.len,
125 inode_dec_link_count(inode);
135 static struct dentry *bfs_lookup(
struct inode *dir,
struct dentry *dentry,
138 struct inode *inode =
NULL;
139 struct buffer_head *bh;
147 bh = bfs_find_entry(dir, dentry->
d_name.name, dentry->
d_name.len, &de);
154 return ERR_CAST(inode);
158 d_add(dentry, inode);
162 static int bfs_link(
struct dentry *old,
struct inode *dir,
165 struct inode *inode = old->
d_inode;
170 err = bfs_add_entry(dir, new->d_name.name, new->d_name.len,
178 mark_inode_dirty(inode);
185 static int bfs_unlink(
struct inode *dir,
struct dentry *dentry)
188 struct inode *inode = dentry->
d_inode;
189 struct buffer_head *bh;
194 bh = bfs_find_entry(dir, dentry->
d_name.name, dentry->
d_name.len, &de);
199 printf(
"unlinking non-existent file %s:%lu (nlink=%d)\n",
207 mark_inode_dirty(dir);
209 inode_dec_link_count(inode);
218 static int bfs_rename(
struct inode *old_dir,
struct dentry *old_dentry,
219 struct inode *new_dir,
struct dentry *new_dentry)
222 struct buffer_head *old_bh, *new_bh;
227 old_bh = new_bh =
NULL;
228 old_inode = old_dentry->
d_inode;
232 info = BFS_SB(old_inode->
i_sb);
235 old_bh = bfs_find_entry(old_dir,
237 old_dentry->
d_name.len, &old_de);
243 new_inode = new_dentry->
d_inode;
244 new_bh = bfs_find_entry(new_dir,
246 new_dentry->
d_name.len, &new_de);
248 if (new_bh && !new_inode) {
253 error = bfs_add_entry(new_dir,
262 mark_inode_dirty(old_dir);
265 inode_dec_link_count(new_inode);
278 .create = bfs_create,
279 .lookup = bfs_lookup,
281 .unlink = bfs_unlink,
282 .rename = bfs_rename,
285 static int bfs_add_entry(
struct inode *dir,
const unsigned char *
name,
288 struct buffer_head *bh;
290 int block, sblock, eblock, off,
pos;
293 dprintf(
"name=%s, namelen=%d\n", name, namelen);
300 sblock = BFS_I(dir)->i_sblock;
301 eblock = BFS_I(dir)->i_eblock;
302 for (block = sblock; block <= eblock; block++) {
303 bh = sb_bread(dir->
i_sb, block);
309 pos = (block - sblock) * BFS_BSIZE + off;
315 mark_inode_dirty(dir);
319 (i < namelen) ? name[
i] : 0;
330 static inline int bfs_namecmp(
int len,
const unsigned char *name,
335 return !
memcmp(name, buffer, len);
338 static struct buffer_head *bfs_find_entry(
struct inode *dir,
339 const unsigned char *name,
int namelen,
342 unsigned long block = 0, offset = 0;
343 struct buffer_head *bh =
NULL;
352 bh = sb_bread(dir->
i_sb, BFS_I(dir)->i_sblock + block);
358 de = (
struct bfs_dirent *)(bh->b_data + offset);
361 bfs_namecmp(namelen, name, de->
name)) {