summaryrefslogtreecommitdiff
path: root/lib9p_util
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p_util')
-rw-r--r--lib9p_util/CMakeLists.txt2
-rw-r--r--lib9p_util/static.c126
2 files changed, 55 insertions, 73 deletions
diff --git a/lib9p_util/CMakeLists.txt b/lib9p_util/CMakeLists.txt
index 2e5790e..feeada7 100644
--- a/lib9p_util/CMakeLists.txt
+++ b/lib9p_util/CMakeLists.txt
@@ -9,5 +9,5 @@ target_sources(lib9p_util INTERFACE
static.c
)
target_link_libraries(lib9p_util INTERFACE
- lib9p
+ lib9p_srv
)
diff --git a/lib9p_util/static.c b/lib9p_util/static.c
index 7f1e6b7..1726319 100644
--- a/lib9p_util/static.c
+++ b/lib9p_util/static.c
@@ -33,40 +33,35 @@ static struct lib9p_qid util9p_static_dir_qid(struct util9p_static_dir *self) {
};
}
-static struct lib9p_stat util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) {
+static struct lib9p_srv_stat util9p_static_dir_stat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
- return (struct lib9p_stat){
- .kern_type = 0,
- .kern_dev = 0,
- .file_qid = util9p_static_dir_qid(self),
- .file_mode = LIB9P_DM_DIR | (self->perm & 0555),
- .file_atime = self->atime,
- .file_mtime = self->mtime,
- .file_size = 0,
- .file_name = lib9p_str(self->name),
- .file_owner_uid = lib9p_str(self->u_name),
- .file_owner_gid = lib9p_str(self->g_name),
- .file_last_modified_uid = lib9p_str(self->m_name),
- .file_extension = lib9p_str(NULL),
- .file_owner_n_uid = self->u_num,
- .file_owner_n_gid = self->g_num,
- .file_last_modified_n_uid = self->m_num,
+ return (struct lib9p_srv_stat){
+ .qid = util9p_static_dir_qid(self),
+ .mode = LIB9P_DM_DIR | (self->perm & 0555),
+ .atime_sec = self->atime,
+ .mtime_sec = self->mtime,
+ .size = 0,
+ .name = lib9p_str(self->name),
+ .owner_uid = { .name = lib9p_str(self->u_name), .num = self->u_num },
+ .owner_gid = { .name = lib9p_str(self->g_name), .num = self->g_num },
+ .last_modifier_uid = { .name = lib9p_str(self->m_name), .num = self->m_num },
+ .extension = lib9p_str(NULL),
};
}
static void util9p_static_dir_wstat(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx,
- struct lib9p_stat) {
+ struct lib9p_srv_stat) {
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
}
static void util9p_static_dir_remove(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
}
static lo_interface lib9p_srv_file util9p_static_dir_dwalk(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx,
@@ -76,25 +71,27 @@ static lo_interface lib9p_srv_file util9p_static_dir_dwalk(struct util9p_static_
for (size_t i = 0; !LO_IS_NULL(self->members[i]); i++) {
lo_interface lib9p_srv_file file = self->members[i];
- struct lib9p_stat stat = LO_CALL(file, stat, ctx);
+ struct lib9p_srv_stat stat = LO_CALL(file, stat, ctx);
if (lib9p_ctx_has_error(&ctx->basectx))
break;
- lib9p_stat_assert(stat);
- if (lib9p_str_eq(stat.file_name, childname))
+ lib9p_srv_stat_assert(stat);
+ if (lib9p_str_eq(stat.name, childname))
return file;
}
lib9p_error(&ctx->basectx,
- LINUX_ENOENT, "no such file or directory");
+ LIB9P_ERRNO_L_ENOENT, "no such file or directory");
return LO_NULL(lib9p_srv_file);
}
static lo_interface lib9p_srv_file util9p_static_dir_dcreate(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx,
struct lib9p_s LM_UNUSED(childname),
- lib9p_dm_t LM_UNUSED(perm), lib9p_o_t LM_UNUSED(flags)) {
+ struct lib9p_srv_userid *LM_UNUSED(user),
+ struct lib9p_srv_userid *LM_UNUSED(group),
+ lib9p_dm_t LM_UNUSED(perm)) {
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
return LO_NULL(lib9p_srv_file);
}
@@ -108,33 +105,23 @@ static lo_interface lib9p_srv_dio util9p_static_dir_dopen(struct util9p_static_d
static void util9p_static_dir_iofree(struct util9p_static_dir *self) {
assert(self);
}
-static size_t util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx,
- uint8_t *buf,
- uint32_t byte_count,
- size_t _obj_offset) {
+static struct lib9p_srv_dirent util9p_static_dir_dread(struct util9p_static_dir *self, struct lib9p_srv_ctx *ctx, size_t idx) {
assert(self);
assert(ctx);
- uint32_t byte_offset = 0;
- size_t obj_offset = _obj_offset;
- while (!LO_IS_NULL(self->members[obj_offset])) {
- lo_interface lib9p_srv_file file = self->members[obj_offset];
- struct lib9p_stat stat = LO_CALL(file, stat, ctx);
- if (lib9p_ctx_has_error(&ctx->basectx))
- break;
- lib9p_stat_assert(stat);
- uint32_t nbytes = lib9p_stat_marshal(&ctx->basectx, byte_count-byte_offset, &stat,
- &buf[byte_offset]);
- if (!nbytes) {
- if (obj_offset == _obj_offset)
- lib9p_error(&ctx->basectx,
- LINUX_ERANGE, "stat object does not fit into negotiated max message size");
- break;
- }
- byte_offset += nbytes;
- obj_offset++;
- }
- return obj_offset - _obj_offset;
+ lo_interface lib9p_srv_file file = self->members[idx];
+ if (LO_IS_NULL(file))
+ return (struct lib9p_srv_dirent){};
+
+ struct lib9p_srv_stat stat = LO_CALL(file, stat, ctx);
+ if (lib9p_ctx_has_error(&ctx->basectx))
+ return (struct lib9p_srv_dirent){};
+ lib9p_srv_stat_assert(stat);
+
+ return (struct lib9p_srv_dirent){
+ .qid = stat.qid,
+ .name = stat.name,
+ };
}
/* file ***********************************************************************/
@@ -164,40 +151,35 @@ static inline size_t util9p_static_file_size(struct util9p_static_file *file) {
}
-static struct lib9p_stat util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) {
+static struct lib9p_srv_stat util9p_static_file_stat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
- return (struct lib9p_stat){
- .kern_type = 0,
- .kern_dev = 0,
- .file_qid = util9p_static_file_qid(self),
- .file_mode = self->perm & 0444,
- .file_atime = self->atime,
- .file_mtime = self->mtime,
- .file_size = (uint64_t)util9p_static_file_size(self),
- .file_name = lib9p_str(self->name),
- .file_owner_uid = lib9p_str(self->u_name),
- .file_owner_gid = lib9p_str(self->g_name),
- .file_last_modified_uid = lib9p_str(self->m_name),
- .file_extension = lib9p_str(NULL),
- .file_owner_n_uid = self->u_num,
- .file_owner_n_gid = self->g_num,
- .file_last_modified_n_uid = self->m_num,
+ return (struct lib9p_srv_stat){
+ .qid = util9p_static_file_qid(self),
+ .mode = self->perm & 0444,
+ .atime_sec = self->atime,
+ .mtime_sec = self->mtime,
+ .size = (uint64_t)util9p_static_file_size(self),
+ .name = lib9p_str(self->name),
+ .owner_uid = { .name = lib9p_str(self->u_name), .num = self->u_num },
+ .owner_gid = { .name = lib9p_str(self->g_name), .num = self->g_num },
+ .last_modifier_uid = { .name = lib9p_str(self->m_name), .num = self->m_num },
+ .extension = lib9p_str(NULL),
};
}
static void util9p_static_file_wstat(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx,
- struct lib9p_stat) {
+ struct lib9p_srv_stat) {
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
}
static void util9p_static_file_remove(struct util9p_static_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
}
LIB9P_SRV_NOTDIR(struct util9p_static_file, util9p_static_file);
@@ -229,7 +211,7 @@ static void util9p_static_file_pread(struct util9p_static_file *self, struct lib
if (byte_offset > (uint64_t)data_size) {
lib9p_error(&ctx->basectx,
- LINUX_EINVAL, "offset is past end-of-file length");
+ LIB9P_ERRNO_L_EINVAL, "offset is past end-of-file length");
return;
}
@@ -247,6 +229,6 @@ static uint32_t util9p_static_file_pwrite(struct util9p_static_file *self, struc
assert(self);
assert(ctx);
- lib9p_error(&ctx->basectx, LINUX_EROFS, "read-only part of filesystem");
+ lib9p_error(&ctx->basectx, LIB9P_ERRNO_L_EROFS, "read-only part of filesystem");
return 0;
}