better cp, 64-bit fileops

git-svn-id: svn://kolibrios.org@6857 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
siemargl 2017-02-06 12:35:58 +00:00
parent d248870812
commit 4e23975970
17 changed files with 107 additions and 104 deletions

View File

@ -1,3 +1,8 @@
Shell 0.7.6 // 06.02.2017 // Siemargl
* ” ©«®¢ë¥ ®¯¥à æ¨¨ ¨á¯®«ì§ãîâ 64-bit à §¬¥àë ä ©«®¢.
cp <file> <dest> ⥯¥àì ¯®­¨¬ ¥â, ¥á«¨ <dest> - ª â «®£
cp ¨á¯®«ì§ã¥â ¡ãä¥à 1Œ¡, ¨«¨ ­¥ ¡®«¥¥ ¯®«®¢¨­ë ᢮¡®¤­®© ¯ ¬ïâ¨
Shell 0.7.5 // 06.01.2017 // Siemargl Shell 0.7.5 // 06.01.2017 // Siemargl
* Œ¥«ª¨¥ ¡ £ä¨ªáë, ¨§¬¥­¥­  «®£¨ª  ®¡à ¡®âª¨ áâ५®ª ¢¢¥àå/¢­¨§, çâ®¡ë ª ª ã ¢á¥å * Œ¥«ª¨¥ ¡ £ä¨ªáë, ¨§¬¥­¥­  «®£¨ª  ®¡à ¡®âª¨ áâ५®ª ¢¢¥àå/¢­¨§, çâ®¡ë ª ª ã ¢á¥å
„®¡ ¢«¥­  ª®¬ ­¤  waitfor ¨ ¢ à¨ ­â ps á ¯ à ¬¥â஬ „®¡ ¢«¥­  ª®¬ ­¤  waitfor ¨ ¢ à¨ ­â ps á ¯ à ¬¥â஬

View File

