a firstworks project
Rudiments
About Documentation Download Licensing News

Using the filesystem class

The filesystem class provides methods for collecting statistics about a filesystem. The "standard" posix function for getting filesystem statistics is either statfs or statvfs. Few operating systems implement statvfs though and the structure returned by statfs varies greatly between operating systems. The filesystem class attempts to remedy this situation. However, no operating system supports every method in this class.

To use the class, open a path on the filesystem of interest and then call the various accessor methods to retrieve statistics.

The following example opens the root filesystem and prints various properties including the filesystem type, block size, block counts, file node counts, maximum filename length, mount point, and device name.

#include <rudiments/filesystem.h>
#include <rudiments/stdio.h>

int main(int argc, const char **argv) {

	filesystem	fs;

	// open the filesystem containing the root directory
	if (!fs.open("/")) {
		stdoutput.write("failed to open filesystem\n");
		return 1;
	}


	// print filesystem properties
	stdoutput.printf("type:              %lld\n",fs.getType());
	stdoutput.printf("type name:         %s\n",fs.getTypeName());
	stdoutput.printf("block size:        %lld\n",fs.getBlockSize());
	stdoutput.printf("optimum block:     %lld\n",
					fs.getOptimumTransferBlockSize());
	stdoutput.printf("total blocks:      %lld\n",fs.getTotalBlocks());
	stdoutput.printf("free blocks:       %lld\n",fs.getFreeBlocks());
	stdoutput.printf("available blocks:  %lld\n",
					fs.getAvailableBlocks());
	stdoutput.printf("reserved blocks:   %lld\n",
					fs.getReservedBlocks());
	stdoutput.write('\n');


	// print file node info
	stdoutput.printf("total file nodes:      %lld\n",
					fs.getTotalFileNodes());
	stdoutput.printf("free file nodes:       %lld\n",
					fs.getFreeFileNodes());
	stdoutput.printf("available file nodes:  %lld\n",
					fs.getAvailableFileNodes());
	stdoutput.printf("reserved file nodes:   %lld\n",
					fs.getReservedFileNodes());
	stdoutput.write('\n');


	// print other properties
	stdoutput.printf("max filename length:   %lld\n",
					fs.getMaximumFileNameLength());
	stdoutput.printf("mount point:           %s\n",
					fs.getMountPoint());
	stdoutput.printf("device name:           %s\n",
					fs.getDeviceName());

	fs.close();
}
Copyright 2017 - David Muse - Contact