Skip to content

Commit

Permalink
libfs: Add libfs_put_dots and put_dir definitions
Browse files Browse the repository at this point in the history
Small helpers for getdirent implementations to use.

Signed-off-by: Pedro Falcato <[email protected]>
  • Loading branch information
heatd committed Dec 24, 2024
1 parent 1aaf9d9 commit 6927793
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions kernel/kernel/fs/libfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Pedro Falcato
* This file is part of Onyx, and is released under the terms of the GPLv2 License
* check LICENSE at the root directory for more information
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#include <onyx/dentry.h>
#include <onyx/libfs.h>
#include <onyx/vfs.h>

off_t libfs_put_dots(struct dirent *buf, off_t off, struct dentry *dent)
{
struct dentry *parent = NULL;
struct inode *ino;
const char *name = NULL;

DCHECK(off < 2);
if (off == 0)
{
/* . , fallthrough */
name = ".";
}
else if (off == 1)
{
/* .. */
parent = dentry_parent(dent);
if (parent)
dent = parent;
name = "..";
}

ino = dent->d_inode;
put_dir(name, off, ino->i_inode, IFTODT(ino->i_mode), buf);
if (parent)
dput(parent);
return off + 1;
}

void put_dir(const char *name, off_t off, ino_t ino, unsigned int dtype, struct dirent *buf)
{
size_t len = strlen(name);
memcpy(buf->d_name, name, len);
buf->d_name[len] = '\0';
buf->d_off = off;
buf->d_ino = ino;
buf->d_type = dtype;
buf->d_reclen = sizeof(struct dirent) - (256 - (len + 1));
}

0 comments on commit 6927793

Please sign in to comment.