@ -3,19 +3,18 @@ int cmd_cp(char param[])
{ {
char* argv[100]; char* argv[100];
int i;
int argc; int argc;
char *filename_in; char *filename_in = NULL;
char *filename_out; char *filename_out = NULL;
char *buffer; char *buffer = NULL;
kol_struct70 k70_in; kol_struct70 k70_in;
kol_struct70 k70_out; kol_struct70 k70_out;
kol_struct_BDVK bdvk; kol_struct_BDVK bdvk;
unsigned filesize, result; unsigned long long filesize;
unsigned n; // ª®«¨ç¥á⢮ à § ª®¯¨à®¢ ­¨ï ¯® 4 ª¡ ©â  unsigned result, buf_size;
argc = parameters_prepare(param, argv); argc = parameters_prepare(param, argv);
@ -58,110 +57,88 @@ if (argv[1][0] != '/')
{ {
strcpy(filename_out, argv[1]); strcpy(filename_out, argv[1]);
} }
// add ability to use directory as destination
if ( dir_check(filename_out) )
{
char *fname = strrchr(filename_in, '/') + 1; // always exist, as we add curdir
if (filename_out[strlen(filename_out)-1] != '/')
strcat(filename_out, "/"); // add slash
strcat(filename_out, fname);
}
k70_in.p00 = 5; k70_in.p00 = 5;
k70_in.p04 = k70_in.p08 = k70_in.p12 = 0; k70_in.p04 = 0LL;
k70_in.p12 = 0;
k70_in.p16 = (unsigned) &bdvk; k70_in.p16 = (unsigned) &bdvk;
k70_in.p20 = 0; k70_in.p20 = 0;
k70_in.p21 = filename_in; k70_in.p21 = filename_in;
result = kol_file_70(&k70_in); // ¯®«ãç ¥¬ ¨­ä®à¬ æ¨î ® ä ©«¥ result = kol_file_70(&k70_in); // ¯®«ãç ¥¬ ¨­ä®à¬ æ¨î ® ä ©«¥
if ( 0 != result ) if ( 0 != result )
{ goto lbl_exit;
parameters_free(argc, argv);
free(filename_in);
free(filename_out);
return TRUE;
}
filesize = bdvk.p32[0]; // ¯®«ãç ¥¬ à §¬¥à ä ©«  (®£à ­¨ç¥­¨¥ - 4 ƒ¡ ©â ) // count buffer size up to 1Mb, but no more than 1/2 of free memory
n = filesize / 4096; buf_size = 1 << 20; // 1Mb
while( ((buf_size >> 10) > kol_system_memfree()) && (buf_size > 4096) )
buf_size /= 2;
buffer = (char*) malloc(4096); filesize = bdvk.p32; // ¯®«ãç ¥¬ à §¬¥à ä ©« (®£à ­¨ç¥­¨¥ - 4 ƒ¡ ©â  ⮫쪮 ¤«ï FAT)
if (buf_size > filesize)
buf_size = (unsigned)filesize; // may be zero!
if (buf_size == 0) buf_size = 4096; // ...
buffer = (char*) malloc(buf_size);
if (!buffer)
{
result = E_NOMEM;
goto lbl_exit;
}
k70_in.p00 = 0; k70_in.p00 = 0;
k70_in.p08 = 0; //k70_in.p08 = 0;
k70_in.p12 = 4096; k70_in.p12 = buf_size;
k70_in.p16 = (unsigned) buffer; k70_in.p16 = (unsigned) buffer;
k70_in.p20 = 0; k70_in.p20 = 0;
k70_in.p21 = filename_in; k70_in.p21 = filename_in;
k70_out.p00 = 2; k70_out.p00 = 2;
k70_out.p08 = 0; //k70_out.p08 = 0;
k70_out.p12 = 4096; k70_out.p12 = buf_size;
k70_out.p16 = (unsigned) buffer; k70_out.p16 = (unsigned) buffer;
k70_out.p20 = 0; k70_out.p20 = 0;
k70_out.p21 = filename_out; k70_out.p21 = filename_out;
i = 0; // ¤«ï ⮣®, çâ®¡ë ª®¯¨à®¢ âì ä ©«ë á à §¬¥à®¬ ¬¥­ìè¥ 4 ª<> ©â unsigned long long offset = 0;
for ( i = 0; i < n; i++) do {
{ k70_in.p04 = offset;
if (offset + buf_size > filesize) // last chunk
k70_in.p04 = i*4096; {
k70_in.p12 = k70_out.p12 = (unsigned)(filesize - offset); // filesize % buf_size;
}
result = kol_file_70(&k70_in); // ç⥭¨¥ result = kol_file_70(&k70_in); // ç⥭¨¥
if (result != 0) if (result != 0)
{ goto lbl_exit;
parameters_free(argc, argv);
free(filename_in);
free(filename_out);
free(buffer);
return FALSE;
}
k70_out.p04 = i*4096; k70_out.p04 = offset;
result = kol_file_70(&k70_out); // § ¯¨áì result = kol_file_70(&k70_out); // § ¯¨áì
if (result != 0) if (result != 0)
{ goto lbl_exit;
parameters_free(argc, argv);
free(filename_in);
free(filename_out);
free(buffer);
return FALSE;
}
if (i == 0) if (k70_out.p00 == 2)
k70_out.p00 = 3; // ¬¥­ï¥¬ äã­ªæ¨î á ᮧ¤ ­¨ï (2) ­  ¤®§ ¯¨áì (3) k70_out.p00 = 3; // ¬¥­ï¥¬ äã­ªæ¨î á ᮧ¤ ­¨ï (2) ­  ¤®§ ¯¨áì (3)
offset += buf_size;
} while (offset < filesize);
} lbl_exit:
if ( (filesize%4096) != 0 ) // ¥á«¨ à §¬¥à ä ©«  ­¥ ªà â¥­ 4 ª<> ©â ¬
{
k70_in.p12 = filesize%4096;
k70_out.p12 = filesize%4096;
k70_in.p04 = i*4096; // ¢ i ¤®«¦­® ¡ëâì ¯à ¢¨«ì­®¥ ᬥ饭¨¥
result = kol_file_70(&k70_in); // ç⥭¨¥
if (result != 0)
{
parameters_free(argc, argv);
free(filename_in);
free(filename_out);
free(buffer);
return FALSE;
}
k70_out.p04 = i*4096;
result = kol_file_70(&k70_out); // § ¯¨áì
if (result != 0)
{
parameters_free(argc, argv);
free(filename_in);
free(filename_out);
free(buffer);
return FALSE;
}
}
parameters_free(argc, argv); parameters_free(argc, argv);
free(filename_in); free(filename_in);
free(filename_out); free(filename_out);
free(buffer); free(buffer);
return (result == 0);
return TRUE;
} }

View File

