22#include <l4/re/util/env_ns>
26namespace L4Re {
namespace Core {
29Ref_ptr<L4Re::Vfs::File>
35 L4::Ipc::String<char> name(
sizeof(name_buf), name_buf);
36 int r =
l4_error(m->interface(0, &proto, &name));
40 return Ref_ptr<L4Re::Vfs::File>();
43 Ref_ptr<L4Re::Vfs::File_factory> factory;
46 factory = L4Re::Vfs::vfs_ops->get_file_factory(proto);
49 factory = L4Re::Vfs::vfs_ops->get_file_factory(name.data);
52 return Ref_ptr<L4Re::Vfs::File>();
55 return factory->create(o);
62 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
67 int err = _ns->query(path, file.get());
72 *ds = cxx::move(file);
77Ns_dir::get_entry(
const char *path,
int flags, mode_t mode,
78 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
80 (void)mode; (void)flags;
83 *f = cxx::ref_ptr(
this);
88 int err = get_ds(path, &file);
103Ns_dir::faccessat(
const char *path,
int mode,
int flags)
noexcept
106 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
108 if (!tmpcap.is_valid())
111 if (_ns->query(path, tmpcap.get()))
121Ns_dir::fstat64(
struct stat64 *b)
const noexcept
125 b->st_mode = S_IRWXU | S_IFDIR;
140Ns_dir::getdents(
char *buf,
size_t dest_sz)
noexcept
142 struct dirent64 *dest = (
struct dirent64 *)buf;
148 int err = get_ds(
".dirinfo", &dirinfofile);
152 infosz = dirinfofile->size();
159 dirinfofile.get(), 0);
163 char *p = (
char *)infoaddr + _current_dir_pos;
164 char *end = (
char *)infoaddr + infosz;
166 char *current_dirinfo_entry = p;
167 while (dest && p < end)
171 for (; p < end && *p >=
'0' && *p <=
'9'; ++p)
190 unsigned l = len + 1;
191 if (l >
sizeof(dest->d_name))
192 l =
sizeof(dest->d_name);
194 unsigned n = offsetof (
struct dirent64, d_name) + l;
195 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
202 memcpy(dest->d_name, p, l - 1);
203 dest->d_name[l - 1] = 0;
205 dest->d_type = DT_REG;
210 dest = (
struct dirent64 *)((
unsigned long)dest + n);
214 while (p < end && *p && (*p ==
'\n' || *p ==
'\r'))
217 current_dirinfo_entry = p;
220 _current_dir_pos = current_dirinfo_entry - (
char *)infoaddr;
223 _current_dir_pos = 0;
234 Vfs::Path first = p.strip_first();
251 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
253 if (!file.is_valid())
256 int err = c->query(p.path(), p.length(), file.get());
261 *ds = cxx::move(file);
266Env_dir::get_entry(
const char *path,
int flags, mode_t mode,
267 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
269 (void)mode; (void)flags;
272 *f = cxx::ref_ptr(
this);
277 int err = get_ds(path, &file);
292Env_dir::faccessat(
const char *path,
int mode,
int flags)
noexcept
296 Vfs::Path first = p.strip_first();
315 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
317 if (!tmpcap.is_valid())
320 if (c->query(p.path(), p.length(), tmpcap.get()))
330Env_dir::check_type(
Env::Cap_entry const *e,
long protocol)
noexcept
333 return m->supports(protocol).label();
337Env_dir::fstat64(
struct stat64 *b)
const noexcept
341 b->st_mode = S_IRWXU | S_IFDIR;
356Env_dir::getdents(
char *buf,
size_t sz)
noexcept
358 struct dirent64 *d = (
struct dirent64 *)buf;
362 && _current_cap_entry
363 && _current_cap_entry->flags != ~0UL)
365 unsigned l = strlen(_current_cap_entry->name) + 1;
366 if (l >
sizeof(d->d_name))
367 l =
sizeof(d->d_name);
369 unsigned n = offsetof (
struct dirent64, d_name) + l;
370 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
376 memcpy(d->d_name, _current_cap_entry->name, l);
377 d->d_name[l - 1] = 0;
379 if (check_type(_current_cap_entry, L4Re::Namespace::Protocol))
381 else if (check_type(_current_cap_entry, L4Re::Dataspace::Protocol))
384 d->d_type = DT_UNKNOWN;
387 d = (
struct dirent64 *)((
unsigned long)d + n);
388 _current_cap_entry++;
396 _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.