bug-ddrescue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-ddrescue] Patch to support -d on Darwin and Mac OS X


From: Christian Franke
Subject: Re: [Bug-ddrescue] Patch to support -d on Darwin and Mac OS X
Date: Fri, 31 Aug 2007 22:24:26 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4

Antonio Diaz Diaz wrote:
Rob Terrell wrote:
I made a modification to main.cc so to support ddrescue's direct mode ("-d") when running on Mac OS X or Darwin systems. It seems to work-- in my test case, without -d a volume copy (with around 300 errors) took more than twice as long.

Thanks for the patch. It may be useful for Darwin users. As it is I find it too intrusive to include it in ddrescue, but perhaps someone could find a more portable way of getting direct disk access.


Both O_DIRECT and F_NOCACHE are not part of POSIX, so there probably is no portable way without at least one more nasty #ifdef. POSIX provides only O_SYNC, I don't know whether this has any effect on raw devices.

Interestingly, F_NOCACHE does also not appear in GNU dd (coreutils 6.9). Hmm...

An alternative patch is attached. It does not require DARWIN defined, but relies on O_DIRECT undefined or defined as 0 in Darwin's includes. Caution: Not actually tested on Darwin ;-)

BTW: On Cygwin, 1.6-pre2 builds OOTB and works.

Christian

--- main.cc.orig        2007-08-18 13:49:47.000000000 +0200
+++ main.cc     2007-08-31 22:00:05.978568800 +0200
@@ -182,7 +182,7 @@
   const int cluster_bytes = 65536, default_hardbs = 512;
   int cluster = 0, hardbs = 512;
   int max_errors = -1, max_retries = 0;
-  int o_direct = 0, o_trunc = 0, verbosity = 0;
+  int o_direct = 0, f_nocache = 0, o_trunc = 0, verbosity = 0;
   bool complete_only = false, nosplit = false, sparse = false;
   invocation_name = argv[0];
 
@@ -227,7 +227,11 @@
 #ifdef O_DIRECT
                 o_direct = O_DIRECT;
 #endif
+#ifdef F_NOCACHE // Darwin
                 if( !o_direct )
+                  f_nocache = F_NOCACHE;
+#endif
+                if( !o_direct && !f_nocache )
                   { show_error( "direct disc access not available" ); return 
1; }
                 break;
       case 'e': max_errors = getnum( arg, 0, -1, INT_MAX ); break;
@@ -267,6 +271,11 @@
 
   const int ides = open( iname, O_RDONLY | o_direct );
   if( ides < 0 ) { show_error( "cannot open input file", errno ); return 1; }
+  if( f_nocache ) {
+    if( fcntl( ides, f_nocache, 1 ) < 0 )
+      { show_error( "cannot disable file caching", errno ); return 1; }
+  }
+
   const long long isize = lseek( ides, 0, SEEK_END );
   if( isize < 0 ) { show_error( "input file is not seekable" ); return 1; }
 
@@ -304,7 +313,7 @@
     if( max_retries >= 0 )
       { nl = true; std::printf( "Max_retries: %d    ", max_retries ); }
     if( nl ) std::printf( "\n" );
-    std::printf( "Direct: %s    ", o_direct ? "yes" : "no" );
+    std::printf( "Direct: %s    ", o_direct || f_nocache ? "yes" : "no" );
     std::printf( "Sparse: %s    ", sparse ? "yes" : "no" );
     std::printf( "Split: %s    ", !nosplit ? "yes" : "no" );
     std::printf( "Truncate: %s\n", o_trunc ? "yes" : "no" );

reply via email to

[Prev in Thread] Current Thread [Next in Thread]