/* SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef V_ALPM_NATIVE_EXTRACT_H #define V_ALPM_NATIVE_EXTRACT_H #include #include #include #include #include #include static int64_t v_alpm_extract_write(int fd, const void *data, size_t size, int64_t offset) { return pwrite(fd, data, size, (off_t)offset); } static int v_alpm_extract_node(int parent, const char *name, uint32_t mode, uint64_t major_number, uint64_t minor_number) { return mknodat(parent, name, mode, makedev(major_number, minor_number)); } static int v_alpm_extract_chown(int fd, const char *path, uint32_t uid, uint32_t gid) { if(fd >= 0) { return fchown(fd, uid, gid); } return fchownat(AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW); } static int v_alpm_extract_chmod(int fd, const char *path, uint32_t mode) { if(fd >= 0) { return fchmod(fd, mode); } return fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW); } static int v_alpm_extract_owner(int fd, const char *path, uint32_t *uid, uint32_t *gid) { struct stat info; if((fd >= 0 ? fstat(fd, &info) : lstat(path, &info)) != 0) { return -1; } *uid = info.st_uid; *gid = info.st_gid; return 0; } static int v_alpm_extract_times(int fd, const char *path, int atime_set, int64_t atime, int64_t atime_nsec, int mtime_set, int64_t mtime, int64_t mtime_nsec, int64_t started_at) { if(!atime_set && !mtime_set) { return 0; } struct timespec times[2] = { {.tv_sec = atime_set ? atime : started_at, .tv_nsec = atime_set ? atime_nsec : 0}, {.tv_sec = mtime_set ? mtime : started_at, .tv_nsec = mtime_set ? mtime_nsec : 0} }; if(fd >= 0) { return futimens(fd, times); } return utimensat(AT_FDCWD, path, times, AT_SYMLINK_NOFOLLOW); } static int v_alpm_extract_xattr(int fd, const char *path, const char *name, const void *value, size_t size) { if(fd >= 0) { return fsetxattr(fd, name, value, size, 0); } return lsetxattr(path, name, value, size, 0); } #endif