Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.         2015
  3.         Author: Pavel Yakovlev.
  4. */
  5.  
  6. #define LIB_NAME "fs"
  7.  
  8. #include "coff.h"
  9. #include <kolibri.c>
  10. #include <stdlib.c>
  11.  
  12.  
  13. //char _PATH_[4096];
  14. char *_PATH_;
  15. dword *_ADR_ = 32;
  16. char *FS_SELF_PATH;
  17. char *FS_SELF_DIR=0;
  18.  
  19. char TMP1[4096] = {0};
  20. char TMP2[4096] = {0};
  21.  
  22. static void*(* _stdcall pointer_callback_copy)(void);
  23. static void*(* _stdcall pointer_callback_move)(void);
  24. static void*(* _stdcall pointer_callback_remove)(void);
  25.  
  26. #pragma pack(push,1)
  27. typedef struct
  28. {
  29. unsigned        p00;
  30. unsigned        p04;
  31. unsigned        p08;
  32. unsigned        p12;
  33. unsigned        p16;
  34. char            p20;
  35. char            *p21;
  36. } FS_struct70;
  37. #pragma pack(pop)
  38.  
  39. #pragma pack(push,1)
  40. typedef struct
  41. {
  42. unsigned        p00;
  43. char            p04;
  44. char            p05[3];
  45. unsigned        p08;
  46. unsigned        p12;
  47. unsigned        p16;
  48. unsigned        p20;
  49. unsigned        p24;
  50. unsigned        p28;
  51. //unsigned      p32[2];
  52. long long p32;
  53. unsigned        p40;
  54. } FS_struct_BDVK;
  55. #pragma pack(pop)
  56.  
  57. #define FS_COPY_BUFFER_SET 0x100000
  58. static inline char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
  59.  
  60. static inline char *string_error_code(char code)
  61. {
  62.         if(!code)return "Successfully!";
  63.         if(code==1)return "Not defined basis and / or hard disk partition (sub-functions 7, 8 function 21)!";
  64.         if(code==2)return "Function is not supported for this file system!";
  65.         if(code==3)return "Unknown file system!";
  66.         if(code==4)return "Reserved, never returned to the current implementation!";
  67.         if(code==5)return "File not found!";
  68.         if(code==6)return "The file is ended!";
  69.         if(code==7)return "Pointer out the application memory!";
  70.         if(code==8)return "Disk is full!";
  71.         if(code==9)return "FAT table is destroyed!";
  72.         if(code==10)return "Access is denied!";
  73.         if(code==11)return "Device error!";
  74.         return "An unexpected error!";
  75. }
  76.  
  77. static inline dword sprintf(char *mstr,const char *fmt,...)
  78. {
  79.        
  80.         dword *arg = &fmt;
  81.         char *tmp = 0;
  82.         char *pos = mstr;
  83.         --pos;
  84.         --fmt;
  85.         while(*++fmt)
  86.         {
  87.                 char s = *fmt;
  88.                 if(s=='%')
  89.                 {
  90.                         s = *++fmt;
  91.                         if(s=='s')
  92.                         {
  93.                                 tmp = *++arg;
  94.                                 while(*tmp)*++pos = *tmp++;
  95.                         }
  96.                         else
  97.                         {
  98.                                 *++pos='%';
  99.                                 --fmt;
  100.                         }
  101.                 }
  102.                 else *++pos=s;
  103.         }
  104.         *++pos = 0;
  105.         return pos-mstr;
  106. }
  107.  
  108. static inline int FS_file_70(FS_struct70 *k)
  109. {
  110.         asm volatile ("int $0x40"::"a"(70), "b"(k));
  111. }
  112.  
  113. FS_struct_BDVK ret_struct;
  114. static inline char get_bdvk(char *path)
  115. {
  116.         FS_struct70 file_read_struct;
  117.         file_read_struct.p00 = 5;
  118.         file_read_struct.p04 = 0;
  119.         file_read_struct.p08 = 0;
  120.         file_read_struct.p12 = 0;
  121.         file_read_struct.p16 = (unsigned)&ret_struct;
  122.         file_read_struct.p20 = 0;
  123.         file_read_struct.p21 = path;
  124.         return FS_file_70(&file_read_struct);
  125.         //return (FS_struct_BDVK*)&ret_struct;
  126. }
  127.  
  128. static inline char set_bdvk(char *path,FS_struct_BDVK *bdvk)
  129. {
  130.         FS_struct70 file_read_struct;
  131.         file_read_struct.p00 = 6;
  132.         file_read_struct.p04 = 0;
  133.         file_read_struct.p08 = 0;
  134.         file_read_struct.p12 = 0;
  135.         file_read_struct.p16 = bdvk;
  136.         file_read_struct.p20 = 0;
  137.         file_read_struct.p21 = path;
  138.         return FS_file_70(&file_read_struct);
  139. }
  140.  
  141. static inline long long file_size(char *path)
  142. {
  143.         FS_struct_BDVK *data =  get_bdvk(path);
  144.         return data->p32;
  145. }
  146.  
  147. static inline byte file_isdir(char *path)
  148. {
  149.         FS_struct_BDVK *data =  get_bdvk(path);
  150.         if(data->p00&0b10000)return 1;
  151.         return 0;
  152. }
  153.  
  154. static inline byte file_ismetka(char *path)
  155. {
  156.         FS_struct_BDVK *data =  get_bdvk(path);
  157.         if(data->p00&0b1000)return 1;
  158.         return 0;
  159. }
  160.  
  161. static inline byte file_isfile()
  162. {
  163.         //FS_struct_BDVK *data =  get_bdvk(path);
  164.         if(ret_struct.p00&0b11000)return 0;
  165.         return 1;
  166. }
  167.  
  168. static inline int file_run(char *path,char *arg)
  169. {
  170.         FS_struct70 file_read_struct;
  171.         file_read_struct.p00 = 7;
  172.         file_read_struct.p04 = 0;
  173.         file_read_struct.p08 = arg;
  174.         file_read_struct.p12 = 0;
  175.         file_read_struct.p16 = 0;
  176.         file_read_struct.p20 = 0;
  177.         file_read_struct.p21 = path;
  178.         return FS_file_70(&file_read_struct);
  179.        
  180. }
  181.  
  182. static inline int file_read_binary(char *path,unsigned pos,unsigned size,void *adr)
  183. {
  184.         FS_struct70 file_read_struct;
  185.         file_read_struct.p00 = 0;
  186.         file_read_struct.p04 = pos;
  187.         file_read_struct.p08 = 0;
  188.         file_read_struct.p12 = size;
  189.         file_read_struct.p16 = (unsigned)adr;
  190.         file_read_struct.p20 = 0;
  191.         file_read_struct.p21 = path;
  192.         char c = FS_file_70(&file_read_struct);
  193.         if(c)
  194.         {
  195.                 sprintf(&BUF_COPY,"'Error read file (%s) file: %s.'E",string_error_code(c),path);
  196.                 file_run("/sys/@notify",&BUF_COPY);
  197.         }
  198.         return c;
  199. }
  200.  
  201. static inline int file_delete(char *path)
  202. {
  203.         FS_struct70 file_read_struct;
  204.         file_read_struct.p00 = 8;
  205.         file_read_struct.p04 = 0;
  206.         file_read_struct.p08 = 0;
  207.         file_read_struct.p12 = 0;
  208.         file_read_struct.p16 = 0;
  209.         file_read_struct.p20 = 0;
  210.         file_read_struct.p21 = path;
  211.         char c = FS_file_70(&file_read_struct);
  212.         if(c)
  213.         {
  214.                 sprintf(&BUF_COPY,"'Error delete file: %s. Info: %s'E",string_error_code(c),path);
  215.                 file_run("/sys/@notify",&BUF_COPY);
  216.         }
  217.         return c;
  218. }
  219.  
  220. static inline int file_mkdir(char *path)
  221. {
  222.         FS_struct70 file_read_struct;
  223.         file_read_struct.p00 = 9;
  224.         file_read_struct.p04 = 0;
  225.         file_read_struct.p08 = 0;
  226.         file_read_struct.p12 = 0;
  227.         file_read_struct.p16 = 0;
  228.         file_read_struct.p20 = 0;
  229.         file_read_struct.p21 = path;
  230.         char c = FS_file_70(&file_read_struct);
  231.         if(c)
  232.         {
  233.                 sprintf(&BUF_COPY,"'Error make dir: %s. Info: %s.'E",string_error_code(c),path);
  234.                 file_run("/sys/@notify",&BUF_COPY);
  235.         }
  236.         return c;
  237. }
  238.  
  239. static inline int file_write(char *path,void *ukaz,dword size)
  240. {
  241.         FS_struct70 file_read_struct;
  242.         file_read_struct.p00 = 2;
  243.         file_read_struct.p04 = 0;
  244.         file_read_struct.p08 = 0;
  245.         file_read_struct.p12 = size;
  246.         file_read_struct.p16 = ukaz;
  247.         file_read_struct.p20 = 0;
  248.         file_read_struct.p21 = path;
  249.         char c = FS_file_70(&file_read_struct);
  250.         if(c)
  251.         {
  252.                 sprintf(&BUF_COPY,"'Error write file: %s. Info: %s.'E",string_error_code(c),path);
  253.                 file_run("/sys/@notify",&BUF_COPY);
  254.         }
  255.         return c;
  256. }
  257.  
  258. static inline int file_rewrite(char *path,dword pos1,dword pos2,void *ukaz,dword size)
  259. {
  260.         FS_struct70 file_read_struct;
  261.         file_read_struct.p00 = 3;
  262.         file_read_struct.p04 = pos1;
  263.         file_read_struct.p08 = pos2;
  264.         file_read_struct.p12 = size;
  265.         file_read_struct.p16 = ukaz;
  266.         file_read_struct.p20 = 0;
  267.         file_read_struct.p21 = path;
  268.         char c = FS_file_70(&file_read_struct);
  269.         if(c)
  270.         {
  271.                 sprintf(&BUF_COPY,"'Error rewrite file (%s) file: %s.'E",string_error_code(c),path);
  272.                 file_run("/sys/@notify",&BUF_COPY);
  273.         }
  274.         return c;
  275. }
  276.  
  277.  
  278. static inline char file_copy(char *path1,char *path2)
  279. {
  280.         long long size = file_size(path1);
  281.         if(!size)file_write(path2,&BUF_COPY,0);
  282.         long long cel = size;
  283.         cel /= FS_COPY_BUFFER_SET;
  284.         dword ost = size-cel*FS_COPY_BUFFER_SET;
  285.         long long i = 0;
  286.         char err=0;
  287.         if(cel)
  288.         {
  289.                 if(file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
  290.                 if(file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
  291.                 ++i;
  292.         }
  293.         else
  294.         {
  295.                 if(file_read_binary(path1,0,ost,&BUF_COPY))goto ERROR;
  296.                 if(file_write(path2,&BUF_COPY,ost))goto ERROR;
  297.                 return 1;
  298.         }
  299.         while(i<cel)
  300.         {
  301.                 if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY))goto ERROR;
  302.                 if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET))goto ERROR;
  303.                 ++i;
  304.         }
  305.         if(file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY))goto ERROR;
  306.         if(file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost))goto ERROR;
  307.         return 1;
  308.         ERROR:
  309.        
  310.         //asm("":"=a"(err));
  311.         //sprintf(&BUF_COPY,"Error %s file: %s.",string_error_code(err),path1);
  312.         //file_run("/sys/@notify",&BUF_COPY);
  313.         return 0;
  314. }
  315.  
  316. /*
  317. dword FS_COPY_BUFFER_SET_POINT = 0x100000;
  318. dword BUF_COPY_POINT = 0;
  319. static inline char file_copy(char *path1,char *path2)
  320. {
  321.         long long size = file_size(path1);
  322.         if(!size)file_write(path2,BUF_COPY_POINT,0);
  323.         long long cel = size;
  324.         cel /= FS_COPY_BUFFER_SET_POINT;
  325.         dword ost = size-cel*FS_COPY_BUFFER_SET_POINT;
  326.         long long i = 0;
  327.         char err=0;
  328.         if(cel)
  329.         {
  330.                 if(file_read_binary(path1,0,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
  331.                 if(file_write(path2,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
  332.                 ++i;
  333.         }
  334.         else
  335.         {
  336.                 if(file_read_binary(path1,0,ost,BUF_COPY_POINT))goto ERROR;
  337.                 if(file_write(path2,BUF_COPY_POINT,ost))goto ERROR;
  338.                 return 1;
  339.         }
  340.         while(i<cel)
  341.         {
  342.                 if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,FS_COPY_BUFFER_SET_POINT,BUF_COPY_POINT))goto ERROR;
  343.                 if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,FS_COPY_BUFFER_SET_POINT))goto ERROR;
  344.                 ++i;
  345.         }
  346.         if(file_read_binary(path1,FS_COPY_BUFFER_SET_POINT*i,ost,BUF_COPY_POINT))goto ERROR;
  347.         if(file_rewrite(path2,FS_COPY_BUFFER_SET_POINT*i,0,BUF_COPY_POINT,ost))goto ERROR;
  348.         return 1;
  349.         ERROR:
  350.        
  351.         //asm("":"=a"(err));
  352.         //sprintf(BUF_COPY_POINT,"Error %s file: %s.",string_error_code(err),path1);
  353.         //file_run("/sys/@notify",BUF_COPY_POINT);
  354.         return 0;
  355. }
  356. */
  357. /*
  358. #define FS_COPY_BUFFER_SET 0x100000
  359. char BUF_COPY[FS_COPY_BUFFER_SET] = {0};
  360. static inline char file_copy(char *path1,char *path2)
  361. {
  362.         long long size = file_size(path1);
  363.         if(!size)file_write(path2,&BUF_COPY,0);
  364.         long long cel = size;
  365.         cel /= FS_COPY_BUFFER_SET;
  366.         dword ost = size-cel*FS_COPY_BUFFER_SET;
  367.         long long i = 0;
  368.        
  369.         if(cel)
  370.         {
  371.                 file_read_binary(path1,0,FS_COPY_BUFFER_SET,&BUF_COPY);
  372.                 file_write(path2,&BUF_COPY,FS_COPY_BUFFER_SET);
  373.                 ++i;
  374.         }
  375.         else
  376.         {
  377.                 file_read_binary(path1,0,ost,&BUF_COPY);
  378.                 file_write(path2,&BUF_COPY,ost);
  379.                 return 1;
  380.         }
  381.         while(i<cel)
  382.         {
  383.                 file_read_binary(path1,FS_COPY_BUFFER_SET*i,FS_COPY_BUFFER_SET,&BUF_COPY);
  384.                 file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,FS_COPY_BUFFER_SET);
  385.                 ++i;
  386.         }
  387.         file_read_binary(path1,FS_COPY_BUFFER_SET*i,ost,&BUF_COPY);
  388.         file_rewrite(path2,FS_COPY_BUFFER_SET*i,0,&BUF_COPY,ost);
  389.         return 1;
  390. }
  391. */
  392. long long size_long_file=0;
  393.  
  394. static inline void *file_read(char *path)
  395. {
  396.         size_long_file = file_size(path);
  397.         void *data = malloc(size_long_file+1);
  398.        
  399.         if(file_read_binary(path,0,size_long_file,data))return 0;
  400.        
  401.         return data;
  402. }
  403.  
  404. static inline void *file_readKPACK(char *path)
  405. {
  406.         void *data = 0;
  407.         dword size=0;
  408.         asm ("int $0x40":"=a"(data),"=d"(size):"a"(68), "b"(27), "c"(path));
  409.         size_long_file = size;
  410.         asm volatile(""::"c"(size));
  411.         return data;
  412. }
  413.  
  414. static inline int file_read_dir(dword begin,dword file_count,dword read_buffer,char *dir_path)
  415. {
  416.         FS_struct70 file_read_struct;
  417.         file_read_struct.p00 = 1;
  418.         file_read_struct.p04 = begin;
  419.         file_read_struct.p08 = 0;
  420.         file_read_struct.p12 = file_count;
  421.         file_read_struct.p16 = read_buffer;
  422.         file_read_struct.p20 = 0;
  423.         file_read_struct.p21 = dir_path;
  424.         return FS_file_70(&file_read_struct);
  425. }
  426.  
  427.  
  428. static inline byte strncmp(char *s1,const char *s2, dword n)
  429. {
  430.         while(n)
  431.         {
  432.                 if(*s1!=*s2)return *s1-*s2;
  433.                 ++s1;
  434.                 ++s2;
  435.                 --n;
  436.         }
  437.         return 0;
  438. }
  439.  
  440. char *strdup(char *str)
  441. {
  442.         char *r = malloc(strlen(str));
  443.         strcpy(r,str);
  444.         return r;
  445. }
  446.  
  447. char *self_get_dir(void)
  448. {
  449.         if(!FS_SELF_DIR)
  450.         {
  451.                 FS_SELF_DIR = malloc(4096);
  452.                 //FS_SELF_PATH = malloc(4096);
  453.                 //strcpy(FS_SELF_PATH,*_ADR_);
  454.                 FS_SELF_PATH = *_ADR_;
  455.                 int pos=0;
  456.                 int tmp=0;
  457.  
  458.                 while(FS_SELF_PATH[pos])
  459.                 {
  460.                         FS_SELF_DIR[pos] = FS_SELF_PATH[pos];
  461.                         if(FS_SELF_PATH[pos]=='/')tmp = pos;
  462.                         ++pos;
  463.                 }
  464.                 if(tmp)pos=tmp;
  465.                 FS_SELF_DIR[pos]=0;
  466.         }
  467.         return FS_SELF_DIR;
  468. }
  469.  
  470.  
  471. char *get_full_path(char *path)
  472. {
  473.         self_get_dir();
  474.         if(!path) return FS_SELF_DIR;
  475.         char *pos = path;
  476.         if(!_PATH_) _PATH_ = malloc(4096);
  477.         if(*pos=='/')
  478.         {
  479.                 ++pos;
  480.                 if(!strncmp(pos,"sys/",4)) return path;
  481.                 if(!strncmp(pos,"kolibrios/",10)) return path;
  482.                 if(!strncmp(pos,"rd/",3)) return path;
  483.                 if(!strncmp(pos,"fd/",3)) return path;
  484.                 if(!strncmp(pos,"cd",2)) return path;
  485.                 if(!strncmp(pos,"hd",2)) return path;
  486.                 if(!strncmp(pos,"bd",2)) return path;
  487.                 if(!strncmp(pos,"tmp",3)) return path;
  488.                 if(!strncmp(pos,"usbhd",5)) return path;
  489.                 if(!*pos)return path;
  490.                 strcpy(_PATH_,"/sys");
  491.                 strcpy(_PATH_+4,path);
  492.                 return _PATH_;
  493.         }
  494.         if(!strncmp(path,"./",2)) return path;
  495.         sprintf(_PATH_,"%s/%s",FS_SELF_DIR,path);
  496.         return _PATH_;
  497. }
  498.  
  499. long long FS_LENGHT=0;
  500.  
  501. dword *__BUF__COUNT__ = 0;
  502. int COUNT_FILE = 0;
  503. int _get_entries_count(char *path)
  504. {
  505.         //char BUF[32];
  506.         if(!__BUF__COUNT__)__BUF__COUNT__=malloc(32);
  507.         if(!file_read_dir(0,0, __BUF__COUNT__, path))
  508.         {
  509.                 if(strcmp(path,"/"))COUNT_FILE = *(__BUF__COUNT__+2)-2;
  510.                 else COUNT_FILE = *(__BUF__COUNT__+2);
  511.                 return COUNT_FILE;
  512.         }
  513.         COUNT_FILE = -1;
  514.         return -1;
  515. }
  516.  
  517. int get_entries_count(char *path)
  518. {
  519.         return _get_entries_count(get_full_path(path));
  520. }
  521.  
  522. dword _get_dir_info(char *path)
  523. {
  524.         _get_entries_count(path);
  525.         if(!strcmp(path,"/"))
  526.         {
  527.                 if(COUNT_FILE==-1)return 0;
  528.                 dword buffer = malloc(304*COUNT_FILE+72);
  529.                 file_read_dir(0,COUNT_FILE,buffer,path);
  530.                 return buffer;
  531.         }
  532.         if(COUNT_FILE==-1)return 0;
  533.         dword buffer = malloc(304*COUNT_FILE+72);
  534.         file_read_dir(2,COUNT_FILE+2,buffer,path);
  535.         return buffer;
  536. }
  537.  
  538. dword get_dir_info(char *path)
  539. {
  540.         return _get_dir_info(get_full_path(path));
  541. }
  542.  
  543. dword get_dir_position(dword a,dword i)
  544. {
  545.         return i*344+32+a;
  546. }
  547.  
  548. char *get_file_name(void *args)
  549. {
  550.         return args+40;
  551. }
  552.  
  553. char BUF_HEADER[5]={0};
  554. dword read(char *path)
  555. {
  556.         dword *adr = &BUF_HEADER;
  557.         path = get_full_path(path);
  558.         file_read_binary(path,0,4,adr);
  559.         if(*adr=='KCPK') return file_readKPACK(path);
  560.         dword ret = file_read(path);
  561.         //FS_LENGHT = size_long_file;
  562.         asm volatile(""::"c"((long)size_long_file));
  563.         return ret;
  564. }
  565.  
  566.  
  567. dword quantity_dir = 0,quantity_file = 0;
  568. long long fs_size_global = 0;
  569. long long LOOP_SIZE(char *path)
  570. {
  571.         dword tmp_len = file_size(path);
  572.         if(ret_struct.p00&0b10000)
  573.         {
  574.                 ++quantity_dir;
  575.                 dword tmp_buf = get_dir_info(path);
  576.                 if(COUNT_FILE<1) return 0;
  577.                
  578.                 char *new_path_file = malloc(4096);
  579.                 int tmp_count = COUNT_FILE;
  580.                 int i = 0;
  581.                 fs_size_global = 0;
  582.                 while(i<tmp_count)
  583.                 {
  584.                         sprintf(new_path_file,"%s/%s",path,304*i+tmp_buf+72);
  585.                         fs_size_global += LOOP_SIZE(new_path_file);
  586.                         ++i;
  587.                 }
  588.                 free(tmp_buf);
  589.                 free(new_path_file);
  590.                 return fs_size_global;
  591.         }
  592.         ++quantity_file;
  593.         return tmp_len;
  594. }
  595.  
  596. dword get_size(char *path)
  597. {
  598.         quantity_dir = 0;
  599.         quantity_file = 0;
  600.         long long size = LOOP_SIZE(get_full_path(path));
  601.         if(quantity_dir>0)--quantity_dir;
  602.         asm volatile(""::"c"(quantity_dir),"d"(quantity_file));
  603.         return (dword)size;
  604. }
  605.  
  606. /*
  607. char set_attributes_loop(char *path,dword strucs)
  608. {
  609.         if(get_bdvk(path))return 0;
  610.         dword tmp = (ret_struct.p00^strucs)&0b111;
  611.         ret_struct.p00=(tmp^ret_struct.p00)^0xFFFFFFFF;
  612.         if(ret_struct.p00&0b10000)
  613.         {
  614.                 dword tmp_buf = _get_dir_info(path);
  615.                 if(!COUNT_FILE) goto END;
  616.                
  617.                 char *new_path_file = malloc(4096);
  618.                 int tmp_count = COUNT_FILE;
  619.                 int i = 0;
  620.                 char *position = tmp_buf+72;
  621.                 while(i<tmp_count)
  622.                 {      
  623.                         sprintf(new_path_file,"%s/%s",path,position);
  624.                         position+=304;
  625.                         if(!set_attributes_loop(new_path_file,strucs))
  626.                         {
  627.                                 free(tmp_buf);
  628.                                 free(new_path_file);
  629.                                 return 0;
  630.                         }
  631.                         ++i;
  632.                 }
  633.                 free(new_path_file);
  634.                 END:
  635.                 free(tmp_buf);
  636.         }
  637.         if(set_bdvk(path,&ret_struct))return 0;
  638.         return 1;
  639. }
  640.  
  641. char set_attributes(char *path,dword strucs,char cmd)
  642. {
  643.         if(cmd)return set_attributes_loop(get_full_path(path),strucs);
  644.        
  645. }
  646. */
  647.  
  648. char remove_loop(char *path)
  649. {
  650.         if(get_bdvk(path))return 0;
  651.         if(ret_struct.p00&0b10000)
  652.         {
  653.                 dword tmp_buf = _get_dir_info(path);
  654.                 if(!COUNT_FILE) goto END;
  655.                
  656.                 char *new_path_file = malloc(4096);
  657.                 int tmp_count = COUNT_FILE;
  658.                 int i = 0;
  659.                 char *position = tmp_buf+72;
  660.                 while(i<tmp_count)
  661.                 {      
  662.                         sprintf(new_path_file,"%s/%s",path,position);
  663.                         position+=304;
  664.                         if(!remove_loop(new_path_file))
  665.                         {
  666.                                 free(tmp_buf);
  667.                                 free(new_path_file);
  668.                                 return 0;
  669.                         }
  670.                         ++i;
  671.                 }
  672.                 free(new_path_file);
  673.                 END:
  674.                 free(tmp_buf);
  675.         }
  676.         if(file_delete(path))return 0;
  677.         return 1;
  678. }
  679.  
  680. char remove(char *path)
  681. {
  682.         return remove_loop(get_full_path(path));
  683. }
  684.  
  685. int make_dir(char *path)
  686. {
  687.         return file_mkdir(get_full_path(path));
  688. }
  689.  
  690. char copy_loop(char *path1,char *path2)
  691. {
  692.         if(get_bdvk(path1))return 0;
  693.         if(ret_struct.p00&0b10000)
  694.         {
  695.                 file_mkdir(path2);
  696.                 set_bdvk(path2,&ret_struct);
  697.                 dword tmp_buf = _get_dir_info(path1);
  698.                 if(!COUNT_FILE) goto END;
  699.                
  700.                 char *new_path_file1 = malloc(4096);
  701.                 char *new_path_file2 = malloc(4096);
  702.                 int tmp_count = COUNT_FILE;
  703.                 int i = 0;
  704.                 dword position = tmp_buf+72;
  705.                 while(i<tmp_count)
  706.                 {
  707.                         sprintf(new_path_file1,"%s/%s",path1,position);
  708.                         sprintf(new_path_file2,"%s/%s",path2,position);
  709.                         if(pointer_callback_copy)
  710.                         {
  711.                                 asm volatile(""::"c"(new_path_file1),"d"(new_path_file2));
  712.                                 pointer_callback_copy();
  713.                         }
  714.                         position+=304;
  715.                         if(!copy_loop(new_path_file1,new_path_file2))
  716.                         {
  717.                                 free(tmp_buf);
  718.                                 free(new_path_file1);
  719.                                 free(new_path_file2);
  720.                                 return 0;
  721.                         }
  722.                         ++i;
  723.                 }
  724.                 free(new_path_file1);
  725.                 free(new_path_file2);
  726.                 END:
  727.                 free(tmp_buf);
  728.                 return 1;
  729.         }
  730.         char r = file_copy(path1,path2);
  731.         set_bdvk(path2,&ret_struct);
  732.         return r;
  733. }
  734.  
  735. char copy(char *path1,char *path2)
  736. {
  737.         char *tmp = get_full_path(path1);
  738.         path1 = malloc(4096);
  739.         strcpy(path1,tmp);
  740.        
  741.         char *r=copy_loop(path1,get_full_path(path2));
  742.        
  743.         free(path1);
  744.         return r;
  745. }
  746.  
  747. char move_loop(char *path1,char *path2)
  748. {
  749.         if(get_bdvk(path1))return 0;
  750.         if(ret_struct.p00&0b10000)
  751.         {
  752.                 file_mkdir(path2);
  753.                 set_bdvk(path2,&ret_struct);
  754.                 dword tmp_buf = _get_dir_info(path1);
  755.                 if(!COUNT_FILE) goto END;
  756.                
  757.                 char *new_path_file1 = malloc(4096);
  758.                 char *new_path_file2 = malloc(4096);
  759.                 int tmp_count = COUNT_FILE;
  760.                 int i = 0;
  761.                 dword position = tmp_buf+72;
  762.                 while(i<tmp_count)
  763.                 {
  764.                         sprintf(new_path_file1,"%s/%s",path1,position);
  765.                         sprintf(new_path_file2,"%s/%s",path2,position);
  766.                         if(pointer_callback_move)
  767.                         {
  768.                                 asm volatile(""::"c"(new_path_file1),"d"(new_path_file2));
  769.                                 pointer_callback_copy();
  770.                         }
  771.                         position+=304;
  772.                         if(!move_loop(new_path_file1,new_path_file2))
  773.                         {
  774.                                 free(tmp_buf);
  775.                                 free(new_path_file1);
  776.                                 free(new_path_file2);
  777.                                 return 0;
  778.                         }
  779.                         ++i;
  780.                 }
  781.                 free(new_path_file1);
  782.                 free(new_path_file2);
  783.                 END:
  784.                 free(tmp_buf);
  785.                 if(file_delete(path1)) return 0;
  786.                 return 1;
  787.         }
  788.         char r = 0;
  789.         if(file_copy(path1,path2)) if(!file_delete(path1))r=1;
  790.         if(r)set_bdvk(path2,&ret_struct);
  791.         return r;
  792. }
  793.  
  794.  
  795. char move(char *path1,char *path2)
  796. {
  797.         char *tmp = get_full_path(path1);
  798.         path1 = malloc(4096);
  799.         strcpy(path1,tmp);
  800.        
  801.         char *r=move_loop(path1,get_full_path(path2));
  802.        
  803.         free(path1);
  804.         return r;
  805. }
  806.  
  807. char write(char *path,void *data,dword size)
  808. {
  809.         if(file_write(get_full_path(path),data,size))return 0;
  810.         return 1;
  811. }
  812.  
  813. dword execute(char *path,char *arg)
  814. {
  815.         return file_run(get_full_path(path),arg);
  816. }
  817.  
  818. dword open(char *path)
  819. {
  820.         return file_run("/sys/@open",get_full_path(path));
  821. }
  822.  
  823. char rename(char *path,char *new_name)
  824. {
  825.         if(!strcmp(path,new_name))return 0;
  826.         char *pos = path;
  827.         char *pos1 = &TMP1;
  828.         char *tmp = 0;
  829.         while(*pos)
  830.         {
  831.                 *pos1=*pos;
  832.                 if(*pos=='/')
  833.                 {
  834.                         if(*++pos)tmp = pos1;
  835.                 }
  836.                 else ++pos;
  837.                 ++pos1;
  838.         }
  839.         if(tmp)
  840.         {
  841.                 while(*new_name)*++tmp = *new_name++;
  842.                 *++tmp = 0;
  843.                 return move(path,&TMP1);
  844.         }
  845.         return move(path,new_name);
  846. }
  847.  
  848. char callback_copy(char *path1,char *path2,dword func)
  849. {
  850.         pointer_callback_copy = func;
  851.         return copy(path1,path2);
  852. }
  853.  
  854. char callback_move(char *path1,char *path2,dword func)
  855. {
  856.         pointer_callback_move = func;
  857.         return move(path1,path2);
  858. }
  859.  
  860. char callback_remove(char *path,dword func)
  861. {
  862.         pointer_callback_remove = func;
  863.         return remove(path);
  864. }
  865.  
  866. char *version = "Ver. 1.3, Author:Pavel Yakovlev, http://vk.com/pavelyakov39";
  867.  
  868. EXPORT_
  869.         export(execute)
  870.         export(open)
  871.         export(read)
  872.         export(write)
  873.         export(copy)
  874.         export(move)
  875.         export(remove)
  876.         export(rename)
  877.         export(get_size)
  878.         //export(set_attributes)
  879.         export(get_entries_count)
  880.         export(get_dir_info)
  881.         export(get_dir_position)
  882.         export(get_file_name)
  883.        
  884.         export(get_full_path)
  885.        
  886.         export(make_dir)
  887.        
  888.         export(callback_copy)
  889.         export(callback_move)
  890.         export(callback_remove)
  891.        
  892.         export(pointer_callback_copy)
  893.         export(pointer_callback_move)
  894.         export(pointer_callback_remove)
  895.        
  896.         export(version)
  897. _EXPORT