2021-04-28 02:18:12 +02:00
|
|
|
#include "stddef.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2022-04-15 11:11:49 +02:00
|
|
|
#include <sys/ksys.h>
|
2021-04-28 02:18:12 +02:00
|
|
|
|
|
|
|
#define DEV_ADD_DISK 1
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
#define TMPDISK_SIZE 10 // Mb
|
2021-04-28 02:18:12 +02:00
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
2022-04-15 11:11:49 +02:00
|
|
|
struct {
|
|
|
|
unsigned disk_size;
|
|
|
|
unsigned char disk_id;
|
|
|
|
} tmpdisk_add;
|
2021-04-28 02:18:12 +02:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
char* tmpdisk_res_text[] = {
|
|
|
|
"TmpDisk operation completed successfully",
|
|
|
|
"Unknown IOCTL code, wrong input/output size...",
|
|
|
|
"DiskId must be from 0 to 9",
|
|
|
|
"DiskSize is too large",
|
|
|
|
"DiskSize is too small, might be too little free RAM",
|
|
|
|
"Memory allocation failed",
|
|
|
|
"Unknown error O_o",
|
|
|
|
0
|
|
|
|
};
|
2021-04-28 02:18:12 +02:00
|
|
|
|
2022-04-15 11:11:49 +02:00
|
|
|
int main()
|
|
|
|
{
|
2021-04-28 02:18:12 +02:00
|
|
|
ksys_drv_hand_t tmpdisk_drv = _ksys_load_driver("tmpdisk");
|
2022-04-15 11:11:49 +02:00
|
|
|
if (!tmpdisk_drv) {
|
2021-04-28 02:18:12 +02:00
|
|
|
puts("tmpdisk.sys driver not load!");
|
|
|
|
exit(0);
|
2022-04-15 11:11:49 +02:00
|
|
|
} else {
|
2021-04-28 02:18:12 +02:00
|
|
|
puts("tmpdisk.sys driver is load!");
|
|
|
|
}
|
2022-04-15 11:11:49 +02:00
|
|
|
|
|
|
|
tmpdisk_add.disk_size = TMPDISK_SIZE * 1024 * 1024 / 512;
|
2021-04-28 02:18:12 +02:00
|
|
|
tmpdisk_add.disk_id = 5;
|
2022-04-15 11:11:49 +02:00
|
|
|
|
2021-05-10 00:12:43 +02:00
|
|
|
ksys_ioctl_t ioctl;
|
2021-04-28 02:18:12 +02:00
|
|
|
ioctl.func_num = DEV_ADD_DISK;
|
|
|
|
ioctl.handler = tmpdisk_drv;
|
|
|
|
ioctl.in_data_ptr = &tmpdisk_add;
|
|
|
|
ioctl.in_data_size = sizeof(tmpdisk_add);
|
|
|
|
ioctl.out_data_ptr = NULL;
|
|
|
|
ioctl.out_data_size = 0;
|
|
|
|
|
|
|
|
printf("Create '/tmp%u/' disk a %u Mb size...\n", tmpdisk_add.disk_id, TMPDISK_SIZE);
|
2022-04-15 11:11:49 +02:00
|
|
|
unsigned status = _ksys_driver_control(&ioctl);
|
|
|
|
if (status < 7) {
|
2021-04-28 02:18:12 +02:00
|
|
|
puts(tmpdisk_res_text[status]);
|
2022-04-15 11:11:49 +02:00
|
|
|
} else {
|
2021-04-28 02:18:12 +02:00
|
|
|
puts(tmpdisk_res_text[6]);
|
|
|
|
}
|
|
|
|
exit(0);
|
2021-05-10 00:12:43 +02:00
|
|
|
}
|