2015-06-29 15:02:08 +00:00
|
|
|
/*
|
|
|
|
* \brief File-operation utilities
|
|
|
|
* \author Christian Helmuth
|
|
|
|
* \date 2015-06-30
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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 _LIBC_FILE_H_
|
|
|
|
#define _LIBC_FILE_H_
|
|
|
|
|
|
|
|
/* Genode includes */
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
#include <base/log.h>
|
2015-06-29 15:02:08 +00:00
|
|
|
|
|
|
|
/* Genode-specific libc interfaces */
|
|
|
|
#include <libc-plugin/fd_alloc.h>
|
|
|
|
#include <libc-plugin/plugin_registry.h>
|
|
|
|
|
|
|
|
|
|
|
|
enum { INVALID_FD = -1 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find plugin responsible for the specified libc file descriptor
|
|
|
|
*
|
|
|
|
* \param func_name function name of the caller for printing an error message
|
|
|
|
*/
|
|
|
|
static inline Libc::File_descriptor *libc_fd_to_fd(int libc_fd, const char *func_name)
|
|
|
|
{
|
|
|
|
Libc::File_descriptor *fd =
|
|
|
|
Libc::file_descriptor_allocator()->find_by_libc_fd(libc_fd);
|
|
|
|
if (!fd)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("no plugin found for ", func_name, "(", libc_fd, ")");
|
2015-06-29 15:02:08 +00:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate body of wrapper function taking a file descriptor as first argument
|
|
|
|
*/
|
|
|
|
#define FD_FUNC_WRAPPER_GENERIC(result_stm, result_err_val, func_name, libc_fd, ...) \
|
|
|
|
{ \
|
|
|
|
File_descriptor *fd = libc_fd_to_fd(libc_fd, #func_name); \
|
|
|
|
if (!fd || !fd->plugin) { \
|
|
|
|
errno = EBADF; \
|
|
|
|
result_stm result_err_val; \
|
|
|
|
} else \
|
|
|
|
result_stm fd->plugin->func_name(fd, ##__VA_ARGS__ ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FD_FUNC_WRAPPER(func_name, libc_fd, ...) \
|
|
|
|
FD_FUNC_WRAPPER_GENERIC(return, INVALID_FD, func_name, libc_fd, ##__VA_ARGS__ )
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate body of wrapper function taking a path name as first argument
|
|
|
|
*/
|
|
|
|
#define FNAME_FUNC_WRAPPER_GENERIC(result_stm, func_name, path, ...) \
|
|
|
|
{ \
|
|
|
|
Plugin *plugin = plugin_registry()->get_plugin_for_##func_name(path, ##__VA_ARGS__); \
|
|
|
|
if (!plugin) { \
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("no plugin found for ", #func_name, "(\"", Genode::Cstring(path), "\")");\
|
2015-06-29 15:02:08 +00:00
|
|
|
errno = ENOSYS; \
|
|
|
|
result_stm -1; \
|
|
|
|
} else \
|
|
|
|
result_stm plugin->func_name(path, ##__VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FNAME_FUNC_WRAPPER(func_name, path, ...) \
|
|
|
|
FNAME_FUNC_WRAPPER_GENERIC(return, func_name, path, ##__VA_ARGS__ )
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _LIBC_FILE_H_ */
|