Use of the Callback Mode in CBFS Storage

To get started using the callback mode of CBFS Storage, you need to understand what virtual file systems are and how they store information.

Types of Virtual File Systems

Consider a dichotomy of virtual file systems:

  1. The file systems that store the files (let's call them Maintainers)
  2. The file systems that redirect file operation requests (let's call the Redirectors)

Maintainers

Maintainers implement an actual file system, i.e., they maintain some storage where they put file data. Redirectors don't maintain a storage but redirect file operation requests to another file system.

No file system can be self-containing, i.e., it must call some external API functions to read or write the data to the media.

Maintainers read or write the logical blocks that don't represent the files. One can think about such blocks as being the sectors of the disk drive or being the blocks of the flash memory media. Maintainers perform read/write operations by calling some file system API or network API or by reading or writing the data blocks to memory (which was previously allocated with some API). But, in all cases, they read or write the blocks of generic data not associated with some particular file in the virtual file system.

Redirectors

Redirectors, on the other hand, forward the requests to another (underlying) file system via a file system API or network API (for network file systems). With minor exceptions, such requests are related to some particular entry (volume, directory, or file) in the virtual file system. Redirectors can perform some preprocessing or postprocessing of the requests, or they forward the requests without any processing.

Example: CBFS Storage

For an example of a Redirector you can take a look at CBFS Connect (our other product).

CBFS Storage is a Maintainer. It maintains a file system structure inside of the storage. The CBFS Storage engine calls the OS' file management API to read or write the pages (sectors) from/to the storage file stored on the actual disk. Besides the actual writing of the pages to the storage file, CBFS Storage supports a so-called callback mode. In callback mode, CBFS Storage does not use the OS' file management API functions. Instead, it calls the application-defined callback functions to read or write the pages from/to the storage. The application needs to implement all callback functions required to manipulate the storage and read/write the pages. Callback mode can be used to keep the storage in memory or somewhere across the network or in database records.

Working with Pages

When the application callback functions are called, they work only with the pages. These pages are not related in any way to the files or directories being stored inside of a CBFS Storage volume. Treat the pages as the raw disk data.

Dynamically Sized Storage

The CBFS Storage architecture is unique as it supports the dynamic sizing of the storage where the file data is kept. The file system can work in fixed and resizable modes. In resizable mode, CBFS Storage automatically resizes the storage size as needed. When you implement the callbacks, you will need to implement and handle correctly the OnFileGetSize and OnFileSetSize callbacks/events.

Getting Started in Callback Mode

You start working in callback mode by defining the callback functions (delegates, event handlers, etc.) and telling CBFS Storage to use those functions. After that, you open the storage (using the Open method or a special form of class constructor depending on the CBFS Storage API you use). Opening the storage involves the following operations:

  • Getting access to the storage media (OnFileOpen)
  • Reading the information about the file system from the storage (OnFileSeek and OnFileRead).

The storage is open ONLY after the open operation is complete, i.e., when execution of the Open method or class constructor is completed. You should not expect the storage to be opened when the OnFileOpen, OnFileSeek, or OnFileRead callback function is called. In the OnFileOpen callback function, you can set some file handle (or another handle that will be used to access the underlying storage later), and this handle will be passed to other callback functions later.

After the storage is open, you use it as you would do normally, i.e., not in callback mode.

Use of callback mode for encryption will be discussed in a future article.

Ready to get started?

Learn more about Callback Technologies or download a free trial.

Download Now