Skip to content

C++ class: FileAccess

Index · Français

Description

Abstract desktop filesystem interface.

Qualified name : gaspardos::desktop::FileAccess.

Header : bindings/cpp/file_explorer.hpp. C++98.

When to use it

Inject a native backend or a fake filesystem for tests.

Simple program example

#include "desktop_native.hpp"
#include <cstdio>
#include <cstring>

int main()
{
    gaspardos::desktop::NativeFileAccess       native;
    gaspardos::desktop::FileAccess&            access = native;
    std::vector<gaspardos::desktop::FileEntry> roots  = access.roots();
    std::printf("%lu volumes\n", static_cast<unsigned long>(roots.size()));
    return 0;
}

Building from Windows

Save the program above as build/api-examples/FileAccess.cpp from the repository root. Create the directory if necessary.

PowerShell — from the repository root:

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-gcc.exe -std=gnu1x -O2 -mno-red-zone -c bindings/native/gaspardos_x64_syscall.c -o build/api-examples/syscall.o
if ($LASTEXITCODE -ne 0) { throw "C compilation failed" }
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/FileAccess.cpp build/api-examples/syscall.o bindings/cpp/file_explorer.cpp bindings/cpp/desktop_native.cpp -o build/api-examples/FileAccess-x64.elf
if ($LASTEXITCODE -ne 0) { throw "C++ compilation/link failed" }

Run the ELF on GaspardOS, not Windows. The driver supplies CRT and libraries. Prepare the required volumes/services; examples bound their waits and may exit on backpressure rather than retry. Successful compilation does not validate kernel execution.

The headers, implementation files, native wrappers and complete examples are available under Source files.

Class methods

virtual ~FileAccess()

Virtual destructor for adapters.

virtual std::vector<FileEntry> roots() = 0

Return discovered volumes, without mounting or formatting.

virtual int64_t stat(const std::string& path, FileEntry& entry) = 0

Fill FileEntry; signed native result.

virtual int64_t openDirectory(const std::string& path) = 0

Open a directory; return handle or negative error.

virtual int64_t next(int64_t handle, FileEntry& entry) = 0

Next entry; one for an entry, zero for end, negative error, -11 for retry.

virtual int64_t close(int64_t handle) = 0

Close the handle; callers must handle failures.

virtual int64_t mkdir(const std::string& path) = 0

Create the requested directory.

virtual int64_t read(const std::string& path, std::string& data, std::size_t limit) = 0

Read with an explicit byte limit; operation result, contents in data.

virtual int64_t create(const std::string& path, const std::string& data) = 0

Exclusive creation; never modify a preexisting file.

virtual int64_t rename(const std::string& from, const std::string& to) = 0

Rename a path; raw negative error on failure.

virtual int64_t remove(const std::string& path) = 0

Remove the specified file.

Native contract

LP64 ABI, 32-bit wchar_t, no packing. Native negative results are not errno. Handle -11 with yield and an application limit. Referenced objects must outlive their users; do not copy handle owners. File uses stdio/errno and invalidates its stream on close, even on error.