Commit Graph

75 Commits

Author SHA1 Message Date
Christian Prochaska 6505ce47ae libc vfs plugin: report non-zero link count in 'stat()'
Fixes #3739
2020-04-28 11:40:58 +02:00
Ehmry - c51b4b5742 New VFS plugin for emulating POSIX pipes
Add a new plugin for creating pipes between pairs of VFS handles. It is
intended to replace the libc_pipe plugin, one of the last remaining libc
plugins.

In contrast to the libc_pipe plugin, this plugin defers cross-handle
notification until I/O signal handling rather than block and unblock
readers using a semaphore. This is a performance regression in the case
of multiple threads blocking on a pipe, but shall be an intermediate
mechanism pending renovations within the libc VFS and threading layers.
As a side effect, threads blocked on a pipe might not be resumed until
the main thread suspends and dispatches I/O signals.

The "test-libc_pipe" test has been adjusted to use the VFS pipe plugin
and tests both local pipes and pipes hosted remotely in the VFS server.

Merge adaptations (such as EOF handling, adjustment to VFS/libc
interface changes) by Norman Feske.

Fix #2303
2019-11-19 14:54:13 +01:00
Norman Feske fab2fc874f libc: write loop for continuous files
This patch improves the libc's write operation to iterate on partial
writes to continuous files until the original write count is reached.
The split of large write operations into small partial writes as
dictated by the VFS infrastructure (e.g., constained by I/O buffer
sizes) becomes invisible to the libc-using application.

Issue #3507
Issue #2303
2019-11-19 14:54:04 +01:00
Norman Feske 7ac32ea60c libc: support for ioctls via ioctl directory
This patch introduces a new scheme of handling ioctl operations that
maps ioctls to pseudo-file accesses, similar to how the libc maps socket
calls to socket-fs operations.

A device file can be accompanied with a (hidden) directory that is named
after the device file and hosts pseudo files for triggering the various
device operations. For example, for accessing a terminal, the directory
structure looks like this:

  /dev/terminal
  /dev/.terminal/info

The 'info' file contains device information in XML format. The type of
the XML node corresponds to the device type. E.g., If the libc receives
a 'TIOCGWINSZ' ioctl for /dev/terminal, it reads the content of
/dev/.terminal/info to obtain the terminal-size information. In this
case, the 'info' file looks as follows:

  <terminal rows="25" columns="80/>

Following this scheme, VFS plugins can support ioctl operations by
providing an ioctl directory in addition to the actual device file.

Internally, the mechanism uses the 'os/vfs.h' API to access pseudo
files. Hence, we need to propagate the Vfs::Env to 'vfs_plugin.cc' to
create an instance of a 'Directory' for the root for the VFS.

Issue #3519
2019-11-19 14:39:09 +01:00
Norman Feske 5ab1505d43 file system: enhanced file status info
This patch extends the 'File_system::Status',
'File_system::Directory_entry', and the related 'Vfs' types with
the following additional information:

