2008-01-07 09:09:04 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Author: Valient Gough <vgough@pobox.com>
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (c) 2004, Valient Gough
|
|
|
|
*
|
2012-10-03 07:12:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
2013-10-20 00:35:26 +02:00
|
|
|
* option) any later version.
|
2008-01-07 09:09:04 +01:00
|
|
|
*
|
2012-10-03 07:12:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
2008-01-07 09:09:04 +01:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2012-10-03 07:12:17 +02:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-01-07 09:09:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FileIO_incl_
|
|
|
|
#define _FileIO_incl_
|
|
|
|
|
2013-01-29 04:07:54 +01:00
|
|
|
#include "base/Interface.h"
|
|
|
|
#include "fs/encfs.h"
|
2008-01-07 09:09:04 +01:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
namespace encfs {
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
struct IORequest {
|
|
|
|
off_t offset;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
// amount of bytes to read/write.
|
|
|
|
int dataLen;
|
|
|
|
unsigned char *data;
|
2008-01-07 09:09:04 +01:00
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
IORequest();
|
2008-01-07 09:09:04 +01:00
|
|
|
};
|
|
|
|
|
2013-10-20 00:35:26 +02:00
|
|
|
inline IORequest::IORequest() : offset(0), dataLen(0), data(0) {}
|
|
|
|
|
|
|
|
class FileIO {
|
|
|
|
public:
|
|
|
|
FileIO();
|
|
|
|
virtual ~FileIO();
|
|
|
|
|
|
|
|
virtual Interface interface() const = 0;
|
|
|
|
|
|
|
|
// default implementation returns 1, meaning this is not block oriented.
|
|
|
|
virtual int blockSize() const;
|
|
|
|
|
|
|
|
virtual void setFileName(const char *fileName) = 0;
|
|
|
|
virtual const char *getFileName() const = 0;
|
|
|
|
|
|
|
|
// Not sure about this -- it is specific to CipherFileIO, but the
|
|
|
|
// alternative methods of exposing this interface aren't much nicer..
|
|
|
|
virtual bool setIV(uint64_t iv);
|
|
|
|
|
|
|
|
// open file for specified mode. There is no corresponding close, so a
|
|
|
|
// file is open until the FileIO interface is destroyed.
|
|
|
|
virtual int open(int flags) = 0;
|
|
|
|
|
|
|
|
// get filesystem attributes for a file
|
|
|
|
virtual int getAttr(struct stat *stbuf) const = 0;
|
|
|
|
virtual off_t getSize() const = 0;
|
|
|
|
|
|
|
|
virtual ssize_t read(const IORequest &req) const = 0;
|
|
|
|
virtual bool write(const IORequest &req) = 0;
|
|
|
|
|
|
|
|
virtual int truncate(off_t size) = 0;
|
|
|
|
|
|
|
|
virtual bool isWritable() const = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// not implemented..
|
|
|
|
FileIO(const FileIO &);
|
|
|
|
FileIO &operator=(const FileIO &);
|
2008-01-07 09:09:04 +01:00
|
|
|
};
|
|
|
|
|
2013-03-05 07:29:58 +01:00
|
|
|
} // namespace encfs
|
|
|
|
|
2008-01-07 09:09:04 +01:00
|
|
|
#endif
|