FAQ SearchLogin
Tuxera Home
View unanswered posts | View active topics It is currently Wed Nov 25, 2020 10:17



Post new topic Reply to topic  [ 5 posts ] 
[PATCH] Fix mount when hibernated and read-only option set 
Author Message

Joined: Fri Aug 15, 2014 19:04
Posts: 2
Post [PATCH] Fix mount when hibernated and read-only option set
I have been struggling with a bug in NTFS-3G where NTFS will refuse to mount due to hibernation or Windows 8 fast restart being enabled, even if I specify the read-only mount option as suggested by the "Windows is hibernated; refusing to mount" error text:

Code:
mount.ntfs-3g -o ro /dev/sda4 /mnt/sda4


The following simple patch fixes the bug and allows read-only mounts even if hibernated or in fast restart mode.

Code:
diff -Naur a/src/ntfs-3g.c b/src/ntfs-3g.c
--- a/src/ntfs-3g.c   2014-02-15 09:07:52.000000000 -0500
+++ b/src/ntfs-3g.c   2014-08-15 12:52:07.543346848 -0400
@@ -3427,7 +3427,12 @@
   if (ctx->hiberfile && ntfs_volume_check_hiberfile(ctx->vol, 0)) {
      if (errno != EPERM)
         goto err_out;
-      if (ntfs_fuse_rm("/hiberfil.sys"))
+      /* Modified by Jody Bruchon to allow read-only mount
+       * even if system is hibernated or in fast restart mode.
+       * This fixes the bug where '-o ro' is suggested as a
+       * workaround but the workaround does not actually work.
+       */
+      if (!ctx->ro && ntfs_fuse_rm("/hiberfil.sys"))
         goto err_out;
   }


Fri Aug 15, 2014 19:13
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: [PATCH] Fix mount when hibernated and read-only option set
Hi,

LGTM, Thanks

Regards

Jean-Pierre


Fri Aug 15, 2014 21:06
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: [PATCH] Fix mount when hibernated and read-only option set
Hi,

There is something wrong with this patch :
Quote:
if (ctx->hiberfile && ntfs_volume_check_hiberfile(ctx->vol, 0)) {
[...]
- if (ntfs_fuse_rm("/hiberfil.sys"))
+ if (!ctx->ro && ntfs_fuse_rm("/hiberfil.sys"))
goto err_out;
}

For this patch to have some effect, ctx->hiberfile has to be true (the option remove_hiberfile has to be set), which is not the case in your mount command.

And removing the /hiberfil.sys file is contradictory with mounting read-only....

Please detail the situation in which the patch is needed, and the ntfs-3g version you are using.

Regards

Jean-Pierre


Sat Aug 16, 2014 12:30
Profile

Joined: Fri Aug 15, 2014 19:04
Posts: 2
Post Re: [PATCH] Fix mount when hibernated and read-only option set
Quote:
For this patch to have some effect, ctx->hiberfile has to be true (the option remove_hiberfile has to be set), which is not the case in your mount command.

I worked backwards from the error text and ntfs_volume_check_hiberfile() to determine that this code path is being taken. On closer analysis it seems that ntfs-3g is not initializing ctx->hiberfile before using it. A grep of the code indicates that ctx->hiberfile (defined as BOOL in typedef struct ntfs_fuse_context_t) is uninitialized and is therefore defaulting to 0 (TRUE), so ctx->hiberfile = TRUE; is effectively a no-op. All mounts are treated as if remove_hiberfile was specified, so this code path is unconditionally followed in the "Windows is hibernated or using fast restart" case. If I were to revise the patch, I'd throw out my previous patch and instead initialize ctx->hiberfile = FALSE; early in ntfs-3g.c.

Quote:
Please detail the situation in which the patch is needed, and the ntfs-3g version you are using.

ntfs-3g_ntfsprogs 2014.02.15 compiled from Tuxera source. I have a computer repair shop and since moving from a version of ntfs-3g released in 2011 we cannot mount and pull data from any Windows 8 filesystems because customers (obviously) do not have fast restart disabled and do not hold SHIFT while shutting it down, plus most modern laptops are set up to hibernate automatically, effectively barring us from recovering any customer data without either using this patch, using another Windows machine (not acceptable in our workflow) or reverting to a non-Win8-aware version of the software.


Sat Aug 16, 2014 16:24
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: [PATCH] Fix mount when hibernated and read-only option set
Hi,

Quote:
A grep of the code indicates that ctx->hiberfile (defined as BOOL in typedef struct ntfs_fuse_context_t) is uninitialized

The full context is initialized and zeroed when it is allocated in function ntfs_fuse_init() by function ntfs_calloc() which zeroes the allocated memory.
Quote:
and is therefore defaulting to 0 (TRUE), so ctx->hiberfile = TRUE;

The usual definition of TRUE is 1, not 0. The initial value of ctx->hiberfile is expected to be FALSE.
Quote:
I'd throw out my previous patch and and instead initialize ctx->hiberfile = FALSE; early in ntfs-3g.c

Please try, this will make the initialization point clear.
Quote:
we cannot mount and pull data from any Windows 8

So you have met some bug, and at least you have a workaround now, but so far I have not been able to reproduce the issue.

Which Linux kernel are you using ? Which compiler ? Which ./configure options ?
What are the mount options shown in your syslog (grep both "Cmdline options" and "Mount options")

Regards

Jean-Pierre


Sat Aug 16, 2014 18:28
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Original forum style by Vjacheslav Trushkin.