From 7659d0d8dfd6b4065b06a63fabb0e71b607e98e7 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Tue, 13 Nov 2012 15:39:00 +0000 Subject: [PATCH] tmpdisk 0.1 git-svn-id: svn://kolibrios.org@3035 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/tmpdisk/compile.bat | 6 ++ programs/system/tmpdisk/tmpdisk.c | 136 ++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 programs/system/tmpdisk/compile.bat create mode 100644 programs/system/tmpdisk/tmpdisk.c diff --git a/programs/system/tmpdisk/compile.bat b/programs/system/tmpdisk/compile.bat new file mode 100644 index 0000000000..b2dccf2546 --- /dev/null +++ b/programs/system/tmpdisk/compile.bat @@ -0,0 +1,6 @@ +..\C--\C-- tmpdisk.c rem /lst +del tmpdisk +rename tmpdisk.com tmpdisk +rem ..\C--\kpack tmpdisk +pause +del warning.txt diff --git a/programs/system/tmpdisk/tmpdisk.c b/programs/system/tmpdisk/tmpdisk.c new file mode 100644 index 0000000000..76b3a909fe --- /dev/null +++ b/programs/system/tmpdisk/tmpdisk.c @@ -0,0 +1,136 @@ +#include "..\lib\kolibri.h" +#include "..\lib\strings.h" +#include "..\lib\file_system.h" + + +//область данных +struct ioctl_struct +{ + dword handle; + dword io_code; + dword input; + dword inp_size; + dword output; + dword out_size; +}; + +#define DEV_ADD_DISK 1 //input = structure add_disk_struc +#define DEV_DEL_DISK 2 //input = structure del_disk_struc + +struct add_disk_struc +{ + dword DiskSize; // in sectors, 1 sector = 512 bytes. Include FAT service data + unsigned char DiskId; // from 0 to 9 +}; + +struct del_disk_struc +{ + unsigned char DiskId; //from 0 to 9 +}; + + +ioctl_struct ioctl; +add_disk_struc add_disk; +del_disk_struc del_disk; + + +void main() +{ + int driver_handle; + int del_st, add_st, size_st; + + debug("=== tmpdisk 0.1 ==="); + driver_handle = LoadDriver("tmpdisk"); + if (driver_handle==0) { + debug("tmpdisk: driver loading failed"); + ExitProcess(); + } + else + debug("tmpdisk: driver loaded successfully"); + + if (!param) + { + debug("tmpdisk error: no command line parameters"); + debug("a[number]s[size in MB] - add RAM disk"); + debug("d[number] - delete RAM disk"); + ExitProcess(); + } + strlwr(#param); + + //удалить диск + del_st=strchr(#param, 'd'); + if (del_st) + { + del_disk.DiskId = atoi(#param+del_st); + ioctl.handle = driver_handle; + + ioctl.io_code = DEV_DEL_DISK; + ioctl.input = #del_disk; + ioctl.inp_size = sizeof(del_disk); + ioctl.output = 0; + ioctl.out_size = 0; + } + + //добавить диск + add_st=strchr(#param, 'a'); + if (add_st) + { + size_st= strchr(#param, 's'); + if (!size_st) + { + debug("tmpdisk: disk size is not specified"); + debug("tmpdisk: DiskSize = 200 MB (by default)"); + add_disk.DiskSize = 200*2048; + } + else + add_disk.DiskSize = atoi(#param+size_st)*2048; + + //if (add_disk.DiskSize>GetFreeRam()) + + param[size_st-1]=NULL; + add_disk.DiskId = atoi(#param+add_st); + + ioctl.handle = driver_handle; + ioctl.io_code = DEV_ADD_DISK; + ioctl.input = #add_disk; + ioctl.inp_size = sizeof(add_disk); + ioctl.output = 0; + ioctl.out_size = 0; + } + + if (!ioctl.io_code) + { + debug("tmpdisk: unknown command line parameters"); + ExitProcess(); + } + + RuleDriver(#ioctl); + switch(EAX) + { + case 0: + if (ioctl.io_code==DEV_ADD_DISK) debug("tmpdisk: disk added successfully"); + else debug("tmpdisk: disk deleted successfully"); + break; + case 1: + debug("tmpdisk: unknown IOCTL code, wrong input/output size..."); + break; + case 2: + debug("tmpdisk: DiskId must be from 0 to 9"); + break; + case 3: + debug("tmpdisk: DiskSize is too large"); + break; + case 4: + debug("tmpdisk: DiskSize is too small"); + break; + case 5: + debug("tmpdisk: memory allocation failed"); + break; + default: + debug("tmpdisk: unknown error O_o"); + } + ExitProcess(); +} + + +stop: