1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 1999 Al Smith
7 * Portions derived from work (c) 1995,1996 Christian Vogelgsang.
10 #include <linux/buffer_head.h>
11 #include <linux/string.h>
12 #include <linux/exportfs.h>
16 static efs_ino_t efs_find_entry(struct inode *inode, const char *name, int len)
18 struct buffer_head *bh;
22 struct efs_dir *dirblock;
23 struct efs_dentry *dirslot;
27 if (inode->i_size & (EFS_DIRBSIZE-1))
28 pr_warn("%s(): directory size not a multiple of EFS_DIRBSIZE\n",
31 for(block = 0; block < inode->i_blocks; block++) {
33 bh = sb_bread(inode->i_sb, efs_bmap(inode, block));
35 pr_err("%s(): failed to read dir block %d\n",
40 dirblock = (struct efs_dir *) bh->b_data;
42 if (be16_to_cpu(dirblock->magic) != EFS_DIRBLK_MAGIC) {
43 pr_err("%s(): invalid directory block\n", __func__);
48 for (slot = 0; slot < dirblock->slots; slot++) {
49 dirslot = (struct efs_dentry *) (((char *) bh->b_data) + EFS_SLOTAT(dirblock, slot));
51 namelen = dirslot->namelen;
52 nameptr = dirslot->name;
54 if ((namelen == len) && (!memcmp(name, nameptr, len))) {
55 inodenum = be32_to_cpu(dirslot->inode);
65 struct dentry *efs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
68 struct inode *inode = NULL;
70 inodenum = efs_find_entry(dir, dentry->d_name.name, dentry->d_name.len);
72 inode = efs_iget(dir->i_sb, inodenum);
74 return d_splice_alias(inode, dentry);
77 static struct inode *efs_nfs_get_inode(struct super_block *sb, u64 ino,
83 return ERR_PTR(-ESTALE);
84 inode = efs_iget(sb, ino);
86 return ERR_CAST(inode);
88 if (generation && inode->i_generation != generation) {
90 return ERR_PTR(-ESTALE);
96 struct dentry *efs_fh_to_dentry(struct super_block *sb, struct fid *fid,
97 int fh_len, int fh_type)
99 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
103 struct dentry *efs_fh_to_parent(struct super_block *sb, struct fid *fid,
104 int fh_len, int fh_type)
106 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
110 struct dentry *efs_get_parent(struct dentry *child)
112 struct dentry *parent = ERR_PTR(-ENOENT);
115 ino = efs_find_entry(d_inode(child), "..", 2);
117 parent = d_obtain_alias(efs_iget(child->d_sb, ino));