diff mbox

[LEDE-DEV,2/4,RFC] fstools: block.c: Add support for checking vfat filesystems

Message ID 1463566368-12396-3-git-send-email-lede@daniel.thecshore.com
State Superseded
Headers show

Commit Message

Daniel Dickinson May 18, 2016, 10:12 a.m. UTC
From: Daniel Dickinson <lede@daniel.thecshore.com>

vfat is a common filesystem which users may want to mount on an
OpenWrt/LEDE device, so support peforming filesystem checks
before mount for vfat.

Signed-off-by: Daniel Dickinson <lede@daniel.thecshore.com>
---
 block.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Conor O'Gorman May 18, 2016, 11:05 a.m. UTC | #1
On 18/05/16 11:12, lede@daniel.thecshore.com wrote:
> +	if (!strncmp(pr->id->name, "vfat", 4)) {
> +		ckfs = e2fsck;
> +	} else if (!strncmp(pr->id->name, "ext", 3)) {
> +		ckfs = dosfsck;
Is this the wrong way round?
Daniel Dickinson May 18, 2016, 11:12 a.m. UTC | #2
On 16-05-18 07:05 AM, Conor O'Gorman wrote:
> On 18/05/16 11:12, lede@daniel.thecshore.com wrote:
>> +    if (!strncmp(pr->id->name, "vfat", 4)) {
>> +        ckfs = e2fsck;
>> +    } else if (!strncmp(pr->id->name, "ext", 3)) {
>> +        ckfs = dosfsck;
> Is this the wrong way round?

Do you mean you mean you think ext should be tested first?


ckfs = x is obvious correction because we're setting the ckfs to the
command to do the filesystem check.

Otherwise I'm not sure what you're asking...

Perhaps your problem is with the C idiom (!strncmp is correct because
strncmp returns 0 on a match (which == false for the if)).

I have no other guesses as to what you're getting at.

Regards,

Daniel
Jo-Philipp Wich May 18, 2016, 11:15 a.m. UTC | #3
Hi,

>>> +    if (!strncmp(pr->id->name, "vfat", 4)) {

"If fs name starts with vfat ..."

>>> +        ckfs = e2fsck;

"... then use the ext4 checker".

>>> +    } else if (!strncmp(pr->id->name, "ext", 3)) {

"... else if fs name starts with ext ..."

>>> +        ckfs = dosfsck;

"... then use the dosfs checker".

>> Is this the wrong way round?
> 
> Do you mean you mean you think ext should be tested first?

That certainly looks swapped to me as well.

~ Jo
Arjen de Korte May 18, 2016, 11:17 a.m. UTC | #4
Citeren Daniel Dickinson <lede@daniel.thecshore.com>:

> On 16-05-18 07:05 AM, Conor O'Gorman wrote:
>> On 18/05/16 11:12, lede@daniel.thecshore.com wrote:
>>> +    if (!strncmp(pr->id->name, "vfat", 4)) {
>>> +        ckfs = e2fsck;
>>> +    } else if (!strncmp(pr->id->name, "ext", 3)) {
>>> +        ckfs = dosfsck;
>> Is this the wrong way round?
>
> Do you mean you mean you think ext should be tested first?
>
>
> ckfs = x is obvious correction because we're setting the ckfs to the
> command to do the filesystem check.
>
> Otherwise I'm not sure what you're asking...
>
> Perhaps your problem is with the C idiom (!strncmp is correct because
> strncmp returns 0 on a match (which == false for the if)).
>
> I have no other guesses as to what you're getting at.

I guess "vfat" should be checked with dosfsck and "ext" with e2fsck.
Daniel Curran-Dickinson May 18, 2016, 11:20 a.m. UTC | #5
On 16-05-18 07:17 AM, Arjen de Korte wrote:
> Citeren Daniel Dickinson <lede@daniel.thecshore.com>:
> 
> 
> I guess "vfat" should be checked with dosfsck and "ext" with e2fsck.
> 

Ah, the old you see what you expect to see psychology thing - I missed that.

Regards,

Daniel
diff mbox

Patch

diff --git a/block.c b/block.c
index 71ffd0b..c2adf3c 100644
--- a/block.c
+++ b/block.c
@@ -628,24 +628,30 @@  static void check_filesystem(struct blkid_struct_probe *pr)
 	pid_t pid;
 	struct stat statbuf;
 	const char *e2fsck = "/usr/sbin/e2fsck";
+	const char *dosfsck = "/sbin/dosfsck";
+	const char *ckfs;
 
 	/* UBIFS does not need stuff like fsck */
 	if (!strncmp(pr->id->name, "ubifs", 5))
 		return;
 
-	if (strncmp(pr->id->name, "ext", 3)) {
+	if (!strncmp(pr->id->name, "vfat", 4)) {
+		ckfs = e2fsck;
+	} else if (!strncmp(pr->id->name, "ext", 3)) {
+		ckfs = dosfsck;
+	} else {
 		ULOG_ERR("check_filesystem: %s is not supported\n", pr->id->name);
 		return;
 	}
 
-	if (stat(e2fsck, &statbuf) < 0) {
+	if (stat(ckfs, &statbuf) < 0) {
 		ULOG_ERR("check_filesystem: %s not found\n", e2fsck);
 		return;
 	}
 
 	pid = fork();
 	if (!pid) {
-		execl(e2fsck, e2fsck, "-p", pr->dev, NULL);
+		execl(ckfs, ckfs, "-p", pr->dev, NULL);
 		exit(-1);
 	} else if (pid > 0) {
 		int status;