11#include <l4/re/util/env_ns>
15namespace L4Re {
namespace Core {
18Ref_ptr<L4Re::Vfs::File>
24 L4::Ipc::String<char> name(
sizeof(name_buf), name_buf);
25 int r =
l4_error(m->interface(0, &proto, &name));
29 return Ref_ptr<L4Re::Vfs::File>();
32 Ref_ptr<L4Re::Vfs::File_factory> factory;
35 factory = L4Re::Vfs::vfs_ops->get_file_factory(proto);
38 factory = L4Re::Vfs::vfs_ops->get_file_factory(name.data);
41 return Ref_ptr<L4Re::Vfs::File>();
44 return factory->create(o);
51 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
56 int err = _ns->query(path, file.get());
61 *ds = cxx::move(file);
66Ns_dir::get_entry(
const char *path,
int , mode_t ,
67 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
71 *f = cxx::ref_ptr(
this);
76 int err = get_ds(path, &file);
91Ns_dir::faccessat(
const char *path,
int mode,
int )
noexcept
93 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
95 if (!tmpcap.is_valid())
98 if (_ns->query(path, tmpcap.get()))
108Ns_dir::fstat64(
struct stat64 *b)
const noexcept
112 b->st_mode = S_IRWXU | S_IFDIR;
127Ns_dir::getdents(
char *buf,
size_t dest_sz)
noexcept
129 struct dirent64 *dest =
reinterpret_cast<struct dirent64 *
>(buf);
135 int err = get_ds(
".dirinfo", &dirinfofile);
139 infosz = dirinfofile->size();
146 dirinfofile.get(), 0);
150 char *p =
reinterpret_cast<char *
>(infoaddr) + _current_dir_pos;
151 char *end =
reinterpret_cast<char *
>(infoaddr) + infosz;
153 char *current_dirinfo_entry = p;
154 while (dest && p < end)
158 for (; p < end && *p >=
'0' && *p <=
'9'; ++p)
177 unsigned l = len + 1;
178 if (l >
sizeof(dest->d_name))
179 l =
sizeof(dest->d_name);
181 unsigned n = offsetof (
struct dirent64, d_name) + l;
182 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
189 memcpy(dest->d_name, p, l - 1);
190 dest->d_name[l - 1] = 0;
192 dest->d_type = DT_UNKNOWN;
197 dest =
reinterpret_cast<struct dirent64 *
>
198 (
reinterpret_cast<unsigned long>(dest) + n);
202 while (p < end && *p && (*p ==
'\n' || *p ==
'\r'))
205 current_dirinfo_entry = p;
208 _current_dir_pos = current_dirinfo_entry -
reinterpret_cast<char *
>(infoaddr);
211 _current_dir_pos = 0;
222 Vfs::Path first = p.strip_first();
239 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
241 if (!file.is_valid())
244 int err = c->query(p.path(), p.length(), file.get());
249 *ds = cxx::move(file);
254Env_dir::get_entry(
const char *path,
int , mode_t ,
255 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
259 *f = cxx::ref_ptr(
this);
264 int err = get_ds(path, &file);
279Env_dir::faccessat(
const char *path,
int mode,
int )
noexcept
282 Vfs::Path first = p.strip_first();
301 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
303 if (!tmpcap.is_valid())
306 if (c->query(p.path(), p.length(), tmpcap.get()))
316Env_dir::check_type(
Env::Cap_entry const *e,
long protocol)
noexcept
319 return m->supports(protocol).label();
323Env_dir::fstat64(
struct stat64 *b)
const noexcept
327 b->st_mode = S_IRWXU | S_IFDIR;
342Env_dir::getdents(
char *buf,
size_t sz)
noexcept
344 struct dirent64 *d =
reinterpret_cast<struct dirent64 *
>(buf);
348 && _current_cap_entry
349 && _current_cap_entry->flags != ~0UL)
351 unsigned l = strlen(_current_cap_entry->name) + 1;
352 if (l >
sizeof(d->d_name))
353 l =
sizeof(d->d_name);
355 unsigned n = offsetof (
struct dirent64, d_name) + l;
356 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
362 memcpy(d->d_name, _current_cap_entry->name, l);
363 d->d_name[l - 1] = 0;
365 if (check_type(_current_cap_entry, L4Re::Namespace::Protocol))
367 else if (check_type(_current_cap_entry, L4Re::Dataspace::Protocol))
370 d->d_type = DT_UNKNOWN;
373 d =
reinterpret_cast<struct dirent64 *
>
374 (
reinterpret_cast<unsigned long>(d) + n);
375 _current_cap_entry++;
383 _current_cap_entry = _env->initial_caps();
static Env const * env() noexcept
Returns the initial environment for the current task.
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
C++ interface for capabilities.
A reference-counting pointer with automatic cleanup.
unsigned long l4_addr_t
Address type.
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
#define L4_PAGESIZE
Minimal page size (in bytes).
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_ALL_SPACES > > Unique_cap
Unique capability that implements automatic free and unmap of the capability selector.
@ Search_addr
Search for a suitable address range.
Unique_cap / Unique_del_cap.