diff mbox series

[OpenWrt-Devel,V2] fstools: mount ntfs with ntfs-3g utility if it exist

Message ID 20181001030413.5053-1-rosysong@rosinson.com
State Rejected
Delegated to: John Crispin
Headers show
Series [OpenWrt-Devel,V2] fstools: mount ntfs with ntfs-3g utility if it exist | expand

Commit Message

Rosy Song Oct. 1, 2018, 3:04 a.m. UTC
Signed-off-by: Rosy Song <rosysong@rosinson.com>
---
 block.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Rosy Song Oct. 1, 2018, 3:09 a.m. UTC | #1
Hi, I updated my commit, please check it agagin, thanks a lot!

This patch can mount ntfs with fuseblk fs type and make the deivces to be
       mounted writable.

Signed-off-by: Rosy Song <rosysong@rosinson.com>
---
 block.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 2651c86..b2cd32b 100644
--- a/block.c
+++ b/block.c
@@ -881,7 +881,13 @@ static int handle_mount(const char *source, const char *target,
  size_t mount_opts_len;
  char *mount_opts = NULL, *ptr;

- err = mount(source, target, fstype, m ? m->flags : 0,
+ /* Mount ntfs filesystem with ntfs-3g utility */
+ if (!strcmp(fstype, "ntfs") &&
+     !access("/sbin/mount.ntfs-3g", X_OK)) {
+     err = -1;
+     errno = ENODEV;
+ } else
+     err = mount(source, target, fstype, m ? m->flags : 0,
              (m && m->options) ? m->options : "");

  /* Requested file system type is not available in kernel,
Philip Prindeville Oct. 1, 2018, 4:21 a.m. UTC | #2
I’m not seeing where “mount.ntfs-3g” is being set as the program to use...  and should the test for the presence and modes of the program be generic? i.e. regardless of what type of FS or which program you use to mount it, you’ll want to test for its presence.

So these are really two independent things.


> On Sep 30, 2018, at 9:04 PM, Rosy Song <rosysong@rosinson.com> wrote:
> 
> Signed-off-by: Rosy Song <rosysong@rosinson.com>
> ---
> block.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 2651c86..b2cd32b 100644
> --- a/block.c
> +++ b/block.c
> @@ -881,7 +881,13 @@ static int handle_mount(const char *source, const char *target,
>    size_t mount_opts_len;
>    char *mount_opts = NULL, *ptr;
> 
> -    err = mount(source, target, fstype, m ? m->flags : 0,
> +    /* Mount ntfs filesystem with ntfs-3g utility */
> +    if (!strcmp(fstype, "ntfs") &&
> +        !access("/sbin/mount.ntfs-3g", X_OK)) {
> +        err = -1;
> +        errno = ENODEV;
> +    } else
> +        err = mount(source, target, fstype, m ? m->flags : 0,
>                (m && m->options) ? m->options : "");
> 
>    /* Requested file system type is not available in kernel,
> -- 
> 2.17.0
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Rosy Song Oct. 1, 2018, 12:40 p.m. UTC | #3
1. Users can decided whether to use ntfs-3g themselves, if so, just slect it at "make menuconfig->utility->filesystem->ntfs-3g-utils";
       2. This sentence "access("/sbin/mount.ntfs-3g", X_OK)"   does the test for its presence or not;
       3. There are 2 way to mount devices of ntfs filesystem, default is readonly while writable with fuseblk(ntfs-3g),  
           so we need to do a special test here that avoid user remount it again and again when system boot.


------------------------------------------------------------------
From:Philip Prindeville <philipp_subx@redfish-solutions.com>
Send Time:2018 Oct 1 (Mon) 12:21
To:Rosy Song <rosysong@rosinson.com>
Cc:openwrt-devel <openwrt-devel@lists.openwrt.org>
Subject:Re: [OpenWrt-Devel] [PATCH, V2] fstools: mount ntfs with ntfs-3g utility if it exist

I’m not seeing where “mount.ntfs-3g” is being set as the program to use...  and should the test for the presence and modes of the program be generic? i.e. regardless of what type of FS or which program you use to mount it, you’ll want to test for its presence.

So these are really two independent things.


> On Sep 30, 2018, at 9:04 PM, Rosy Song <rosysong@rosinson.com> wrote:
> 
> Signed-off-by: Rosy Song <rosysong@rosinson.com>
> ---
> block.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/block.c b/block.c
> index 2651c86..b2cd32b 100644
> --- a/block.c
> +++ b/block.c
> @@ -881,7 +881,13 @@ static int handle_mount(const char *source, const char *target,
>    size_t mount_opts_len;
>    char *mount_opts = NULL, *ptr;
> 
> -    err = mount(source, target, fstype, m ? m->flags : 0,
> +    /* Mount ntfs filesystem with ntfs-3g utility */
> +    if (!strcmp(fstype, "ntfs") &&
> +        !access("/sbin/mount.ntfs-3g", X_OK)) {
> +        err = -1;
> +        errno = ENODEV;
> +    } else
> +        err = mount(source, target, fstype, m ? m->flags : 0,
>                (m && m->options) ? m->options : "");
> 
>    /* Requested file system type is not available in kernel,
> -- 
> 2.17.0
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
<div class="__aliyun_email_body_block"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;1. Users can decided whether to use ntfs-3g themselves, if so, just slect it at "make menuconfig-&gt;utility-&gt;filesystem-&gt;ntfs-3g-utils";</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">&nbsp; &nbsp; &nbsp; &nbsp;2. This sentence "<span  style="color:#000000;font-family:Tahoma,Arial;font-size:14.0px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;text-align:start;text-indent:.0px;text-transform:none;widows:2;background-color:#ffffff;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline;">access("/sbin/mount.ntfs-3g",&nbsp;X_OK)</span>"&nbsp; &nbsp;does the test for its presence or not;</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">&nbsp; &nbsp; &nbsp; &nbsp;3. There&nbsp;are&nbsp;2&nbsp;way&nbsp;to&nbsp;mount&nbsp;devices&nbsp;of&nbsp;ntfs&nbsp;filesystem,&nbsp;default&nbsp;is&nbsp;readonly&nbsp;while&nbsp;writable&nbsp;with&nbsp;fuseblk(ntfs-3g),&nbsp;&nbsp;</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;so&nbsp;we&nbsp;need&nbsp;to&nbsp;do&nbsp;a&nbsp;special&nbsp;test&nbsp;here&nbsp;that&nbsp;avoid&nbsp;user&nbsp;remount&nbsp;it&nbsp;again&nbsp;and&nbsp;again&nbsp;when&nbsp;system&nbsp;boot.</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div><blockquote  style="margin-right:.0px;margin-top:.0px;margin-bottom:.0px;"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">------------------------------------------------------------------</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">From:Philip Prindeville &lt;philipp_subx@redfish-solutions.com&gt;</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Send Time:2018 Oct 1 (Mon) 12:21</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">To:Rosy Song &lt;rosysong@rosinson.com&gt;</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Cc:openwrt-devel &lt;openwrt-devel@lists.openwrt.org&gt;</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Subject:Re: [OpenWrt-Devel] [PATCH, V2] fstools: mount ntfs with ntfs-3g utility if it exist</span></div><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;"><br ></span></div>I’m&nbsp;not&nbsp;seeing&nbsp;where&nbsp;“mount.ntfs-3g”&nbsp;is&nbsp;being&nbsp;set&nbsp;as&nbsp;the&nbsp;program&nbsp;to&nbsp;use...&nbsp;&nbsp;and&nbsp;should&nbsp;the&nbsp;test&nbsp;for&nbsp;the&nbsp;presence&nbsp;and&nbsp;modes&nbsp;of&nbsp;the&nbsp;program&nbsp;be&nbsp;generic?&nbsp;i.e.&nbsp;regardless&nbsp;of&nbsp;what&nbsp;type&nbsp;of&nbsp;FS&nbsp;or&nbsp;which&nbsp;program&nbsp;you&nbsp;use&nbsp;to&nbsp;mount&nbsp;it,&nbsp;you’ll&nbsp;want&nbsp;to&nbsp;test&nbsp;for&nbsp;its&nbsp;presence.<br ><br >So&nbsp;these&nbsp;are&nbsp;really&nbsp;two&nbsp;independent&nbsp;things.<br ><br ><br >&gt;&nbsp;On&nbsp;Sep&nbsp;30,&nbsp;2018,&nbsp;at&nbsp;9:04&nbsp;PM,&nbsp;Rosy&nbsp;Song&nbsp;&lt;rosysong@rosinson.com&gt;&nbsp;wrote:<br >&gt;&nbsp;<br >&gt;&nbsp;Signed-off-by:&nbsp;Rosy&nbsp;Song&nbsp;&lt;rosysong@rosinson.com&gt;<br >&gt;&nbsp;---<br >&gt;&nbsp;block.c&nbsp;|&nbsp;8&nbsp;+++++++-<br >&gt;&nbsp;1&nbsp;file&nbsp;changed,&nbsp;7&nbsp;insertions(+),&nbsp;1&nbsp;deletion(-)<br >&gt;&nbsp;<br >&gt;&nbsp;diff&nbsp;--git&nbsp;a/block.c&nbsp;b/block.c<br >&gt;&nbsp;index&nbsp;2651c86..b2cd32b&nbsp;100644<br >&gt;&nbsp;---&nbsp;a/block.c<br >&gt;&nbsp;+++&nbsp;b/block.c<br >&gt;&nbsp;@@&nbsp;-881,7&nbsp;+881,13&nbsp;@@&nbsp;static&nbsp;int&nbsp;handle_mount(const&nbsp;char&nbsp;*source,&nbsp;const&nbsp;char&nbsp;*target,<br >&gt;&nbsp;&nbsp;&nbsp;&nbsp;size_t&nbsp;mount_opts_len;<br >&gt;&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*mount_opts&nbsp;=&nbsp;NULL,&nbsp;*ptr;<br >&gt;&nbsp;<br >&gt;&nbsp;-&nbsp;&nbsp;&nbsp;&nbsp;err&nbsp;=&nbsp;mount(source,&nbsp;target,&nbsp;fstype,&nbsp;m&nbsp;?&nbsp;m-&gt;flags&nbsp;:&nbsp;0,<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Mount&nbsp;ntfs&nbsp;filesystem&nbsp;with&nbsp;ntfs-3g&nbsp;utility&nbsp;*/<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!strcmp(fstype,&nbsp;"ntfs")&nbsp;&amp;&amp;<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!access("/sbin/mount.ntfs-3g",&nbsp;X_OK))&nbsp;{<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;err&nbsp;=&nbsp;-1;<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;errno&nbsp;=&nbsp;ENODEV;<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else<br >&gt;&nbsp;+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;err&nbsp;=&nbsp;mount(source,&nbsp;target,&nbsp;fstype,&nbsp;m&nbsp;?&nbsp;m-&gt;flags&nbsp;:&nbsp;0,<br >&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(m&nbsp;&amp;&amp;&nbsp;m-&gt;options)&nbsp;?&nbsp;m-&gt;options&nbsp;:&nbsp;"");<br >&gt;&nbsp;<br >&gt;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;Requested&nbsp;file&nbsp;system&nbsp;type&nbsp;is&nbsp;not&nbsp;available&nbsp;in&nbsp;kernel,<br >&gt;&nbsp;--&nbsp;<br >&gt;&nbsp;2.17.0<br >&gt;&nbsp;<br >&gt;&nbsp;<br >&gt;&nbsp;_______________________________________________<br >&gt;&nbsp;openwrt-devel&nbsp;mailing&nbsp;list<br >&gt;&nbsp;openwrt-devel@lists.openwrt.org<br >&gt;&nbsp;https://lists.openwrt.org/mailman/listinfo/openwrt-devel</blockquote><div ><br ></div></div>
Jerome BENOIT Oct. 1, 2018, 4:22 p.m. UTC | #4
Le 01/10/2018 à 06:21, Philip Prindeville a écrit :
> I’m not seeing where “mount.ntfs-3g” is being set as the program to use... 

I think this patch is just plain wrong.
A correct one has been done here :
http://lists.infradead.org/pipermail/openwrt-devel/2018-September/014108.html

++
Philip Prindeville Oct. 1, 2018, 4:57 p.m. UTC | #5
> On Oct 1, 2018, at 10:22 AM, Jérôme Benoit <jbenoit100@gmail.com> wrote:
> 
> Signed PGP part
> Le 01/10/2018 à 06:21, Philip Prindeville a écrit :
>> I’m not seeing where “mount.ntfs-3g” is being set as the program to use...
> 
> I think this patch is just plain wrong.
> A correct one has been done here :
> http://lists.infradead.org/pipermail/openwrt-devel/2018-September/014108.html


That one is buggy, too.

@@ -725,6 +726,8 @@ static void check_filesystem(struct probe_info *pr)
 		ckfs = e2fsck;
 	} else if (!strncmp(pr->type, "btrfs", 5)) {
 		ckfs = btrfsck;
+	} else if (!strncmp(pr->type, "ntfs", 5)) {
+		ckfs = ntfsck;
 	} else {
 		ULOG_ERR("check_filesystem: %s is not supported\n", pr->type);
 		return;
@@ -743,6 +746,9 @@ static void check_filesystem(struct probe_info *pr)
 		} else if(!strncmp(pr->type, "btrfs", 5)) {
 			execl(ckfs, ckfs, "--repair", pr->dev, NULL);
 			exit(-1);
+		} else if(!strncmp(pr->type, "ntfs", 5)) {
+			execl(ckfs, ckfs, "-b", pr->dev, NULL);
+			exit(-1);
 		} else {
 			execl(ckfs, ckfs, "-p", pr->dev, NULL);
 			exit(-1);
@@ -1437,8 +1443,9 @@ static int mount_extroot(char *cfg)
 		if (strncmp(pr->type, "ext", 3) &&
 		    strncmp(pr->type, "f2fs", 4) &&
 		    strncmp(pr->type, "btrfs", 5) &&
+		    strncmp(pr->type, "ntfs", 5) &&
 		    strncmp(pr->type, "ubifs", 5)) {
-			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs or ubifs\n", pr->type);
+			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs, ntfs or ubifs\n", pr->type);
 			return -1;
 		}


Uhhh… by my count, “ntfs” is 4 letters, not 5.


> 
> ++
>
Philip Prindeville Oct. 1, 2018, 4:58 p.m. UTC | #6
> On Oct 1, 2018, at 10:22 AM, Jérôme Benoit <jbenoit100@gmail.com> wrote:
> 
> Signed PGP part
> Le 01/10/2018 à 06:21, Philip Prindeville a écrit :
>> I’m not seeing where “mount.ntfs-3g” is being set as the program to use...
> 
> I think this patch is just plain wrong.
> A correct one has been done here :
> http://lists.infradead.org/pipermail/openwrt-devel/2018-September/014108.html


That one is buggy, too.

@@ -725,6 +726,8 @@ static void check_filesystem(struct probe_info *pr)
		ckfs = e2fsck;
	} else if (!strncmp(pr->type, "btrfs", 5)) {
		ckfs = btrfsck;
+	} else if (!strncmp(pr->type, "ntfs", 5)) {
+		ckfs = ntfsck;
	} else {
		ULOG_ERR("check_filesystem: %s is not supported\n", pr->type);
		return;
@@ -743,6 +746,9 @@ static void check_filesystem(struct probe_info *pr)
		} else if(!strncmp(pr->type, "btrfs", 5)) {
			execl(ckfs, ckfs, "--repair", pr->dev, NULL);
			exit(-1);
+		} else if(!strncmp(pr->type, "ntfs", 5)) {
+			execl(ckfs, ckfs, "-b", pr->dev, NULL);
+			exit(-1);
		} else {
			execl(ckfs, ckfs, "-p", pr->dev, NULL);
			exit(-1);
@@ -1437,8 +1443,9 @@ static int mount_extroot(char *cfg)
		if (strncmp(pr->type, "ext", 3) &&
		    strncmp(pr->type, "f2fs", 4) &&
		    strncmp(pr->type, "btrfs", 5) &&
+		    strncmp(pr->type, "ntfs", 5) &&
		    strncmp(pr->type, "ubifs", 5)) {
-			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs or ubifs\n", pr->type);
+			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs, ntfs or ubifs\n", pr->type);
			return -1;
		}


Uhhh… by my count, “ntfs” is 4 letters, not 5.


> 
> ++
>
Rosy Song Oct. 2, 2018, 10:24 a.m. UTC | #7
Sorry,  NO,  I just care about how to mount the ntfs with writable accessibility not for its checking or fixing.


------------------------------------------------------------------
From:Jérôme Benoit <jbenoit100@gmail.com>
Send Time:2018 Oct 2 (Tue) 00:23
To:openwrt-devel <openwrt-devel@lists.openwrt.org>
Subject:Re: [OpenWrt-Devel] [PATCH, V2] fstools: mount ntfs with ntfs-3g utility if it exist

Le 01/10/2018 à 06:21, Philip Prindeville a écrit :
> I’m not seeing where “mount.ntfs-3g” is being set as the program to use... 

I think this patch is just plain wrong.
A correct one has been done here :
http://lists.infradead.org/pipermail/openwrt-devel/2018-September/014108.html

++
Jerome BENOIT Oct. 2, 2018, 12:10 p.m. UTC | #8
...
> @@ -1437,8 +1443,9 @@ static int mount_extroot(char *cfg)
>   		if (strncmp(pr->type, "ext", 3) &&
>   		    strncmp(pr->type, "f2fs", 4) &&
>   		    strncmp(pr->type, "btrfs", 5) &&
> +		    strncmp(pr->type, "ntfs", 5) &&
>   		    strncmp(pr->type, "ubifs", 5)) {
> -			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs or ubifs\n", pr->type);
> +			ULOG_ERR("extroot: unsupported filesystem %s, try ext4, f2fs, btrfs, ntfs or ubifs\n", pr->type);
>   			return -1;
>   		}
>
>
> Uhhh… by my count, “ntfs” is 4 letters, not 5.
>

It's easily fixable. And as long as the ntfs-3g package provide the 
right mount.X binary will just permit to fsck ntfs.
Christian Marangi Oct. 2, 2018, 1:02 p.m. UTC | #9
ntf-3g provide both mount.ntfs and mount.ntfs-3g
Il giorno mar 2 ott 2018 alle ore 14:29 Jerome BENOIT
<jbenoit100@gmail.com> ha scritto:
>
>
> On 02/10/2018 14:24, Ansuel Smith wrote:
> > ntfs-3g provide both mount.ntfs and mount.ntfs-3g
>
> Good, but you should reply also on the list :)
>
> --
> Jérôme Benoit aka fraggle
> Piment Noir - https://piment-noir.org
> OpenPGP Key ID : 27B535D3
> Key fingerprint : B799 BBF6 8EC8 911B B8D7 CDBC C3B1 92C6 27B5 35D3
>
diff mbox series

Patch

diff --git a/block.c b/block.c
index 2651c86..b2cd32b 100644
--- a/block.c
+++ b/block.c
@@ -881,7 +881,13 @@  static int handle_mount(const char *source, const char *target,
 	size_t mount_opts_len;
 	char *mount_opts = NULL, *ptr;
 
-	err = mount(source, target, fstype, m ? m->flags : 0,
+	/* Mount ntfs filesystem with ntfs-3g utility */
+	if (!strcmp(fstype, "ntfs") &&
+	    !access("/sbin/mount.ntfs-3g", X_OK)) {
+	    err = -1;
+	    errno = ENODEV;
+	} else
+	    err = mount(source, target, fstype, m ? m->flags : 0,
 	            (m && m->options) ? m->options : "");
 
 	/* Requested file system type is not available in kernel,