FileSystemInfo

Since: BlackBerry 10.0.0

#include <bb/FileSystemInfo>

To link against this class, add the following line to your .pro file: LIBS += -lbb

The FileSystemInfo class provides information about the file system on a device.

Instances of this class provide the capacity and amount of free space on the file system on a device.


Overview

Public Functions Index

FileSystemInfo (QObject *parent=0)
virtual ~FileSystemInfo ()
Q_INVOKABLE qint64availableFileSystemSpace (const QString &path)
Q_INVOKABLE interror () const
Q_INVOKABLE QStringerrorString () const
Q_INVOKABLE qint64fileSystemCapacity (const QString &path)

Public Functions

FileSystemInfo (

Creates a new FileSystemInfo object.

Example usage in C++
#include <bb/FileSystemInfo>

void checkFileSystem()
{
    bb::FileSystemInfo fileSystemInfo;

    // Call methods on fileSystemInfo object.
}
Example usage in QML
// QML plugin for libbb
import bb 1.0

import bb.cascades 1.0

Page {
    Container {
        // FileSystemInfo isn't a visible object so it must be wrapped
        // as an attached object.
        attachedObjects: [
            FileSystemInfo {
                id: fileSystemInfo
            }
        ]
        // Additional QML that can use fileSystemInfo
    }
}
Parameters
parent

If not 0, the supplied parent will be responsible for deleting this instance.

Since:

BlackBerry 10.0.0

virtual~FileSystemInfo ()

Destructor.

Since:

BlackBerry 10.0.0

Q_INVOKABLE qint64 availableFileSystemSpace (

Returns the amount of free space available on the file system for the provided path in bytes.

This method returns the user-accessible free space of the file system. The device may reserve a portion of the file system for its own use. Where possible, this method corrects for this reserved space and returns the amount of storage that is accessible to an application.

Example usage in C++
#include <bb/FileSystemInfo>

bool deviceHasSufficientFileSpace(qint64 dataSize, QString destinationFileSystem)
{
    bb::FileSystemInfo fileSystemInfo;

    qint64 freeSpace = fileSystemInfo.availableFileSystemSpace(destinationFileSystem);
    if (freeSpace == -1) {
        qWarning() << "Failed to get free space - " << fileSystemInfo.errorString()
                   << "(" << fileSystemInfo.error() << ")";
        return(false);
    }
    return(freeSpace > dataSize);
}
Example usage in QML
// QML plugin for libbb
import bb 1.0

import bb.cascades 1.0

Page {
    Container {
        // FileSystemInfo isn't a visible object so it must be wrapped
        // as an attached object.
        attachedObjects: [
            FileSystemInfo {
                id: fileSystemInfo
            }
        ]
        
        Button {
            text: "Save"
            onClicked: {
                var freeSpace = fileSystemInfo.availableFileSystemSpace(app.destinationFileSystem,
                                                                        app.dataSize);
                if (freeSpace == -1) {
                    console.log("Failed to get free space - " + fileSystemInfo.errorString()
                                + " (" + fileSystemInfo.error() + ")");
                } else {
                    save();
                }
            }
        }
        // Additional QML
    }
}
Parameters
path

A path to any existing file or directory within the file system being queried.

Return:

The user-accessible free space of the file system in bytes, or -1 in the event of an error. On error, call error() to identify the cause.

Since:

BlackBerry 10.0.0

Q_INVOKABLE int error ()

Returns the POSIX error code for the last API call on this object.

Example usage in C++
#include <bb/FileSystemInfo>

bool deviceHasSufficientFileSpace(qint64 dataSize, QString destinationFileSystem)
{
    bb::FileSystemInfo fileSystemInfo;

    qint64 freeSpace = fileSystemInfo.availableFileSystemSpace(destinationFileSystem);
    if (freeSpace == -1) {
        qWarning() << "Failed to get free space - " << fileSystemInfo.errorString()
                   << "(" << fileSystemInfo.error() << ")";
        return(false);
    }
    return(freeSpace > dataSize);
}
Example usage in QML
// QML plugin for libbb
import bb 1.0

import bb.cascades 1.0

Page {
    Container {
        // FileSystemInfo isn't a visible object so it must be wrapped
        // as an attached object.
        attachedObjects: [
            FileSystemInfo {
                id: fileSystemInfo
            }
        ]
        
        Button {
            text: "Save"
            onClicked: {
                var freeSpace = fileSystemInfo.availableFileSystemSpace(app.destinationFileSystem,
                                                                        app.dataSize);
                if (freeSpace == -1) {
                    console.log("Failed to get free space - " + fileSystemInfo.errorString()
                                + " (" + fileSystemInfo.error() + ")");
                } else {
                    save();
                }
            }
        }
        // Additional QML
    }
Return:

EOK if the last API call succeeded, the POSIX error code for the failure ( from errno.h ) otherwise.

Since:

BlackBerry 10.0.0

Q_INVOKABLE QString errorString ()

Returns a human-readable description of the POSIX error code returned by error().

This is the value produced by strerror(), from string.h.

Example usage in C++
#include <bb/FileSystemInfo>

bool deviceHasSufficientFileSpace(qint64 dataSize, QString destinationFileSystem)
{
    bb::FileSystemInfo fileSystemInfo;

    qint64 freeSpace = fileSystemInfo.availableFileSystemSpace(destinationFileSystem);
    if (freeSpace == -1) {
        qWarning() << "Failed to get free space - " << fileSystemInfo.errorString()
                   << "(" << fileSystemInfo.error() << ")";
        return(false);
    }
    return(freeSpace > dataSize);
}
Example usage in QML
// QML plugin for libbb
import bb 1.0

import bb.cascades 1.0

Page {
    Container {
        // FileSystemInfo isn't a visible object so it must be wrapped
        // as an attached object.
        attachedObjects: [
            FileSystemInfo {
                id: fileSystemInfo
            }
        ]
        
        Button {
            text: "Save"
            onClicked: {
                var freeSpace = fileSystemInfo.availableFileSystemSpace(app.destinationFileSystem,
                                                                        app.dataSize);
                if (freeSpace == -1) {
                    console.log("Failed to get free space - " + fileSystemInfo.errorString()
                                + " (" + fileSystemInfo.error() + ")");
                } else {
                    save();
                }
            }
        }
        // Additional QML
    }
Return:

A string describing the POSIX error code from error().

Since:

BlackBerry 10.0.0

Q_INVOKABLE qint64 fileSystemCapacity (

Returns the capacity of the file system for the provided path in bytes.

This method returns the user-accessible capacity of the file system. The device may reserve a portion of the file system for its own use. Where possible, this method corrects for this reserved space and returns the amount of storage that is accessible to an application.

Example usage in C++
#include <bb/FileSystemInfo>

const QString SD_MOUNT_POINT = ...;

qint64 getSDCardCapacity()
{
    FileSystemInfo fileSystemInfo;

    return(fileSystemInfo.fileSystemCapacity(SD_MOUNT_POINT));
}
Example usage in QML
// QML plugin for libbb
import bb 1.0

import bb.cascades 1.0

Page {
    Container {
        // FileSystemInfo isn't a visible object so it must be wrapped
        // as an attached object.
        attachedObjects: [
            FileSystemInfo {
                id: fileSystemInfo
            }
        ]
        
        Label {
            text: "SD Card Capacity " + fileSystemInfo.fileSystemCapacity(app.sdCardMountPoint());
        }
        // Additional QML
    }
Parameters
path

A path to any existing file or directory within the file system being queried.

Return:

The user-accessible capacity of the file system in bytes, or -1 in the event of an error. On error, call error() to identify the cause.

Since:

BlackBerry 10.0.0

Last modified: 2014-03-13

comments powered by Disqus