aboutsummaryrefslogtreecommitdiff
path: root/src/3rdparty/smount/smount.h
blob: c0836a7558adb2c8e1d99b73e7ba42a721d88070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright (c) 2018 chai 
*/
#ifndef SMOUNT_H
#define SMOUNT_H

// path type 
enum
{
    PATH_DIR = 1, // directory  
    PATH_REG = 2   // regular file
};

// sm status
enum
{
    SMT_SUCCESS = 0,
    SMT_INVALIDMOUNT = 1, // invalid mount directory.
    SMT_NOSUCHDIR = 2,    // directory or file doesn't exsist. 
    SMT_UNABLEOPEN = 3,   // 
    SMT_CANTWRITE = 4,
};

typedef struct smtPath
{
    int type;
    char* path;
    struct smtPath* next;
}smtPath;

/**
* A shared context structrue.
*/
typedef struct smtShared
{
    smtPath* mount;    // the root directory
}smtShared;

smtShared* smtnewshared();

void smtcloseshared(smtShared* S);

/**
* Get error string with given error code.
*/
const char *smterrstr(int err);

/**
* Mount a sub file system.
*/
int smtmount(smtShared* S, const char *path);

/**
* Free mount
*/
void smtunmount(smtShared* S);

int smtexists(smtShared* S, const char *path);

/**
* Get size of a file.
*/
int smtsize(smtShared* S, const char *path);

/**
* Can only read files under root directory.
*/
void *smtread(smtShared* S, const char *path, unsigned int *size);

int smtisdir(smtShared* S, const char *path);

int smtisreg(smtShared* S, const char *path);

/**
* List all folders and files inside current mount directory.
*/
smtPath *smtlist(smtShared*S, const char *path);

void smtfreelist(smtPath* S);

int smtwrite(smtShared* S, const char *path, const void *data, int size);

void smtdelete(smtShared* S, const char *path);

int smtmkdir(smtShared* S, const char *path);

char* smtfullpath(smtShared* S, const char* path);

#endif