# (chibi filesystem)

Interface to the filesystem and file descriptor objects. Note that file descriptors are currently represented as integers, but may be replaced with opaque (and gc-managed) objects in a future release.

#### `(create-directory* dir [mode])`

Creates the directory `dir`, including any parent directories as needed. Returns `#t` on success and `#f` on failure.

#### `(directory-fold dir kons knil)`

The fundamental directory iterator. Applies `kons` to each filename in directory `dir` and the result of the previous application, beginning with `knil`. With `kons` as `cons` and `knil` as `'()`, equivalent to `directory-files`.

#### `(directory-files dir)`

Returns a list of the files in `dir` in an unspecified order.

#### `(directory-fold-tree file down up here [knil])`

The fundamental directory traverser.

#### `(delete-file file)`

Unlinks the file named `string` from the filesystem. Returns `#t` on success and `#f` on failure.

#### `(delete-file-hierarchy dir [ignore-errors?])`

Recursively delete all files and directories under `dir`. Unless optional arg `ignore-errors?` is true, raises an error if any file can't be deleted.

#### `(with-directory dir thunk)`

Runs `thunk` with the current directory of the process temporarily set to `dir`.

#### `(file-status file)`

Returns the `status` object for the given `file`, which should be a string indicating the path or a file descriptor.

#### `(file-device x)`

#### `(file-inode x)`

#### `(file-mode x)`

#### `(file-num-links x)`

#### `(file-owner x)`

#### `(file-group x)`

#### `(file-represented-device x)`

#### `(file-size x)`

#### `(file-access-time x)`

#### `(file-modification-time x)`

#### `(file-modification-time/safe x)`

#### `(file-change-time x)`

File status accessors. `x` should be a string indicating the file to lookup the status for, or an existing status object. Raises an error in the string case for non-existing files.

#### `(file-test-mode op x)`

#### `(file-regular? x)`

#### `(file-directory? x)`

#### `(file-character? x)`

#### `(file-block? x)`

#### `(file-fifo? x)`

#### `file-link?`

#### `(file-socket? x)`

#### `(file-exists? x)`

File type tests. `x` should be a string indicating the file to lookup the status for, or an existing status object. Returns `#t` if the file exists and the given type is satisfied, and `#f` otherwise.

#### `(file-is-readable? path)`

#### `(file-is-writable? path)`

#### `(file-is-executable? path)`

File access tests. Returns true iff the current real UID and GID have the corresponding permissions on path. Equivalent to the test -r, -w, -x operators in sh.

#### `(renumber-file-descriptor old new)`

Equivalent to duplicating the file descriptor `old` to `new` and closing `old`.

#### `read-link`

Returns the path the symbolic link `file` points to, or `#f` on error.

#### `(open-output-file/append path)`

Returns a new output-port for the path, creating it if needed otherwise appending to it.

#### `(file-link-status string)`

#### `(link-file string string)`

Creates a hard link to the first arg from the second. Returns `#t` on success and `#f` on failure.

#### `(symbolic-link-file string string)`

Creates a symbolic link to the first arg from the second. Returns `#t` on success and `#f` on failure.

#### `(rename-file string string)`

Renames the first arg to the second. Returns `#t` on success and `#f` on failure.

#### `(current-directory)`

Returns the current working directory of the process as a string.

#### `(change-directory string)`

Change the current working directory of the process.

#### `(create-directory string int)`

Creates a new directory with the given mode. Returns `#t` on success and `#f` on failure.

#### `(delete-directory string)`

Deletes the directory named `string` from the filesystem. Does not attempt to delete recursively. Returns `#t` on success and `#f` on failure.

#### `(duplicate-file-descriptor fileno)`

Duplicates the given file descriptor, returning he new value,

#### `(duplicate-file-descriptor-to fileno fileno)`

Copies the first file descriptor to the second, closing it if needed. Returns `#t` on success and `#f` on failure.

#### `(close-file-descriptor fileno)`

Closes the given file descriptor. Returns `#t` on success and `#f` on failure.

#### `(open string int int)`

Opens the given file and returns a file descriptor.

#### `(open-pipe)`

Returns a list of 2 new file descriptors, the input and output end of a new pipe, respectively.

#### `(make-fifo string int)`

Creates a new named pipe in the given path. Returns `#t` on success and `#f` on failure.

#### `(get-file-descriptor-flags port-or-fileno)
(set-file-descriptor-flags! port-or-fileno long)`

Get and set the flags for the given file descriptor.

#### `(get-file-descriptor-status port-or-fileno)
(set-file-descriptor-status! port-or-fileno long)`

Get and set the status for the given file descriptor.

#### `int: open/read`

#### `int: open/write`

#### `int: open/read-write`

#### `int: open/create`

#### `int: open/exclusive`

#### `int: open/truncate`

#### `int: open/append`

#### `int: open/non-block`

File opening modes.

#### `(file-truncate port-or-fileno off_t)`

Truncate the file to the given size.

#### `(file-lock port-or-fileno int)
(const: int lock/shared)
(const: int lock/exclusive)
(const: int lock/non-blocking)
(const: int lock/unlock)`

Applies the specified locking operation using flock(2) to the port or file-descriptor.Locking operations.

#### `(chmod string int)`

Sets the file permissions as in chmod.

#### `(chown string uid_t gid_t)`

Sets the file owner and group as in chown.

#### `(is-a-tty? port-or-fileno)`

Returns `#t` if the given port of file descriptor if backed by a TTY object, and `#f` otherwise.