Miosix  2.0alpha1
miosix::FileDescriptorTable Class Reference

#include <file_access.h>

Public Member Functions

 FileDescriptorTable ()
 
 FileDescriptorTable (const FileDescriptorTable &rhs)
 
FileDescriptorTableoperator= (const FileDescriptorTable &rhs)
 
int open (const char *name, int flags, int mode)
 
int close (int fd)
 
void closeAll ()
 
ssize_t write (int fd, const void *data, size_t len)
 
ssize_t read (int fd, void *data, size_t len)
 
off_t lseek (int fd, off_t pos, int whence)
 
int fstat (int fd, struct stat *pstat) const
 
int isatty (int fd) const
 
int stat (const char *name, struct stat *pstat)
 
int lstat (const char *name, struct stat *pstat)
 
int fcntl (int fd, int cmd, int opt)
 
int ioctl (int fd, int cmd, void *arg)
 
int getdents (int fd, void *dp, int len)
 
int getcwd (char *buf, size_t len)
 
int chdir (const char *name)
 
int mkdir (const char *name, int mode)
 
int rmdir (const char *name)
 
int unlink (const char *name)
 
int rename (const char *oldName, const char *newName)
 
intrusive_ref_ptr< FileBasegetFile (int fd) const
 
 ~FileDescriptorTable ()
 

Detailed Description

This class maps file descriptors to file objects, allowing to perform file operations

Constructor & Destructor Documentation

miosix::FileDescriptorTable::FileDescriptorTable ( )

Constructor

miosix::FileDescriptorTable::FileDescriptorTable ( const FileDescriptorTable rhs)

Copy constructor

Parameters
rhsobject to copy from
miosix::FileDescriptorTable::~FileDescriptorTable ( )

Destructor

Member Function Documentation

int miosix::FileDescriptorTable::chdir ( const char *  name)

Change current directory

Parameters
pathnew current directory
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::close ( int  fd)

Close a file

Parameters
fdfile descriptor to close
Returns
0 on success or a negative number on failure
void miosix::FileDescriptorTable::closeAll ( )

Close all files

int miosix::FileDescriptorTable::fcntl ( int  fd,
int  cmd,
int  opt 
)
inline

Perform various operations on a file descriptor

Parameters
cmdspecifies the operation to perform
optoptional argument that some operation require
Returns
the exact return value depends on CMD, -1 is returned on error
int miosix::FileDescriptorTable::fstat ( int  fd,
struct stat pstat 
) const
inline

Return file information.

Parameters
pstatpointer to stat struct
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::getcwd ( char *  buf,
size_t  len 
)

Return current directory

Parameters
bufthe current directory is stored here
lenbuffer length, if it is not big enough, ERANGE is returned
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::getdents ( int  fd,
void *  dp,
int  len 
)
inline

List directory content

Parameters
dpdp pointer to a memory buffer where one or more struct dirent will be placed. dp must be four words aligned.
lenmemory buffer size.
Returns
the number of bytes read on success, or a negative number on failure.
intrusive_ref_ptr<FileBase> miosix::FileDescriptorTable::getFile ( int  fd) const
inline

Retrieves an entry in the file descriptor table

Parameters
fdfile descriptor, index into the table
Returns
a refcounted poiter to the file at the desired entry (which may be empty), or an empty refcounted pointer if the index is out of bounds
int miosix::FileDescriptorTable::ioctl ( int  fd,
int  cmd,
void *  arg 
)
inline

Perform various operations on a file descriptor

Parameters
cmdspecifies the operation to perform
argoptional argument that some operation require
Returns
the exact return value depends on CMD, -1 is returned on error
int miosix::FileDescriptorTable::isatty ( int  fd) const
inline

Check whether the file refers to a terminal.

Returns
1 if it is a terminal, 0 if it is not, or a negative number in case of errors
off_t miosix::FileDescriptorTable::lseek ( int  fd,
off_t  pos,
int  whence 
)
inline

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
int miosix::FileDescriptorTable::lstat ( const char *  name,
struct stat pstat 
)
inline

Return file information, does not follow last symlink

Parameters
pathfile to stat
pstatpointer to stat struct
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::mkdir ( const char *  name,
int  mode 
)

Create a directory

Parameters
namedirectory to create
modedirectory permissions
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::open ( const char *  name,
int  flags,
int  mode 
)

Open a file

Parameters
namefile name
flagsfile open mode
modeallows to set file permissions
Returns
a file descriptor, or a negative number on error
FileDescriptorTable & miosix::FileDescriptorTable::operator= ( const FileDescriptorTable rhs)

Operator=

Parameters
rhsobject to copy from
Returns
*this
ssize_t miosix::FileDescriptorTable::read ( int  fd,
void *  data,
size_t  len 
)
inline

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
int miosix::FileDescriptorTable::rename ( const char *  oldName,
const char *  newName 
)

Rename a file or directory

Parameters
oldNameold file name
newNamenew file name
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::rmdir ( const char *  name)

Remove a directory if empty

Parameters
namedirectory to create
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::stat ( const char *  name,
struct stat *  pstat 
)
inline

Return file information, follows last symlink

Parameters
pathfile to stat
pstatpointer to stat struct
Returns
0 on success, or a negative number on failure
int miosix::FileDescriptorTable::unlink ( const char *  name)

Remove a file or directory

Parameters
namefile or directory to remove
Returns
0 on success, or a negative number on failure
ssize_t miosix::FileDescriptorTable::write ( int  fd,
const void *  data,
size_t  len 
)
inline

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

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