- Distinction between continuous and transactional files (Node_type)
  (issue #3507)
- Readable, writeable, and executable attributes (Node_rwx),
  replacing the former 'mode' bits
  (issue #3030)

The types 'Node_rwx', 'Node_type' are defined twice,
once for the VFS (vfs/types.h) and once for the 'File_system'
session (file_system_session/file_system_session.h).
Similarly, there is a direct correspondance between
'Vfs::Directory_service::Dirent' and 'File_system::Directory_entry'.

This duplication of types follows the existing pattern of keeping the
VFS and file-system session independent from each other.
2019-11-19 14:23:56 +01:00
Christian Helmuth 732215a83f libc: limit fcntl(F_SETFL) to file-status flags
This fixes unintended (and unpermitted) changes of O_ACCMODE bits.
2019-11-19 14:23:55 +01:00
Norman Feske 979d823d85 libc: make mtime update configurable
By specifying <libc update_mtime="no"...>, the modification-time update
on VFS-sync operations (as issued whenever a written file is closed)
can explicitly be disabled.

Issue #1784
2019-11-19 14:19:34 +01:00
Josef Söntgen 180f9e6384 libc: handle modified files
Issue #1784.
2019-11-19 14:17:30 +01:00
Josef Söntgen d0bf6d2b52 libc: add modification time
Issue #1784.
2019-11-19 14:17:30 +01:00
Norman Feske c8b7710e5d libc: improve dup/dup2 in vfs_plugin
This patch replaces the naive dup2 implementation (that merely
duplicated the context pointer) by the replication of the original
FD state by re-opening the same file with the same flags and seek
position. This prevents a potential double release of the VFS handle
(the FD context). It also implements 'dup'.

Fixes #3505
Fixes #3477
2019-11-19 14:10:55 +01:00
Norman Feske 648bcd1505 libc: unify use of namespaces
This patch unifies the patterns of using the 'Genode' and 'Libc'
namespaces.

Types defined in the 'internal/' headers reside in the 'Libc'
namespace. The code in the headers does not need to use the
'Libc::' prefix.

Compilation units import the 'Libc' namespace after the definition of
local types. Local types reside in the 'Libc' namespace (and should
eventually move to an 'internal/' header).

Since the 'Libc' namespace imports the 'Genode' namespace, there is
no need to use the 'Genode::' prefix. Consequently, code in the
compilation units rarely need to qualify the 'Genode' or 'Libc'
namespaces.

There are a few cases where the 'Libc', the 'Genode', and the global
(libc) namespaces are ambigious. In these cases, an explicit
clarification is needed:

- 'Genode::Allocator' differs from 'Libc::Allocator'.
- 'Genode::Env' differs from 'Libc::Env'.
- Genode's string functions (strcmp, memcpy, strcpy) conflict
  with the names of the (global) libc functions.
- There exist both 'Genode::uint64_t' and the libc'c 'uint64_t'.

Issue #3497
2019-11-19 14:10:55 +01:00
Norman Feske bf92232698 libc: split task.cc into multiple files
This patch is the first step of re-organizing the internal structure of
the libc. The original version involved many direct calls of global
functions (often with side effects) across compilation units, which
made the control flow (e.g., the initialization sequence) hard to
follow.

The new version replaces those ad-hoc interactions with dedicated
interfaces (like suspend.h, resume.h, select.h, current_time.h). The
underlying facilities are provided by the central Libc::Kernel and
selectively propagated to the various compilation units. The latter is
done by a sequence of 'init_*' calls, which eventually will be replaced
by constructor calls.

The addition of new headers increases the chance for name clashes with
existing (public) headers. To disambiguate libc-internal header files
from public headers, this patch moves the former into a new 'internal/'
subdirectory. This makes the include directives easier to follow and the
libc's source-tree structure more tidy.

There are still a few legacies left, which cannot easily be removed
right now (e.g., because noux relies on them). However, the patch moves
those bad apples to legacy.h and legacy.cc, which highlights the
deprecation of those functions.

Issue #3497
2019-11-19 14:10:55 +01:00
Alexander Senier 2a3cebdd6e libc: Allow private writable mappings
Fixes #3480
2019-08-28 14:18:45 +02:00
Christian Helmuth 45f3ccc42a vfs: fix empty-node handling in inline fs
Now <inline></inline> as well as <inline/> are supported.
2019-06-13 12:22:49 +02:00
Ehmry - 43315444a8 Libc: wrap VFS sync's in VFS_THREAD_SAFE
Move the _vfs_sync implementation from vfs_plugin.h to vfs_plugin.cc and
wrap all VFS access in the VFS_THREAD_SAFE macro.

Syncing must be made thread safe because it often happens when closing
files and may require suspending the current thread for I/O signal
dispatching.

Ref #3409
2019-06-13 12:22:49 +02:00
Ehmry - 863654d188 Libc: update port to Freebsd 12
Fix #3289
2019-05-27 14:46:53 +02:00
Ehmry - a635873568 VFS: Replace global response handlers with local handlers
Replace the I/O response handler that is passed to the VFS at
construction with an object that is dynamically attached to handles.
This object shall also accept read-ready notifications, and plugins are
encouraged to keep handles awaiting ready-ready notifications separate
from handles that await I/O progress.

Replace the use of handle lists in plugins with handle queues, this
makes the code easier to understand and the ordering of notifications to
the application more explicit.

These changes replace the use of the Post_signal_hook from all VFS
plugins, applications must assume that read-ready and I/O notifications
occur during I/O signal dispatch and use an Io_progress_handler at its
entrypoints to defer response until after signal dispatching.

Fix #3257
2019-04-09 12:30:34 +02:00
Josef Söntgen 5af0162b3f libc: fix storing TIOCGWINSZ result
Fixes #3266.
2019-04-09 12:30:34 +02:00
Norman Feske 6154d9067e libports: avoid using deprecated APIs
Issue #1987
Issue #3125
2019-01-30 13:49:55 +01:00
Ben Larson cde542c37c libc: read whole file into buffer
Fix #3023
2018-11-27 11:36:36 +01:00
Christian Prochaska 35f61475f5 libc_vfs: don't suspend in 'notify_read_ready()'
When 'notify_read_ready()' is called during 'select()' and fails,
suspending can cause a deadlock when the libc IO response handler becomes
active and calls 'select_notify()', which tries to acquire the
'select callback list lock', which is already acquired by the suspended
'select()' call.

It seems possible to ignore a failed 'notify_read_ready()' call instead of
suspending. When the VFS plugin calls the IO handler later when the
notification request can be processed, the 'select_notify()' call of the
libc IO response handler will eventually call 'notify_read_ready()' again.

Fixes #2970
2018-09-13 15:21:10 +02:00
Christian Prochaska e3005266b6 vfs: no 'handle_io_response()' in regular VFS functions
Calling 'handle_io_response()' in a regular VFS function (in contrast to a
post-signal hook) can cause problems if the caller of the VFS function holds
a lock which prevents the io response handler from returning.

With this commit, the user of the VFS becomes responsible for unblocking
threads which might be blocking after a failed 'queue_read()', 'queue_sync()'
or 'write()' call.

Fixes #2896
2018-08-02 14:36:43 +02:00
Christian Prochaska b4dd9bc802 libc vfs plugin: serialize more file system calls
Issue #2635
2018-08-02 14:36:42 +02:00
Josef Söntgen 74dcc7a3d5 libc: use socket fs for DNS information
The libc will now use the file given by the 'nameserver_file' attribute
to get the DNS nameserver address instead of reading '/etc/resolv.conf'.
It defaults to '/socket/nameserver' which is the common location when
using the lxip VFS plugin. As a constraint the libc will read the first
line and expects the nameserver address without any keywords in front of
it.

Fixes #2861.
2018-06-29 10:44:55 +02:00
Sebastian Sumpf 9cdc24bd32 vfs: serialize file system calls
issue #2635
issue #2791
2018-05-30 13:36:06 +02:00
Ehmry - 0b980073c1 VFS: close handles via handle method
The using pattern 'handle->close' is less error prone than attempting
'handle->ds().close(handle)' or 'fs.close(handle)'.

Ref #2782
2018-05-03 15:31:57 +02:00
Josef Söntgen 77a2e02a0d libc: increase FS_BLOCK_SIZE to 4KiB
Fixes #2752.
2018-04-19 12:38:23 +02:00
Christian Helmuth db23227ac3 libc: sync before calling ftruncate()
Issue #2695
2018-03-08 12:05:05 +01:00
Josef Söntgen d67e369433 libc: sync before calling fstat()
Issue #2695
2018-03-08 12:05:04 +01:00
Emery Hemingway 88757a674a libc: sync socket control files to check for write errors
Ref #2335
2018-02-28 11:04:58 +01:00
Ehmry - 2bbb183a18 Libc: check O_DIRECTORY flag at 'open' and 'read'
Return an error when opening a file with 'O_DIRECTORY'. Return an error
when reading directories.

Ref #2533
2018-02-15 10:22:09 +01:00
Christian Helmuth b1c9db8a0d libc: dispatch pending signals at selective points 2017-11-24 09:02:03 +01:00
Alexander Senier 520eedb829 libc: Signal ELOOP if file not found and O_NOFOLLOW set 2017-11-09 12:18:40 +01:00
Josef Söntgen 3b5a34c163 libc: fix DIOCGMEDIASIZE handling in VFS plugin
Use the provided argp pointer to store the result but bail out early if
it points into the void.

Issue #2558.
2017-11-06 13:57:24 +01:00
Christian Prochaska b0935ef9b2 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-28 16:49:38 +02:00
Emery Hemingway 2deddf1e6d Check for symlink target length errors
Check for symlink length errors at the VFS library and the ram_fs and
vfs servers.

Fix #2462
2017-08-17 11:04:21 +02:00
Emery Hemingway c5c9d71df3 libc: track O_ACCMODE flags from open
Fix #2457
2017-08-17 11:04:19 +02:00
Alexander Senier 87c19cb11a libc: handle O_CREAT|O_NOFOLLOW in open correctly
We return ELOOP if the file already exists on
open(...,O_CREAT|O_NOFOLLOW).

Fixes #2458
2017-08-17 11:04:19 +02:00
Christian Helmuth c9db94313c libc: improve VFS error handling 2017-06-19 12:35:57 +02:00
Christian Helmuth b3819f30dc libc: support for O_NONBLOCK in read() 2017-05-31 13:15:57 +02:00
Christian Helmuth 67ac0dde6e libc: checks for initialization and user context
We check if the libc (kernel singleton, config) was initialized and also
if suspend() is called from the valid user context.

Issue #2332
2017-03-24 16:20:03 +01:00
Emery Hemingway 7ef8c81607 libc: socket fcntl flags inheritence
Set O_NONBLOCK on sockets from the fcntl syscall and propagate this flag
to socket_fs control files and sockets returned from accept.

Fix #2318
2017-03-24 16:19:55 +01:00
Alexander Boettcher 1d36ecc13f libc: fix config parsing in vfs_plugin
The Xml_node contains already only the libc sub_node.

Issue #2306

Broken due to commit:

 libc: remove global config accessor

 Issue #2280.
2017-03-15 12:24:44 +01:00
Norman Feske 29b8d609c9 Adjust file headers to refer to the AGPLv3 2017-02-28 12:59:29 +01:00
Josef Söntgen 9ec553474e libc: remove global config accessor
Issue #2280.
2017-02-28 12:59:27 +01:00
Alexander Boettcher 1a6963813c libc: avoid race using Libc::suspend with pthreads
TOCTTOU bug, in our case time of check to time of sleep bug
2017-02-28 12:59:24 +01:00
Christian Helmuth fdad5116dd libc: support for socket file system
The socket file system can be configured in the "socket" attribute of
the libc config node like follows.

  <vfs> <dir name="socket"> <fs/> </dir> </vfs>
  <libc ... socket="/socket"/>

This configures the socket file system libc backend to access files in
"/socket" for socket operations.
2017-02-28 12:59:16 +01:00
Christian Helmuth 61b6dccf13 Queued read/write/read_ready in VFS and servers 2017-02-23 15:03:28 +01:00
Christian Helmuth f9389109bf Support select in libc VFS plugin by read_ready() 2017-02-07 11:12:29 +01:00
Christian Helmuth c0d61858c3 Support for suspendable read in VFS and libC
The support has two parts. First, a VFS plugin now gets passed an
I/O-response handler callback on construction, which informs users of the
VFS that an I/O event occurred. This enables, for example, the libC to
check if blocking read can be completed. Further, the VFS file I/O
interface provides now functions for suspendable reads, i.e.,
queue_read() and complete_read().
2017-02-07 11:12:27 +01:00