@ -12,8 +12,8 @@ int i, result;
k70.p00 = 1; k70.p00 = 1;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 10000; k70.p12 = 2; // just for test exist & read number of entries
k70.p16 = (unsigned) malloc(32+k70.p12*560); k70.p16 = (unsigned) malloc(32+k70.p12*560);
k70.p20 = 0; k70.p20 = 0;
@ -34,6 +34,20 @@ if ( !((result==0) || (result==6)) ) //
n = (unsigned*) (k70.p16+8); n = (unsigned*) (k70.p16+8);
num_of_file = *n; // ç¨á«® ä ©«®¢ ¢ ª â «®£¥ num_of_file = *n; // ç¨á«® ä ©«®¢ ¢ ª â «®£¥
// now read full directory
k70.p12 = num_of_file;
free( (void*) k70.p16);
k70.p16 = (unsigned) malloc(32+k70.p12*560);
if ( !k70.p16 )
return FALSE;
result = kol_file_70(&k70);
if ( !((result==0) || (result==6)) )
{
free( (void*) k70.p16);
return FALSE;
}
for (i = 0; i < num_of_file; i++) for (i = 0; i < num_of_file; i++)
{ {
printf (" %s", k70.p16+32+40+(264+40)*i); printf (" %s", k70.p16+32+40+(264+40)*i);

View File

@ -24,7 +24,7 @@ if ( 0 == strcmp(dir, ".") || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cur_di
k70.p00 = 9; k70.p00 = 9;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -4,7 +4,8 @@ int cmd_more(char file[])
kol_struct70 k70; kol_struct70 k70;
kol_struct_BDVK bdvk; kol_struct_BDVK bdvk;
unsigned result, filesize, pos, i; unsigned result, i;
unsigned long long filesize, pos;
char buf[81]; //¡ãä¥à char buf[81]; //¡ãä¥à
char temp[FILENAME_MAX]; char temp[FILENAME_MAX];
unsigned flags; unsigned flags;
@ -44,7 +45,8 @@ else
} }
k70.p00 = 5; k70.p00 = 5;
k70.p04 = k70.p08 = k70.p12 = 0; k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk; k70.p16 = (unsigned) &bdvk;
k70.p20 = 0; k70.p20 = 0;
k70.p21 = temp; k70.p21 = temp;
@ -53,7 +55,7 @@ result = kol_file_70(&k70); //
if ( 0 != result ) if ( 0 != result )
return FALSE; return FALSE;
filesize = bdvk.p32[0]; // ¯®«ãç ¥¬ à §¬¥à ä ©«  filesize = bdvk.p32; // ¯®«ãç ¥¬ à §¬¥à ä ©« 
buf[80]=0; buf[80]=0;
flags = con_get_flags(); flags = con_get_flags();
@ -65,7 +67,7 @@ for (pos=0;pos<filesize;pos+=80)
k70.p00 = 0; k70.p00 = 0;
k70.p04 = pos; k70.p04 = pos;
k70.p08 = 0; // k70.p08 = 0; // bug for over 4Gb files, but "more" is unusable there
k70.p12 = 80; k70.p12 = 80;
k70.p16 = (unsigned) buf; k70.p16 = (unsigned) buf;
k70.p20 = 0; k70.p20 = 0;

View File

@ -40,7 +40,7 @@ else
k70.p00 = 8; k70.p00 = 8;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -23,7 +23,7 @@ if ( ( 0 == strcmp(dir, ".") ) || ( 0 == strcmp(dir, "..") ) || ( 0 == strcmp(cu
k70.p00 = 8; k70.p00 = 8;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -43,7 +43,7 @@ else
} }
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -1,5 +1,5 @@
#define SHELL_VERSION "0.7.5" #define SHELL_VERSION "0.7.6"
extern char PATH[256]; extern char PATH[256];
extern char PARAM[256]; extern char PARAM[256];

View File

@ -359,7 +359,7 @@ for (i = 0; i < NUM_OF_CMD; i++)
if (!strcmp(cmd, COMMANDS[i].name)) if (!strcmp(cmd, COMMANDS[i].name))
{ {
result = ((handler1_t)COMMANDS[i].handler)(args); result = ((handler1_t)COMMANDS[i].handler)(args);
if (result != TRUE) if (result == FALSE)
{ {
#if LANG_ENG #if LANG_ENG
printf(" Error!\n\r"); printf(" Error!\n\r");

View File

@ -6,7 +6,8 @@ kol_struct70 k70;
k70.p00 = 7; k70.p00 = 7;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = (unsigned) param; //k70.p08 = (unsigned) param;
*((unsigned*)&k70 + 2) = (unsigned) param;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -9,7 +9,7 @@ char buf[4];
k70.p00 = 0; k70.p00 = 0;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 4; // ÷èòàòü 4 áàéòà k70.p12 = 4; // ÷èòàòü 4 áàéòà
k70.p16 = (unsigned) buf; k70.p16 = (unsigned) buf;
k70.p20 = 0; k70.p20 = 0;
@ -30,11 +30,13 @@ int script_run(char exec[], char args[])
kol_struct70 k70; kol_struct70 k70;
kol_struct_BDVK bdvk; kol_struct_BDVK bdvk;
unsigned result, filesize, pos, i; unsigned result, i;
unsigned long long filesize, pos;
char *buf; //áóôåğ, êóäà êîïèğóåòñÿ ñêğèïò char *buf; //áóôåğ, êóäà êîïèğóåòñÿ ñêğèïò
k70.p00 = 5; k70.p00 = 5;
k70.p04 = k70.p08 = k70.p12 = 0; k70.p04 = k70.p12 = 0;
//k70.p08 = 0;
k70.p16 = (unsigned) &bdvk; k70.p16 = (unsigned) &bdvk;
k70.p20 = 0; k70.p20 = 0;
k70.p21 = exec; k70.p21 = exec;
@ -43,16 +45,17 @@ result = kol_file_70(&k70); //
if ( 0 != result ) if ( 0 != result )
return FALSE; return FALSE;
filesize = bdvk.p32[0]; // ïîëó÷àåì ğàçìåğ ôàéëà filesize = bdvk.p32; // ïîëó÷àåì ğàçìåğ ôàéëà
buf = malloc(filesize+256); buf = malloc(filesize+256); // may fail for over 4Gb file, but impossible case
if (NULL == buf) if (NULL == buf)
return FALSE; return FALSE;
buf[filesize]=0; buf[filesize]=0;
k70.p00 = 0; k70.p00 = 0;
k70.p04 = k70.p08 = 0; k70.p04 = 0;
//k70.p08 = 0;
k70.p12 = filesize; k70.p12 = filesize;
k70.p16 = (unsigned) buf; k70.p16 = (unsigned) buf;
k70.p20 = 0; k70.p20 = 0;

View File

@ -19,7 +19,7 @@ int command_get_cmd(char cmd[]);
int script_check(char file[]); int script_check(char file[]);
int script_run(char exec[], char args[]); int script_run(char exec[], char args[]);
int aliases_check(char alias[]); int alias_check(char alias[]);
int alias_search(char alias[]); int alias_search(char alias[]);
int alias_add(char alias[]); int alias_add(char alias[]);
int alias_split (char alias[], char s1[], char s2[]); int alias_split (char alias[], char s1[], char s2[]);

View File

@ -4,15 +4,16 @@
/// =========================================================== /// ===========================================================
int dir_check(char dir[]) int dir_check(char dir[])
/// just checks, if dir[] is really a directory
{ {
kol_struct70 k70; kol_struct70 k70;
int result; int result;
k70.p00 = 1; k70.p00 = 1;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 2*1024*1024; // 2 MB k70.p12 = 2; // enough to read . & ..
k70.p16 = (unsigned) malloc(2*1024*1024); k70.p16 = (unsigned)malloc(32+k70.p12*560);
k70.p20 = 0; k70.p20 = 0;
k70.p21 = dir; k70.p21 = dir;
@ -20,7 +21,7 @@ result = kol_file_70(&k70);
free((void*)k70.p16); free((void*)k70.p16);
if ( (0 == result)||(6 == result) ) if ( (0 == result)||(6 == result) ) // 6 is possible ???
return TRUE; return TRUE;
else else
return FALSE; return FALSE;
@ -50,7 +51,7 @@ int result;
k70.p00 = 0; k70.p00 = 0;
k70.p04 = 0; k70.p04 = 0;
k70.p08 = 0; //k70.p08 = 0;
k70.p12 = 0; k70.p12 = 0;
k70.p16 = 0; k70.p16 = 0;
k70.p20 = 0; k70.p20 = 0;

View File

@ -18,8 +18,7 @@
typedef struct typedef struct
{ {
unsigned p00; unsigned p00;
unsigned p04; unsigned long long p04;
unsigned p08;
unsigned p12; unsigned p12;
unsigned p16; unsigned p16;
char p20; char p20;
@ -40,7 +39,7 @@ unsigned p16;
unsigned p20; unsigned p20;
unsigned p24; unsigned p24;
unsigned p28; unsigned p28;
unsigned p32[2]; unsigned long long p32;
unsigned p40; unsigned p40;
} kol_struct_BDVK; } kol_struct_BDVK;
#pragma pack(pop) #pragma pack(pop)

View File

@ -29,5 +29,5 @@ asm ("int $0x40"::"a"(68), "b"(13), "c"(p) );
void* realloc(void *p, unsigned s) void* realloc(void *p, unsigned s)
{ {
asm ("int $0x40"::"a"(68), "b"(12), "c"(p), "d"(s) ); asm ("int $0x40"::"a"(68), "b"(20), "c"(p), "d"(s) );
} }

View File

@ -1,5 +1,6 @@
#include "string.h" #include "string.h"
#include "ctype.h"
void* memset(void *mem, int c, unsigned size) void* memset(void *mem, int c, unsigned size)
{ {