* [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity
@ 2014-07-25 6:16 Satoru Takeuchi
2014-07-29 13:32 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Satoru Takeuchi @ 2014-07-25 6:16 UTC (permalink / raw)
To: linux-btrfs@vger.kernel.org
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
There are many duplicated codes to check if the given string is
correct subvolume name. Introduce test_issubvolname() for this
purpose for simplicity.
Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
---
cmds-subvolume.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 639fb10..b7bfb3e 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -43,6 +43,18 @@ static const char * const subvolume_cmd_group_usage[] = {
};
/*
+ * test if name is a correct subvolume name
+ * this function return
+ * 0-> name is not a correct subvolume name
+ * 1-> name is a correct subvolume name
+ */
+static int test_issubvolname(char *name)
+{
+ return name[0] != '\0' && !strchr(name, '/') &&
+ strcmp(name, ".") && strcmp(name, "..");
+}
+
+/*
* test if path is a directory
* this function return
* 0-> path exists but it is not a directory
@@ -127,8 +139,7 @@ static int cmd_subvol_create(int argc, char **argv)
dupdir = strdup(dst);
dstdir = dirname(dupdir);
- if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
- strchr(newname, '/') ){
+ if (!test_issubvolname(newname)) {
fprintf(stderr, "ERROR: uncorrect subvolume name ('%s')\n",
newname);
goto out;
@@ -302,8 +313,7 @@ again:
vname = basename(dupvname);
free(cpath);
- if (!strcmp(vname, ".") || !strcmp(vname, "..") ||
- strchr(vname, '/')) {
+ if (!test_issubvolname(vname)) {
fprintf(stderr, "ERROR: incorrect subvolume name ('%s')\n",
vname);
ret = 1;
@@ -711,8 +721,7 @@ static int cmd_snapshot(int argc, char **argv)
dstdir = dirname(dupdir);
}
- if (!strcmp(newname, ".") || !strcmp(newname, "..") ||
- strchr(newname, '/') ){
+ if (!test_issubvolname(newname)) {
fprintf(stderr, "ERROR: incorrect snapshot name ('%s')\n",
newname);
goto out;
--
1.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity
2014-07-25 6:16 [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity Satoru Takeuchi
@ 2014-07-29 13:32 ` David Sterba
2014-07-30 2:58 ` Satoru Takeuchi
0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2014-07-29 13:32 UTC (permalink / raw)
To: Satoru Takeuchi; +Cc: linux-btrfs@vger.kernel.org
On Fri, Jul 25, 2014 at 03:16:58PM +0900, Satoru Takeuchi wrote:
> From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
>
> There are many duplicated codes to check if the given string is
> correct subvolume name. Introduce test_issubvolname() for this
> purpose for simplicity.
Please move it to utils.c
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity
2014-07-29 13:32 ` David Sterba
@ 2014-07-30 2:58 ` Satoru Takeuchi
2014-07-30 15:54 ` David Sterba
0 siblings, 1 reply; 4+ messages in thread
From: Satoru Takeuchi @ 2014-07-30 2:58 UTC (permalink / raw)
To: dsterba, linux-btrfs@vger.kernel.org
Hi David,
(2014/07/29 22:32), David Sterba wrote:
> On Fri, Jul 25, 2014 at 03:16:58PM +0900, Satoru Takeuchi wrote:
>> From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
>>
>> There are many duplicated codes to check if the given string is
>> correct subvolume name. Introduce test_issubvolname() for this
>> purpose for simplicity.
>
> Please move it to utils.c
OK, I'll do. In addition, how about moving test_isdir() and
test_issubvolume() to utils.c too? These are also utility functions.
Thanks,
Satoru
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity
2014-07-30 2:58 ` Satoru Takeuchi
@ 2014-07-30 15:54 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2014-07-30 15:54 UTC (permalink / raw)
To: Satoru Takeuchi; +Cc: dsterba, linux-btrfs@vger.kernel.org
On Wed, Jul 30, 2014 at 11:58:37AM +0900, Satoru Takeuchi wrote:
> Hi David,
>
> (2014/07/29 22:32), David Sterba wrote:
> >On Fri, Jul 25, 2014 at 03:16:58PM +0900, Satoru Takeuchi wrote:
> >>From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
> >>
> >>There are many duplicated codes to check if the given string is
> >>correct subvolume name. Introduce test_issubvolname() for this
> >>purpose for simplicity.
> >
> >Please move it to utils.c
>
> OK, I'll do. In addition, how about moving test_isdir() and
> test_issubvolume() to utils.c too? These are also utility functions.
Yes, makes sense.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-07-30 15:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-25 6:16 [PATCH 1/2] btrfs-progs: introduce test_issubvolname() for simplicity Satoru Takeuchi
2014-07-29 13:32 ` David Sterba
2014-07-30 2:58 ` Satoru Takeuchi
2014-07-30 15:54 ` David Sterba
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).