Kazuki Yamamoto / USBFileSystem

Dependents:   USBMSD_CDC_11U35test

Fork of USBFileSystem by Erik -

Embed: (wiki syntax)

« Back to documentation index

USBFileSystem Class Reference

USBFileSystem Class Reference

Class which combines FATFileSystem with USBMSD device. More...

#include <USBFileSystem.h>

Inherits FATFileSystem_ds, and USBMSD_ds.

Public Member Functions

 USBFileSystem (const char *n)
 Constructor for USBFileSystem.
void attachLocal (void(*function)(bool))
 Attach a function to be called when locally the filesystem is occupied/freed.
void attachUSB (void(*function)(bool))
 Attach a function to be called when USB occupies/frees the filesystem.
bool localSafe (void)
 Check if locally files are opened for write.
bool usbSafe (void)
 Check if via USB files files are being written.
void usbMode (int mode)
 Sets the USB mode.
virtual int remove (const char *filename)
 Removes a file path.
virtual int rename (const char *oldname, const char *newname)
 Renames a file.
virtual int format ()
 Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster.
virtual DirHandle * opendir (const char *name)
 Opens a directory on the filesystem.
virtual int mkdir (const char *name, mode_t mode)
 Creates a directory path.
virtual int mount ()
 Mounts the filesystem.
virtual int unmount ()
 Unmounts the filesystem.

Protected Member Functions

virtual FileHandle * open (const char *name, int flags)
 Opens a file on the filesystem.

Detailed Description

Class which combines FATFileSystem with USBMSD device.

The functions to be implemented by the child class are the same as those that have to be implemented when using FATFileSystem/USBMSD. However there are some caveats: _disk_status() and _disk_write MUST be named with the '_' in front of it. You are not allowed to have a function without the '_'. Those functions may not be inherited, but with this version of C++ I cannot prevent the child from doing so.

Next the size of a disk sector must be 512 bytes. This is because FATFileSystem only accepts that. If disk_size is not implemented this is done automatically.

What the library does is block write access locally when USB writes, and USB write access is blocked when with fopen a file is opened for write locally. This way they can't both write at the same time. Read access is not blocked.

The final issue to take into account is caching: FATFileSystem will not re-open a file if you read twice the same data from it. So if USBMSD changed it, it will not show up different. If you close the file and call fopen again it will work. The USBMSD part has the same issue, but worse. Windows at least will only load everything once! So if you open a file, and then change it manually, you will never find out until the device is disconnected. If the disk is write protected it will not tell you so. It will write/delete what you want, only when you reconnect the device will it show it didn't actually do anything!

See the program's wiki for more documentation!

Definition at line 56 of file USBFileSystem.h.


Constructor & Destructor Documentation

USBFileSystem ( const char *  n )

Constructor for USBFileSystem.

Parameters:
n- Name for the file system

Definition at line 5 of file USBFileSystem.cpp.


Member Function Documentation

void attachLocal ( void(*)(bool)  function )

Attach a function to be called when locally the filesystem is occupied/freed.

The function is called with 'true' as argument when it is freed, false when it is occupied

Parameters:
function- Function to be called, must have void as return type, and a single boolean argument

Definition at line 116 of file USBFileSystem.cpp.

void attachUSB ( void(*)(bool)  function )

Attach a function to be called when USB occupies/frees the filesystem.

The function is called with 'true' as argument when it is freed, false when it is occupied

Parameters:
function- Function to be called, must have void as return type, and a single boolean argument

Definition at line 120 of file USBFileSystem.cpp.

int format (  ) [virtual, inherited]

Formats a logical drive, FDISK artitioning rule, 512 bytes per cluster.

Definition at line 120 of file FATFileSystem.cpp.

bool localSafe ( void   )

Check if locally files are opened for write.

Returns:
- true if none are opened for write, false otherwise

Definition at line 52 of file USBFileSystem.cpp.

int mkdir ( const char *  name,
mode_t  mode 
) [virtual, inherited]

Creates a directory path.

Definition at line 138 of file FATFileSystem.cpp.

int mount (  ) [virtual, inherited]

Mounts the filesystem.

Definition at line 143 of file FATFileSystem.cpp.

FileHandle * open ( const char *  name,
int  flags 
) [protected, virtual]

Opens a file on the filesystem.

Reimplemented from FATFileSystem.

Definition at line 14 of file USBFileSystem.cpp.

DirHandle * opendir ( const char *  name ) [virtual, inherited]

Opens a directory on the filesystem.

Definition at line 129 of file FATFileSystem.cpp.

int remove ( const char *  filename ) [virtual, inherited]

Removes a file path.

Definition at line 102 of file FATFileSystem.cpp.

int rename ( const char *  oldname,
const char *  newname 
) [virtual, inherited]

Renames a file.

Definition at line 111 of file FATFileSystem.cpp.

int unmount (  ) [virtual, inherited]

Unmounts the filesystem.

Definition at line 148 of file FATFileSystem.cpp.

void usbMode ( int  mode )

Sets the USB mode.

Argument = 0: USB is write protected when not available. Argument = 1: USB is disconnected when not available (default).

Parameters:
mode- USB safety mode

Definition at line 130 of file USBFileSystem.cpp.

bool usbSafe ( void   )

Check if via USB files files are being written.

Returns:
- true if none are being written, false otherwise

Definition at line 56 of file USBFileSystem.cpp.