4 * Copyright (c) 1999 Al Smith
6 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
9 #include <linux/buffer_head.h>
10 #include <linux/string.h>
11 #include <linux/smp_lock.h>
12 #include <linux/exportfs.h>
16 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len) {
17 struct buffer_head *bh;
21 struct efs_dir *dirblock;
22 struct efs_dentry *dirslot;
26 if (inode->i_size & (EFS_DIRBSIZE-1))
27 printk(KERN_WARNING "EFS: WARNING: find_entry(): directory size not a multiple of EFS_DIRBSIZE\n");
29 for(block = 0; block < inode->i_blocks; block++) {
31 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
33 printk(KERN_ERR "EFS: find_entry(): failed to read dir block %d\n", block);
37 dirblock = (struct efs_dir *) bh->b_data;
39 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
40 printk(KERN_ERR "EFS: find_entry(): invalid directory block\n");
45 for(slot = 0; slot < dirblock->slots; slot++) {
46 dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
48 namelen = dirslot->namelen;
49 nameptr = dirslot->name;
51 if ((namelen == len) && (!memcmp(name, nameptr, len))) {
52 inodenum = be32_to_cpu(dirslot->inode);
62 struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) {
64 struct inode * inode = NULL;
67 inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
69 inode = efs_iget(dir->i_sb, inodenum);
72 return ERR_CAST(inode);
77 return d_splice_alias(inode, dentry);
80 static struct inode *efs_nfs_get_inode(struct super_block *sb, u64 ino,
86 return ERR_PTR(-ESTALE);
87 inode = efs_iget(sb, ino);
89 return ERR_CAST(inode);
91 if (generation && inode->i_generation != generation) {
93 return ERR_PTR(-ESTALE);
99 struct dentry *efs_fh_to_dentry(struct super_block *sb, struct fid *fid,
100 int fh_len, int fh_type)
102 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
106 struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
107 int fh_len, int fh_type)
109 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
113 struct dentry *efs_get_parent(struct dentry *child)
115 struct dentry *parent = ERR_PTR(-ENOENT);
119 ino = efs_find_entry(child->d_inode, "..", 2);
121 parent = d_obtain_alias(efs_iget(child->d_inode->i_sb, ino));