diff mbox series

[9/9] Killing dirstream: remove unused functions

Message ID ce355406e95eb53fbb8b63170a7251986b49fdf7.1707423567.git.kreijack@inwind.it (mailing list archive)
State New, archived
Headers show
Series Remove unused dirstream variable | expand

Commit Message

Goffredo Baroncelli Feb. 8, 2024, 8:19 p.m. UTC
From: Goffredo Baroncelli <kreijack@inwind.it>

Remove the following unused functions:
- btrfs_open_dir()
- open_file_or_dir()
- btrfs_open_file_or_dir()
- btrfs_open()
- open_path_or_dev_mnt()
- open_file_or_dir3()
- close_file_or_dir()

Signed-off-by: Goffredo Baroncelli <kreijack@libero.it>
---
 common/open-utils.c | 135 --------------------------------------------
 common/open-utils.h |  10 ----
 2 files changed, 145 deletions(-)
diff mbox series

Patch

diff --git a/common/open-utils.c b/common/open-utils.c
index 87f71196..cac89bc3 100644
--- a/common/open-utils.c
+++ b/common/open-utils.c
@@ -183,141 +183,6 @@  out:
 	return ret;
 }
 
-/*
- * Given a pathname, return a filehandle to:
- * 	the original pathname or,
- * 	if the pathname is a mounted btrfs device, to its mountpoint.
- *
- * On error, return -1, errno should be set.
- */
-int open_path_or_dev_mnt(const char *path, DIR **dirstream, int verbose)
-{
-	char mp[PATH_MAX];
-	int ret;
-
-	if (path_is_block_device(path)) {
-		ret = get_btrfs_mount(path, mp, sizeof(mp));
-		if (ret < 0) {
-			/* not a mounted btrfs dev */
-			error_on(verbose, "'%s' is not a mounted btrfs device",
-				 path);
-			errno = EINVAL;
-			return -1;
-		}
-		ret = open_file_or_dir(mp, dirstream);
-		error_on(verbose && ret < 0, "can't access '%s': %m",
-			 path);
-	} else {
-		ret = btrfs_open_dir(path, dirstream, 1);
-	}
-
-	return ret;
-}
-
-/*
- * Do the following checks before calling open_file_or_dir():
- * 1: path is in a btrfs filesystem
- * 2: path is a directory if dir_only is 1
- */
-int btrfs_open(const char *path, DIR **dirstream, int verbose, int dir_only)
-{
-	struct statfs stfs;
-	struct stat st;
-	int ret;
-
-	if (stat(path, &st) != 0) {
-		error_on(verbose, "cannot access '%s': %m", path);
-		return -1;
-	}
-
-	if (dir_only && !S_ISDIR(st.st_mode)) {
-		error_on(verbose, "not a directory: %s", path);
-		return -3;
-	}
-
-	if (statfs(path, &stfs) != 0) {
-		error_on(verbose, "cannot access '%s': %m", path);
-		return -1;
-	}
-
-	if (stfs.f_type != BTRFS_SUPER_MAGIC) {
-		error_on(verbose, "not a btrfs filesystem: %s", path);
-		return -2;
-	}
-
-	ret = open_file_or_dir(path, dirstream);
-	if (ret < 0) {
-		error_on(verbose, "cannot access '%s': %m", path);
-	}
-
-	return ret;
-}
-
-int btrfs_open_dir(const char *path, DIR **dirstream, int verbose)
-{
-	return btrfs_open(path, dirstream, verbose, 1);
-}
-
-int btrfs_open_file_or_dir(const char *path, DIR **dirstream, int verbose)
-{
-	return btrfs_open(path, dirstream, verbose, 0);
-}
-
-int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags)
-{
-	int ret;
-	struct stat st;
-	int fd;
-
-	ret = stat(fname, &st);
-	if (ret < 0) {
-		return -1;
-	}
-	if (S_ISDIR(st.st_mode)) {
-		*dirstream = opendir(fname);
-		if (!*dirstream)
-			return -1;
-		fd = dirfd(*dirstream);
-	} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
-		fd = open(fname, open_flags);
-	} else {
-		/*
-		 * we set this on purpose, in case the caller output
-		 * strerror(errno) as success
-		 */
-		errno = EINVAL;
-		return -1;
-	}
-	if (fd < 0) {
-		fd = -1;
-		if (*dirstream) {
-			closedir(*dirstream);
-			*dirstream = NULL;
-		}
-	}
-	return fd;
-}
-
-int open_file_or_dir(const char *fname, DIR **dirstream)
-{
-	return open_file_or_dir3(fname, dirstream, O_RDWR);
-}
-
-void close_file_or_dir(int fd, DIR *dirstream)
-{
-	int old_errno;
-
-	old_errno = errno;
-	if (dirstream) {
-		closedir(dirstream);
-	} else if (fd >= 0) {
-		close(fd);
-	}
-
-	errno = old_errno;
-}
-
-
 /*
  * Do the following checks before calling open:
  * 1: path is in a btrfs filesystem
diff --git a/common/open-utils.h b/common/open-utils.h
index 96d99f5d..5642b951 100644
--- a/common/open-utils.h
+++ b/common/open-utils.h
@@ -28,16 +28,6 @@  int check_mounted_where(int fd, const char *file, char *where, int size,
 			bool noscan);
 int check_mounted(const char* file);
 int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
-int open_path_or_dev_mnt(const char *path, DIR **dirstream, int verbose);
-
-int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags);
-int open_file_or_dir(const char *fname, DIR **dirstream);
-
-int btrfs_open(const char *path, DIR **dirstream, int verbose, int dir_only);
-int btrfs_open_dir(const char *path, DIR **dirstream, int verbose);
-int btrfs_open_file_or_dir(const char *path, DIR **dirstream, int verbose);
-
-void close_file_or_dir(int fd, DIR *dirstream);
 
 int btrfs_open_fd2(const char *path, bool verbose, bool read_write, bool dir_only);
 int btrfs_open_file_or_dir_fd(const char *path);