genode/repos/os/include/vfs/vfs_handle.h

97 lines
1.8 KiB
C
Raw Normal View History

/*
* \brief Representation of an open file
* \author Norman Feske
* \date 2011-02-17
*/
/*
* Copyright (C) 2011-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__VFS__VFS_HANDLE_H_
#define _INCLUDE__VFS__VFS_HANDLE_H_
#include <vfs/directory_service.h>
namespace Vfs{
class Vfs_handle;
class File_io_service;
}
class Vfs::Vfs_handle
{
private:
Directory_service &_ds;
File_io_service &_fs;
Genode::Allocator &_alloc;
int _status_flags;
file_size _seek = 0;
public:
/**
* Opaque handle context
*/
VFS: nonblocking interface The VFS library can be used in single-threaded or multi-threaded environments and depending on that, signals are handled by the same thread which uses the VFS library or possibly by a different thread. If a VFS plugin needs to block to wait for a signal, there is currently no way which works reliably in both environments. For this reason, this commit makes the interface of the VFS library nonblocking, similar to the File_system session interface. The most important changes are: - Directories are created and opened with the 'opendir()' function and the directory entries are read with the recently introduced 'queue_read()' and 'complete_read()' functions. - Symbolic links are created and opened with the 'openlink()' function and the link target is read with the 'queue_read()' and 'complete_read()' functions and written with the 'write()' function. - The 'write()' function does not wait for signals anymore. This can have the effect that data written by a VFS library user has not been processed by a file system server yet when the library user asks for the size of the file or closes it (both done with RPC functions at the file system server). For this reason, a user of the VFS library should request synchronization before calling 'stat()' or 'close()'. To make sure that a file system server has processed all write request packets which a client submitted before the synchronization request, synchronization is now requested at the file system server with a synchronization packet instead of an RPC function. Because of this change, the synchronization interface of the VFS library is now split into 'queue_sync()' and 'complete_sync()' functions. Fixes #2399
2017-08-15 20:51:53 +02:00
struct Context : List<Context>::Element { };
Context *context = nullptr;
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_ */