src/dirbuf.h
changeset 27 461be4cd34a3
parent 26 61668c57f4bb
equal deleted inserted replaced
26:61668c57f4bb 27:461be4cd34a3
    11  * Holds the dir entries
    11  * Holds the dir entries
    12  */ 
    12  */ 
    13 struct dirbuf {
    13 struct dirbuf {
    14     char *buf;
    14     char *buf;
    15     size_t len;
    15     size_t len;
    16     size_t off;
    16     off_t off, req_off;
    17 };
    17 };
    18 
    18 
    19 // maximum length for a dirbuf name, including NUL byte
    19 // maximum length for a dirbuf name, including NUL byte
    20 #define DIRBUF_NAME_MAX 256
    20 #define DIRBUF_NAME_MAX 256
    21 
    21 
    22 /*
    22 /*
       
    23  * Initialize a dirbuf for a request. The dirbuf will be filled with at most req_size bytes of dir entries.
       
    24  *
       
    25  *  req_size    - how many bytes of dirbuf data we want, at most 
       
    26  *  req_off     - the offset of the first dirent to include
       
    27  */
       
    28 int dirbuf_init (struct dirbuf *buf, size_t req_size, off_t req_off);
       
    29 
       
    30 /*
    23  * Estimate how many dir entries will, at most, fit into a difbuf of the given size, based on a minimum filename size.
    31  * Estimate how many dir entries will, at most, fit into a difbuf of the given size, based on a minimum filename size.
    24  */
    32  */
    25 size_t difbuf_estimate (size_t req_size, size_t min_namelen);
    33 size_t dirbuf_estimate (struct dirbuf *buf, size_t min_namelen);
    26 
       
    27 /*
       
    28  * Initialize a dirbuf for a request. The dirbuf will be filled with at most req_size bytes of dir entries.
       
    29  */
       
    30 int dirbuf_init (struct dirbuf *buf, size_t req_size);
       
    31 
    34 
    32 /*
    35 /*
    33  * Add an dir entry to the dirbuf. The dirbuf should not be full.
    36  * Add an dir entry to the dirbuf. The dirbuf should not be full.
    34  *
    37  *
    35  * Offsets are followed:
    38  * Offsets are followed:
    36  *  req_off     - the offset of the first dirent to include
       
    37  *  ent_off     - the offset of this dirent
    39  *  ent_off     - the offset of this dirent
    38  *  next_off    - the offset of the next dirent
    40  *  next_off    - the offset of the next dirent
    39  *
    41  *
    40  * Only the S_IFMT bits of ent_mode are relevant.
    42  * Only the S_IFMT bits of ent_mode are relevant.
    41  *
    43  *
    42  * Returns 0 if the ent was added or skipped, -1 on error, 1 if the dirbuf is full (no more ents should be added).
    44  * Returns 0 if the ent was added or skipped, -1 on error, 1 if the dirbuf is full (no more ents should be added).
    43  */
    45  */
    44 int dirbuf_add (fuse_req_t req, off_t req_off, struct dirbuf *buf, off_t ent_off, off_t next_off, const char *ent_name, fuse_ino_t ent_ino, mode_t ent_mode);
    46 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);
    45 
    47 
    46 /*
    48 /*
    47  * Attempt to send the readdir reply, free the buf, and return the error code from fuse_reply_buf
    49  * Attempt to send the readdir reply, free the buf, and return the error code from fuse_reply_buf
    48  */
    50  */
    49 int dirbuf_done (fuse_req_t req, struct dirbuf *buf);
    51 int dirbuf_done (fuse_req_t req, struct dirbuf *buf);
    50 
    52 
       
    53 /*
       
    54  * Release the dirop without sending any reply back.
       
    55  *
       
    56  * This is safe to be called multiple times.
       
    57  */
       
    58 void dirbuf_release (struct dirbuf *buf);
       
    59 
    51 #endif /* DIRBUF_H */
    60 #endif /* DIRBUF_H */