Help functions for Storage related things.
More...
#include <StorageHelper.h>
|
static int | loopDeviceAssociate (int fileFd, std::string *loopDevPath) |
| Associates a give file descriptor with a loop device.
|
|
static int | openLoopDevice (std::string *loopDevice) |
| Attempts to open an available loop device.
|
|
static bool | attachFileToLoopDevice (int loopFd, int fileFd) |
| Attempts to attach the file to the loop device.
|
|
static int | attachLoopDevice (const std::string &sourceFile, std::string *loopDevice) |
| Attaches the given file to an available loop device.
|
|
static bool | createFileIfNeeded (const std::string &filePath, const size_t storageSize, const uid_t userId, const std::string &fileSystem) |
| Checks if file exists, if yes return true, if not try to create it. If success return true, if file don't exist and cannot be created return false.
|
|
static void | cleanMountLostAndFound (const std::string &mountPoint, const std::string &logTag) |
| Logs and deletes any files found in the lost+found directory of the mount point.
|
|
static std::string | getLoopDevice (const std::string &backingFile) |
| Get the loop device for a given backing file.
|
|
static int | getMountOptions (const std::list< std::string > &mountOptions) |
|
static bool | rmdirRecursive (int dirFd, const std::string &path) |
| Removes a directory and all it's contents.
|
|
static bool | rmdirContents (int dirFd, const std::string &path) |
| Removes the contents of a directory but leave the actual directory in place.
|
|
static bool | deleteRecursive (int dirfd, int depth) |
| Recursive function that deletes everything within the supplied directory (as a descriptor).
|
|
Help functions for Storage related things.
All low level help functions that doesn't rely on current state
◆ attachFileToLoopDevice()
bool StorageHelper::attachFileToLoopDevice |
( |
int |
loopFd, |
|
|
int |
fileFd |
|
) |
| |
|
static |
Attempts to attach the file to the loop device.
- Parameters
-
[in] | loopFd | An open file descriptor to the loop device |
[in] | fileFd | An open file descriptor that should be associate with the loop device. |
- Returns
- on success a positive file desccriptor corresponding to a free loop device, -1 on error.
◆ attachLoopDevice()
int StorageHelper::attachLoopDevice |
( |
const std::string & |
sourceFile, |
|
|
std::string * |
loopDevice |
|
) |
| |
|
static |
Attaches the given file to an available loop device.
- Parameters
-
[in] | sourceFile | The path to the image file. |
[out] | loopDevice | The path to the loop device that was attached. |
- Returns
- the file descriptor to the loop device if attached, otherwise -1.
◆ cleanMountLostAndFound()
void StorageHelper::cleanMountLostAndFound |
( |
const std::string & |
mountPoint, |
|
|
const std::string & |
logTag |
|
) |
| |
|
static |
Logs and deletes any files found in the lost+found directory of the mount point.
We should be clearing the lost+found to avoid cruft building up and taking all the space in the loop mount.
- Parameters
-
[in] | mountPoint | The absolute path to the mounted device, NOT the the location of the lost+found dir. |
[in] | logTag | If not empty then a log warning message will be printed containing the name of the file that was deleted and referencing the the string in logTag. |
◆ createFileIfNeeded()
bool StorageHelper::createFileIfNeeded |
( |
const std::string & |
filePath, |
|
|
const size_t |
storageSize, |
|
|
const uid_t |
userId, |
|
|
const std::string & |
fileSystem |
|
) |
| |
|
static |
Checks if file exists, if yes return true, if not try to create it. If success return true, if file don't exist and cannot be created return false.
- Parameters
-
[in] | filePath | Path to the file that should exist after this function exits |
[in] | storageSize | Size of the created image file (in bytes) |
[in] | userId | The expected user id set in the xattr of the image file |
[in] | fileSystem | Filesystem of created image file |
◆ deleteRecursive()
bool StorageHelper::deleteRecursive |
( |
int |
dirfd, |
|
|
int |
availDepth |
|
) |
| |
|
static |
Recursive function that deletes everything within the supplied directory (as a descriptor).
- Parameters
-
[in] | dirFd | If specified the path should be relative to to this directory. |
[in] | availDepth | Maximal depth of recursion |
- Returns
- true on success, false on failure.
◆ getLoopDevice()
std::string StorageHelper::getLoopDevice |
( |
const std::string & |
backingFile | ) |
|
|
static |
Get the loop device for a given backing file.
- Parameters
-
[in] | backingFile | Path of backing file. |
- Returns
- on success a string containing the name of the loop device, empty string on error.
◆ loopDeviceAssociate()
int StorageHelper::loopDeviceAssociate |
( |
int |
fileFd, |
|
|
std::string * |
loopDevPath |
|
) |
| |
|
static |
Associates a give file descriptor with a loop device.
First the function attempts to get a free loop device, if that succeeds it attaches the supplied file descriptor to it and returns an fd to the loop device and (optionally) writes the path to the loop device in the loopDevPath string.
- Parameters
-
[in] | fileFd | An open file descriptor to associate with the loop device. |
[out] | loopDevPath | If not null, the method will write the path to the loop device dev node into the string |
- Returns
- on success returns the open file descriptor to the loop device associated with the file, on failure -1.
◆ openLoopDevice()
int StorageHelper::openLoopDevice |
( |
std::string * |
loopDevice | ) |
|
|
static |
Attempts to open an available loop device.
WARNING this method requires sudo
- Parameters
-
[out] | loopDevice | Loop device name |
- Returns
- on success a positive file descriptor corresponding to a free loop device, -1 on error.
◆ rmdirContents()
bool StorageHelper::rmdirContents |
( |
int |
dirFd, |
|
|
const std::string & |
path |
|
) |
| |
|
static |
Removes the contents of a directory but leave the actual directory in place.
This is equivalent to the 'rm -rf <dir>/ *' command.
If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirFd, if dirFd is not supplied then it's relative to the cwd.
- Warning
- This function only supports deleting directories with contents that are less than 128 levels deep, this is to avoid running out of file descriptors.
- Parameters
-
[in] | dirFd | If specified the path should be relative to to this directory. |
[in] | path | The path to the directory to create. |
- Returns
- true on success, false on failure.
This is equivalent to the 'cd <dir>; rm -rf *' command.
If the pathname given in path is relative, then it is interpreted relative to the directory referred to by the file descriptor dirFd, if dirFd is not supplied then it's relative to the cwd.
- Warning
- This function only supports deleting directories with contents that are less than 128 levels deep, this is to avoid running out of file descriptors.
- Parameters
-
[in] | dirFd | If specified the path should be relative to to this directory. |
[in] | path | The path to the directory to create. |
- Returns
- true on success, false on failure.
◆ rmdirRecursive()
bool StorageHelper::rmdirRecursive |
( |
int |
dirFd, |
|
|
const std::string & |
path |
|
) |
| |
|
static |
Removes a directory and all it's contents.
This is equivalent to the 'rm -rf <dir>' command.
If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirFd, if dirFd is not supplied then it's relative to the cwd.
- Warning
- This function only supports deleting directories with contents that are less than 128 levels deep, this is to avoid running out of file descriptors.
- Parameters
-
[in] | dirFd | If specified the path should be relative to to this directory. |
[in] | path | The path to the directory to create. |
- Returns
- true on success, false on failure.
This is equivalent to the 'rm -rf' command.
If the pathname given in pathname is relative, then it is interpreted relative to the directory referred to by the file descriptor dirFd, if dirFd is not supplied then it's relative to the cwd.
- Warning
- This function only supports deleting directories with contents that are less than 128 levels deep, this is to avoid running out of file descriptors.
- Parameters
-
[in] | dirFd | If specified the path should be relative to to this directory. |
[in] | path | The path to the directory to create. |
- Returns
- true on success, false on failure.
The documentation for this class was generated from the following files:
- rdkPlugins/Storage/source/StorageHelper.h
- rdkPlugins/Storage/source/StorageHelper.cpp