bugfix: OFD:FLAGS
This commit is contained in:
@@ -475,7 +475,7 @@ int io_engine_init(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_create(uint64_t size_hint, uint64_t *blob_id_out, uint64_t *handle_id_out) {
|
||||
int blob_create(uint64_t size_hint, int open_flags, uint64_t *blob_id_out, uint64_t *handle_id_out) {
|
||||
if (!blob_id_out || !handle_id_out) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -485,6 +485,7 @@ int blob_create(uint64_t size_hint, uint64_t *blob_id_out, uint64_t *handle_id_o
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_CREATE;
|
||||
req.size_hint = size_hint;
|
||||
req.open_flags = (uint32_t)open_flags;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
@@ -502,7 +503,7 @@ int blob_create(uint64_t size_hint, uint64_t *blob_id_out, uint64_t *handle_id_o
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_open(uint64_t blob_id, uint64_t *handle_id_out) {
|
||||
int blob_open(uint64_t blob_id, int open_flags, uint64_t *handle_id_out) {
|
||||
if (!handle_id_out) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -512,6 +513,7 @@ int blob_open(uint64_t blob_id, uint64_t *handle_id_out) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_OPEN;
|
||||
req.blob_id = blob_id;
|
||||
req.open_flags = (uint32_t)open_flags;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
@@ -571,7 +573,12 @@ int blob_write(uint64_t handle_id, uint64_t offset, const void *buf, size_t len)
|
||||
return blob_write_ex(handle_id, offset, buf, len, 0);
|
||||
}
|
||||
|
||||
int blob_read(uint64_t handle_id, uint64_t offset, void *buf, size_t len) {
|
||||
int blob_write_shared(uint64_t handle_id, uint64_t logical_size, const void *buf, size_t len, uint32_t write_flags) {
|
||||
return blob_write_ex(handle_id, logical_size, buf, len,
|
||||
write_flags | ZVFS_RW_F_USE_HANDLE_POS);
|
||||
}
|
||||
|
||||
ssize_t blob_read_ex(uint64_t handle_id, uint64_t offset, void *buf, size_t len, uint32_t read_flags) {
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -586,6 +593,7 @@ int blob_read(uint64_t handle_id, uint64_t offset, void *buf, size_t len) {
|
||||
req.handle_id = handle_id;
|
||||
req.offset = offset;
|
||||
req.length = (uint64_t)len;
|
||||
req.write_flags = read_flags;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
@@ -594,7 +602,7 @@ int blob_read(uint64_t handle_id, uint64_t offset, void *buf, size_t len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!resp.data || resp.length != (uint64_t)len) {
|
||||
if (!resp.data && resp.length != 0) {
|
||||
if (resp.data) {
|
||||
free(resp.data);
|
||||
}
|
||||
@@ -602,11 +610,35 @@ int blob_read(uint64_t handle_id, uint64_t offset, void *buf, size_t len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(buf, resp.data, len);
|
||||
if (resp.length > len) {
|
||||
free(resp.data);
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (resp.length > 0) {
|
||||
memcpy(buf, resp.data, (size_t)resp.length);
|
||||
}
|
||||
free(resp.data);
|
||||
return (ssize_t)resp.length;
|
||||
}
|
||||
|
||||
int blob_read(uint64_t handle_id, uint64_t offset, void *buf, size_t len) {
|
||||
ssize_t nr = blob_read_ex(handle_id, offset, buf, len, 0);
|
||||
if (nr < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((size_t)nr != len) {
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t blob_read_shared(uint64_t handle_id, uint64_t logical_size, void *buf, size_t len) {
|
||||
return blob_read_ex(handle_id, logical_size, buf, len, ZVFS_RW_F_USE_HANDLE_POS);
|
||||
}
|
||||
|
||||
int blob_resize(uint64_t handle_id, uint64_t new_size) {
|
||||
if (handle_id == 0) {
|
||||
errno = EINVAL;
|
||||
@@ -769,3 +801,106 @@ int blob_add_ref_batch(const uint64_t *handle_ids, const uint32_t *ref_deltas, u
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_seek(uint64_t handle_id, int64_t offset, int whence, uint64_t logical_size, uint64_t *new_offset_out) {
|
||||
if (handle_id == 0 || !new_offset_out) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct zvfs_req req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_SEEK;
|
||||
req.handle_id = handle_id;
|
||||
req.seek_offset = offset;
|
||||
req.seek_whence = (uint32_t)whence;
|
||||
req.size_hint = logical_size;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (ipc_do_req(&req, &resp) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*new_offset_out = resp.offset;
|
||||
if (resp.data) {
|
||||
free(resp.data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_get_pos(uint64_t handle_id, uint64_t *offset_out) {
|
||||
if (handle_id == 0 || !offset_out) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct zvfs_req req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_GET_POS;
|
||||
req.handle_id = handle_id;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (ipc_do_req(&req, &resp) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*offset_out = resp.offset;
|
||||
if (resp.data) {
|
||||
free(resp.data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_get_flags(uint64_t handle_id, uint32_t *flags_out) {
|
||||
if (handle_id == 0 || !flags_out) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct zvfs_req req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_GET_FLAGS;
|
||||
req.handle_id = handle_id;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (ipc_do_req(&req, &resp) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*flags_out = resp.handle_flags;
|
||||
if (resp.data) {
|
||||
free(resp.data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int blob_set_flags(uint64_t handle_id, uint32_t flags) {
|
||||
if (handle_id == 0) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct zvfs_req req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.opcode = ZVFS_OP_SET_FLAGS;
|
||||
req.handle_id = handle_id;
|
||||
req.handle_flags = flags;
|
||||
|
||||
struct zvfs_resp resp;
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
|
||||
if (ipc_do_req(&req, &resp) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (resp.data) {
|
||||
free(resp.data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user