示例#1
0
/* pack element into buffer and return number of bytes written */
static size_t list_elem_pack2(void* buf, int detail, uint64_t chars, const elem_t* elem)
{
    /* set pointer to start of buffer */
    char* start = (char*) buf;
    char* ptr = start;

    /* copy in detail flag */
    mfu_pack_uint32(&ptr, (uint32_t) detail);

    /* copy in length of file name field */
    mfu_pack_uint32(&ptr, (uint32_t) chars);

    /* copy in file name */
    char* file = elem->file;
    strcpy(ptr, file);
    ptr += chars;

    if (detail) {
        /* copy in fields */
        mfu_pack_uint64(&ptr, elem->mode);
        mfu_pack_uint64(&ptr, elem->uid);
        mfu_pack_uint64(&ptr, elem->gid);
        mfu_pack_uint64(&ptr, elem->atime);
        mfu_pack_uint64(&ptr, elem->atime_nsec);
        mfu_pack_uint64(&ptr, elem->mtime);
        mfu_pack_uint64(&ptr, elem->mtime_nsec);
        mfu_pack_uint64(&ptr, elem->ctime);
        mfu_pack_uint64(&ptr, elem->ctime_nsec);
        mfu_pack_uint64(&ptr, elem->size);
    }
    else {
        /* just have the file type */
        mfu_pack_uint32(&ptr, elem->type);
    }

    size_t bytes = (size_t)(ptr - start);
    return bytes;
}
示例#2
0
static void mfu_pack_stat(char** pptr, const struct stat* s)
{
    mfu_pack_uint64(pptr, (uint64_t) s->st_dev);
    mfu_pack_uint64(pptr, (uint64_t) s->st_ino);
    mfu_pack_uint64(pptr, (uint64_t) s->st_mode);
    mfu_pack_uint64(pptr, (uint64_t) s->st_nlink);
    mfu_pack_uint64(pptr, (uint64_t) s->st_uid);
    mfu_pack_uint64(pptr, (uint64_t) s->st_gid);
    mfu_pack_uint64(pptr, (uint64_t) s->st_rdev);
    mfu_pack_uint64(pptr, (uint64_t) s->st_size);
    mfu_pack_uint64(pptr, (uint64_t) s->st_blksize);
    mfu_pack_uint64(pptr, (uint64_t) s->st_blocks);

    uint64_t secs, nsecs;
    mfu_stat_get_atimes(s, &secs, &nsecs);
    mfu_pack_uint64(pptr, secs);
    mfu_pack_uint64(pptr, nsecs);

    mfu_stat_get_mtimes(s, &secs, &nsecs);
    mfu_pack_uint64(pptr, secs);
    mfu_pack_uint64(pptr, nsecs);

    mfu_stat_get_ctimes(s, &secs, &nsecs);
    mfu_pack_uint64(pptr, secs);
    mfu_pack_uint64(pptr, nsecs);

    return;
}