aboutsummaryrefslogtreecommitdiff
path: root/include/base/fs.h
blob: bc639f860fdc6fad96f88b72b017a2873d3031ef (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
#pragma once

/* directories */
typedef sys·DirEntry  fs·DirEntry;
typedef sys·Directory fs·Directory;

int     fs·open(char *path, fs·Directory *dir);
int     fs·openfd(int fd, fs·Directory *dir);
int     fs·close(fs·Directory *dir);

int     fs·read(fs·Directory *, fs·DirEntry **);

/* small utilities */
int     fs·access(byte *path, int flag);
byte   *fs·dirname(byte *path);
byte   *fs·basename(byte *path);

#define iota(x) 1 << (x)
enum
{
    fs·preorder = iota(0),
    fs·nolinks  = iota(1),
    fs·verbose  = iota(2),
};
#undef iota

typedef struct fs·Walker    fs·Walker;
typedef struct fs·History   fs·History;

/* node in filesystem */

// XXX: simplify with our newer code
/* walk a filesystem hierarchy */
struct fs·Walker
{
    int fd, lev, max, err;
    uchar  flags : 4;
    fs·History *hist;
    struct {
        void  *data;
        int  (*func)(void *data, char *relp, char *absp, sys·Info *info);
    };
    char *base, *end, path[4096];
};

int  fs·init(fs·Walker *, char *path);
void fs·fini(fs·Walker *);
void fs·walk(fs·Walker *);