lib: xpc: implement support for iterating through directories

This commit is contained in:
2026-03-24 12:41:12 +00:00
parent 1eb6853cb0
commit 30614e679b
6 changed files with 61 additions and 3 deletions

View File

@@ -0,0 +1,34 @@
#include "../file.h"
#include <errno.h>
#include <fs/context.h>
#include <fs/file.h>
#include <fs/status.h>
kern_status_t fs_msg_getdents(
xpc_context_t *xpc,
const xpc_endpoint_t *sender,
int *out_err,
xpc_buffer_t *out_dents,
void *arg)
{
struct fs_context *ctx = arg;
struct fs_file *f = fs_context_get_file(ctx, sender->e_port);
if (!f) {
*out_err = EBADF;
return KERN_OK;
}
if (!(f->f_inode->i_mode & FS_INODE_DIR)) {
*out_err = ENOTDIR;
return KERN_OK;
}
size_t start = fs_file_get_cursor(f);
enum fs_status status = fs_file_readdir(f, out_dents);
size_t end = fs_file_get_cursor(f);
*out_err = fs_status_to_errno(status);
return KERN_OK;
}

View File

@@ -8,7 +8,6 @@ extern kern_status_t fs_msg_read(
xpc_endpoint_t *sender,
size_t count,
int *out_err,
size_t *out_nr_read,
xpc_buffer_t *out_data,
void *arg)
{
@@ -24,7 +23,7 @@ extern kern_status_t fs_msg_read(
size_t end = fs_file_get_cursor(f);
*out_err = fs_status_to_errno(status);
*out_nr_read = end - start;
out_data->buf_len = end - start;
return KERN_OK;
}