blob: f32f21c3bbc7b0fcdfb73b11193d3f1e52feb861 [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
Al Virob455ecd2018-04-30 19:14:44 -040024static int bfs_add_entry(struct inode *dir, const struct qstr *child, int ino);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080025static struct buffer_head *bfs_find_entry(struct inode *dir,
Al Viro33ebdeb2018-04-30 19:10:34 -040026 const struct qstr *child,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080027 struct bfs_dirent **res_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Al Viro81b9f662013-05-16 13:41:48 -040029static int bfs_readdir(struct file *f, struct dir_context *ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Al Viro496ad9a2013-01-23 17:07:38 -050031 struct inode *dir = file_inode(f);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080032 struct buffer_head *bh;
33 struct bfs_dirent *de;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 unsigned int offset;
35 int block;
36
Al Viro81b9f662013-05-16 13:41:48 -040037 if (ctx->pos & (BFS_DIRENT_SIZE - 1)) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080038 printf("Bad f_pos=%08lx for %s:%08lx\n",
Al Viro81b9f662013-05-16 13:41:48 -040039 (unsigned long)ctx->pos,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080040 dir->i_sb->s_id, dir->i_ino);
Al Viro81b9f662013-05-16 13:41:48 -040041 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 }
43
Al Viro81b9f662013-05-16 13:41:48 -040044 while (ctx->pos < dir->i_size) {
45 offset = ctx->pos & (BFS_BSIZE - 1);
46 block = BFS_I(dir)->i_sblock + (ctx->pos >> BFS_BSIZE_BITS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 bh = sb_bread(dir->i_sb, block);
48 if (!bh) {
Al Viro81b9f662013-05-16 13:41:48 -040049 ctx->pos += BFS_BSIZE - offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 continue;
51 }
52 do {
53 de = (struct bfs_dirent *)(bh->b_data + offset);
54 if (de->ino) {
55 int size = strnlen(de->name, BFS_NAMELEN);
Al Viro81b9f662013-05-16 13:41:48 -040056 if (!dir_emit(ctx, de->name, size,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080057 le16_to_cpu(de->ino),
Al Viro81b9f662013-05-16 13:41:48 -040058 DT_UNKNOWN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 brelse(bh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 return 0;
61 }
62 }
63 offset += BFS_DIRENT_SIZE;
Al Viro81b9f662013-05-16 13:41:48 -040064 ctx->pos += BFS_DIRENT_SIZE;
65 } while ((offset < BFS_BSIZE) && (ctx->pos < dir->i_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 brelse(bh);
67 }
Al Viro81b9f662013-05-16 13:41:48 -040068 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080071const struct file_operations bfs_dir_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 .read = generic_read_dir,
Al Viroc51da202016-04-30 22:37:34 -040073 .iterate_shared = bfs_readdir,
Christoph Hellwig1b061d92010-05-26 17:53:41 +020074 .fsync = generic_file_fsync,
Christoph Hellwig3222a3e2008-09-03 21:53:01 +020075 .llseek = generic_file_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076};
77
Al Viro4acdaf22011-07-26 01:42:34 -040078static int bfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
Al Viroebfc3b42012-06-10 18:05:36 -040079 bool excl)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 int err;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080082 struct inode *inode;
83 struct super_block *s = dir->i_sb;
84 struct bfs_sb_info *info = BFS_SB(s);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned long ino;
86
87 inode = new_inode(s);
88 if (!inode)
Sanidhya Kashyapc3fe5872015-04-16 12:48:32 -070089 return -ENOMEM;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -070090 mutex_lock(&info->bfs_lock);
Akinobu Mita69b195b2011-03-21 08:32:53 -040091 ino = find_first_zero_bit(info->si_imap, info->si_lasti + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 if (ino > info->si_lasti) {
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -070093 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 iput(inode);
95 return -ENOSPC;
96 }
Dmitri Vorobievf433dc52007-11-14 16:59:47 -080097 set_bit(ino, info->si_imap);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 info->si_freei--;
Dmitry Monakhove6ecdc72010-03-04 17:31:46 +030099 inode_init_owner(inode, dir, mode);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700100 inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
Theodore Ts'oba52de12006-09-27 01:50:49 -0700101 inode->i_blocks = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 inode->i_op = &bfs_file_inops;
103 inode->i_fop = &bfs_file_operations;
104 inode->i_mapping->a_ops = &bfs_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 inode->i_ino = ino;
Alexey Dobriyance0fe7e2005-10-04 17:43:06 +0100106 BFS_I(inode)->i_dsk_ino = ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 BFS_I(inode)->i_sblock = 0;
108 BFS_I(inode)->i_eblock = 0;
109 insert_inode_hash(inode);
110 mark_inode_dirty(inode);
Fabian Frederick1da85fd2014-08-08 14:22:29 -0700111 bfs_dump_imap("create", s);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Al Virob455ecd2018-04-30 19:14:44 -0400113 err = bfs_add_entry(dir, &dentry->d_name, inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (err) {
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700115 inode_dec_link_count(inode);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700116 mutex_unlock(&info->bfs_lock);
Eric Sesterhenn15581822008-09-13 02:33:12 -0700117 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 return err;
119 }
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700120 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 d_instantiate(dentry, inode);
122 return 0;
123}
124
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800125static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry,
Al Viro00cd8dd2012-06-10 17:13:09 -0400126 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800128 struct inode *inode = NULL;
129 struct buffer_head *bh;
130 struct bfs_dirent *de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700131 struct bfs_sb_info *info = BFS_SB(dir->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 if (dentry->d_name.len > BFS_NAMELEN)
134 return ERR_PTR(-ENAMETOOLONG);
135
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700136 mutex_lock(&info->bfs_lock);
Al Viro33ebdeb2018-04-30 19:10:34 -0400137 bh = bfs_find_entry(dir, &dentry->d_name, &de);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (bh) {
Andrew Stribblehillfac92be2005-09-09 13:02:04 -0700139 unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 brelse(bh);
David Howellse33ab082008-02-07 00:15:32 -0800141 inode = bfs_iget(dir->i_sb, ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700143 mutex_unlock(&info->bfs_lock);
Al Viroa596a232018-04-30 19:05:17 -0400144 return d_splice_alias(inode, dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145}
146
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800147static int bfs_link(struct dentry *old, struct inode *dir,
148 struct dentry *new)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
David Howells2b0143b2015-03-17 22:25:59 +0000150 struct inode *inode = d_inode(old);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700151 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 int err;
153
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700154 mutex_lock(&info->bfs_lock);
Al Virob455ecd2018-04-30 19:14:44 -0400155 err = bfs_add_entry(dir, &new->d_name, inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 if (err) {
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700157 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return err;
159 }
Dave Hansend8c76e62006-09-30 23:29:04 -0700160 inc_nlink(inode);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700161 inode->i_ctime = current_time(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 mark_inode_dirty(inode);
Al Viro7de9c6ee2010-10-23 11:11:40 -0400163 ihold(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 d_instantiate(new, inode);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700165 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return 0;
167}
168
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800169static int bfs_unlink(struct inode *dir, struct dentry *dentry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
171 int error = -ENOENT;
David Howells2b0143b2015-03-17 22:25:59 +0000172 struct inode *inode = d_inode(dentry);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800173 struct buffer_head *bh;
174 struct bfs_dirent *de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700175 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700177 mutex_lock(&info->bfs_lock);
Al Viro33ebdeb2018-04-30 19:10:34 -0400178 bh = bfs_find_entry(dir, &dentry->d_name, &de);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800179 if (!bh || (le16_to_cpu(de->ino) != inode->i_ino))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 goto out_brelse;
181
182 if (!inode->i_nlink) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800183 printf("unlinking non-existent file %s:%lu (nlink=%d)\n",
184 inode->i_sb->s_id, inode->i_ino,
185 inode->i_nlink);
Miklos Szeredibfe86842011-10-28 14:13:29 +0200186 set_nlink(inode, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188 de->ino = 0;
Al Viro4427f0c2009-06-08 01:15:58 -0400189 mark_buffer_dirty_inode(bh, dir);
Deepa Dinamani02027d42016-09-14 07:48:05 -0700190 dir->i_ctime = dir->i_mtime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 mark_inode_dirty(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 inode->i_ctime = dir->i_ctime;
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700193 inode_dec_link_count(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 error = 0;
195
196out_brelse:
197 brelse(bh);
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700198 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return error;
200}
201
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800202static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
Miklos Szeredif03b8ad2016-09-27 11:03:57 +0200203 struct inode *new_dir, struct dentry *new_dentry,
204 unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800206 struct inode *old_inode, *new_inode;
207 struct buffer_head *old_bh, *new_bh;
208 struct bfs_dirent *old_de, *new_de;
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700209 struct bfs_sb_info *info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 int error = -ENOENT;
211
Miklos Szeredif03b8ad2016-09-27 11:03:57 +0200212 if (flags & ~RENAME_NOREPLACE)
213 return -EINVAL;
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 old_bh = new_bh = NULL;
David Howells2b0143b2015-03-17 22:25:59 +0000216 old_inode = d_inode(old_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (S_ISDIR(old_inode->i_mode))
218 return -EINVAL;
219
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700220 info = BFS_SB(old_inode->i_sb);
221
222 mutex_lock(&info->bfs_lock);
Al Viro33ebdeb2018-04-30 19:10:34 -0400223 old_bh = bfs_find_entry(old_dir, &old_dentry->d_name, &old_de);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800225 if (!old_bh || (le16_to_cpu(old_de->ino) != old_inode->i_ino))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 goto end_rename;
227
228 error = -EPERM;
David Howells2b0143b2015-03-17 22:25:59 +0000229 new_inode = d_inode(new_dentry);
Al Viro33ebdeb2018-04-30 19:10:34 -0400230 new_bh = bfs_find_entry(new_dir, &new_dentry->d_name, &new_de);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 if (new_bh && !new_inode) {
233 brelse(new_bh);
234 new_bh = NULL;
235 }
236 if (!new_bh) {
Al Virob455ecd2018-04-30 19:14:44 -0400237 error = bfs_add_entry(new_dir, &new_dentry->d_name,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800238 old_inode->i_ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (error)
240 goto end_rename;
241 }
242 old_de->ino = 0;
Deepa Dinamani02027d42016-09-14 07:48:05 -0700243 old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 mark_inode_dirty(old_dir);
245 if (new_inode) {
Deepa Dinamani02027d42016-09-14 07:48:05 -0700246 new_inode->i_ctime = current_time(new_inode);
Dave Hansen9a53c3a2006-09-30 23:29:03 -0700247 inode_dec_link_count(new_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
Al Viro4427f0c2009-06-08 01:15:58 -0400249 mark_buffer_dirty_inode(old_bh, old_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 error = 0;
251
252end_rename:
Dmitri Vorobiev3f165e42008-07-25 19:44:54 -0700253 mutex_unlock(&info->bfs_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 brelse(old_bh);
255 brelse(new_bh);
256 return error;
257}
258
Arjan van de Ven754661f2007-02-12 00:55:38 -0800259const struct inode_operations bfs_dir_inops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 .create = bfs_create,
261 .lookup = bfs_lookup,
262 .link = bfs_link,
263 .unlink = bfs_unlink,
264 .rename = bfs_rename,
265};
266
Al Virob455ecd2018-04-30 19:14:44 -0400267static int bfs_add_entry(struct inode *dir, const struct qstr *child, int ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Al Virob455ecd2018-04-30 19:14:44 -0400269 const unsigned char *name = child->name;
270 int namelen = child->len;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800271 struct buffer_head *bh;
272 struct bfs_dirent *de;
273 int block, sblock, eblock, off, pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 int i;
275
276 dprintf("name=%s, namelen=%d\n", name, namelen);
277
278 if (!namelen)
279 return -ENOENT;
280 if (namelen > BFS_NAMELEN)
281 return -ENAMETOOLONG;
282
283 sblock = BFS_I(dir)->i_sblock;
284 eblock = BFS_I(dir)->i_eblock;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800285 for (block = sblock; block <= eblock; block++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 bh = sb_bread(dir->i_sb, block);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800287 if (!bh)
Sanidhya Kashyapc3fe5872015-04-16 12:48:32 -0700288 return -EIO;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800289 for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 de = (struct bfs_dirent *)(bh->b_data + off);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (!de->ino) {
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800292 pos = (block - sblock) * BFS_BSIZE + off;
293 if (pos >= dir->i_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 dir->i_size += BFS_DIRENT_SIZE;
Deepa Dinamani02027d42016-09-14 07:48:05 -0700295 dir->i_ctime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
Deepa Dinamani02027d42016-09-14 07:48:05 -0700297 dir->i_mtime = current_time(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 mark_inode_dirty(dir);
Andrew Stribblehillfac92be2005-09-09 13:02:04 -0700299 de->ino = cpu_to_le16((u16)ino);
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800300 for (i = 0; i < BFS_NAMELEN; i++)
301 de->name[i] =
302 (i < namelen) ? name[i] : 0;
Al Viro4427f0c2009-06-08 01:15:58 -0400303 mark_buffer_dirty_inode(bh, dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 brelse(bh);
305 return 0;
306 }
307 }
308 brelse(bh);
309 }
310 return -ENOSPC;
311}
312
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800313static inline int bfs_namecmp(int len, const unsigned char *name,
314 const char *buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800316 if ((len < BFS_NAMELEN) && buffer[len])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return 0;
318 return !memcmp(name, buffer, len);
319}
320
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800321static struct buffer_head *bfs_find_entry(struct inode *dir,
Al Viro33ebdeb2018-04-30 19:10:34 -0400322 const struct qstr *child,
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800323 struct bfs_dirent **res_dir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324{
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800325 unsigned long block = 0, offset = 0;
326 struct buffer_head *bh = NULL;
327 struct bfs_dirent *de;
Al Viro33ebdeb2018-04-30 19:10:34 -0400328 const unsigned char *name = child->name;
329 int namelen = child->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 *res_dir = NULL;
332 if (namelen > BFS_NAMELEN)
333 return NULL;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 while (block * BFS_BSIZE + offset < dir->i_size) {
336 if (!bh) {
337 bh = sb_bread(dir->i_sb, BFS_I(dir)->i_sblock + block);
338 if (!bh) {
339 block++;
340 continue;
341 }
342 }
343 de = (struct bfs_dirent *)(bh->b_data + offset);
344 offset += BFS_DIRENT_SIZE;
Dmitri Vorobievf433dc52007-11-14 16:59:47 -0800345 if (le16_to_cpu(de->ino) &&
346 bfs_namecmp(namelen, name, de->name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 *res_dir = de;
348 return bh;
349 }
350 if (offset < bh->b_size)
351 continue;
352 brelse(bh);
353 bh = NULL;
354 offset = 0;
355 block++;
356 }
357 brelse(bh);
358 return NULL;
359}