Create platform specific I/O module, prepare for io_uring
This commit is contained in:
parent
f1b6893e4d
commit
783545bdf8
27
linux/io.c
Normal file
27
linux/io.c
Normal file
@ -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 <dunkaist@gmail.com>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
21
linux/io.h
Normal file
21
linux/io.h
Normal file
@ -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 <dunkaist@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef IO_H_INCLUDED
|
||||
#define IO_H_INCLUDED
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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
|
11
makefile
11
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 $@
|
||||
|
||||
|
2
shell.c
2
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);
|
||||
|
@ -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);
|
||||
|
4
vdisk.c
4
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;
|
||||
}
|
||||
|
4
vdisk.h
4
vdisk.h
@ -19,9 +19,11 @@ struct vdisk {
|
||||
uint64_t sect_cnt;
|
||||
unsigned 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
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
||||
|
27
windows/io.c
Normal file
27
windows/io.c
Normal file
@ -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 <dunkaist@gmail.com>
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#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;
|
||||
}
|
21
windows/io.h
Normal file
21
windows/io.h
Normal file
@ -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 <dunkaist@gmail.com>
|
||||
*/
|
||||
|
||||
#ifndef IO_H_INCLUDED
|
||||
#define IO_H_INCLUDED
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user