btrfs-progs: remove unused opening functions

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>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Goffredo Baroncelli 2024-02-08 21:19:27 +01:00 committed by David Sterba
parent 89867394e5
commit 67a0cfd914
2 changed files with 0 additions and 144 deletions

View File

@ -183,140 +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;
}
/*
* Open the given path and check if it's a btrfs filesystem.
*/

View File

@ -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);