2014-04-07 14:15:40 +00:00
|
|
|
/*
|
|
|
|
* \brief Representation of an open file
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2011-02-17
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2011-2017 Genode Labs GmbH
|
2014-04-07 14:15:40 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-04-07 14:15:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INCLUDE__VFS__VFS_HANDLE_H_
|
|
|
|
#define _INCLUDE__VFS__VFS_HANDLE_H_
|
|
|
|
|
|
|
|
#include <vfs/directory_service.h>
|
|
|
|
|
2017-02-01 20:07:14 +00:00
|
|
|
namespace Vfs{
|
|
|
|
class Vfs_handle;
|
|
|
|
class File_io_service;
|
|
|
|
}
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Vfs::Vfs_handle
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
Directory_service &_ds;
|
|
|
|
File_io_service &_fs;
|
2016-03-30 13:24:19 +00:00
|
|
|
Genode::Allocator &_alloc;
|
2014-04-07 14:15:40 +00:00
|
|
|
int _status_flags;
|
2016-03-30 13:24:19 +00:00
|
|
|
file_size _seek = 0;
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-02-01 20:07:14 +00:00
|
|
|
/**
|
|
|
|
* Opaque handle context
|
|
|
|
*/
|
2017-08-15 18:51:53 +00:00
|
|
|
struct Context : List<Context>::Element { };
|
2017-02-01 20:07:14 +00:00
|
|
|
|
|
|
|
Context *context = nullptr;
|
|
|
|
|
2015-01-27 16:04:52 +00:00
|
|
|
struct Guard
|
|
|
|
{
|
|
|
|
Vfs_handle *handle;
|
|
|
|
|
|
|
|
Guard(Vfs_handle *handle) : handle(handle) { }
|
|
|
|
|
|
|
|
~Guard()
|
|
|
|
{
|
|
|
|
if (handle)
|
2016-03-30 13:24:19 +00:00
|
|
|
handle->_ds.close(handle);
|
2015-01-27 16:04:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
enum { STATUS_RDONLY = 0, STATUS_WRONLY = 1, STATUS_RDWR = 2 };
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
Vfs_handle(Directory_service &ds,
|
|
|
|
File_io_service &fs,
|
|
|
|
Genode::Allocator &alloc,
|
|
|
|
int status_flags)
|
2014-04-07 14:15:40 +00:00
|
|
|
:
|
2016-03-30 13:24:19 +00:00
|
|
|
_ds(ds), _fs(fs),
|
|
|
|
_alloc(alloc),
|
|
|
|
_status_flags(status_flags)
|
2014-04-07 14:15:40 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~Vfs_handle() { }
|
|
|
|
|
|
|
|
Directory_service &ds() { return _ds; }
|
|
|
|
File_io_service &fs() { return _fs; }
|
2016-03-30 13:24:19 +00:00
|
|
|
Allocator &alloc() { return _alloc; }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
int status_flags() const { return _status_flags; }
|
|
|
|
|
2015-11-05 10:07:19 +00:00
|
|
|
void status_flags(int flags) { _status_flags = flags; }
|
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
/**
|
|
|
|
* Return seek offset in bytes
|
|
|
|
*/
|
2014-09-09 12:32:31 +00:00
|
|
|
file_size seek() const { return _seek; }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set seek offset in bytes
|
|
|
|
*/
|
2014-09-09 12:32:31 +00:00
|
|
|
void seek(file_offset seek) { _seek = seek; }
|
2014-04-07 14:15:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Advance seek offset by 'incr' bytes
|
|
|
|
*/
|
2014-09-09 12:32:31 +00:00
|
|
|
void advance_seek(file_size incr) { _seek += incr; }
|
2014-04-07 14:15:40 +00:00
|
|
|
};
|
|
|
|
|
2016-03-30 13:24:19 +00:00
|
|
|
|
2014-04-07 14:15:40 +00:00
|
|
|
#endif /* _INCLUDE__VFS__VFS_HANDLE_H_ */
|