kolibrios-fun/programs/cmm/tmpdisk/t_console.c
Kirill Lipatov (Leency) 324f214b01 Tmpdisk v0.6: show disks sizes, use much less memory
git-svn-id: svn://kolibrios.org@5482 a494cfbc-eb01-0410-851d-a64ba20cac60
2015-02-27 01:44:22 +00:00

96 lines
3.0 KiB
C

/////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// Console ////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
#ifdef LANG_RUS
?define ADD_DISK_TEXT "¯à®¡ãî ¤®¡ ¢¨âì ¢¨àâã «ì­ë© ¤¨áª"
?define DELETE_DISK_TEXT "¯à®¡ãî 㤠«¨âì ¢¨àâã «ì­ë© ¤¨áª"
?define DONT_KNOW_DISK_SIZE_TEXT "¥£® à §¬¥à ­¥ 㪠§ ­, 10% ᢮¡®¤­®© Ž‡“ ¡ã¤¥â ¨á¯®«ì§®¢ ­®"
?define NEW_DISK_TEXT "à §¬¥à ¤¨áª  ¡ã¤¥â: "
char *rezult_text[]={
"®¯¥à æ¨ï ãᯥ譮 § ¢¥à襭 ",
"­¥¨§¢¥áâ­ë© IOCTL, ­¥¢¥à­ë© à §¬¥à ¯à¥¤®áâ ¢«ï¥¬ëå ¤ ­­ëå...",
"­®¬¥à ¤¨áª  ¤®«¦¥­ ¡ëâì ®â 0 ¤® 9",
"à §¬¥à ᮧ¤ ¢ ¥¬®£® ¤¨áª  ᫨誮¬ ¢¥«¨ª",
"à §¬¥à ᮧ¤ ¢ ¥¬®£® ¤¨áª  ᫨誮¬ ¬ «",
"®è¨¡ª  ¢ë¤¥«¥­¨ï ¯ ¬ïâ¨",
"­¥¨§¢¥áâ­ ï ®è¨¡ª  O_o",
0};
#else
?define ADD_DISK_TEXT "trying to add disk"
?define DELETE_DISK_TEXT "trying to delete virtual disk"
?define DONT_KNOW_DISK_SIZE_TEXT "its size is not specified, 10% from free RAM will be used"
?define NEW_DISK_TEXT "new DiskSize: "
char *rezult_text[]={
"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};
#endif
char Console_Work()
{
unsigned int disk_size, driver_rezult;
char size_t[256];
strlwr(#param);
switch (param[0])
{
case '?': //ïîìîùü ïî êîììàíäàì
case 'h':
debugln("tmpdisk command line parameters:");
debugln("a[number]s[size in MB] - add RAM disk");
debugln("d[number] - delete RAM disk");
ExitProcess();
break;
case 'd': //óäàëèòü äèñê
debugln(DELETE_DISK_TEXT);
del_disk.DiskId = param[1]-'0';
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;
disk_sizes[del_disk.DiskId] = 0;
break;
case 'a': //äîáàâèòü äèñê
debugln(ADD_DISK_TEXT);
disk_size= strchr(#param, 's');
if (!disk_size)
{
add_disk.DiskSize = GetFreeRAM() / 5;
debugln(DONT_KNOW_DISK_SIZE_TEXT);
}
else
add_disk.DiskSize = atoi(#param+disk_size)*2048;
strcpy(#size_t, NEW_DISK_TEXT);
strcat(#size_t, itoa(add_disk.DiskSize/2048));
strcat(#size_t, " MB");
debugln(#size_t);
add_disk.DiskId = param[1]-'0';
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;
disk_sizes[add_disk.DiskId] = add_disk.DiskSize * 512;
break;
default:
debugln("unknown command line parameters");
debugln("use 'h' or '?' for help");
ExitProcess();
}
driver_rezult = RuleDriver(#ioctl);
if (driver_rezult<7) debugln(rezult_text[driver_rezult]);
return driver_rezult;
}