Miosix  2.01
miosix::DirectoryBase Class Reference

#include <file.h>

Inheritance diagram for miosix::DirectoryBase:
Collaboration diagram for miosix::DirectoryBase:

Public Member Functions

 DirectoryBase (intrusive_ref_ptr< FilesystemBase > parent)
 
virtual ssize_t write (const void *data, size_t len)
 
virtual ssize_t read (void *data, size_t len)
 
virtual off_t lseek (off_t pos, int whence)
 
virtual int fstat (struct stat *pstat) const
 
- Public Member Functions inherited from miosix::FileBase
 FileBase (intrusive_ref_ptr< FilesystemBase > parent)
 
virtual int isatty () const
 
virtual int fcntl (int cmd, int opt)
 
virtual int ioctl (int cmd, void *arg)
 
virtual int getdents (void *dp, int len)
 
const intrusive_ref_ptr< FilesystemBasegetParent () const
 
virtual ~FileBase ()
 

Static Protected Member Functions

static int addEntry (char **pos, char *end, int ino, char type, const StringPart &n)
 
static int addDefaultEntries (char **pos, int thisIno, int upIno)
 
static int addTerminatingEntry (char **pos, char *end)
 

Static Protected Attributes

static const int direntHeaderSizeNoPadding =offsetof(struct dirent,d_name)
 
static const int direntHeaderSize =(direntHeaderSizeNoPadding+3+3)/4*4
 
static const int minimumBufferSize =3*direntHeaderSize
 Minimum buffer accepted by getdents, two for . and .., plus terminating.
 

Additional Inherited Members

- Protected Member Functions inherited from miosix::IntrusiveRefCounted
 IntrusiveRefCounted ()
 
 IntrusiveRefCounted (const IntrusiveRefCounted &)
 
IntrusiveRefCountedoperator= (const IntrusiveRefCounted &)
 

Detailed Description

Directories are a special kind of files that implement the getdents() call Classes of this type are reference counted, must be allocated on the heap and managed through intrusive_ref_ptr<DirectoryBase>

Constructor & Destructor Documentation

miosix::DirectoryBase::DirectoryBase ( intrusive_ref_ptr< FilesystemBase parent)
inline

Constructor

Parameters
parentthe filesystem to which this file belongs

Member Function Documentation

int miosix::DirectoryBase::addDefaultEntries ( char **  pos,
int  thisIno,
int  upIno 
)
staticprotected

Helper function to add the default directory entries . and .. to a buffer

Parameters
posposition where to add the entry (four word aligned). Pointer is incremented. The caller is responsible to guarantee that there is at least space for 2*direntHeaderSize
thisInoinode number of .
upInodeinode number of ..
Returns
the number of bytes written
int miosix::DirectoryBase::addEntry ( char **  pos,
char *  end,
int  ino,
char  type,
const StringPart &  n 
)
staticprotected

Helper function to add a directory entry to a buffer

Parameters
posposition where to add the entry (four word aligned). Pointer is incremented.
endend of buffer (one char past the last), for bound checking
inoinode of file
typefile type
namefile name to append after the DirentHeader
Returns
the number of bytes written or -1 on failure (no space in buffer)
int miosix::DirectoryBase::addTerminatingEntry ( char **  pos,
char *  end 
)
staticprotected

Add an entry with d_reclen=0 which is used to terminate directory listing

Parameters
posposition where to add the entry (four word aligned). Pointer is incremented. The caller is responsible to guarantee that there is at least space for direntHeaderSize, including padding
endend of buffer (one char past the last), for bound checking
Returns
the number of bytes written or -1 on failure (no space in buffer)
int miosix::DirectoryBase::fstat ( struct stat *  pstat) const
virtual

Return file information.

Parameters
pstatpointer to stat struct
Returns
0 on success, or a negative number on failure

Implements miosix::FileBase.

off_t miosix::DirectoryBase::lseek ( off_t  pos,
int  whence 
)
virtual

Move file pointer, if the file supports random-access.

Parameters
posoffset to sum to the beginning of the file, current position or end of file, depending on whence
whenceSEEK_SET, SEEK_CUR or SEEK_END
Returns
the offset from the beginning of the file if the operation completed, or a negative number in case of errors

Implements miosix::FileBase.

ssize_t miosix::DirectoryBase::read ( void *  data,
size_t  len 
)
virtual

Read data from the file, if the file supports reading.

Parameters
databuffer to store read data
lenthe number of bytes to read
Returns
the number of read characters, or a negative number in case of errors

Implements miosix::FileBase.

ssize_t miosix::DirectoryBase::write ( const void *  data,
size_t  len 
)
virtual

Write data to the file, if the file supports writing.

Parameters
datathe data to write
lenthe number of bytes to write
Returns
the number of written characters, or a negative number in case of errors

Implements miosix::FileBase.

Member Data Documentation

const int miosix::DirectoryBase::direntHeaderSize =(direntHeaderSizeNoPadding+3+3)/4*4
staticprotected

Size of struct dirent including room for the "." and ".." string in d_name, including terminating \0 and padding for 4-word alignment. First +3: make room for '..\0', 3 bytes Second +3 and /4*4: four word alignment

const int miosix::DirectoryBase::direntHeaderSizeNoPadding =offsetof(struct dirent,d_name)
staticprotected

Size of struct dirent excluding d_name. That is, the size of d_ino, d_off, d_reclen and d_type. Notice that there are 4 bytes of padding between d_ino and d_off as d_off is a 64 bit number. Should be 19.


The documentation for this class was generated from the following files: