terom@7: #ifndef DIRBUF_H terom@7: #define DIRBUF_H terom@7: terom@7: /* terom@7: * Simple dirent building terom@7: */ terom@7: terom@7: #include "evfuse.h" terom@7: terom@7: /* terom@7: * Holds the dir entries terom@7: */ terom@7: struct dirbuf { terom@7: char *buf; terom@7: size_t len; terom@27: off_t off, req_off; terom@7: }; terom@7: terom@26: // maximum length for a dirbuf name, including NUL byte terom@26: #define DIRBUF_NAME_MAX 256 terom@26: terom@26: /* terom@27: * Initialize a dirbuf for a request. The dirbuf will be filled with at most req_size bytes of dir entries. terom@27: * terom@27: * req_size - how many bytes of dirbuf data we want, at most terom@27: * req_off - the offset of the first dirent to include terom@27: */ terom@27: int dirbuf_init (struct dirbuf *buf, size_t req_size, off_t req_off); terom@27: terom@27: /* terom@26: * Estimate how many dir entries will, at most, fit into a difbuf of the given size, based on a minimum filename size. terom@26: */ terom@27: size_t dirbuf_estimate (struct dirbuf *buf, size_t min_namelen); terom@7: terom@7: /* terom@7: * Add an dir entry to the dirbuf. The dirbuf should not be full. terom@7: * terom@7: * Offsets are followed: terom@7: * ent_off - the offset of this dirent terom@7: * next_off - the offset of the next dirent terom@7: * terom@7: * Only the S_IFMT bits of ent_mode are relevant. terom@7: * terom@7: * Returns 0 if the ent was added or skipped, -1 on error, 1 if the dirbuf is full (no more ents should be added). terom@7: */ terom@27: int dirbuf_add (fuse_req_t req, struct dirbuf *buf, off_t ent_off, off_t next_off, const char *ent_name, fuse_ino_t ent_ino, mode_t ent_mode); terom@7: terom@7: /* terom@7: * Attempt to send the readdir reply, free the buf, and return the error code from fuse_reply_buf terom@7: */ terom@7: int dirbuf_done (fuse_req_t req, struct dirbuf *buf); terom@7: terom@27: /* terom@27: * Release the dirop without sending any reply back. terom@27: * terom@27: * This is safe to be called multiple times. terom@27: */ terom@27: void dirbuf_release (struct dirbuf *buf); terom@27: terom@7: #endif /* DIRBUF_H */