aboutsummaryrefslogtreecommitdiff
path: root/src/tests/myriadfs.cpp
blob: 5946b279135460e516b4dc07606e08f8edb93af7 (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
#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( int argc, char *argv[] )
{
//	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!");
	}

	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;
	}
}