aboutsummaryrefslogtreecommitdiff
path: root/src/tests/myriadfs.cpp
blob: 1266e4b0207374b909b6152eea802231d5836756 (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
#include "bu/file.h"
#include "bu/membuf.h"
#include "bu/myriadfs.h"
#include "bu/myriadstream.h"
#include "bu/sio.h"

using namespace Bu;

int main()
{
//  Bu::MemBuf mb;
    Bu::File mb("store.myr", File::Read|File::Write|File::Create );
    Bu::MyriadFs mfs( mb, 512 );

    sio << "Creating dirs..." << sio.nl;
    mfs.create("/etc", Bu::MyriadFs::typeDir|0755 );
    mfs.create("/dev", Bu::MyriadFs::typeDir|0755 );
    mfs.create("/usr", Bu::MyriadFs::typeDir|0755 );

    mfs.create("/dev/null", Bu::MyriadFs::typeChrDev|0666, 1, 3 );
    mfs.create("/dev/zero", Bu::MyriadFs::typeChrDev|0666, 1, 5 );
    mfs.create("/dev/sda", Bu::MyriadFs::typeBlkDev|0660, 8, 0 );

    sio << "Creating files..." << sio.nl;
    {
        Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read );
        ms.write("world!");
    }
    {
        Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read );
        ms.write("world, again!");
    }
    {
        Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Write );
        ms.write("[longer text shouldn't be seen]");
    }
    {
        Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Write|Bu::MyriadFs::Create|Bu::MyriadFs::Truncate );
        ms.write("[short text]");
    }

    sio << "Reading files..." << sio.nl;
    {
        Bu::MyriadStream ms = mfs.open("/hello", Bu::MyriadFs::Read );
        char buf[512];
        buf[ms.read( buf, 512 )] = '\0';
        sio << "read: '" << buf << "'" << sio.nl;
    }
    {
        Bu::MyriadStream ms = mfs.open("/etc/hello", Bu::MyriadFs::Read );
        char buf[512];
        buf[ms.read( buf, 512 )] = '\0';
        sio << "read: '" << buf << "'" << sio.nl;
    }
    {
        Bu::MyriadStream ms = mfs.open("/etc/trunc", Bu::MyriadFs::Read );
        char buf[512];
        buf[ms.read( buf, 512 )] = '\0';
        sio << "read: '" << buf << "'" << sio.nl;
    }
}