Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include "..\lib\kolibri.h"
  2. #include "..\lib\strings.h"
  3. #include "..\lib\file_system.h"
  4.  
  5.  
  6. //îáëàñòü äàííûõ
  7. struct ioctl_struct
  8. {
  9.         dword   handle;
  10.         dword   io_code;
  11.         dword   input;
  12.         dword   inp_size;
  13.         dword   output;
  14.         dword   out_size;
  15. };
  16.  
  17. #define DEV_ADD_DISK 1  //input = structure add_disk_struc
  18. #define DEV_DEL_DISK 2  //input = structure del_disk_struc
  19.  
  20. struct add_disk_struc
  21. {
  22.         dword DiskSize; // in sectors, 1 sector = 512 bytes. Include FAT service data
  23.         unsigned char DiskId; // from 0 to 9
  24. };
  25.  
  26. struct del_disk_struc
  27. {
  28.         unsigned char DiskId; //from 0 to 9
  29. };
  30.  
  31.  
  32. ioctl_struct ioctl;
  33. add_disk_struc add_disk;
  34. del_disk_struc del_disk;
  35.  
  36.  
  37. void main()
  38. {  
  39.         int driver_handle;
  40.         int del_st, add_st, size_st;
  41.        
  42.         debug("===  tmpdisk 0.1  ===");
  43.         driver_handle = LoadDriver("tmpdisk");
  44.         if (driver_handle==0) {
  45.                 debug("tmpdisk: driver loading failed");
  46.                 ExitProcess();
  47.         }
  48.         else
  49.                 debug("tmpdisk: driver loaded successfully");
  50.        
  51.         if (!param)
  52.         {
  53.                 debug("tmpdisk error: no command line parameters");
  54.                 debug("a[number]s[size in MB] - add RAM disk");
  55.                 debug("d[number] - delete RAM disk");
  56.                 ExitProcess();
  57.         }
  58.         strlwr(#param);
  59.        
  60.         //óäàëèòü äèñê
  61.         del_st=strchr(#param, 'd');
  62.         if (del_st)
  63.         {
  64.                 del_disk.DiskId = atoi(#param+del_st);
  65.                 ioctl.handle   = driver_handle;
  66.                
  67.                 ioctl.io_code  = DEV_DEL_DISK;
  68.                 ioctl.input    = #del_disk;
  69.                 ioctl.inp_size = sizeof(del_disk);
  70.                 ioctl.output   = 0;
  71.                 ioctl.out_size = 0;
  72.         }
  73.        
  74.         //äîáàâèòü äèñê
  75.         add_st=strchr(#param, 'a');
  76.         if (add_st)
  77.         {
  78.                 size_st= strchr(#param, 's');
  79.                 if (!size_st)
  80.                 {
  81.                         debug("tmpdisk: disk size is not specified");
  82.                         debug("tmpdisk: DiskSize = 200 MB (by default)");
  83.                         add_disk.DiskSize = 200*2048;
  84.                 }
  85.                 else
  86.                         add_disk.DiskSize = atoi(#param+size_st)*2048;
  87.                
  88.                 //if (add_disk.DiskSize>GetFreeRam())
  89.                
  90.                 param[size_st-1]=NULL;
  91.                 add_disk.DiskId = atoi(#param+add_st);
  92.                
  93.                 ioctl.handle   = driver_handle;
  94.                 ioctl.io_code  = DEV_ADD_DISK;
  95.                 ioctl.input    = #add_disk;
  96.                 ioctl.inp_size = sizeof(add_disk);
  97.                 ioctl.output   = 0;
  98.                 ioctl.out_size = 0;
  99.         }
  100.        
  101.         if (!ioctl.io_code)
  102.         {
  103.                 debug("tmpdisk: unknown command line parameters");
  104.                 ExitProcess();
  105.         }
  106.        
  107.         RuleDriver(#ioctl);
  108.         switch(EAX)
  109.         {
  110.                 case 0:
  111.                         if (ioctl.io_code==DEV_ADD_DISK) debug("tmpdisk: disk added successfully");
  112.                         else debug("tmpdisk: disk deleted successfully");
  113.                         break;
  114.                 case 1:
  115.                         debug("tmpdisk: unknown IOCTL code, wrong input/output size...");
  116.                         break;
  117.                 case 2:
  118.                         debug("tmpdisk: DiskId must be from 0 to 9");
  119.                         break;
  120.                 case 3:
  121.                         debug("tmpdisk: DiskSize is too large");
  122.                         break;
  123.                 case 4:
  124.                         debug("tmpdisk: DiskSize is too small");
  125.                         break;
  126.                 case 5:
  127.                         debug("tmpdisk: memory allocation failed");
  128.                         break;
  129.                 default:
  130.                         debug("tmpdisk: unknown error O_o");
  131.         }
  132.         ExitProcess();
  133. }
  134.  
  135.  
  136. stop:
  137.