Hey,
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); write(fd,"Hello",6); close(fd); fd=open(filename,O_RDONLY); char buf[15]; read(fd,buf,15); printf("file content: %s\n",buf); cxx::Ref_ptrL4Re::Vfs::File fp = L4Re::Vfs::vfs_ops->get_file(fd); printf("Got file!\n"); L4::CapL4Re::Dataspace ds = fp->data_space(); printf("Got Dataspace!"); long int size = ds->size(); printf("Dataspace size: %li\n",size); printf("Done.\n"); close(fd);
============================
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?
Thanks, Josef
Hi,
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); write(fd,"Hello",6); close(fd);
fd=open(filename,O_RDONLY); char buf[15]; read(fd,buf,15); printf("file content: %s\n",buf);
cxx::Ref_ptrL4Re::Vfs::File fp = L4Re::Vfs::vfs_ops->get_file(fd); printf("Got file!\n"); L4::CapL4Re::Dataspace ds = fp->data_space(); printf("Got Dataspace!"); long int size = ds->size(); printf("Dataspace size: %li\n",size); printf("Done.\n"); close(fd);
============================
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
l4-hackers@os.inf.tu-dresden.de