Subversion Repositories Kolibri OS

Rev

Rev 8289 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8540 superturbo 1
/* Copyright (C) 2019-2021 Logaev Maxim (turbocat2001), GPLv3 */
2
 
8280 superturbo 3
#include 
4
#include 
5
#include 
6
 
7
#pragma pack(push,1)
8
typedef struct {
9
    unsigned	p00;
10
    unsigned long long	p04;
11
    unsigned	p12;
12
    unsigned	p16;
13
    char		p20;
14
    char		*p21;
15
} kol_struct70;
16
#pragma pack(pop)
17
 
18
int kol_file_70(kol_struct70 *k)
19
{
20
    asm volatile ("int $0x40"::"a"(70), "b"(k));
21
}
22
 
23
bool dir_operations(unsigned char fun_num, char *path)
24
{
25
    kol_struct70 inf;
26
    inf.p00 = fun_num;
27
    inf.p04 = 0;
28
    inf.p12 = 0;
29
    inf.p16 = 0;
30
    inf.p20 = 0;
31
    inf.p21 = path;
32
    if(!kol_file_70(&inf)){
33
        return true;
34
    }
35
    else {
36
	    return false;
37
    }
38
}
39
 
8289 superturbo 40
int lsdir(const char* dir, short_file_info **list)
41
{
42
    int num_of_file=0;
43
    kol_struct70 inf;
44
 
45
    inf.p00 = 1;
46
    inf.p04 = 0;
47
    inf.p12 = 2;
8540 superturbo 48
    inf.p16 = (unsigned) malloc(32+inf.p12*560);
8289 superturbo 49
    inf.p20 = 0;
8540 superturbo 50
    inf.p21 = (char*)dir;
8289 superturbo 51
 
52
    if(kol_file_70(&inf))
53
    {
54
        free((void*)inf.p16);
55
        return FS_ERROR;
56
    }
57
 
58
    num_of_file = *(unsigned*)(inf.p16+8);
59
    inf.p12 = num_of_file;
60
    free((void*)inf.p16);
61
    inf.p16 = (unsigned) malloc(32+inf.p12*560);
62
    *list = (short_file_info*)malloc(num_of_file*sizeof(short_file_info));
63
 
64
    if(kol_file_70(&inf))
65
    {
66
        free((void*)inf.p16);
67
        return FS_ERROR;
68
    }
69
 
70
    for(int i=0; i
71
    {
72
       (*list)[i].type = *(unsigned*)(inf.p16+32+(264+40)*i);
73
       (*list)[i].name =(char*)(inf.p16+32+40+(264+40)*i);
74
    }
75
    return num_of_file;
76
}
77
 
78
 
8280 superturbo 79
char *getcwd(char *buf, unsigned size)
80
{
81
    if(buf == NULL){
8289 superturbo 82
       if((buf = malloc(size))==NULL)
83
       {
84
            return NULL;
85
       }
8280 superturbo 86
    }
87
    __asm__ __volatile__(
88
    "int $0x40"
89
    ::"a"(30),"b"(2),"c"(buf), "d"(size));
90
    return(buf);
91
}
92
 
93
void setcwd(const char* cwd)
94
{
95
    __asm__ __volatile__(
96
    "int $0x40"
97
    ::"a"(30),"b"(1),"c"(cwd));
98
}
99
 
100
bool rmdir(const char* dir)
101
{
8540 superturbo 102
    return dir_operations(8, (char*)dir);
8280 superturbo 103
}
104
 
105
bool mkdir(const char* dir)
106
{
8540 superturbo 107
    return dir_operations(9, (char*)dir);
8280 superturbo 108
}