22 #include <l4/re/util/env_ns>
26 namespace L4Re {
namespace Core {
29 Ref_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);
77 Ns_dir::get_entry(
const char *path,
int flags, mode_t mode,
78 Ref_ptr<L4Re::Vfs::File> *f)
throw()
80 (void)mode; (void)flags;
83 *f = cxx::ref_ptr(
this);
88 int err = get_ds(path, &file);
103 Ns_dir::faccessat(
const char *path,
int mode,
int flags)
throw()
106 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
108 if (!tmpcap.is_valid())
111 if (_ns->query(path, tmpcap.get()))
121 Ns_dir::fstat64(
struct stat64 *b)
const throw()
125 b->st_mode = S_IRWXU | S_IFDIR;
140 Ns_dir::getdents(
char *buf,
size_t sz)
throw()
142 struct dirent64 *d = (
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;
170 for (len = 0; p < end && *p >=
'0' && *p <=
'9'; ++p)
182 unsigned l = len + 1;
183 if (l >
sizeof(d->d_name))
184 l =
sizeof(d->d_name);
186 unsigned n = offsetof (
struct dirent64, d_name) + l;
187 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
194 memcpy(d->d_name, p, len);
195 d->d_name[l - 1] = 0;
200 d = (
struct dirent64 *)((
unsigned long)d + n);
204 while (p < end && *p && *p !=
'\n' && *p !=
'\r')
206 while (p < end && *p && (*p ==
'\n' || *p ==
'\r'))
210 _current_dir_pos += p - (
char *)infoaddr;
213 _current_dir_pos = 0;
224 Vfs::Path first = p.strip_first();
241 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
243 if (!file.is_valid())
246 int err = c->
query(p.path(), p.length(), file.get());
251 *ds = cxx::move(file);
256 Env_dir::get_entry(
const char *path,
int flags, mode_t mode,
257 Ref_ptr<L4Re::Vfs::File> *f)
throw()
259 (void)mode; (void)flags;
262 *f = cxx::ref_ptr(
this);
267 int err = get_ds(path, &file);
282 Env_dir::faccessat(
const char *path,
int mode,
int flags)
throw()
286 Vfs::Path first = p.strip_first();
305 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
307 if (!tmpcap.is_valid())
310 if (c->
query(p.path(), p.length(), tmpcap.get()))
320 Env_dir::check_type(
Env::Cap_entry const *e,
long protocol)
throw()
323 return m->supports(protocol).label();
327 Env_dir::fstat64(
struct stat64 *b)
const throw()
331 b->st_mode = S_IRWXU | S_IFDIR;
346 Env_dir::getdents(
char *buf,
size_t sz)
throw()
348 struct dirent64 *d = (
struct dirent64 *)buf;
352 && _current_cap_entry
353 && _current_cap_entry->flags != ~0UL)
355 unsigned l = strlen(_current_cap_entry->name) + 1;
356 if (l >
sizeof(d->d_name))
357 l =
sizeof(d->d_name);
359 unsigned n = offsetof (
struct dirent64, d_name) + l;
360 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
366 memcpy(d->d_name, _current_cap_entry->name, l);
367 d->d_name[l - 1] = 0;
369 if (check_type(_current_cap_entry, L4Re::Namespace::Protocol))
371 else if (check_type(_current_cap_entry, L4Re::Dataspace::Protocol))
374 d->d_type = DT_UNKNOWN;
377 d = (
struct dirent64 *)((
unsigned long)d + n);
378 _current_cap_entry++;
386 _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.
long query(char const *name, L4::Cap< void > const &cap, int timeout=To_default, l4_umword_t *local_id=0, bool iterate=true) const noexcept
Query the name space for a named object.
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
C++ interface for capabilities.
unsigned long l4_addr_t
Address type.
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
#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.