From 783545bdf8201bcba948b91bedc67ca40046fbea Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 16 Jan 2023 04:54:34 +0000 Subject: [PATCH] Create platform specific I/O module, prepare for io_uring --- linux/io.c | 27 +++++++++++++++++++++++++++ linux/io.h | 21 +++++++++++++++++++++ makefile | 11 ++++++++--- shell.c | 2 +- umka_fuse.c | 2 +- vdisk.c | 4 +++- vdisk.h | 6 ++++-- vdisk/raw.c | 7 +++++-- windows/io.c | 27 +++++++++++++++++++++++++++ windows/io.h | 21 +++++++++++++++++++++ 10 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 linux/io.c create mode 100644 linux/io.h create mode 100644 windows/io.c create mode 100644 windows/io.h diff --git a/linux/io.c b/linux/io.c new file mode 100644 index 0000000..4f4db58 --- /dev/null +++ b/linux/io.c @@ -0,0 +1,27 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + io - input/output platform specific code + + Copyright (C) 2023 Ivan Baravy +*/ + +#include +#include "io.h" + +ssize_t +io_read(int fd, void *buf, size_t count, int change_task) { + (void)change_task; + ssize_t res; + res = read(fd, buf, count); + return res; +} + +ssize_t +io_write(int fd, const void *buf, size_t count, int change_task) { + (void)change_task; + ssize_t res; + res = write(fd, buf, count); + return res; +} diff --git a/linux/io.h b/linux/io.h new file mode 100644 index 0000000..f773bd2 --- /dev/null +++ b/linux/io.h @@ -0,0 +1,21 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + io - input/output platform specific code + + Copyright (C) 2023 Ivan Baravy +*/ + +#ifndef IO_H_INCLUDED +#define IO_H_INCLUDED + +#include + +ssize_t +io_read(int fd, void *buf, size_t count, int change_task); + +ssize_t +io_write(int fd, const void *buf, size_t count, int change_task); + +#endif // IO_H_INCLUDED diff --git a/makefile b/makefile index d4cda09..a1c0d88 100644 --- a/makefile +++ b/makefile @@ -57,16 +57,18 @@ test: umka_shell umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o \ vdisk/raw.o vdisk/qcow2.o vdisk/miniz/miniz.a vnet.o lodepng.o \ - $(HOST)/pci.o $(HOST)/thread.o util.o optparse.o bestline.o + $(HOST)/pci.o $(HOST)/thread.o $(HOST)/io.o util.o optparse.o \ + bestline.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o vdisk/raw.o \ - vdisk/qcow2.o vdisk/miniz/miniz.a $(HOST)/pci.o $(HOST)/thread.o + vdisk/qcow2.o vdisk/miniz/miniz.a $(HOST)/pci.o $(HOST)/thread.o \ + $(HOST)/io.o $(CC) $(LDFLAGS_32) $^ -o $@ `pkg-config fuse3 --libs` -T umka.ld umka_os: umka_os.o umka.o shell.o lodepng.o vdisk.o vdisk/raw.o vdisk/qcow2.o \ vdisk/miniz/miniz.a vnet.o trace.o trace_lbr.o $(HOST)/pci.o \ - $(HOST)/thread.o util.o bestline.o optparse.o + $(HOST)/thread.o $(HOST)/io.o util.o bestline.o optparse.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld umka_gen_devices_dat: umka_gen_devices_dat.o umka.o $(HOST)/pci.o \ @@ -79,6 +81,9 @@ umka.o umka.fas: umka.asm shell.o: shell.c lodepng.h $(CC) $(CFLAGS_32) -c $< +$(HOST)/io.o: $(HOST)/io.c $(HOST)/io.h + $(CC) $(CFLAGS_32) -c $< -o $@ + $(HOST)/thread.o: $(HOST)/thread.c $(CC) $(CFLAGS_32) -c $< -o $@ diff --git a/shell.c b/shell.c index d9a8d60..eb9f0f9 100644 --- a/shell.c +++ b/shell.c @@ -618,7 +618,7 @@ cmd_disk_add(struct shell_ctx *ctx, int argc, char **argv) { } struct vdisk *umka_disk = vdisk_init(file_name, adjust_cache_size, - cache_size); + cache_size, umka_tool == UMKA_OS); if (umka_disk) { COVERAGE_ON(); disk_t *disk = disk_add(&umka_disk->diskfunc, disk_name, umka_disk, 0); diff --git a/umka_fuse.c b/umka_fuse.c index 7eadf5e..5bbb4a2 100644 --- a/umka_fuse.c +++ b/umka_fuse.c @@ -151,7 +151,7 @@ main(int argc, char *argv[]) { kos_boot.pitch = UMKA_DEFAULT_DISPLAY_WIDTH*4; // 32bpp umka_init(); - struct vdisk *umka_disk = vdisk_init(argv[2], 1, 0u); + struct vdisk *umka_disk = vdisk_init(argv[2], 1, 0u, 0); disk_t *disk = disk_add(&umka_disk->diskfunc, "hd0", umka_disk, 0); disk_media_changed(disk, 1); return fuse_main(argc-1, argv, &umka_oper, NULL); diff --git a/vdisk.c b/vdisk.c index b1a9cbd..f5a475c 100644 --- a/vdisk.c +++ b/vdisk.c @@ -41,7 +41,8 @@ vdisk_adjust_cache_size(void *userdata, size_t suggested_size) { } struct vdisk* -vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) { +vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size, + int change_task) { size_t fname_len = strlen(fname); size_t dot_raw_len = strlen(RAW_SUFFIX); size_t dot_qcow2_len = strlen(QCOW2_SUFFIX); @@ -62,5 +63,6 @@ vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) { disk->diskfunc.adjust_cache_size = vdisk_adjust_cache_size; disk->adjust_cache_size = adjust_cache_size; disk->cache_size = cache_size; + disk->change_task = change_task; return disk; } diff --git a/vdisk.h b/vdisk.h index 7a7d146..93644b0 100644 --- a/vdisk.h +++ b/vdisk.h @@ -18,10 +18,12 @@ struct vdisk { uint32_t sect_size; uint64_t sect_cnt; unsigned cache_size; - int adjust_cache_size; + int adjust_cache_size; + int change_task; }; struct vdisk* -vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size); +vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size, + int change_task); #endif // VDISK_H_INCLUDED diff --git a/vdisk/raw.c b/vdisk/raw.c index a4985db..cb2c6a5 100644 --- a/vdisk/raw.c +++ b/vdisk/raw.c @@ -12,6 +12,7 @@ #include #include #include "../trace.h" +#include "io.h" #include "raw.h" struct vdisk_raw { @@ -34,7 +35,8 @@ vdisk_raw_read(void *userdata, void *buffer, off_t startsector, COVERAGE_OFF(); struct vdisk_raw *disk = userdata; lseek(disk->fd, startsector * disk->vdisk.sect_size, SEEK_SET); - read(disk->fd, buffer, *numsectors * disk->vdisk.sect_size); + io_read(disk->fd, buffer, *numsectors * disk->vdisk.sect_size, + disk->vdisk.change_task); COVERAGE_ON(); return ERROR_SUCCESS; } @@ -45,7 +47,8 @@ vdisk_raw_write(void *userdata, void *buffer, off_t startsector, COVERAGE_OFF(); struct vdisk_raw *disk = userdata; lseek(disk->fd, startsector * disk->vdisk.sect_size, SEEK_SET); - write(disk->fd, buffer, *numsectors * disk->vdisk.sect_size); + io_write(disk->fd, buffer, *numsectors * disk->vdisk.sect_size, + disk->vdisk.change_task); COVERAGE_ON(); return ERROR_SUCCESS; } diff --git a/windows/io.c b/windows/io.c new file mode 100644 index 0000000..4f4db58 --- /dev/null +++ b/windows/io.c @@ -0,0 +1,27 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + io - input/output platform specific code + + Copyright (C) 2023 Ivan Baravy +*/ + +#include +#include "io.h" + +ssize_t +io_read(int fd, void *buf, size_t count, int change_task) { + (void)change_task; + ssize_t res; + res = read(fd, buf, count); + return res; +} + +ssize_t +io_write(int fd, const void *buf, size_t count, int change_task) { + (void)change_task; + ssize_t res; + res = write(fd, buf, count); + return res; +} diff --git a/windows/io.h b/windows/io.h new file mode 100644 index 0000000..f773bd2 --- /dev/null +++ b/windows/io.h @@ -0,0 +1,21 @@ +/* + SPDX-License-Identifier: GPL-2.0-or-later + + UMKa - User-Mode KolibriOS developer tools + io - input/output platform specific code + + Copyright (C) 2023 Ivan Baravy +*/ + +#ifndef IO_H_INCLUDED +#define IO_H_INCLUDED + +#include + +ssize_t +io_read(int fd, void *buf, size_t count, int change_task); + +ssize_t +io_write(int fd, const void *buf, size_t count, int change_task); + +#endif // IO_H_INCLUDED