Allow per-vdisk cache adjusting settings.
Also, move vdisk_functions callback structure to vdisk.c.
This commit is contained in:
parent
728172f401
commit
cea3923666
@ -111,7 +111,7 @@ typedef struct {
|
|||||||
int (*read)(void *userdata, void *buffer, off_t startsector, size_t *numsectors) __attribute__((__stdcall__));
|
int (*read)(void *userdata, void *buffer, off_t startsector, size_t *numsectors) __attribute__((__stdcall__));
|
||||||
int (*write)(void *userdata, void *buffer, off_t startsector, size_t *numsectors) __attribute__((__stdcall__));
|
int (*write)(void *userdata, void *buffer, off_t startsector, size_t *numsectors) __attribute__((__stdcall__));
|
||||||
int (*flush)(void *userdata) __attribute__((__stdcall__));
|
int (*flush)(void *userdata) __attribute__((__stdcall__));
|
||||||
unsigned int (*adjust_cache_size)(void *userdata, uint32_t suggested_size) __attribute__((__stdcall__));
|
unsigned int (*adjust_cache_size)(void *userdata, size_t suggested_size) __attribute__((__stdcall__));
|
||||||
} diskfunc_t;
|
} diskfunc_t;
|
||||||
|
|
||||||
struct disk_t {
|
struct disk_t {
|
||||||
|
13
umka_fuse.c
13
umka_fuse.c
@ -123,24 +123,13 @@ static struct fuse_operations umka_oper = {
|
|||||||
.read = umka_read,
|
.read = umka_read,
|
||||||
};
|
};
|
||||||
|
|
||||||
diskfunc_t vdisk_functions = {
|
|
||||||
.strucsize = sizeof(diskfunc_t),
|
|
||||||
.close = vdisk_close,
|
|
||||||
.closemedia = NULL,
|
|
||||||
.querymedia = vdisk_querymedia,
|
|
||||||
.read = vdisk_read,
|
|
||||||
.write = vdisk_write,
|
|
||||||
.flush = NULL,
|
|
||||||
.adjust_cache_size = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
printf("usage: umka_fuse dir img\n");
|
printf("usage: umka_fuse dir img\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
kos_init();
|
kos_init();
|
||||||
void *userdata = vdisk_init(argv[2], 0u);
|
void *userdata = vdisk_init(argv[2], 1, 0u);
|
||||||
void *vdisk = disk_add(&vdisk_functions, "hd0", userdata, 0);
|
void *vdisk = disk_add(&vdisk_functions, "hd0", userdata, 0);
|
||||||
disk_media_changed(vdisk, 1);
|
disk_media_changed(vdisk, 1);
|
||||||
return fuse_main(argc-1, argv, &umka_oper, NULL);
|
return fuse_main(argc-1, argv, &umka_oper, NULL);
|
||||||
|
18
umka_shell.c
18
umka_shell.c
@ -50,17 +50,6 @@
|
|||||||
#define DEFAULT_READDIR_ENCODING UTF8
|
#define DEFAULT_READDIR_ENCODING UTF8
|
||||||
#define DEFAULT_PATH_ENCODING UTF8
|
#define DEFAULT_PATH_ENCODING UTF8
|
||||||
|
|
||||||
diskfunc_t vdisk_functions = {
|
|
||||||
.strucsize = sizeof(diskfunc_t),
|
|
||||||
.close = vdisk_close,
|
|
||||||
.closemedia = NULL,
|
|
||||||
.querymedia = vdisk_querymedia,
|
|
||||||
.read = vdisk_read,
|
|
||||||
.write = vdisk_write,
|
|
||||||
.flush = NULL,
|
|
||||||
.adjust_cache_size = NULL,
|
|
||||||
};
|
|
||||||
|
|
||||||
net_device_t vnet = {
|
net_device_t vnet = {
|
||||||
.device_type = NET_TYPE_ETH,
|
.device_type = NET_TYPE_ETH,
|
||||||
.mtu = 1514,
|
.mtu = 1514,
|
||||||
@ -275,7 +264,8 @@ void shell_disk_add(int argc, char **argv) {
|
|||||||
puts(usage);
|
puts(usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsigned cache_size = 0u;
|
size_t cache_size = 0;
|
||||||
|
int adjust_cache_size = 0;
|
||||||
int opt;
|
int opt;
|
||||||
optind = 1;
|
optind = 1;
|
||||||
const char *file_name = argv[optind++];
|
const char *file_name = argv[optind++];
|
||||||
@ -284,7 +274,7 @@ void shell_disk_add(int argc, char **argv) {
|
|||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
cache_size = strtoul(optarg, NULL, 0);
|
cache_size = strtoul(optarg, NULL, 0);
|
||||||
vdisk_functions.adjust_cache_size = vdisk_adjust_cache_size;
|
adjust_cache_size = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
puts(usage);
|
puts(usage);
|
||||||
@ -292,7 +282,7 @@ void shell_disk_add(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *userdata = vdisk_init(file_name, cache_size);
|
void *userdata = vdisk_init(file_name, adjust_cache_size, cache_size);
|
||||||
if (userdata) {
|
if (userdata) {
|
||||||
COVERAGE_ON();
|
COVERAGE_ON();
|
||||||
void *vdisk = disk_add(&vdisk_functions, disk_name, userdata, 0);
|
void *vdisk = disk_add(&vdisk_functions, disk_name, userdata, 0);
|
||||||
|
28
vdisk.c
28
vdisk.c
@ -5,15 +5,17 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "kolibri.h"
|
#include "kolibri.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
#include "vdisk.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
uint32_t sect_size;
|
uint32_t sect_size;
|
||||||
uint64_t sect_cnt;
|
uint64_t sect_cnt;
|
||||||
unsigned cache_size;
|
unsigned cache_size;
|
||||||
|
int adjust_cache_size;
|
||||||
} vdisk_t;
|
} vdisk_t;
|
||||||
|
|
||||||
void *vdisk_init(const char *fname, unsigned cache_size) {
|
void *vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) {
|
||||||
FILE *f = fopen(fname, "r+");
|
FILE *f = fopen(fname, "r+");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
printf("vdisk: can't open file '%s': %s\n", fname, strerror(errno));
|
printf("vdisk: can't open file '%s': %s\n", fname, strerror(errno));
|
||||||
@ -30,7 +32,8 @@ void *vdisk_init(const char *fname, unsigned cache_size) {
|
|||||||
*vdisk = (vdisk_t){.file = f,
|
*vdisk = (vdisk_t){.file = f,
|
||||||
.sect_size = sect_size,
|
.sect_size = sect_size,
|
||||||
.sect_cnt = (uint64_t)fsize / sect_size,
|
.sect_cnt = (uint64_t)fsize / sect_size,
|
||||||
.cache_size = cache_size};
|
.cache_size = cache_size,
|
||||||
|
.adjust_cache_size = adjust_cache_size};
|
||||||
return vdisk;
|
return vdisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +80,22 @@ int vdisk_querymedia(void *userdata, diskmediainfo_t *minfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__stdcall__))
|
__attribute__((__stdcall__))
|
||||||
unsigned vdisk_adjust_cache_size(vdisk_t *vdisk, unsigned suggested_size) {
|
size_t vdisk_adjust_cache_size(void *userdata, size_t suggested_size) {
|
||||||
(void)suggested_size;
|
vdisk_t *vdisk = userdata;
|
||||||
return vdisk->cache_size;
|
if (vdisk->adjust_cache_size) {
|
||||||
|
return vdisk->cache_size;
|
||||||
|
} else {
|
||||||
|
return suggested_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
diskfunc_t vdisk_functions = {
|
||||||
|
.strucsize = sizeof(diskfunc_t),
|
||||||
|
.close = vdisk_close,
|
||||||
|
.closemedia = NULL,
|
||||||
|
.querymedia = vdisk_querymedia,
|
||||||
|
.read = vdisk_read,
|
||||||
|
.write = vdisk_write,
|
||||||
|
.flush = NULL,
|
||||||
|
.adjust_cache_size = vdisk_adjust_cache_size,
|
||||||
|
};
|
||||||
|
4
vdisk.h
4
vdisk.h
@ -5,7 +5,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "kolibri.h"
|
#include "kolibri.h"
|
||||||
|
|
||||||
void *vdisk_init(const char *fname, unsigned cache_size);
|
void *vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size);
|
||||||
|
|
||||||
__attribute__((__stdcall__))
|
__attribute__((__stdcall__))
|
||||||
void vdisk_close(void *userdata);
|
void vdisk_close(void *userdata);
|
||||||
@ -24,4 +24,6 @@ int vdisk_querymedia(void *userdata, diskmediainfo_t *minfo);
|
|||||||
__attribute__((__stdcall__))
|
__attribute__((__stdcall__))
|
||||||
unsigned int vdisk_adjust_cache_size(void *userdata, unsigned suggested_size);
|
unsigned int vdisk_adjust_cache_size(void *userdata, unsigned suggested_size);
|
||||||
|
|
||||||
|
extern diskfunc_t vdisk_functions;
|
||||||
|
|
||||||
#endif // VDISK_H_INCLUDED
|
#endif // VDISK_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user