aegis::p_file Class Reference

A single file in a protected store. More...

#include <aegis_storage.h>

List of all members.

Public Member Functions

virtual ~p_file ()
 Destructor.
virtual bool p_open (int flags)
 Open file.
virtual ssize_t p_read (foff_t at, RAWDATA_PTR data, size_t len)
 Read data from a file.
virtual ssize_t p_write (foff_t at, const RAWDATA_PTR data, size_t len)
 Write data to a file.
virtual int p_trunc (foff_t at)
 Truncate the file.
virtual void p_close ()
 Close the file.
bool is_open ()
 Is the file currently open.
virtual int p_stat (struct stat *st)
 Get file status.
virtual const char * digest ()
 Get the digest of the file.
const char * name ()
 The name shown to outside.
storageowner ()
 Return a pointer to the owning pstore.
virtual int p_rename (const char *new_name)
 Rename the file.
virtual int p_chmod (mode_t flags)
 Change mode flags.
virtual int p_chown (uid_t uid, gid_t gid)
 Change ownership.
virtual int p_utime (struct utimbuf *ntime)
 Change access times.
void p_rollback (void)
 Forget pending changes.

Friends

class storage
class pe_file
class storage_lock


Detailed Description

A single file in a protected store.

Implements the usual POSIX semantics of open, close, read and write.


Constructor & Destructor Documentation

virtual aegis::p_file::~p_file (  )  [virtual]

Destructor.

Notice that the constructor of this class is private, i.e. a p_file instance can only be created by function storage::member.


Member Function Documentation

virtual bool aegis::p_file::p_open ( int  flags  )  [virtual]

Open file.

Parameters:
flags (in) as in man(2) open, flags plus O_RECOVER
Returns:
true if the file could be opened/created * For opening a file for writing in a signed store one must have the storage token. For opening a file in any way in an encrypted store one must have the storage token.
Opening of a file may fail because of the protection was violated. For instance the file contents didn't match its stored hash (it has been tampered) or the caller doesn't have the required credentials to open the file for writing or to decrypt and encrypted file. In all these cases the errno will be set to EACCES.

virtual ssize_t aegis::p_file::p_read ( foff_t  at,
RAWDATA_PTR  data,
size_t  len 
) [virtual]

Read data from a file.

Parameters:
at (in) The offset from which to read
data (in) The buffer to copy read data
len (in) The number of bytes to read
Returns:
The number of bytes actually read. Can be smaller than the given len if an EOF is detected.

virtual ssize_t aegis::p_file::p_write ( foff_t  at,
const RAWDATA_PTR  data,
size_t  len 
) [virtual]

Write data to a file.

Parameters:
at (in) The offset to which to write
data (in) A pointer to the buffer to write from
len (in) Number of bytes to write
Returns:
The number of bytes actually written. Can be smaller than the given len if the filesystem is full.

virtual int aegis::p_file::p_trunc ( foff_t  at  )  [virtual]

Truncate the file.

Parameters:
at (in) The new size of the file
Returns:
0 on success, otherwise -1. Use errno to find out the actual error condition.

virtual void aegis::p_file::p_close (  )  [virtual]

Close the file.

The contents of the file are flushed to the disk and if it was opened with O_CREAT or O_TRUNC, its size is set to the last written byte offset. Also a O_RDWR file grows if data was written beoynd its original size.

bool aegis::p_file::is_open (  ) 

Is the file currently open.

Returns:
true if it is, false otherwise
Attempts to read or write into a non-open file return and error and errno is set to EBADF.

virtual int aegis::p_file::p_stat ( struct stat *  st  )  [virtual]

Get file status.

Parameters:
st (in,out) A pointer to the status buffer
Returns:
0, on success, -1 otherwise. Errno is set. * For reading the attributes of a file in an encrypted store one must have the storage token.

virtual const char* aegis::p_file::digest (  )  [virtual]

Get the digest of the file.

Returns:
A base64 encoded hash computed of the current contents of the file, terminated with a NUL.

const char* aegis::p_file::name (  ) 

The name shown to outside.

Returns:
The public name, not necessarily the place where the actual contents are stored

storage* aegis::p_file::owner (  ) 

Return a pointer to the owning pstore.

Returns:
A pointer to the pstore this file belongs to

virtual int aegis::p_file::p_rename ( const char *  new_name  )  [virtual]

Rename the file.

Parameters:
new_name (in) The new name
Returns:
0 on success, -1 otherwise. Errno is set.

virtual int aegis::p_file::p_chmod ( mode_t  flags  )  [virtual]

Change mode flags.

Parameters:
flags (in) new value of mode flags
Returns:
0 on success, -1 otherwise

virtual int aegis::p_file::p_chown ( uid_t  uid,
gid_t  gid 
) [virtual]

Change ownership.

Parameters:
uid (in) new file owner uid
gid (in) new group owner gid
Returns:
0 on success, -1 otherwise

virtual int aegis::p_file::p_utime ( struct utimbuf *  ntime  )  [virtual]

Change access times.

Parameters:
ntime (in) new access and modification times
Returns:
0 on success, -1 otherwise

void aegis::p_file::p_rollback ( void   ) 

Forget pending changes.

This function only has effect if the called instance is opened for writing. It changes the open mode as read only to prevent committing any changes in the protected store when the file is closed. Any changes already made will not be rolled back in the current implementation, however. The main use of this function is to discard pending changes when a file is removed from the storage while it was still open.


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

Generated on Sat Jun 30 13:18:51 2012 for Aegis Crypto by  doxygen 1.5.6