Mbed OS Reference
Loading...
Searching...
No Matches
LocalFileSystem Class Reference

A filesystem for accessing the local mbed Microcontroller USB disk drive. More...

#include <LocalFileSystem.h>

Inheritance diagram for LocalFileSystem:
FileSystemLike NonCopyable< LocalFileSystem > FileSystemHandle FileBase NonCopyable< FileSystemLike > NonCopyable< FileSystemHandle > NonCopyable< FileBase >

Public Member Functions

virtual int open (FileHandle **file, const char *path, int flags)
 Open a file on the filesystem. More...
 
virtual int open (DirHandle **dir, const char *name)
 Open a directory on the filesystem. More...
 
virtual int remove (const char *filename)
 Remove a file from the filesystem. More...
 
virtual int rename (const char *path, const char *newpath)
 Rename a file in the filesystem. More...
 
virtual int stat (const char *path, struct stat *st)
 Store information about the file in a stat structure. More...
 
virtual int mkdir (const char *path, mode_t mode)
 Create a directory in the filesystem. More...
 
virtual int statvfs (const char *path, struct statvfs *buf)
 Store information about the mounted filesystem in a statvfs structure. More...
 

Detailed Description

A filesystem for accessing the local mbed Microcontroller USB disk drive.

This allows programs to read and write files on the same disk drive that is used to program the mbed Microcontroller. Once created, the standard C file access functions are used to open, read and write files.

Note
Synchronization level: Thread safe

Example:

#include "mbed.h"
LocalFileSystem local("local"); // Create the local filesystem under the name "local"
int main() {
FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
fprintf(fp, "Hello World!");
fclose(fp);
remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
DIR *d = opendir("/local"); // Opens the root directory of the local file system
struct dirent *p;
while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
printf("%s\n", p->d_name); // to stdout.
}
closedir(d);
}
A filesystem for accessing the local mbed Microcontroller USB disk drive.
virtual int remove(const char *filename)
Remove a file from the filesystem.
char d_name[255+1]
Name of file.
Note
If the microcontroller program makes an access to the local drive, it will be marked as "removed" on the Host computer. This means it is no longer accessible from the Host Computer.

The drive will only re-appear when the microcontroller program exists. Note that if the program does not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!

Definition at line 106 of file LocalFileSystem.h.

Member Function Documentation

◆ open() [1/2]

virtual int open ( FileHandle **  file,
const char *  filename,
int  flags 
)
virtual

Open a file on the filesystem.

Parameters
fileDestination for the handle to a newly created file
filenameThe name of the file to open
flagsThe flags to open the file in, one of O_RDONLY, O_WRONLY, O_RDWR, bitwise or'd with one of O_CREAT, O_TRUNC, O_APPEND
Returns
0 on success, negative error code on failure

Implements FileSystemHandle.

◆ open() [2/2]

virtual int open ( DirHandle **  dir,
const char *  path 
)
virtual

Open a directory on the filesystem.

Parameters
dirDestination for the handle to the directory
pathName of the directory to open
Returns
0 on success, negative error code on failure

Reimplemented from FileSystemHandle.

◆ remove()

virtual int remove ( const char *  path)
virtual

Remove a file from the filesystem.

Parameters
pathThe name of the file to remove.
Returns
0 on success, negative error code on failure

Reimplemented from FileSystemHandle.

◆ rename()

virtual int rename ( const char *  path,
const char *  newpath 
)
virtualinherited

Rename a file in the filesystem.

Parameters
pathThe name of the file to rename.
newpathThe name to rename it to
Returns
0 on success, negative error code on failure

Reimplemented in FATFileSystem, FileSystem, LittleFileSystem, and LittleFileSystem2.

◆ stat()

virtual int stat ( const char *  path,
struct stat st 
)
virtualinherited

Store information about the file in a stat structure.

Parameters
pathThe name of the file to find information about
stThe stat buffer to write to
Returns
0 on success, negative error code on failure

Reimplemented in FATFileSystem, FileSystem, LittleFileSystem, and LittleFileSystem2.

◆ mkdir()

virtual int mkdir ( const char *  path,
mode_t  mode 
)
virtualinherited

Create a directory in the filesystem.

Parameters
pathThe name of the directory to create.
modeThe permissions with which to create the directory
Returns
0 on success, negative error code on failure

Reimplemented in FATFileSystem, FileSystem, LittleFileSystem, and LittleFileSystem2.

◆ statvfs()

virtual int statvfs ( const char *  path,
struct statvfs buf 
)
virtualinherited

Store information about the mounted filesystem in a statvfs structure.

Parameters
pathThe name of the file to find information about
bufThe stat buffer to write to
Returns
0 on success, negative error code on failure

Reimplemented in FATFileSystem, FileSystem, LittleFileSystem, and LittleFileSystem2.