Skip to content

Commit 7beea72

Browse files
chuckleverbrauner
authored andcommitted
libfs: Define a minimum directory offset
This value is used in several places, so make it a symbolic constant. Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Link: https://lore.kernel.org/r/170820142741.6328.12428356024575347885.stgit@91.116.238.104.host.secureserver.net Signed-off-by: Christian Brauner <[email protected]>
1 parent 3f6d810 commit 7beea72

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

fs/libfs.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ const struct inode_operations simple_dir_inode_operations = {
240240
};
241241
EXPORT_SYMBOL(simple_dir_inode_operations);
242242

243+
/* 0 is '.', 1 is '..', so always start with offset 2 or more */
244+
enum {
245+
DIR_OFFSET_MIN = 2,
246+
};
247+
243248
static void offset_set(struct dentry *dentry, u32 offset)
244249
{
245250
dentry->d_fsdata = (void *)((uintptr_t)(offset));
@@ -261,9 +266,7 @@ void simple_offset_init(struct offset_ctx *octx)
261266
{
262267
xa_init_flags(&octx->xa, XA_FLAGS_ALLOC1);
263268
lockdep_set_class(&octx->xa.xa_lock, &simple_offset_xa_lock);
264-
265-
/* 0 is '.', 1 is '..', so always start with offset 2 */
266-
octx->next_offset = 2;
269+
octx->next_offset = DIR_OFFSET_MIN;
267270
}
268271

269272
/**
@@ -276,7 +279,7 @@ void simple_offset_init(struct offset_ctx *octx)
276279
*/
277280
int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry)
278281
{
279-
static const struct xa_limit limit = XA_LIMIT(2, U32_MAX);
282+
static const struct xa_limit limit = XA_LIMIT(DIR_OFFSET_MIN, U32_MAX);
280283
u32 offset;
281284
int ret;
282285

@@ -481,7 +484,7 @@ static int offset_readdir(struct file *file, struct dir_context *ctx)
481484
return 0;
482485

483486
/* In this case, ->private_data is protected by f_pos_lock */
484-
if (ctx->pos == 2)
487+
if (ctx->pos == DIR_OFFSET_MIN)
485488
file->private_data = NULL;
486489
else if (file->private_data == ERR_PTR(-ENOENT))
487490
return 0;

0 commit comments

Comments
 (0)