Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

CTCardFS Class Reference
[Low Level Card File System]

Provides a file system on memory cards. More...

#include <ctfilesystem2.h>

List of all members.

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 CTSuperBlocksuperBlock () 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 ()


Detailed Description

Provides a file system on memory cards.

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

Author:
Martin Preuss<martin@libchipcard.de>


Constructor & Destructor Documentation

CTCardFS::CTCardFS const CTCard c  ) 
 

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 !!

Parameters:
c reference to the CTCard object to be transformed
Author:
Martin Preuss<martin@libchipcard.de>

virtual CTCardFS::~CTCardFS  )  [virtual]
 


Member Function Documentation

virtual int CTCardFS::blocks  )  [inline, virtual]
 

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.

Returns:
number of blocks on this card
Author:
Martin Preuss<martin@libchipcard.de>

virtual int CTCardFS::blockSize  )  const [inline, virtual]
 

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;

 
Author:
Martin Preuss<martin@libchipcard.de>
Returns:
block size in bytes

virtual CTError CTCardFS::createMedium unsigned int  mediumSize,
const string &  mediumName,
const string &  userName,
const string &  passwd
[virtual]
 

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)
Note: This method does not leave the medium mounted !

Author:
Martin Preuss<martin@libchipcard.de>
Parameters:
mediumSize capacity of the card in bytes
mediumName assigns a name to the medium (up to 16 chars)
userName used for encryption, see introduction
passwd used for encryption

virtual int CTCardFS::flush int  maxb = 0x800000  )  throw (class CTError) [inline, virtual]
 

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).

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
number of blocks flushed (0 if none, -1 on error)
Parameters:
maxb number of blocks to flush. Flushing the whole cache can take up to a minute or even longer, so if you just want to flush some blocks of the cache (like the CardFS daemon) without being busy and unresponsive for such a long time you can give the number of blocks to write (8 is a fair value). However, when omitted this number defaults to a value high enough to flush all blocks.

virtual int CTCardFS::freeBlocks  )  [inline, virtual]
 

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.

Returns:
number of unused blocks
Author:
Martin Preuss<martin@libchipcard.de>

bool CTCardFS::isReadOnly  )  const [inline]
 

Currently this flag is ignored by libcardfs, but maybe later I will implement a write protection.

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
true if the medium is write protected

virtual CTError CTCardFS::mountMedium const string &  username = "",
const string &  passwd = ""
[virtual]
 

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).

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
error object (call isOk() on it to see if there was an error)
Parameters:
username name of the owner of the card. This name is given upon creation of the file system on the card and cannot be altered.
passwd the password used for en-/decryption.

virtual void CTCardFS::purge  )  [inline, virtual]
 

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 !)

Author:
Martin Preuss<martin@libchipcard.de>

void CTCardFS::setReadOnly bool  b  )  [inline]
 

Currently this flag is ignored by libcardfs, but maybe later I will implement a write protection.

Author:
Martin Preuss<martin@libchipcard.de>
Parameters:
b true if the medium shall be write protected

const CTSuperBlock& CTCardFS::superBlock  )  const [inline]
 

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 !

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
const reference to the superblock of this medium.

virtual CTError CTCardFS::unmountMedium  )  [inline, virtual]
 

Unmounts the file system thus disconnecting the card physically. Before disconnecting the cache is flushed.

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
error object (call isOk() on it to see if there was an error)


The documentation for this class was generated from the following file:
Generated on Mon Jun 6 18:17:40 2005 for libchipcard by  doxygen 1.4.2