Getting dataspace of a tmpfs-file blocks forever
adam at os.inf.tu-dresden.de
Tue Feb 10 23:47:40 CET 2015
On Thu Feb 05, 2015 at 20:41:40 +0000, Stark, Josef wrote:
> when I have created and filled a file in tmpfs,
> reading normally (-> read() ) from it works fine.
> However, I cannot get the associated dataspace.
> The call would just block forever.
> Here is an example code snippet:
> const char* filename="/tmp/test";
> mount("/", "tmp", "tmpfs", 0, 0);
> int fd=open(filename,O_WRONLY|O_CREAT);
> char buf;
> printf("file content: %s\n",buf);
> cxx::Ref_ptr<L4Re::Vfs::File> fp = L4Re::Vfs::vfs_ops->get_file(fd);
> printf("Got file!\n");
> L4::Cap<L4Re::Dataspace> ds = fp->data_space();
> printf("Got Dataspace!");
> long int size = ds->size();
> printf("Dataspace size: %li\n",size);
> It would just output
> file content: Hello
> Got file!
> but nothing more, which tells me that reading
> normally from the file works, but the
> fp->data_space() call blocks.
> If I tried the same with an existing file in /rom/, it
> works just fine (except for the writing part, obviously).
> How can I make this work?
What you look up there is the dataspace that backs the file. For tmpfs
there's no file doing this. I'd guess that ds is not valid in this case.
However, what you can do to get the dataspace is to use L4Re::Rm::find()
on an mmap'ed area of the tmpfs file. That sounds hacky but should work.
Adam adam at os.inf.tu-dresden.de
More information about the l4-hackers