A file system API is an application programming interface through which a utility or user program requests services of a file system. An operating system may provide abstractions for accessing different file systems transparently.

Some file system APIs may also include interfaces for maintenance operations, such as creating or initializing a file system, verifying the file system for integrity, and defragmentation.

File system API

Each operating system includes the APIs needed for the file systems it supports. Microsoft Windows has file system APIs for NTFS and several FAT file systems. Linux systems can include APIs for ext2, ext3, ReiserFS, and Btrfs to name a few.

File system API

History

Some early operating systems were capable of handling only tape and disk file systems. These provided the most basic of interfaces with: Write, read and position

File system API

More coordination such as device allocation and deallocation required the addition of: Open and close

As file systems provided more services, more interfaces were defined: Metadata management File system maintenance

As additional file system types, hierarchy structure and supported media increased, additional features needed some specialized functions: Directory management Data structure management Record management Non-data operations

Multi-user systems required APIs for: Sharing Restricting access Encryption

API overviews

Write, read and position

Writing user data to a file system is provided for use directly by the user program or the run-time library. The run-time library for some programming languages may provide type conversion, formatting and blocking. Some file systems provide identification of records by key and may include re-writing an existing record. This operation is sometimes called PUT or PUTX (if the record exists)

Reading user data, sometimes called GET, may include a direction (forward or reverse) or in the case of a keyed file system, a specific key. As with writing run-time libraries may intercede for the user program.

Positioning includes adjusting the location of the next record. This may include skipping forward or reverse as well as positioning to the beginning or end of the file.

Open and close

The open API may be explicitly requested or implicitly invoked upon the issuance of the first operation by a process on an object. It may cause the mounting of removable media, establishing a connection to another host and validating the location and accessibility of the object. It updates system structures to indicate that the object is in use.

Usual requirements for requesting access to a file system object include: The object which is to be accessed (file, directory, media and location) The intended type of operations to be performed after the open (reads, updates, deletions) Additional information may be necessary, for example a password a declaration that other processes may access the same object while the opening process is using the object (sharing). This may depend on the intent of the other process. In contrast, a declaration that no other process may access the object regardless of the other processes intent (exclusive use). These are requested via a programming language library which may provide coordination among modules in the process in addition to forwarding the request to the file system.

It must be expected that something may go wrong during the processing of the open. The object or intent may be improperly specified (the name may include an unacceptable character or the intent is unrecognized). The process may be prohibited from accessing the object (it may be only accessible by a group or specific user). The file system may be unable to create or update structures required to coordinate activities among users. In the case of a new (or replacement) object, there may not be sufficient capacity on the media.

Depending on the programming language, additional specifications in the open may establish the modules to handle these conditions. Some libraries specify a library module to the file system permitting analysis should the opening program be unable to perform any meaningful action as a result of a failure. For example, if the failure is on the attempt to open the necessary input file, the only action may be to report the failure and abort the program. Some languages simply return a code indicating the type of failure which always must be checked by the program, which decides what to report and if it can continue.