lio-fs-0.0.0.1: Labeled File System interface for LIO

Safe HaskellUnsafe
LanguageHaskell98

LIO.FS.TCB

Contents

Description

This module exports the basic interface for creating and using the labeled file system, implemented as a file store. Trusted code should use initFSTCB to set the root of the labeled file system. Moreover, trusted code should implement all the IO functions in terms of createFileTCB, createDirectoryTCB, and getPathLabelTCB and setPathLabelTCB.

The current implementation uses the Show and Read instance to serialize and de-serialize labels, respectively. While this is inefficient, it make it easy to use tools like getfattr to inspect the labels of files. In a future version we may modify this implementation to use binary encoding and/or compression (since filesystem extended attributes are large, but limited).

Synopsis

Initializing labeled filesystem

initFSTCB :: Label l => FilePath -> Maybe l -> LIO l l Source

Initialize filesystem at the given path. The supplied path must be absolute, otherwise initFSTCB throw FSRootInvalid. If the FS has already been created then initFSTCB solely verifies that the root directory is not corrupt (see setFSTCB) and returns the label of the root. Otherwise, a new FS is created with the supplied label (see mkFSTCB).

This function performs several checks that setFSTCB and mkFSTCB perform, so when considering performance they should be called directly.

mkFSTCB Source

Arguments

:: Label l 
=> FilePath

Path to the filesystem root

-> l

Label of root

-> LIO l () 

Create a the file store (i.e., labeled file system) with a given label and root file path. The path must be an absolute path, otherwise initFSTCB throws FSRootInvalid.

setFSTCB :: Label l => FilePath -> LIO l l Source

Set the given file path as the root of the labeled filesystem. This function throws a FSLabelCorrupt if the directory does not contain a valid label, and a FSRootCorrupt if the magicAttr attribute is missing.

getRootDirTCB :: Label l => LIO l FilePath Source

Get the root directory.

Handling path labels

setPathLabelTCB :: Label l => FilePath -> l -> IO () Source

Set the label of a given path. This function sets the labelAttr attribute to the encoded label, and the hash to labelHashAttr.

getPathLabelTCB :: Label l => FilePath -> IO l Source

Get the label of a given path. If the object does not have an associated label or the hash of the label and stored-hash are not equal, this function throws FSLabelCorrupt.

Helpers for creating labeled objects

createFileTCB :: Label l => l -> FilePath -> IOMode -> LIO l Handle Source

Create a file object with the given label and return a handle to the new file.

createBinaryFileTCB :: Label l => l -> FilePath -> IOMode -> LIO l Handle Source

Same as createFileTCB but opens the file in binary mode.

createDirectoryTCB :: Label l => l -> FilePath -> LIO l () Source

Create a directory object with the given label.

Filesystem errors

data FSError Source

Filesystem errors

Constructors

FSRootCorrupt

Root structure is corrupt.

FSRootInvalid

Root is invalid (must be absolute).

FSRootExists

Root already exists.

FSRootNoExist

Root does not exists.

FSRootNeedLabel

Cannot create root, missing label.

FSObjNeedLabel

FSobjectcannot be created without a label.

FSLabelCorrupt FilePath

Object label is corrupt.

FSIllegalFileName

Supplied file name is illegal.