2 * (c) 2010 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU General Public License 2.
5 * Please see the COPYING-GPL-2 file for details.
7 * As a special exception, you may use this file as part of a free software
8 * library without restriction. Specifically, if other files instantiate
9 * templates or use macros or inline functions from this file, or you compile
10 * this file and link it with other files to produce an executable, this
11 * file does not by itself cause the resulting executable to be covered by
12 * the GNU General Public License. This exception does not however
13 * invalidate any other reasons why the executable file might be covered by
14 * the GNU General Public License.
20 #include <l4/re/dataspace>
21 #include <l4/re/util/env_ns>
24 namespace L4Re { namespace Core {
26 Simple_store_sz<Env_dir::Size> Ns_base_dir::store;
29 Ns_base_dir::operator new(size_t s) throw()
38 Ns_base_dir::operator delete(void *b) throw()
45 Ns_dir::get_ds(const char *path, L4Re::Auto_cap<L4Re::Dataspace>::Cap *ds) throw()
47 L4Re::Auto_cap<L4Re::Dataspace>::Cap file(cap_alloc()->alloc<L4Re::Dataspace>(), cap_alloc());
52 int err = _ns->query(path, file.get());
62 Ns_dir::get_entry(const char *path, int flags, mode_t mode,
63 Ref_ptr<L4Re::Vfs::File> *f) throw()
65 (void)mode; (void)flags;
72 L4Re::Auto_cap<Dataspace>::Cap file;
73 int err = get_ds(path, &file);
78 // FIXME: should check if it is a dataspace, somehow
79 L4Re::Vfs::File *fi = 0;
81 L4::Cap<L4Re::Namespace> nsc
82 = L4::cap_dynamic_cast<L4Re::Namespace>(file.get());
85 fi = new Ro_file(file.get());
86 else // use mat protocol here!!
98 Ns_dir::faccessat(const char *path, int mode, int flags) throw()
101 L4Re::Auto_cap<void>::Cap tmpcap(cap_alloc()->alloc<void>(), cap_alloc());
103 if (!tmpcap.is_valid())
106 if (_ns->query(path, tmpcap.get()))
116 fstat64(struct stat64 *b) const throw()
120 b->st_mode = S_IRWXU | S_IFDIR;
135 Env_dir::get_ds(const char *path, L4Re::Auto_cap<L4Re::Dataspace>::Cap *ds) throw()
138 Vfs::Path first = p.strip_first();
143 L4::Cap<L4Re::Namespace>
144 c = _env->get_cap<L4Re::Namespace>(first.path(), first.length());
151 *ds = L4Re::Auto_cap<L4Re::Dataspace>::Cap(L4::cap_reinterpret_cast<L4Re::Dataspace>(c));
155 L4Re::Auto_cap<L4Re::Dataspace>::Cap file(cap_alloc()->alloc<L4Re::Dataspace>(), cap_alloc());
157 if (!file.is_valid())
160 int err = c->query(p.path(), p.length(), file.get());
170 Env_dir::get_entry(const char *path, int flags, mode_t mode,
171 Ref_ptr<L4Re::Vfs::File> *f) throw()
173 (void)mode; (void)flags;
180 L4Re::Auto_cap<Dataspace>::Cap file;
181 int err = get_ds(path, &file);
186 // FIXME: should check if it is a dataspace, somehow
187 L4Re::Vfs::File *fi = 0;
189 L4::Cap<L4Re::Namespace> nsc
190 = L4::cap_dynamic_cast<L4Re::Namespace>(file.get());
193 fi = new Ro_file(file.get());
194 else // use mat protocol here!!
195 fi = new Ns_dir(nsc);
206 Env_dir::faccessat(const char *path, int mode, int flags) throw()
210 Vfs::Path first = p.strip_first();
215 L4::Cap<L4Re::Namespace>
216 c = _env->get_cap<L4Re::Namespace>(first.path(), first.length());
229 L4Re::Auto_cap<void>::Cap tmpcap(cap_alloc()->alloc<void>(), cap_alloc());
231 if (!tmpcap.is_valid())
234 if (c->query(p.path(), p.length(), tmpcap.get()))
244 Env_dir::fstat64(struct stat64 *b) const throw()
248 b->st_mode = S_IRWXU | S_IFDIR;
263 Env_dir::getdents(char *buf, size_t sz) throw()
265 struct dirent64 *d = (struct dirent64 *)buf;
269 && _current_cap_entry
270 && _current_cap_entry->flags != ~0UL)
272 unsigned l = strlen(_current_cap_entry->name) + 1;
273 if (l > sizeof(d->d_name))
274 l = sizeof(d->d_name);
276 unsigned n = offsetof (struct dirent64, d_name) + l;
282 memcpy(d->d_name, _current_cap_entry->name, l);
283 d->d_name[l - 1] = 0;
287 d = (struct dirent64 *)((unsigned long)d + n);
288 _current_cap_entry++;
294 // bit of a hack because we should only (re)set this when opening the dir
296 _current_cap_entry = _env->initial_caps();