/* unpack element from buffer and return number of bytes read */ static size_t list_elem_unpack2(const void* buf, elem_t* elem) { /* set pointer to start of buffer */ const char* start = (const char*) buf; const char* ptr = start; /* extract detail field */ uint32_t detail; mfu_unpack_uint32(&ptr, &detail); /* extract length of file name field */ uint32_t chars; mfu_unpack_uint32(&ptr, &chars); /* get name and advance pointer */ const char* file = ptr; ptr += chars; /* copy path */ elem->file = MFU_STRDUP(file); /* set depth */ elem->depth = mfu_flist_compute_depth(file); elem->detail = (int) detail; if (detail) { /* extract fields */ mfu_unpack_uint64(&ptr, &elem->mode); mfu_unpack_uint64(&ptr, &elem->uid); mfu_unpack_uint64(&ptr, &elem->gid); mfu_unpack_uint64(&ptr, &elem->atime); mfu_unpack_uint64(&ptr, &elem->atime_nsec); mfu_unpack_uint64(&ptr, &elem->mtime); mfu_unpack_uint64(&ptr, &elem->mtime_nsec); mfu_unpack_uint64(&ptr, &elem->ctime); mfu_unpack_uint64(&ptr, &elem->ctime_nsec); mfu_unpack_uint64(&ptr, &elem->size); /* use mode to set file type */ elem->type = mfu_flist_mode_to_filetype((mode_t)elem->mode); } else { /* only have type */ uint32_t type; mfu_unpack_uint32(&ptr, &type); elem->type = (mfu_filetype) type; } size_t bytes = (size_t)(ptr - start); return bytes; }
static void mfu_unpack_stat(const char** pptr, struct stat* s) { uint64_t val; mfu_unpack_uint64(pptr, &val); s->st_dev = (dev_t) val; mfu_unpack_uint64(pptr, &val); s->st_ino = (ino_t) val; mfu_unpack_uint64(pptr, &val); s->st_mode = (mode_t) val; mfu_unpack_uint64(pptr, &val); s->st_nlink = (nlink_t) val; mfu_unpack_uint64(pptr, &val); s->st_uid = (uid_t) val; mfu_unpack_uint64(pptr, &val); s->st_gid = (gid_t) val; mfu_unpack_uint64(pptr, &val); s->st_rdev = (dev_t) val; mfu_unpack_uint64(pptr, &val); s->st_size = (off_t) val; mfu_unpack_uint64(pptr, &val); s->st_blksize = (blksize_t) val; mfu_unpack_uint64(pptr, &val); s->st_blocks = (blkcnt_t) val; uint64_t secs, nsecs; mfu_unpack_uint64(pptr, &secs); mfu_unpack_uint64(pptr, &nsecs); mfu_stat_set_atimes(s, secs, nsecs); mfu_unpack_uint64(pptr, &secs); mfu_unpack_uint64(pptr, &nsecs); mfu_stat_set_mtimes(s, secs, nsecs); mfu_unpack_uint64(pptr, &secs); mfu_unpack_uint64(pptr, &nsecs); mfu_stat_set_ctimes(s, secs, nsecs); return; }