blob: ee832ca5f734aac252bae4ba754fa4c1e34f1730 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * fs/bfs/dir.c
4 * BFS directory operations.
5 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com>
Andrew Stribblehillfac92be2005-09-09 13:02:04 -07006 * Made endianness-clean by Andrew Stribblehill <ads@wompom.org> 2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#include <linux/time.h>
10#include <linux/string.h>
11#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/buffer_head.h>
13#include <linux/sched.h>
14#include "bfs.h"
15
16#undef DEBUG
17
18#ifdef DEBUG
19#define dprintf(x...) printf(x)
20#else
21#define dprintf(x...)
22#endif
23
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080024static int bfs_add_entry(struct inode *dir, const unsigned char *name,
25 int namelen, int ino);
26static struct buffer_head *bfs_find_entry(struct inode *dir,
27 const unsigned char *name, int namelen,
28 struct bfs_dirent **res_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Al Viro81b9f662013-05-16 13:41:48 -040030static int bfs_readdir(struct file *f, struct dir_context *ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Al Viro496ad9a2013-01-23 17:07:38 -050032 struct inode *dir = file_inode(f);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080033 struct buffer_head *bh;
34 struct bfs_dirent *de;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 unsigned int offset;
36 int block;
37
Al Viro81b9f662013-05-16 13:41:48 -040038 if (ctx->pos & (BFS_DIRENT_SIZE - 1)) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080039 printf("Bad f_pos=%08lx for %s:%08lx\n",
Al Viro81b9f662013-05-16 13:41:48 -040040 (unsigned long)ctx->pos,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080041 dir->i_sb->s_id, dir->i_ino);
Al Viro81b9f662013-05-16 13:41:48 -040042 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 }
44
Al Viro81b9f662013-05-16 13:41:48 -040045 while (ctx->pos < dir->i_size) {
46 offset = ctx->pos & (BFS_BSIZE - 1);
47 block = BFS_I(dir)->i_sblock + (ctx->pos >> BFS_BSIZE_BITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 bh = sb_bread(dir->i_sb, block);
49 if (!bh) {
Al Viro81b9f662013-05-16 13:41:48 -040050 ctx->pos += BFS_BSIZE - offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 continue;
52 }
53 do {
54 de = (struct bfs_dirent *)(bh->b_data + offset);
55 if (de->ino) {
56 int size = strnlen(de->name, BFS_NAMELEN);
Al Viro81b9f662013-05-16 13:41:48 -040057 if (!dir_emit(ctx, de->name, size,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080058 le16_to_cpu(de->ino),
Al Viro81b9f662013-05-16 13:41:48 -040059 DT_UNKNOWN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return 0;
62 }
63 }
64 offset += BFS_DIRENT_SIZE;
Al Viro81b9f662013-05-16 13:41:48 -040065 ctx->pos += BFS_DIRENT_SIZE;
66 } while ((offset < BFS_BSIZE) && (ctx->pos < dir->i_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 brelse(bh);
68 }
Al Viro81b9f662013-05-16 13:41:48 -040069 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080072const struct file_operations bfs_dir_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .read = generic_read_dir,
Al Viroc51da202016-04-30 22:37:34 -040074 .iterate_shared = bfs_readdir,
Christoph Hellwig1b061d92010-05-26 17:53:41 +020075 .fsync = generic_file_fsync,
Christoph Hellwig3222a3e2008-09-03 21:53:01 +020076 .llseek = generic_file_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
Al Viro4acdaf22011-07-26 01:42:34 -040079static int bfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
Al Viroebfc3b42012-06-10 18:05:36 -040080 bool excl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 int err;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080083 struct inode *inode;
84 struct super_block *s = dir->i_sb;
85 struct bfs_sb_info *info = BFS_SB(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned long ino;
87
88 inode = new_inode(s);
89 if (!inode)
Sanidhya Kashyapc3fe5872015-04-16 12:48:32 -070090 return -ENOMEM;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -070091 mutex_lock(&info->bfs_lock);
Akinobu Mita69b195b2011-03-21 08:32:53 -040092 ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (ino > info->si_lasti) {
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -070094 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 iput(inode);
96 return -ENOSPC;
97 }
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080098 set_bit(ino, info->si_imap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 info->si_freei--;
Dmitry Monakhove6ecdc72010-03-04 17:31:46 +0300100 inode_init_owner(inode, dir, mode);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700101 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Theodore Ts'oba52de12006-09-27 01:50:49 -0700102 inode->i_blocks = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 inode->i_op = &bfs_file_inops;
104 inode->i_fop = &bfs_file_operations;
105 inode->i_mapping->a_ops = &bfs_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 inode->i_ino = ino;
Alexey Dobriyance0fe7e2005-10-04 17:43:06 +0100107 BFS_I(inode)->i_dsk_ino = ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 BFS_I(inode)->i_sblock = 0;
109 BFS_I(inode)->i_eblock = 0;
110 insert_inode_hash(inode);
111 mark_inode_dirty(inode);
Fabian Frederick1da85fd2014-08-08 14:22:29 -0700112 bfs_dump_imap("create", s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800114 err = bfs_add_entry(dir, dentry->d_name.name, dentry->d_name.len,
115 inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (err) {
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700117 inode_dec_link_count(inode);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700118 mutex_unlock(&info->bfs_lock);
Eric Sesterhenn15581822008-09-13 02:33:12 -0700119 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 return err;
121 }
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700122 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 d_instantiate(dentry, inode);
124 return 0;
125}
126
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800127static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
Al Viro00cd8dd2012-06-10 17:13:09 -0400128 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800130 struct inode *inode = NULL;
131 struct buffer_head *bh;
132 struct bfs_dirent *de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700133 struct bfs_sb_info *info = BFS_SB(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 if (dentry->d_name.len > BFS_NAMELEN)
136 return ERR_PTR(-ENAMETOOLONG);
137
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700138 mutex_lock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
140 if (bh) {
Andrew Stribblehillfac92be2005-09-09 13:02:04 -0700141 unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 brelse(bh);
David Howellse33ab082008-02-07 00:15:32 -0800143 inode = bfs_iget(dir->i_sb, ino);
144 if (IS_ERR(inode)) {
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700145 mutex_unlock(&info->bfs_lock);
David Howellse33ab082008-02-07 00:15:32 -0800146 return ERR_CAST(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
148 }
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700149 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 d_add(dentry, inode);
151 return NULL;
152}
153
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800154static int bfs_link(struct dentry *old, struct inode *dir,
155 struct dentry *new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
David Howells2b0143b2015-03-17 22:25:59 +0000157 struct inode *inode = d_inode(old);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700158 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 int err;
160
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700161 mutex_lock(&info->bfs_lock);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800162 err = bfs_add_entry(dir, new->d_name.name, new->d_name.len,
163 inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 if (err) {
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700165 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return err;
167 }
Dave Hansend8c76e62006-09-30 23:29:04 -0700168 inc_nlink(inode);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700169 inode->i_ctime = current_time(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 mark_inode_dirty(inode);
Al Viro7de9c6ee2010-10-23 11:11:40 -0400171 ihold(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 d_instantiate(new, inode);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700173 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return 0;
175}
176
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800177static int bfs_unlink(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
179 int error = -ENOENT;
David Howells2b0143b2015-03-17 22:25:59 +0000180 struct inode *inode = d_inode(dentry);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800181 struct buffer_head *bh;
182 struct bfs_dirent *de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700183 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700185 mutex_lock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800187 if (!bh || (le16_to_cpu(de->ino) != inode->i_ino))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 goto out_brelse;
189
190 if (!inode->i_nlink) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800191 printf("unlinking non-existent file %s:%lu (nlink=%d)\n",
192 inode->i_sb->s_id, inode->i_ino,
193 inode->i_nlink);
Miklos Szeredibfe86842011-10-28 14:13:29 +0200194 set_nlink(inode, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196 de->ino = 0;
Al Viro4427f0c2009-06-08 01:15:58 -0400197 mark_buffer_dirty_inode(bh, dir);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700198 dir->i_ctime = dir->i_mtime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 mark_inode_dirty(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 inode->i_ctime = dir->i_ctime;
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700201 inode_dec_link_count(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 error = 0;
203
204out_brelse:
205 brelse(bh);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700206 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return error;
208}
209
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800210static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredif03b8ad2016-09-27 11:03:57 +0200211 struct inode *new_dir, struct dentry *new_dentry,
212 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800214 struct inode *old_inode, *new_inode;
215 struct buffer_head *old_bh, *new_bh;
216 struct bfs_dirent *old_de, *new_de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700217 struct bfs_sb_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 int error = -ENOENT;
219
Miklos Szeredif03b8ad2016-09-27 11:03:57 +0200220 if (flags & ~RENAME_NOREPLACE)
221 return -EINVAL;
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 old_bh = new_bh = NULL;
David Howells2b0143b2015-03-17 22:25:59 +0000224 old_inode = d_inode(old_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (S_ISDIR(old_inode->i_mode))
226 return -EINVAL;
227
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700228 info = BFS_SB(old_inode->i_sb);
229
230 mutex_lock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 old_bh = bfs_find_entry(old_dir,
232 old_dentry->d_name.name,
233 old_dentry->d_name.len, &old_de);
234
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800235 if (!old_bh || (le16_to_cpu(old_de->ino) != old_inode->i_ino))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 goto end_rename;
237
238 error = -EPERM;
David Howells2b0143b2015-03-17 22:25:59 +0000239 new_inode = d_inode(new_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 new_bh = bfs_find_entry(new_dir,
241 new_dentry->d_name.name,
242 new_dentry->d_name.len, &new_de);
243
244 if (new_bh && !new_inode) {
245 brelse(new_bh);
246 new_bh = NULL;
247 }
248 if (!new_bh) {
249 error = bfs_add_entry(new_dir,
250 new_dentry->d_name.name,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800251 new_dentry->d_name.len,
252 old_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (error)
254 goto end_rename;
255 }
256 old_de->ino = 0;
Deepa Dinamani02027d42016-09-14 07:48:05 -0700257 old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 mark_inode_dirty(old_dir);
259 if (new_inode) {
Deepa Dinamani02027d42016-09-14 07:48:05 -0700260 new_inode->i_ctime = current_time(new_inode);
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700261 inode_dec_link_count(new_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Al Viro4427f0c2009-06-08 01:15:58 -0400263 mark_buffer_dirty_inode(old_bh, old_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 error = 0;
265
266end_rename:
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700267 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 brelse(old_bh);
269 brelse(new_bh);
270 return error;
271}
272
Arjan van de Ven754661f2007-02-12 00:55:38 -0800273const struct inode_operations bfs_dir_inops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .create = bfs_create,
275 .lookup = bfs_lookup,
276 .link = bfs_link,
277 .unlink = bfs_unlink,
278 .rename = bfs_rename,
279};
280
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800281static int bfs_add_entry(struct inode *dir, const unsigned char *name,
282 int namelen, int ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800284 struct buffer_head *bh;
285 struct bfs_dirent *de;
286 int block, sblock, eblock, off, pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 int i;
288
289 dprintf("name=%s, namelen=%d\n", name, namelen);
290
291 if (!namelen)
292 return -ENOENT;
293 if (namelen > BFS_NAMELEN)
294 return -ENAMETOOLONG;
295
296 sblock = BFS_I(dir)->i_sblock;
297 eblock = BFS_I(dir)->i_eblock;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800298 for (block = sblock; block <= eblock; block++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 bh = sb_bread(dir->i_sb, block);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800300 if (!bh)
Sanidhya Kashyapc3fe5872015-04-16 12:48:32 -0700301 return -EIO;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800302 for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 de = (struct bfs_dirent *)(bh->b_data + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (!de->ino) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800305 pos = (block - sblock) * BFS_BSIZE + off;
306 if (pos >= dir->i_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 dir->i_size += BFS_DIRENT_SIZE;
Deepa Dinamani02027d42016-09-14 07:48:05 -0700308 dir->i_ctime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
Deepa Dinamani02027d42016-09-14 07:48:05 -0700310 dir->i_mtime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 mark_inode_dirty(dir);
Andrew Stribblehillfac92be2005-09-09 13:02:04 -0700312 de->ino = cpu_to_le16((u16)ino);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800313 for (i = 0; i < BFS_NAMELEN; i++)
314 de->name[i] =
315 (i < namelen) ? name[i] : 0;
Al Viro4427f0c2009-06-08 01:15:58 -0400316 mark_buffer_dirty_inode(bh, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 brelse(bh);
318 return 0;
319 }
320 }
321 brelse(bh);
322 }
323 return -ENOSPC;
324}
325
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800326static inline int bfs_namecmp(int len, const unsigned char *name,
327 const char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800329 if ((len < BFS_NAMELEN) && buffer[len])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return 0;
331 return !memcmp(name, buffer, len);
332}
333
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800334static struct buffer_head *bfs_find_entry(struct inode *dir,
335 const unsigned char *name, int namelen,
336 struct bfs_dirent **res_dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800338 unsigned long block = 0, offset = 0;
339 struct buffer_head *bh = NULL;
340 struct bfs_dirent *de;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 *res_dir = NULL;
343 if (namelen > BFS_NAMELEN)
344 return NULL;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 while (block * BFS_BSIZE + offset < dir->i_size) {
347 if (!bh) {
348 bh = sb_bread(dir->i_sb, BFS_I(dir)->i_sblock + block);
349 if (!bh) {
350 block++;
351 continue;
352 }
353 }
354 de = (struct bfs_dirent *)(bh->b_data + offset);
355 offset += BFS_DIRENT_SIZE;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800356 if (le16_to_cpu(de->ino) &&
357 bfs_namecmp(namelen, name, de->name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *res_dir = de;
359 return bh;
360 }
361 if (offset < bh->b_size)
362 continue;
363 brelse(bh);
364 bh = NULL;
365 offset = 0;
366 block++;
367 }
368 brelse(bh);
369 return NULL;
370}