From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/3] btrfs-progs: move find_mount_root to utils.[ch]
Date: Mon, 10 Feb 2014 15:28:28 +0800 [thread overview]
Message-ID: <1392017310-19951-2-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1392017310-19951-1-git-send-email-quwenruo@cn.fujitsu.com>
Move find_mount_root to utils.[ch] for general use.
Signed-off-by: Qu Wenruo <quwenruo@cn.fuijitsu.com>
---
cmds-send.c | 49 +------------------------------------------------
commands.h | 1 -
utils.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
utils.h | 1 +
4 files changed, 50 insertions(+), 49 deletions(-)
diff --git a/cmds-send.c b/cmds-send.c
index fc9a01e..9d49ce9 100644
--- a/cmds-send.c
+++ b/cmds-send.c
@@ -39,6 +39,7 @@
#include "ioctl.h"
#include "commands.h"
#include "list.h"
+#include "utils.h"
#include "send.h"
#include "send-utils.h"
@@ -57,54 +58,6 @@ struct btrfs_send {
struct subvol_uuid_search sus;
};
-int find_mount_root(const char *path, char **mount_root)
-{
- FILE *mnttab;
- int fd;
- struct mntent *ent;
- int len;
- int ret;
- int longest_matchlen = 0;
- char *longest_match = NULL;
-
- fd = open(path, O_RDONLY | O_NOATIME);
- if (fd < 0)
- return -errno;
- close(fd);
-
- mnttab = setmntent("/proc/self/mounts", "r");
- if (!mnttab)
- return -errno;
-
- while ((ent = getmntent(mnttab))) {
- len = strlen(ent->mnt_dir);
- if (strncmp(ent->mnt_dir, path, len) == 0) {
- /* match found */
- if (longest_matchlen < len) {
- free(longest_match);
- longest_matchlen = len;
- longest_match = strdup(ent->mnt_dir);
- }
- }
- }
- endmntent(mnttab);
-
- if (!longest_match) {
- fprintf(stderr,
- "ERROR: Failed to find mount root for path %s.\n",
- path);
- return -ENOENT;
- }
-
- ret = 0;
- *mount_root = realpath(longest_match, NULL);
- if (!*mount_root)
- ret = -errno;
-
- free(longest_match);
- return ret;
-}
-
static int get_root_id(struct btrfs_send *s, const char *path, u64 *root_id)
{
struct subvol_info *si;
diff --git a/commands.h b/commands.h
index 23c1201..db70043 100644
--- a/commands.h
+++ b/commands.h
@@ -126,5 +126,4 @@ int cmd_rescue(int argc, char **argv);
int test_issubvolume(char *path);
/* send.c */
-int find_mount_root(const char *path, char **mount_root);
char *get_subvol_name(char *mnt, char *full_path);
diff --git a/utils.c b/utils.c
index 75b37f3..8f06d4e 100644
--- a/utils.c
+++ b/utils.c
@@ -2110,3 +2110,51 @@ int lookup_ino_rootid(int fd, u64 *rootid)
return 0;
}
+
+int find_mount_root(const char *path, char **mount_root)
+{
+ FILE *mnttab;
+ int fd;
+ struct mntent *ent;
+ int len;
+ int ret;
+ int longest_matchlen = 0;
+ char *longest_match = NULL;
+
+ fd = open(path, O_RDONLY | O_NOATIME);
+ if (fd < 0)
+ return -errno;
+ close(fd);
+
+ mnttab = setmntent("/proc/self/mounts", "r");
+ if (!mnttab)
+ return -errno;
+
+ while ((ent = getmntent(mnttab))) {
+ len = strlen(ent->mnt_dir);
+ if (strncmp(ent->mnt_dir, path, len) == 0) {
+ /* match found */
+ if (longest_matchlen < len) {
+ free(longest_match);
+ longest_matchlen = len;
+ longest_match = strdup(ent->mnt_dir);
+ }
+ }
+ }
+ endmntent(mnttab);
+
+ if (!longest_match) {
+ fprintf(stderr,
+ "ERROR: Failed to find mount root for path %s.\n",
+ path);
+ return -ENOENT;
+ }
+
+ ret = 0;
+ *mount_root = realpath(longest_match, NULL);
+ if (!*mount_root)
+ ret = -errno;
+
+ free(longest_match);
+ return ret;
+}
diff --git a/utils.h b/utils.h
index 512c51b..e074732 100644
--- a/utils.h
+++ b/utils.h
@@ -96,5 +96,6 @@ int ask_user(char *question);
int lookup_ino_rootid(int fd, u64 *rootid);
int btrfs_scan_lblkid(int update_kernel);
int get_btrfs_mount(const char *dev, char *mp, size_t mp_size);
+int find_mount_root(const char *path, char **mount_root);
#endif
--
1.8.5.4
next prev parent reply other threads:[~2014-02-10 7:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-10 7:28 [PATCH 0/3] make 'btrfs fi show /mnt/point/' works with ending '/' character Qu Wenruo
2014-02-10 7:28 ` Qu Wenruo [this message]
2014-02-10 7:28 ` [PATCH 2/3] btrfs-progs: Add path_is_mp option for find_mount_root Qu Wenruo
2014-02-10 7:28 ` [PATCH 3/3] btrfs-progs: reuse find_mount_root to determine arg type and so on Qu Wenruo
2014-02-12 2:18 ` [PATCH 0/3] make 'btrfs fi show /mnt/point/' works with ending '/' character Qu Wenruo
2014-02-12 14:31 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392017310-19951-2-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).