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 , mode_t ,
78 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
82 *f = cxx::ref_ptr(
this);
87 int err = get_ds(path, &file);
102Ns_dir::faccessat(
const char *path,
int mode,
int )
noexcept
104 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
106 if (!tmpcap.is_valid())
109 if (_ns->query(path, tmpcap.get()))
119Ns_dir::fstat64(
struct stat64 *b)
const noexcept
123 b->st_mode = S_IRWXU | S_IFDIR;
138Ns_dir::getdents(
char *buf,
size_t dest_sz)
noexcept
140 struct dirent64 *dest =
reinterpret_cast<struct dirent64 *
>(buf);
146 int err = get_ds(
".dirinfo", &dirinfofile);
150 infosz = dirinfofile->size();
157 dirinfofile.get(), 0);
161 char *p =
reinterpret_cast<char *
>(infoaddr) + _current_dir_pos;
162 char *end =
reinterpret_cast<char *
>(infoaddr) + infosz;
164 char *current_dirinfo_entry = p;
165 while (dest && p < end)
169 for (; p < end && *p >=
'0' && *p <=
'9'; ++p)
188 unsigned l = len + 1;
189 if (l >
sizeof(dest->d_name))
190 l =
sizeof(dest->d_name);
192 unsigned n = offsetof (
struct dirent64, d_name) + l;
193 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
200 memcpy(dest->d_name, p, l - 1);
201 dest->d_name[l - 1] = 0;
203 dest->d_type = DT_UNKNOWN;
208 dest =
reinterpret_cast<struct dirent64 *
>
209 (
reinterpret_cast<unsigned long>(dest) + n);
213 while (p < end && *p && (*p ==
'\n' || *p ==
'\r'))
216 current_dirinfo_entry = p;
219 _current_dir_pos = current_dirinfo_entry -
reinterpret_cast<char *
>(infoaddr);
222 _current_dir_pos = 0;
233 Vfs::Path first = p.strip_first();
250 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
252 if (!file.is_valid())
255 int err = c->query(p.path(), p.length(), file.get());
260 *ds = cxx::move(file);
265Env_dir::get_entry(
const char *path,
int , mode_t ,
266 Ref_ptr<L4Re::Vfs::File> *f)
noexcept
270 *f = cxx::ref_ptr(
this);
275 int err = get_ds(path, &file);
290Env_dir::faccessat(
const char *path,
int mode,
int )
noexcept
293 Vfs::Path first = p.strip_first();
312 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
314 if (!tmpcap.is_valid())
317 if (c->query(p.path(), p.length(), tmpcap.get()))
327Env_dir::check_type(
Env::Cap_entry const *e,
long protocol)
noexcept
330 return m->supports(protocol).label();
334Env_dir::fstat64(
struct stat64 *b)
const noexcept
338 b->st_mode = S_IRWXU | S_IFDIR;
353Env_dir::getdents(
char *buf,
size_t sz)
noexcept
355 struct dirent64 *d =
reinterpret_cast<struct dirent64 *
>(buf);
359 && _current_cap_entry
360 && _current_cap_entry->flags != ~0UL)
362 unsigned l = strlen(_current_cap_entry->name) + 1;
363 if (l >
sizeof(d->d_name))
364 l =
sizeof(d->d_name);
366 unsigned n = offsetof (
struct dirent64, d_name) + l;
367 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
373 memcpy(d->d_name, _current_cap_entry->name, l);
374 d->d_name[l - 1] = 0;
376 if (check_type(_current_cap_entry, L4Re::Namespace::Protocol))
378 else if (check_type(_current_cap_entry, L4Re::Dataspace::Protocol))
381 d->d_type = DT_UNKNOWN;
384 d =
reinterpret_cast<struct dirent64 *
>
385 (
reinterpret_cast<unsigned long>(d) + n);
386 _current_cap_entry++;
394 _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.