8 #include <linux/ctype.h>
16 hash ^=
tolower(name[i]) << (i % 24);
24 static struct buffer_head *omfs_get_bucket(
struct inode *dir,
25 const char *name,
int namelen,
int *ofs)
28 int bucket = omfs_hash(name, namelen, nbuckets);
34 static struct buffer_head *omfs_scan_list(
struct inode *dir,
u64 block,
35 const char *name,
int namelen,
38 struct buffer_head *bh;
67 static struct buffer_head *omfs_find_entry(
struct inode *dir,
68 const char *name,
int namelen)
70 struct buffer_head *bh;
74 bh = omfs_get_bucket(dir, name, namelen, &ofs);
81 return omfs_scan_list(dir, block, name, namelen, &dummy);
87 struct buffer_head *bh;
113 struct inode *dir = dentry->
d_parent->d_inode;
114 const char *name = dentry->
d_name.name;
115 int namelen = dentry->
d_name.len;
117 struct buffer_head *bh;
123 bh = omfs_get_bucket(dir, name, namelen, &ofs);
127 entry = (
__be64 *) &bh->b_data[ofs];
149 mark_inode_dirty(dir);
150 mark_inode_dirty(inode);
156 static int omfs_delete_entry(
struct dentry *dentry)
158 struct inode *dir = dentry->
d_parent->d_inode;
160 const char *name = dentry->
d_name.name;
161 int namelen = dentry->
d_name.len;
163 struct buffer_head *bh, *bh2;
170 bh = omfs_get_bucket(dir, name, namelen, &ofs);
174 entry = (
__be64 *) &bh->b_data[ofs];
177 bh2 = omfs_scan_list(dir, block, name, namelen, &prev);
203 if (!IS_ERR(dirty)) {
204 mark_inode_dirty(dirty);
216 static int omfs_dir_is_empty(
struct inode *inode)
219 struct buffer_head *bh;
230 for (i = 0; i < nbuckets; i++, ptr++)
238 static int omfs_remove(
struct inode *dir,
struct dentry *dentry)
240 struct inode *inode = dentry->
d_inode;
245 !omfs_dir_is_empty(inode))
248 ret = omfs_delete_entry(dentry);
253 mark_inode_dirty(inode);
254 mark_inode_dirty(dir);
258 static int omfs_add_node(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
264 return PTR_ERR(inode);
270 err = omfs_add_link(dentry, inode);
282 static int omfs_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
284 return omfs_add_node(dir, dentry, mode |
S_IFDIR);
287 static int omfs_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
290 return omfs_add_node(dir, dentry, mode |
S_IFREG);
293 static struct dentry *omfs_lookup(
struct inode *dir,
struct dentry *dentry,
296 struct buffer_head *bh;
297 struct inode *inode =
NULL;
302 bh = omfs_find_entry(dir, dentry->
d_name.name, dentry->
d_name.len);
309 return ERR_CAST(inode);
311 d_add(dentry, inode);
321 is_bad = ((ino != fsblock) || (ino < sbi->s_root_ino) ||
331 u64 fsblock,
int hindex)
333 struct inode *dir = filp->f_dentry->d_inode;
334 struct buffer_head *bh;
338 unsigned char d_type;
341 while (fsblock != ~0) {
375 static int omfs_rename(
struct inode *old_dir,
struct dentry *old_dentry,
376 struct inode *new_dir,
struct dentry *new_dentry)
379 struct inode *old_inode = old_dentry->
d_inode;
384 err = omfs_remove(new_dir, new_dentry);
391 err = omfs_delete_entry(old_dentry);
395 mark_inode_dirty(old_dir);
396 err = omfs_add_link(new_dentry, old_inode);
401 mark_inode_dirty(old_inode);
406 static int omfs_readdir(
struct file *filp,
void *dirent,
filldir_t filldir)
408 struct inode *dir = filp->f_dentry->d_inode;
409 struct buffer_head *bh;
411 unsigned int hchain, hindex;
416 if (filp->
f_pos >> 32)
419 switch ((
unsigned long) filp->
f_pos) {
421 if (filldir(dirent,
".", 1, 0, dir->
i_ino,
DT_DIR) < 0)
426 if (filldir(dirent,
"..", 2, 1,
429 filp->
f_pos = 1 << 20;
436 hchain = (filp->
f_pos >> 20) - 1;
437 hindex = filp->
f_pos & 0xfffff;
445 for (; hchain < nbuckets; hchain++, offset += 8) {
448 res = omfs_fill_chain(filp, dirent, filldir, fsblock, hindex);
453 filp->
f_pos = (hchain+2) << 20;
463 .lookup = omfs_lookup,
465 .rename = omfs_rename,
466 .create = omfs_create,
467 .unlink = omfs_remove,
468 .rmdir = omfs_remove,
473 .readdir = omfs_readdir,