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);
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);
160 char *p = (
char *)infoaddr + _current_dir_pos;
161 char *end = (
char *)infoaddr + infosz;
167 for (len = 0; p < end && *p >=
'0' && *p <=
'9'; ++p)
179 unsigned l = len + 1;
180 if (l >
sizeof(d->d_name))
181 l =
sizeof(d->d_name);
183 unsigned n = offsetof (
struct dirent64, d_name) + l;
184 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
191 memcpy(d->d_name, p, len);
192 d->d_name[l - 1] = 0;
197 d = (
struct dirent64 *)((
unsigned long)d + n);
201 while (p < end && *p && *p !=
'\n' && *p !=
'\r')
203 while (p < end && *p && (*p ==
'\n' || *p ==
'\r'))
207 _current_dir_pos += p - (
char *)infoaddr;
210 _current_dir_pos = 0;
221 Vfs::Path first = p.strip_first();
238 auto file = L4Re::make_unique_cap<L4Re::Dataspace>(L4Re::virt_cap_alloc);
240 if (!file.is_valid())
243 int err = c->
query(p.path(), p.length(), file.get());
248 *ds = cxx::move(file);
253 Env_dir::get_entry(
const char *path,
int flags, mode_t mode,
254 Ref_ptr<L4Re::Vfs::File> *f)
throw()
256 (void)mode; (void)flags;
259 *f = cxx::ref_ptr(
this);
264 int err = get_ds(path, &file);
279 Env_dir::faccessat(
const char *path,
int mode,
int flags)
throw()
283 Vfs::Path first = p.strip_first();
302 auto tmpcap = L4Re::make_unique_cap<void>(L4Re::virt_cap_alloc);
304 if (!tmpcap.is_valid())
307 if (c->
query(p.path(), p.length(), tmpcap.get()))
317 Env_dir::check_type(
Env::Cap_entry const *e,
long protocol)
throw()
324 Env_dir::fstat64(
struct stat64 *b)
const throw()
328 b->st_mode = S_IRWXU | S_IFDIR;
343 Env_dir::getdents(
char *buf,
size_t sz)
throw()
345 struct dirent64 *d = (
struct dirent64 *)buf;
349 && _current_cap_entry
350 && _current_cap_entry->flags != ~0UL)
352 unsigned l = strlen(_current_cap_entry->name) + 1;
353 if (l >
sizeof(d->d_name))
354 l =
sizeof(d->d_name);
356 unsigned n = offsetof (
struct dirent64, d_name) + l;
357 n = (n +
sizeof(long) - 1) & ~(
sizeof(long) - 1);
363 memcpy(d->d_name, _current_cap_entry->name, l);
364 d->d_name[l - 1] = 0;
366 if (check_type(_current_cap_entry, L4Re::Namespace::Protocol))
368 else if (check_type(_current_cap_entry, L4Re::Dataspace::Protocol))
371 d->d_type = DT_UNKNOWN;
374 d = (
struct dirent64 *)((
unsigned long)d + n);
375 _current_cap_entry++;
383 _current_cap_entry = _env->initial_caps();
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
long query(char const *name, L4::Cap< void > const &cap, int timeout=To_default, l4_umword_t *local_id=0, bool iterate=true) const
Query the name space for a named object.
Search for a suitable address range.
long label() const
Get the protocol value.
Interface for memory-like objects.
Cap< T > cap_reinterpret_cast(Cap< F > const &c)
reinterpret_cast for capabilities.
#define L4_PAGESIZE
Minimal page size (in bytes).
static Env const * env()
Returns the initial environment for the current task.
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.
Unique_cap / Unique_del_cap.
bool is_valid() const
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag.
C++ interface for capabilities.
unsigned long l4_addr_t
Address type.
L4::Cap< Rm > rm() const
Object-capability to the region map.