Skip to content

Commit

Permalink
!adapt to msg api changes
Browse files Browse the repository at this point in the history
JIRA: RTOS-792
  • Loading branch information
lukileczo authored and agkaminski committed Mar 21, 2024
1 parent fb25adf commit 4f278a7
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 299 deletions.
2 changes: 0 additions & 2 deletions include/sys/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ enum { mtMount = 0xf50, mtUmount, mtSync, mtStat, mtMountPoint };


typedef struct {
oid_t dev;
oid_t mnt;
unsigned long mode;
char fstype[16];
} mount_i_msg_t;


typedef struct {
int err;
oid_t oid;
} mount_o_msg_t;

Expand Down
13 changes: 8 additions & 5 deletions include/sys/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ extern "C" {
int ioctl(int fd, unsigned long cmd, ...);


const void *ioctl_unpack(const msg_t *msg, unsigned long *request, id_t *id);
const void *ioctl_unpack(msg_t *msg, unsigned long *request, id_t *id);

const void *ioctl_unpackEx(const msg_t *msg, unsigned long *request, id_t *id, void **response_buf);

pid_t ioctl_getSenderPid(const msg_t *msg);
const void *ioctl_unpackEx(msg_t *msg, unsigned long *request, id_t *id, void **response_buf);


void ioctl_setResponse(msg_t *msg, unsigned long request, int err, const void *data);
static inline pid_t ioctl_getSenderPid(const msg_t *msg)
{
return (pid_t)msg->pid;
}

void ioctl_setResponseErr(msg_t *msg, unsigned long request, int err);

void ioctl_setResponse(msg_t *msg, unsigned long request, int err, const void *data);


#ifdef __cplusplus
Expand Down
16 changes: 8 additions & 8 deletions sys/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ static struct {

int eventsSend(event_t *event, int count)
{
msg_t msg;
int err = -ENOSYS;

if (event_common.sink_open || (event_common.sink_open = (lookup("/dev/event/sink", NULL, &event_common.sink) == EOK))) {
msg.type = mtWrite;

msg.i.io.oid = event_common.sink;
msg.i.data = event;
msg.i.size = count * sizeof(event_t);
msg.o.data = NULL;
msg.o.size = 0;
msg_t msg = {
.type = mtWrite,
.oid = event_common.sink,
.i.data = event,
.i.size = count * sizeof(event_t),
.o.data = NULL,
.o.size = 0
};

err = msgSend(event_common.sink.port, &msg);
}
Expand Down
35 changes: 8 additions & 27 deletions sys/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
#include <stdlib.h>


const void *ioctl_unpack(const msg_t *msg, unsigned long *request, id_t *id)
const void *ioctl_unpack(msg_t *msg, unsigned long *request, id_t *id)
{
return ioctl_unpackEx(msg, request, id, NULL);
}


const void *ioctl_unpackEx(const msg_t *msg, unsigned long *request, id_t *id, void **response_buf)
const void *ioctl_unpackEx(msg_t *msg, unsigned long *request, id_t *id, void **response_buf)
{
size_t size;
const void *data = NULL;
Expand All @@ -44,7 +44,7 @@ const void *ioctl_unpackEx(const msg_t *msg, unsigned long *request, id_t *id, v
}

if (id != NULL) {
*id = ioctl->id;
*id = msg->oid.id;
}

size = IOCPARM_LEN(ioctl->request);
Expand Down Expand Up @@ -91,9 +91,8 @@ const void *ioctl_unpackEx(const msg_t *msg, unsigned long *request, id_t *id, v
}

if ((response_buf != NULL) && ((ioctl->request & IOC_OUT) != 0)) {
ioctl_out_t *ioctl_out = (ioctl_out_t *)msg->o.raw;
if (size <= (sizeof(msg->o.raw) - sizeof(ioctl_out_t))) {
*response_buf = ioctl_out->data;
if (size <= sizeof(msg->o.raw)) {
*response_buf = msg->o.raw;
}
else {
*response_buf = msg->o.data;
Expand All @@ -108,24 +107,16 @@ const void *ioctl_unpackEx(const msg_t *msg, unsigned long *request, id_t *id, v
}


pid_t ioctl_getSenderPid(const msg_t *msg)
{
const ioctl_in_t *ioctl = (const ioctl_in_t *)msg->i.raw;
return (pid_t)ioctl->pid;
}


void ioctl_setResponse(msg_t *msg, unsigned long request, int err, const void *data)
{
size_t size = IOCPARM_LEN(request);
void *dst;
ioctl_out_t *ioctl = (ioctl_out_t *)msg->o.raw;

ioctl->err = err;
msg->o.err = err;

if (((request & IOC_OUT) != 0) && (data != NULL)) {
if (size <= (sizeof(msg->o.raw) - sizeof(ioctl_out_t))) {
dst = ioctl->data;
if (size <= sizeof(msg->o.raw)) {
dst = msg->o.raw;
}
else {
dst = msg->o.data;
Expand All @@ -134,13 +125,3 @@ void ioctl_setResponse(msg_t *msg, unsigned long request, int err, const void *d
(void)memcpy(dst, data, size);
}
}


void ioctl_setResponseErr(msg_t *msg, unsigned long request, int err)
{
ioctl_out_t *ioctl = (ioctl_out_t *)msg->o.raw;

(void)request;

ioctl->err = err;
}
95 changes: 50 additions & 45 deletions sys/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@

int mount(const char *source, const char *target, const char *fstype, unsigned long mode, const char *data)
{
struct stat buf;
oid_t toid, soid, doid;
msg_t msg = {0};
char *source_abspath, *target_abspath;
int err;

mount_i_msg_t *imnt = (mount_i_msg_t *)msg.i.raw;
mount_o_msg_t *omnt = (mount_o_msg_t *)msg.o.raw;

if ((target_abspath = resolve_path(target, NULL, 1, 0)) == NULL)
char *target_abspath = resolve_path(target, NULL, 1, 0);
if (target_abspath == NULL) {
return -1; /* errno set by resolve_path */

if ((source_abspath = resolve_path(source, NULL, 1, 0)) == NULL) {
}
char *source_abspath = resolve_path(source, NULL, 1, 0);
if (source_abspath == NULL) {
free(target_abspath);
return -1; /* errno set by resolve_path */
}

oid_t toid, soid, doid;

if (lookup(target_abspath, NULL, &toid) < 0) {
free(target_abspath);
free(source_abspath);
Expand All @@ -53,61 +48,69 @@ int mount(const char *source, const char *target, const char *fstype, unsigned l
return SET_ERRNO(-ENOENT);
}

err = stat(target_abspath, &buf);
struct stat buf;
int err = stat(target_abspath, &buf);

free(target_abspath);
free(source_abspath);

if (err < 0)
if (err < 0) {
return err;
}

if (!S_ISDIR(buf.st_mode))
if (!S_ISDIR(buf.st_mode)) {
return SET_ERRNO(-ENOTDIR);
}

msg_t msg = {
.type = mtMount,
.i.size = (data != NULL) ? strlen(data) : 0,
.i.data = data,
.oid = soid
};

mount_i_msg_t *imnt = (mount_i_msg_t *)msg.i.raw;
mount_o_msg_t *omnt = (mount_o_msg_t *)msg.o.raw;

msg.type = mtMount;
imnt->dev = soid;
imnt->mnt = toid;
imnt->mode = mode;
strncpy(imnt->fstype, fstype, sizeof(imnt->fstype));
imnt->fstype[sizeof(imnt->fstype) - 1] = '\0';

msg.i.size = data != NULL ? strlen(data) : 0;
msg.i.data = (char *)data; /* FIXME: dropping const because of broken msg_t declaration */

if (msgSend(soid.port, &msg) < 0)
if (msgSend(soid.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}

/* Mount failed */
if (omnt->err < 0) {
return SET_ERRNO(omnt->err);
if (msg.o.err < 0) {
return SET_ERRNO(msg.o.err);
}
doid = omnt->oid;

/* Create mountpoint */
memset(&msg, 0, sizeof(msg));

msg.type = mtSetAttr;
msg.i.attr.oid = toid;
msg.oid = toid;
msg.i.attr.type = atDev;
msg.i.data = &doid;
msg.i.size = sizeof(oid_t);

if (msgSend(toid.port, &msg) < 0)
if (msgSend(toid.port, &msg) < 0) {
return SET_ERRNO(-EIO); /* FIXME: rollback partial mount */
}

return SET_ERRNO(msg.o.attr.err);
return SET_ERRNO(msg.o.err);
}


int umount(const char *target)
{
msg_t msg = { 0 };
mount_o_msg_t *omnt = (mount_o_msg_t *)msg.o.raw;
int rootfs = 0;
oid_t oid, dev;
char *abspath;

abspath = resolve_path(target, NULL, 1, 0);
char *abspath = resolve_path(target, NULL, 1, 0);
if (abspath == NULL) {
/* errno set by resolve_path() */
return -1;
Expand All @@ -133,16 +136,18 @@ int umount(const char *target)
free(abspath);

/* Check file type */
msg.type = mtGetAttr;
msg.i.attr.type = atMode;
msg.i.attr.oid = oid;
msg_t msg = {
.type = mtGetAttr,
.oid = oid,
.i.attr.type = atMode,
};

if (msgSend(oid.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}

if (msg.o.attr.err < 0) {
return SET_ERRNO(msg.o.attr.err);
if (msg.o.err < 0) {
return SET_ERRNO(msg.o.err);
}

/* Got mountpoint */
Expand All @@ -153,23 +158,24 @@ int umount(const char *target)
/* Got mounted device */
/* TODO: check device type (should be S_IFBLK?) */
else {
mount_o_msg_t *omnt = (mount_o_msg_t *)msg.o.raw;

/* Get mountpoint */
msg.type = mtMountPoint;
msg.i.data = &dev;
msg.i.size = sizeof(dev);
msg.oid = dev;

if (msgSend(dev.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}

if (omnt->err < 0) {
if (msg.o.err < 0) {
/* Check for rootfs */
if (omnt->err == -ENOENT) {
if (msg.o.err == -ENOENT) {
rootfs = 1;
}
/* No mountpoint */
else {
return SET_ERRNO(omnt->err);
return SET_ERRNO(msg.o.err);
}
}
else {
Expand All @@ -179,30 +185,29 @@ int umount(const char *target)

/* Unmount filesystem */
msg.type = mtUmount;
msg.i.data = &dev;
msg.i.size = sizeof(dev);
msg.oid = dev;

if (msgSend(dev.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}

if (msg.o.io.err < 0) {
return SET_ERRNO(msg.o.io.err);
if (msg.o.err < 0) {
return SET_ERRNO(msg.o.err);
}

/* Remove mountpoint */
if (rootfs == 0) {
msg.type = mtSetAttr;
msg.oid = oid;
msg.i.attr.type = atDev;
msg.i.attr.oid = oid;
msg.i.data = &oid;
msg.i.size = sizeof(oid);

if (msgSend(oid.port, &msg) < 0) {
return SET_ERRNO(-EIO);
}

return SET_ERRNO(msg.o.attr.err);
return SET_ERRNO(msg.o.err);
}
/* TODO: unregister root in kernel */
else {
Expand Down
Loading

0 comments on commit 4f278a7

Please sign in to comment.