#include <ctfilesystem2.h>
Public Member Functions | |
Constructors/Destructors | |
CTCardFS (const CTCard &c) | |
virtual | ~CTCardFS () |
Mounting and creating | |
These methods allow mounting/unmounting and formatting of a memory card. Mounting the card means to connect to the card thus making it's content available. Upon mount all information necessary to manage the medium is read from the card. | |
virtual CTError | mountMedium (const string &username="", const string &passwd="") |
virtual CTError | unmountMedium () |
virtual CTError | createMedium (unsigned int mediumSize, const string &mediumName, const string &userName, const string &passwd) |
Information about the medium | |
These method tell about the size of the medium, the number of free blocks etc. They do only work if the medium is mounted. | |
virtual int | blocks () |
virtual int | freeBlocks () |
virtual int | blockSize () const |
const CTSuperBlock & | superBlock () const |
bool | isReadOnly () const |
void | setReadOnly (bool b) |
Cache Management | |
These methods allow flushing and invalidating the data cache. This cache holds all data blocks of the card that have been read or written. The cache holds the data blocks as they are on the card, so when using encryption the cache will only hold encrypted blocks. This way the cache mechanism does not corrupt the security. | |
virtual int | flush (int maxb=0x800000) throw (class CTError) |
virtual void | purge () |
This class provides a file system on memory cards. If you want to access files and/or directories on such a file system you need the classes CTFile and CTDirectory.
For information about the Card File System itself please go to Card File System 1.0
|
This constructor is mainly used by derived classes to transform a basic CTCard object to a more special one. This allows opening a card as a CTCard object and then create e.g. a CTMemoryCard from this one. The source card will be immediately closed. The only thing you should do with it is to delete it. You should NOT use it any longer !!
|
|
|
|
All data of the file system is organized in data blocks. The size of such a block depends on the capacity of your memory card.
|
|
This method returns the size of a data block. This size depends on the capacity of your card. It is computed this way:
int i; int p; int l; int datasize;
// calculate data size // number of base blocks for superblock p=CTFS_SUPERBLOCK_LENGTH/CTFILESYSTEM_BASEBLOCKSIZE; if (CTFS_SUPERBLOCK_LENGTH % CTFILESYSTEM_BASEBLOCKSIZE) p++;
// calculate number of base blocks for FAT l=CTFILESYSTEM_FAT_LENGTH/CTFILESYSTEM_BASEBLOCKSIZE; if (CTFILESYSTEM_FAT_LENGTH % CTFILESYSTEM_BASEBLOCKSIZE) l++;
datasize=mediumsize-((p+l)*CTFILESYSTEM_BASEBLOCKSIZE);
// calculate appropriate block size _blockSize=datasize/253; // size smaller than base block size ? if (_blockSize<CTFILESYSTEM_BASEBLOCKSIZE) _blockSize=CTFILESYSTEM_BASEBLOCKSIZE; // is there a modulo ? i=_blockSize % CTFILESYSTEM_BASEBLOCKSIZE; if (i) { // make block big enough to be divideable by base block size _blockSize+=(CTFILESYSTEM_BASEBLOCKSIZE-i); }
// calculate block count (ignore modulo) _blocks=datasize/_blockSize;
|
|
Format a memory card for use by the Card File System. This method will create and write all data needed to manage a file system on it. If username and password are given then all data will be encrypted. If either of them is missing, then the card will not be in crypto mode (not recommended)
|
|
Flushes the cache. This means that all unwritten data will be written to the card. This method should be called every once in a while (as the CardFS daemon does) to protect your data against getting lost (maybe due to a failure in one of the programs using the Card File System).
|
|
This method tells you how many unused blocks there are. This method and blockSize() will help you to determine the number of free bytes on the card.
|
|
Currently this flag is ignored by libcardfs, but maybe later I will implement a write protection.
|
|
Connects the card and reads all information needed to manage the file system on it (CTSuperBlock, the FAT). If neither username nor passwd are given (or either one is empty) then no encryption is assumed. However, the file system stores a flag on the card (in the CTSuperBlock) to determine whether the data is encrypted and refuses to mount when in the case of missing username or password. This does not protect against reading raw data bytes from the card but it prevents this class from accidentally corrupting your data (in case of wrong or missing password).
|
|
Invalidate the cache. You should call this prior to unmounting the card if you don't want to committ changes to the card (Please remember that unmountMedium will flush the cache !)
|
|
Currently this flag is ignored by libcardfs, but maybe later I will implement a write protection.
|
|
The super block consists of the first blocks of the medium. It is never encrypted (except the userName, which is encrypted). This block holds some basic facts about the medium. Please refer to CTSuperBlock. The medium must already be mounted !
|
|
Unmounts the file system thus disconnecting the card physically. Before disconnecting the cache is flushed.
|