diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/dms/dms_engine.c | 106 | ||||
-rw-r--r-- | src/sys/include/compat/unix/syscall.h | 4 | ||||
-rw-r--r-- | src/sys/include/dms/dms.h | 6 | ||||
-rw-r--r-- | src/sys/include/sys/dms.h | 60 | ||||
-rw-r--r-- | src/sys/include/sys/syscall.h | 1 |
5 files changed, 176 insertions, 1 deletions
diff --git a/src/sys/dms/dms_engine.c b/src/sys/dms/dms_engine.c new file mode 100644 index 0000000..35388cc --- /dev/null +++ b/src/sys/dms/dms_engine.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and L5 engineers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/syscall.h> +#include <sys/types.h> +#include <sys/errno.h> +#include <sys/dms.h> +#include <os/systm.h> +#include <os/kalloc.h> +#include <dms/dms.h> + +static ssize_t +dms_io(struct dms_frame *dfp) +{ + struct dms_disk *dp; + size_t len; + ssize_t retval = -ENXIO; + int error; + void *kbuf; + + if (dfp == NULL) { + return -EINVAL; + } + + if ((len = dfp->len) == 0) { + return -EINVAL; + } + + if ((dp = dms_get(dfp->id)) == NULL) { + return -ENODEV; + } + + if ((kbuf = kalloc(dfp->len)) == NULL) { + return -ENOMEM; + } + + switch (dfp->opcode) { + case DMS_OPC_READ: + retval = dms_read(dp, kbuf, dfp->offset, dfp->len); + if (retval < 0) { + break; + } + error = copyout(kbuf, dfp->buf, dfp->len); + if (error < 0) { + retval = error; + break; + } + break; + case DMS_OPC_WRITE: + error = copyin(dfp->buf, kbuf, dfp->len); + if (error < 0) { + retval = error; + break; + } + + retval = dms_write(dp, kbuf, dfp->offset, dfp->len); + break; + } + + kfree(kbuf); + return retval; +} + +/* + * ARG0: DMS frame pointer + */ +scret_t +sys_dmsio(struct syscall_args *scargs) +{ + struct dms_frame *u_dfp = SCARG(scargs, struct dms_frame *, 0); + struct dms_frame df; + int error; + + error = copyin(u_dfp, &df, sizeof(df)); + if (error < 0) { + return error; + } + + return dms_io(&df); +} diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index 13bd617..8b7e7d7 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -36,6 +36,7 @@ #include <sys/syscall.h> #include <os/iotap.h> #include <os/reboot.h> +#include <dms/dms.h> /* * Exit the current process - exit(2) syscall @@ -75,7 +76,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_muxtap] = sys_muxtap, [SYS_getargv] = sys_getargv, [SYS_reboot] = sys_reboot, - [SYS_waitpid] = sys_waitpid + [SYS_waitpid] = sys_waitpid, + [SYS_dmsio] = sys_dmsio }; #endif /* !_NEED_UNIX_SCTAB */ diff --git a/src/sys/include/dms/dms.h b/src/sys/include/dms/dms.h index 06e78ac..8453723 100644 --- a/src/sys/include/dms/dms.h +++ b/src/sys/include/dms/dms.h @@ -30,6 +30,7 @@ #ifndef _DMS_DMS_H_ #define _DMS_DMS_H_ +#include <sys/syscall.h> #include <sys/queue.h> #include <sys/cdefs.h> #include <sys/types.h> @@ -139,4 +140,9 @@ int dms_register(const char *name, struct dms_ops *ops, struct dms_disk **res); */ struct dms_disk *dms_get(disk_id_t disk_id); +/* + * Perform I/O on a disk + */ +scret_t sys_dmsio(struct syscall_args *scargs); + #endif /* !_DMS_DMS_H_ */ diff --git a/src/sys/include/sys/dms.h b/src/sys/include/sys/dms.h new file mode 100644 index 0000000..7d80c33 --- /dev/null +++ b/src/sys/include/sys/dms.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and L5 engineers + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_DMS_H_ +#define _SYS_DMS_H_ 1 + +#include <sys/types.h> +#if !defined(_KERNEL) +#include <stdint.h> +#include <stddef.h> +#endif /* !_KERNEL */ + +#define DMS_OPC_READ 0x00 /* Read from drive */ +#define DMS_OPC_WRITE 0x01 /* Write to drive */ + +/* + * Represents data that can be sent between the + * DMS framework and certain user applications + * + * @id: ID of disk to operate on + * @opcode: Operation code + * @buf: Data buffer (direction depends on opcode) + * @offset: Offset to perform operation at (depends on opcode) + * @len: Length of buffer + */ +struct dms_frame { + uint16_t id; + uint8_t opcode; + void *buf; + off_t offset; + size_t len; +}; + +#endif /* !_SYS_DMS_H_ */ diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index ac03055..2ff6087 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -55,6 +55,7 @@ #define SYS_getargv 0x0A /* get process argv */ #define SYS_reboot 0x0B /* reboot the system */ #define SYS_waitpid 0x0C /* wait for child to exit */ +#define SYS_dmsio 0x0D /* DMS I/O */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; |