From 1f7d4c72f4d8b01d72a0e2bb27fa19689533ca25 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Mon, 23 Mar 2026 04:48:14 +0000 Subject: remove dead code WIP Signed-off-by: Leah Rowe --- util/nvmutil/lib/file.c | 143 ++++-------------------------------------------- 1 file changed, 12 insertions(+), 131 deletions(-) (limited to 'util/nvmutil/lib/file.c') diff --git a/util/nvmutil/lib/file.c b/util/nvmutil/lib/file.c index a490b358..b605d488 100644 --- a/util/nvmutil/lib/file.c +++ b/util/nvmutil/lib/file.c @@ -936,11 +936,23 @@ mkhtemp_try_create(int dirfd, if (fd_verify_dir_identity(dirfd, st_dir_initial) < 0) goto err; + if (fstat(*fd, &st_open) < 0) + goto err; + + if (!S_ISDIR(st_open.st_mode)) { + errno = ENOTDIR; + goto err; + } + *fd = openat2p(dirfd, fname_copy, O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0); if (*fd < 0) goto err; + /* NOTE: could check nlink count here, + * but it's not very reliable here. skipped. + */ + if (fd_verify_dir_identity(dirfd, st_dir_initial) < 0) goto err; @@ -1883,137 +1895,6 @@ fs_rename_at(int olddirfd, const char *old, return renameat(olddirfd, old, newdirfd, new); } -int -fs_rm_rf_at(int dirfd, const char *path) -{ - int fd = -1; - struct stat st; - - if (path == NULL) { - errno = EFAULT; - return -1; - } - - fd = fs_resolve_at(dirfd, path, O_RDONLY | O_DIRECTORY); - if (fd >= 0) { - /* directory */ - /* iterate entries */ - /* recurse */ - /* unlinkat(dirfd, path, AT_REMOVEDIR) */ - - return 0; - } - - /* fallback: file */ - return unlinkat(dirfd, path, 0); -} - -int -fs_mkdir_p(const char *path, mode_t mode) -{ - struct filesystem *fs; - - if (path == NULL) { - errno = EFAULT; - return -1; - } - if (path[0] != '/') { - errno = EINVAL; - return -1; - } - - fs = rootfs(); - if (fs == NULL) - return -1; - - return fs_mkdir_p_at(fs->rootfd, path + 1, mode); -} - -/* implementation of: mkdir -p - */ -int -fs_mkdir_p_at(int dirfd, const char *path, mode_t mode) -{ - const char *p = path; - char name[256]; - int nextfd = -1; - struct stat st_parent_initial; - struct stat st_parent_now; - int saved_errno = errno; - int close_errno; - int dir_created = 0; - int r; - - if (path == NULL) { - - errno = EFAULT; - return -1; - } - - if (dirfd < 0 || *path == '\0') { - - errno = EINVAL; - return -1; - } - - if (fstat(dirfd, &st_parent_initial) < 0) - return -1; - - for (;;) { - - r = fs_next_component(&p, name, sizeof(name)); - if (r < 0) - goto err; - if (r == 0) - break; - - /* check parent integrity */ - if (fd_verify_identity(dirfd, &st_parent_initial, - &st_parent_now) < 0) - goto err; - - nextfd = openat2p(dirfd, name, - O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0); - - if (nextfd < 0) { - if (errno != ENOENT) - goto err; - - if (mkdirat_on_eintr(dirfd, name, mode) < 0) - goto err; - - dir_created = 1; - - nextfd = openat2p(dirfd, name, - O_RDONLY | O_DIRECTORY | O_CLOEXEC, 0); - if (nextfd < 0) - goto err; - } - - close_errno = errno; - (void)close_on_eintr(dirfd); - errno = close_errno; - dirfd = nextfd; - nextfd = -1; - - st_parent_initial = st_parent_now; - } - - errno = saved_errno; - return (0); - -err: - if (dirfd >= 0) - (void) close_on_eintr(dirfd); - if (nextfd >= 0) - (void) close_on_eintr(nextfd); - if (dir_created) - (void) unlinkat(dirfd, name, AT_REMOVEDIR); - - errno = saved_errno; - return (-1); -} - /* secure open, based on * relative path to root * -- cgit v1.2.1