123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112module juptune.event.io;
struct PosixFile
{
/++ ALIASES ++/
///
alias __xdtor = __MARMOS_BUG__;
///
alias __xpostblit = __MARMOS_BUG__;
/++ FUNCTIONS ++/
/// Helper function around .open for when you want to create a new file (the file must not exist already).
static Result createNew(const char[] path, PosixFile file, PosixFile.PermissionFlags permissions = cast(PermissionFlags)504, PosixFile.ResolveFlags resolveFlags = ResolveFlags.asNormal, PosixDirectory* cwd = null, bool pathIsNullTerminated = false);
/// Helper function around .open for when you want to create a new file if it doesn't exist, or truncate it if it already exists.
static Result createOrTruncate(const char[] path, PosixFile file, PosixFile.PermissionFlags permissions = cast(PermissionFlags)504, PosixFile.ResolveFlags resolveFlags = ResolveFlags.asNormal, PosixDirectory* cwd = null, bool pathIsNullTerminated = false);
///
PosixFile opAssign(PosixFile p);
/// Opens/creates a file at the given path, using the provided flags & modes to determine the exact behaviour of the opened file.
static Result open(const char[] path, PosixFile.AccessMode accessMode, PosixFile.CreateMode createMode, PosixFile.Flags flags, PosixFile.ResolveFlags resolveFlags, PosixFile.PermissionFlags permissions, PosixDirectory* cwd, PosixFile file, bool pathIsNullTerminated = false);
/// Helper function around .open for when you want to open a prexisting file for reading.
static Result openForReading(const char[] path, PosixFile file, PosixFile.ResolveFlags resolveFlags = ResolveFlags.asNormal, PosixDirectory* cwd = null, bool pathIsNullTerminated = false);
/++ ENUMS ++/
/// Determines whether the file can be written to and/or read from.
enum AccessMode : int
{
///
FAILSAFE = -1,
/// The file can only be read from.
readOnly = 0,
/// The file can only be written to.
writeOnly = 1,
/// The file can be both written to and read from.
readWrite = 2
}
/// Determines how to deal with files that don't/already exist.
enum CreateMode : int
{
/// Don't create a new file. If the file doesn't exist then you'll run into an error result.
dontCreate = 0,
/// Always attempt to create a new file. If the file already exists, then you'll run into an error result.
create = 192,
/// Always attempt to create a new file. If the file already exists then it'll be truncated.
truncate = 576
}
/// Additional flags related to opening the file. This is a bit mask that can be ORed together.
enum Flags : int
{
///
none = 0,
/// Attempt to bypass any kernal-level caching and data duplication.
direct = 16384,
/// Writes will not return until all of the data & metadata required for the file to still function, have been fully committed to disk.
dsync = 4096,
/// The file access timestamp won't be updated.
noAccessTime = 262144,
/// If the last segment of the path is a symlink, you'll run into an error result instead of opening the file.
noFollowTrailingSymlink = 131072
}
///
enum PermissionFlags : int
{
///
none = 0,
///
ownerRead = 256,
///
ownerWrite = 128,
///
ownerExecute = 64,
///
groupRead = 32,
///
groupWrite = 16,
///
groupExecute = 8,
///
otherRead = 4,
///
otherWrite = 2,
///
otherExecute = 1,
///
ownerAll = 448,
///
groupAll = 56
}
/// Flags related to changing the behaviour for how file paths are resolved. This is a bit mask that can be ORed together.
enum ResolveFlags : int
{
/// No changes. They work as you'd expect.
asNormal = 0,
/// The path to the file being opened MUST belong to the same mounting point as the current working directory.
mustBeOnSameMountAsCwd = 1,
/// "Magic links" (google it) will generate an error result upon being opened.
noMagicLinks = 2,
/// The path to the file being opened MUST NOT contain a symlink at any point in its path.
noSymlinksAtAnyPoint = 4,
/// The path MUST NOT contain a starting "/", and MUST NOT contain any usage of things like "../". This guarentees that the file being opened, is directly under the current working directory. (TODO: Would be really nice to detach this functionality from the CWD).
mustBeBeneathCwd = 8,
/// The current working directory is treated as a fake root, so "/" resolves to the CWD, and "../" cannot break out of the CWD.
cwdIsFakeRoot = 16
}
/++ VARIABLES ++/
///
GenericIoDriver!(FileDescriptorReadWriteType.writeAndRead) _driver;
}
A Fileimplementation that's probably not actually POSIX compatible.
As with all IO Driver implementations, this struct inherits GenericIoDriverfor common IO functions.
GenericIoDriver
| Name | Description |
|---|---|
| __xdtor | |
| __xpostblit |
| Name | Description |
|---|---|
| AccessMode |
Determines whether the file can be written to and/or read from. |
| CreateMode |
Determines how to deal with files that don't/already exist. |
| Flags |
Additional flags related to opening the file. This is a bit mask that can be ORed together. |
| PermissionFlags | |
| ResolveFlags |
Flags related to changing the behaviour for how file paths are resolved. This is a bit mask that can be ORed together. |
| Name | Description |
|---|---|
| createNew |
Helper function around |
| createOrTruncate |
Helper function around |
| opAssign | |
| open |
Opens/creates a file at the given path, using the provided flags & modes to determine the exact behaviour of the opened file. |
| openForReading |
Helper function around |
| Name | Description |
|---|---|
| _driver |