genode/repos/os/include/vfs/vfs_handle.h
Emery Hemingway 82a7799638 lib/vfs: pass handle allocator to open(...)
Opening a VFS handle previously involved allocating from the global heap
at each VFS file system. By amending open with an allocator argument,
dynamic allocation can be partitioned.

A new close method is used to deallocate open handles.

Issue #1751
Issue #1891
2016-04-11 12:56:54 +02:00

88 lines
1.7 KiB
C++

/*
* \brief Representation of an open file
* \author Norman Feske
* \date 2011-02-17
*/
/*
* Copyright (C) 2011-2016 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__VFS__VFS_HANDLE_H_
#define _INCLUDE__VFS__VFS_HANDLE_H_
#include <vfs/file_io_service.h>
#include <vfs/directory_service.h>
namespace Vfs { class Vfs_handle; }
class Vfs::Vfs_handle
{
private:
Directory_service &_ds;
File_io_service &_fs;
Genode::Allocator &_alloc;
int _status_flags;
file_size _seek = 0;
public:
struct Guard
{
Vfs_handle *handle;
Guard(Vfs_handle *handle) : handle(handle) { }
~Guard()
{
if (handle)
handle->_ds.close(handle);
}
};
enum { STATUS_RDONLY = 0, STATUS_WRONLY = 1, STATUS_RDWR = 2 };
Vfs_handle(Directory_service &ds,
File_io_service &fs,
Genode::Allocator &alloc,
int status_flags)
:
_ds(ds), _fs(fs),
_alloc(alloc),
_status_flags(status_flags)
{ }
virtual ~Vfs_handle() { }
Directory_service &ds() { return _ds; }
File_io_service &fs() { return _fs; }
Allocator &alloc() { return _alloc; }
int status_flags() const { return _status_flags; }
void status_flags(int flags) { _status_flags = flags; }
/**
* Return seek offset in bytes
*/
file_size seek() const { return _seek; }
/**
* Set seek offset in bytes
*/
void seek(file_offset seek) { _seek = seek; }
/**
* Advance seek offset by 'incr' bytes
*/
void advance_seek(file_size incr) { _seek += incr; }
};
#endif /* _INCLUDE__VFS__VFS_HANDLE_H_ */