@zenfs/core
Version:
A filesystem, anywhere
249 lines (248 loc) • 7.39 kB
TypeScript
import { BufferView } from 'utilium/buffer';
import { Stats } from '../node/stats.js';
import { type V_Context } from './contexts.js';
/**
* Root inode
* @hidden
*/
export declare const rootIno = 0;
declare const Attributes_base: import("memium").StructConstructor<BufferView<any>>;
/**
* Extended attributes
* @category Internals
* @internal
*/
export declare class Attributes extends Attributes_base {
static name: string;
accessor size: number;
get byteSize(): number;
has(name: string): boolean;
get(name: string): Uint8Array | undefined;
set(name: string, value: Uint8Array): void;
remove(name: string): boolean;
copyFrom(other: Attributes): void;
keys(): Generator<string, void, unknown>;
values(): Generator<Uint8Array<ArrayBufferLike>, void, unknown>;
entries(): Generator<(string | Uint8Array<ArrayBufferLike>)[], void, unknown>;
}
/**
* @internal @hidden
*/
export interface InodeFields {
data?: number;
flags?: number;
version?: number;
}
/**
* @category Internals
* @internal
*/
export interface InodeLike<T extends number | bigint = number> extends InodeFields {
/**
* Size of the item in bytes.
* For directories/symlinks, this is normally the size of the struct that represents the item.
*/
size: T;
/**
* Unix-style file mode (e.g. 0o644) that includes the item type
*/
mode: T;
/**
* Time of last access, since epoch
*/
atimeMs: T;
/**
* Time of last modification, since epoch
*/
mtimeMs: T;
/**
* Time of last time file status was changed, since epoch
*/
ctimeMs: T;
/**
* Time of file creation, since epoch
*/
birthtimeMs: T;
/**
* The id of the user that owns the file
*/
uid: T;
/**
* The id of the group that owns the file
*/
gid: T;
/**
* Inode number
*/
ino: T;
/**
* Number of hard links
*/
nlink: T;
/**
* Extended attributes
*/
attributes?: Attributes;
}
/**
* @internal @hidden
*/
export declare const _inode_fields: readonly ["ino", "data", "size", "mode", "flags", "nlink", "uid", "gid", "atimeMs", "birthtimeMs", "mtimeMs", "ctimeMs", "version"];
/**
* Represents which version of the `Inode` format we are on.
* 1. 58 bytes. The first member was called `ino` but used as the ID for data.
* 2. 66 bytes. Renamed the first member from `ino` to `data` and added a separate `ino` field
* 3. 72 bytes. Changed the ID fields from 64 to 32 bits and added `flags`.
* 4. >= 128 bytes. Added extended attributes.
* 5. (current) 4 KiB. Changed flags
* @internal @hidden
*/
export declare const _inode_version = 5;
/**
* Inode flags
* @see `S_*` in `include/linux/fs.h` (around L2325)
* @experimental
*/
export declare enum InodeFlags {
/** Writes are synced at once */
Sync = 1,
/** Do not update access times */
NoAtime = 2,
/** Append-only file */
Append = 4,
/** Immutable file */
Immutable = 8,
/** removed, but still open directory */
Dead = 16,
/** Inode is not counted to quota */
NoQuota = 32,
/** Directory modifications are synchronous */
Dirsync = 64,
/** Do not update file c/mtime */
NoCMtime = 128,
/** Do not truncate: swapon got its bmaps */
SwapFile = 256,
/** Inode is fs-internal */
Private = 512,
/** Inode has an associated IMA struct */
IMA = 1024,
/** Automount/referral quasi-directory */
AutoMount = 2048,
/** no suid or xattr security attributes */
NoSec = 4096,
/** Direct Access, avoiding the page cache */
DAX = 8192,
/** Encrypted file (using fs/crypto/) */
Encrypted = 16384,
/** Casefolded file */
CaseFold = 32768,
/** Verity file (using fs/verity/) */
Verity = 65536,
/** File is in use by the kernel (eg. fs/cachefiles) */
KernelFile = 131072
}
/** User visible flags */
export declare const userVisibleFlags = 253951;
/** User modifiable flags */
export declare const userModifiableFlags = 229631;
declare const Inode_base: import("memium").StructConstructor<BufferView<any>>;
/**
* Generic inode definition that can easily be serialized.
* @category Internals
* @internal
*/
export declare class Inode extends Inode_base implements InodeLike {
static name: string;
constructor(...args: ConstructorParameters<typeof BufferView> | [Readonly<Partial<InodeLike>>]);
accessor data: number;
/** For future use */
accessor __data_old: number;
accessor size: number;
accessor mode: number;
accessor nlink: number;
accessor uid: number;
accessor gid: number;
accessor atimeMs: number;
accessor birthtimeMs: number;
accessor mtimeMs: number;
/**
* The time the inode was changed.
*
* This is automatically updated whenever changed are made using `update()`.
*/
accessor ctimeMs: number;
accessor ino: number;
/** For future use */
accessor __ino_old: number;
accessor flags: number;
/** For future use */
protected accessor __after_flags: number;
/**
* The "version" of the inode/data.
* Unrelated to the inode format!
*/
accessor version: number;
/**
* Padding up to 128 bytes.
* This ensures there is enough room for expansion without breaking the ABI.
* @internal
*/
protected accessor __padding: Uint8Array;
accessor attributes: Attributes;
/**
* Since the attribute data uses dynamic arrays,
* it is necessary to add this so attributes can be added.
* @internal @hidden
*/
protected accessor __data: Uint8Array;
toString(): string;
toJSON(): InodeLike;
/**
* Handy function that converts the Inode to a Node Stats object.
* @deprecated Use `new Stats(inode)` instead.
*/
toStats(): Stats;
/**
* Updates the Inode using information from the stats object. Used by file
* systems at sync time, e.g.:
* - Program opens file and gets a File object.
* - Program mutates file. File object is responsible for maintaining
* metadata changes locally -- typically in a Stats object.
* - Program closes file. File object's metadata changes are synced with the
* file system.
* @returns whether any changes have occurred.
*/
update(data?: Partial<Readonly<InodeLike>>): boolean;
}
export declare function isFile(metadata: {
mode: number;
}): boolean;
export declare function isDirectory(metadata: {
mode: number;
}): boolean;
export declare function isSymbolicLink(metadata: {
mode: number;
}): boolean;
export declare function isSocket(metadata: {
mode: number;
}): boolean;
export declare function isBlockDevice(metadata: {
mode: number;
}): boolean;
export declare function isCharacterDevice(metadata: {
mode: number;
}): boolean;
export declare function isFIFO(metadata: {
mode: number;
}): boolean;
/**
* Checks if a given user/group has access to this item
* @param access The requested access, combination of `W_OK`, `R_OK`, and `X_OK`
* @internal
*/
export declare function hasAccess($: V_Context, inode: Pick<InodeLike, 'mode' | 'uid' | 'gid'>, access: number): boolean;
/**
* @hidden @internal
*/
export declare function _chown(stats: Partial<InodeLike>, uid: number, gid: number): boolean;
export {};