Re: Could you do me a favour

31 views
Skip to first unread message

Martin Lindsay

unread,
Mar 7, 2022, 11:05:40 AM3/7/22
to wuweiil, stora...@fuchsia.dev
This is a good question. Personally, I've never tried to use a normal file in this way, but it seems like a reasonable way to await another process's write to it. However looking over the posix specification, it seems like return immediately is the correct response when using a normal file, though I may be misunderstanding it:
File descriptors associated with regular files always select true for ready to read, ready to write, and error conditions.
 
 Looking at your code though, you may want to record errno as part of this, since you're getting back -1, which means there's probably something else going on anyways. In this case you're using "fd+1" as the num fd's when you should probably just be using "1". If the fd number assigned is 1024 or greater, you should get EINVAL for exceeding the maximum allowed set of fd's for select(). If you're opening this file while it doesn't yet exist (you didn't include O_CREAT in the open call), you're expected to get back EBADF.

I've included the storage team public mailing list in case anyone would like to correct my assessment or add any more detail.

Thanks

Martin

On Sun, 6 Mar 2022 at 03:49, wuweiil <wei_...@126.com> wrote:
hi,
I'm a begginner of fuchia,Hope I can get your help.
i want to monitor a file's read/write event.,I have a example program like this:

int fd,ret;
fd_set readfd;
struct timeval timeout;
timeout.tv_sec=5;
timeout.tv_usec=0;
fd = open("/data/test.txt",O_RDONLY);
FD_ZERO(&readfd);
FD_SET(fd,&readfd);
ret=select(fd+1,&readfd,NULL,NULL,&timeout);

the "select" return immediately and the value is "-1",but when the fd is a pipe fd or timerfd it will be blocked,then  return 0(seems work fine )
there is a class may related to this in file src/lib/storage/vfs/cpp/vfs_types.h
class VnodeRepresentation {
 public:
  struct Connector {};
  struct File {
    zx::event observer = {};
  };
...
}
but,observer seems  can only inform this filesystem ready for read,not a file on a file system can be read/write.
I want to know , fuchsia support for monitoring a file's read/write event or not ?
look forward to your kind reply!
Thank you very much.

wuweiil

unread,
Mar 13, 2022, 6:33:57 PM3/13/22
to Martin Lindsay, stora...@fuchsia.dev
Thank you very much 
I can resolved this issue,adding some code in minifs filesystm,like in blobfs https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/src/storage/blobfs/blob.cc.
zx_status_t Blob::GetReadableEvent(zx::event* out) {
TRACE_DURATION("blobfs", "Blobfs::GetReadableEvent");

zx_status_t status;

// This is the first 'wait until read event' request received.

if (!readable_event_.is_valid()) {

status = zx::event::create(0, &readable_event_);

if (status != ZX_OK) {

return status;

} else if (state() == BlobState::kReadable) {

readable_event_.signal(0u, ZX_USER_SIGNAL_0);

}

}

zx::event out_event;

status = readable_event_.duplicate(ZX_RIGHTS_BASIC, &out_event);

if (status != ZX_OK) {

return status;

}

*out = std::move(out_event);

return ZX_OK;

}

now i have another problem,when i use poll function to poll a file of procfs(path“/proc/xxxx”) and  compiled this example program whith --satic and run it in startnix,it blocked.
I expect it retuned  immediately,because it is a regular file.
how can to fix it ? do you have any idea?

Martin Lindsay

unread,
Mar 14, 2022, 11:15:50 AM3/14/22
to wuweiil, stora...@fuchsia.dev
procfs is really just marked as a proof of concept right now: https://fuchsia.googlesource.com/fuchsia/+/refs/heads/main/sdk/lib/procfs/README.md I'm not sure if I'd rely on it to handle any kind of edge cases.




Suraj Malhotra

unread,
Mar 14, 2022, 11:27:04 AM3/14/22
to Martin Lindsay, wuweiil, stora...@fuchsia.dev
procfs for binaries run under starnix is implemented here: https://cs.opensource.google/fuchsia/fuchsia/+/main:src/proc/bin/starnix/fs/proc/

The one you pointed to, Martin, is for binaries targeting fuchsia.

--
All posts must follow the Fuchsia Code of Conduct https://fuchsia.dev/fuchsia-src/CODE_OF_CONDUCT or may be removed.
---
You received this message because you are subscribed to the Google Groups "storage-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to storage-dev...@fuchsia.dev.
To view this discussion on the web visit https://groups.google.com/a/fuchsia.dev/d/msgid/storage-dev/CAMsdVDNz%2BKCpUs%2Bk%2BqM5zgM11bX%2BcD1k3_X5_N0O120qFJdctw%40mail.gmail.com.

Adam Barth

unread,
Mar 14, 2022, 11:48:40 AM3/14/22
to Suraj Malhotra, Martin Lindsay, wuweiil, stora...@fuchsia.dev
The version in //sdk/lib/procfs didn't really work.  I'll send a CL to delete it.

Adam


Adam Barth

unread,
Mar 14, 2022, 11:57:20 AM3/14/22
to Suraj Malhotra, Martin Lindsay, wuweiil, stora...@fuchsia.dev
Reply all
Reply to author
Forward
0 new messages