From 03cafb600101c4bc659521b833a1f3a8c56938be Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 1 Oct 2024 11:45:17 -0700 Subject: More fixes opening files & exclusive mode. --- src/tests/myriadfs.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/tests/myriadfs.cpp (limited to 'src/tests/myriadfs.cpp') diff --git a/src/tests/myriadfs.cpp b/src/tests/myriadfs.cpp new file mode 100644 index 0000000..1266e4b --- /dev/null +++ b/src/tests/myriadfs.cpp @@ -0,0 +1,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; + } +} + -- cgit v1.2.3