C++ class: NativeFileAccess¶
Description¶
FileAccess adapter for x64 syscalls.
Qualified name : gaspardos::desktop::NativeFileAccess.
Header : bindings/cpp/desktop_native.hpp. C++98.
When to use it¶
Connect explorer, tree and dialog to GaspardOS volumes.
Simple program example¶
#include "desktop_native.hpp"
#include <cstdio>
#include <cstring>
int main()
{
gaspardos::desktop::NativeFileAccess access;
gaspardos::desktop::FileEntry entry;
return access.stat("/AHCIDISK0", entry) == 0 && entry.directory ? 0 : 1;
}
Building from Windows¶
Save the program above as build/api-examples/NativeFileAccess.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/NativeFileAccess.cpp build/api-examples/syscall.o bindings/cpp/file_explorer.cpp bindings/cpp/desktop_native.cpp -o build/api-examples/NativeFileAccess-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¶
std::vector<FileEntry> roots()¶
Return discovered volumes, without mounting or formatting.
int64_t stat(const std::string& path, FileEntry& entry)¶
Fill FileEntry; signed native result.
int64_t openDirectory(const std::string& path)¶
Open a directory; return handle or negative error.
int64_t next(int64_t handle, FileEntry& entry)¶
Next entry; one for an entry, zero for end, negative error, -11 for retry.
int64_t close(int64_t handle)¶
Close the handle; callers must handle failures.
int64_t mkdir(const std::string& path)¶
Create the requested directory.
int64_t read(const std::string& path, std::string& data, std::size_t limit)¶
Read with an explicit byte limit; operation result, contents in data.
int64_t create(const std::string& path, const std::string& data)¶
Exclusive creation; never modify a preexisting file.
int64_t rename(const std::string& from, const std::string& to)¶
Rename a path; raw negative error on failure.
int64_t remove(const std::string& path)¶
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.