diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonShared.ml ./src/daemon/common/commonShared.ml
--- ./src/daemon/common/commonShared.ml	2005-04-24 21:44:16.000000000 +0200
+++ ./src/daemon/common/commonShared.ml	2005-05-24 01:18:38.000000000 +0200
@@ -142,8 +142,7 @@
   if !verbose_share then
     lprintf "\ndirname %s \nfilename %s \nfullname %s\ncodedname %s\n"
       dirname filename fullname codedname; 
-
-  let size = Unix32.getsize fullname in
+  let size = Unix32.getsize fullname false in
   incr files_scanned;
   files_scanned_size := !files_scanned_size ++ size;
   if Unix2.is_directory fullname then begin
@@ -215,7 +214,6 @@
 let shared_iter f =
   H.iter f shareds_by_num
 
-let file_size filename =  Unix32.getsize filename
 let local_dirname = Sys.getcwd ()
   
 (* Prevent sharing of temp directory to avoid sending incomplete files *)
@@ -253,7 +251,7 @@
                 end
               else
               try
-                let size = file_size full_name in
+                let size = (Unix32.getsize full_name) false in
                 if size > strategy.sharing_minsize && 
                   size < strategy.sharing_maxsize &&
                   (strategy.sharing_extensions = [] ||
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonShared.mli ./src/daemon/common/commonShared.mli
--- ./src/daemon/common/commonShared.mli	2004-08-19 09:56:52.000000000 +0200
+++ ./src/daemon/common/commonShared.mli	2005-05-24 01:18:38.000000000 +0200
@@ -42,7 +42,6 @@
 val dummy_shared : int shared_impl
 val shared_find : int -> CommonTypes.shared
 val shared_iter : (CommonTypes.shared -> unit) -> unit
-val file_size : string -> int64
 val local_dirname : string
 val can_share : string -> bool
 val shared_add_directory : CommonTypes.shared_directory -> unit
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonSwarming2.ml ./src/daemon/common/commonSwarming2.ml
--- ./src/daemon/common/commonSwarming2.ml	2005-05-13 23:15:46.000000000 +0200
+++ ./src/daemon/common/commonSwarming2.ml	2005-05-24 01:18:38.000000000 +0200
@@ -3299,7 +3299,8 @@
     
     
     let nfiles = Array.length block_sizes
-    let file_size = Unix32.getsize file       
+    let file_size = Unix32.getsize file true
+    (* I know this module is commented out, but change it anyway *)
     
     let _ =
       
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonUploads.ml ./src/daemon/common/commonUploads.ml
--- ./src/daemon/common/commonUploads.ml	2005-05-17 15:18:05.000000000 +0200
+++ ./src/daemon/common/commonUploads.ml	2005-05-24 01:18:38.000000000 +0200
@@ -505,7 +505,7 @@
         let md5ext =  
           try
             let fd = Unix32.create_rw info.shared_fullname in
-            let file_size = Unix32.getsize64 fd in
+            let file_size = Unix32.getsize64 fd false in
             let len64 = min (Int64.of_int 307200) file_size in
             let len = Int64.to_int len64 in
             let s = String.create len in
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/driver/driverLink.ml ./src/daemon/driver/driverLink.ml
--- ./src/daemon/driver/driverLink.ml	2005-03-02 20:28:14.000000000 +0100
+++ ./src/daemon/driver/driverLink.ml	2005-05-24 01:18:38.000000000 +0200
@@ -374,7 +374,7 @@
       let file = correct_file file in
       if !verbose_dp500 then lprintf "Size of [%s]\n" file;
       let fd = Unix32.create_ro file in
-      let size = Unix32.getsize64 fd in
+      let size = Unix32.getsize64 fd false in
       write_string sock (Printf.sprintf "%015Ld" size)
     else
     if command = "GET" then
@@ -395,7 +395,7 @@
             end;
           let pclink_buf, len_read = 
             if len_read = 0 then
-              let size = Unix32.getsize64 fd in
+              let size = Unix32.getsize64 fd false in
               let size = Int64.to_int size in
               String.create size, size
             else
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/bittorrent/bTTorrent.ml ./src/networks/bittorrent/bTTorrent.ml
--- ./src/networks/bittorrent/bTTorrent.ml	2005-03-02 20:28:14.000000000 +0100
+++ ./src/networks/bittorrent/bTTorrent.ml	2005-05-24 01:18:38.000000000 +0200
@@ -241,7 +241,7 @@
               if Unix2.is_directory fullname then
                 iter_directory list basename
               else
-                (basename, Unix32.getsize fullname) :: list
+                (basename, Unix32.getsize fullname false) :: list
             in
             iter_files left dirname tail
       in
@@ -253,7 +253,7 @@
   in
   
   Unix32.flush_fd t;
-  let length = Unix32.getsize64 t in
+  let length = Unix32.getsize64 t false in
   let npieces = 1+ Int64.to_int ((length -- one) // chunk_size) in
   let pieces = Array.create npieces Sha1.null in
   for i = 0 to npieces - 1 do
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/donkey/donkeyGlobals.ml ./src/networks/donkey/donkeyGlobals.ml
--- ./src/networks/donkey/donkeyGlobals.ml	2005-05-17 15:18:05.000000000 +0200
+++ ./src/networks/donkey/donkeyGlobals.ml	2005-05-24 01:18:38.000000000 +0200
@@ -334,13 +334,13 @@
       let file_size =
         if file_size = Int64.zero then
           try
-            Unix32.getsize file_diskname
+            Unix32.getsize file_diskname writable
           with _ ->
               failwith "Zero length file ?"
         else file_size
       in
       
-      if file_size <> zero then
+      if file_size <> zero && writable then (* do not truncate if not writable *)
         Unix32.ftruncate64 t file_size;
       
       let nchunks = Int64.to_int (Int64.div 
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/donkey/donkeyInteractive.ml ./src/networks/donkey/donkeyInteractive.ml
--- ./src/networks/donkey/donkeyInteractive.ml	2005-05-24 01:24:32.000000000 +0200
+++ ./src/networks/donkey/donkeyInteractive.ml	2005-05-24 01:18:38.000000000 +0200
@@ -1308,7 +1308,7 @@
     ignore (Hashtbl.find files_by_md4 md4)
   with Not_found ->
       let file_diskname = Filename.concat !!temp_directory filename in
-      let size = Unix32.getsize file_diskname in
+      let size = Unix32.getsize file_diskname true in
       if size <> zero then
         let names =
             (* TODO RESULT
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/donkey/donkeyMain.ml ./src/networks/donkey/donkeyMain.ml
--- ./src/networks/donkey/donkeyMain.ml	2005-05-17 15:18:05.000000000 +0200
+++ ./src/networks/donkey/donkeyMain.ml	2005-05-24 01:18:38.000000000 +0200
@@ -195,14 +195,15 @@
       
       Hashtbl.iter (fun _ file ->
           try
-            if file_state file <> FileDownloaded then begin
+            if file_state file <> FileDownloaded then begin (* add not finished files *)
                 current_files := file :: !current_files;
 (*                set_file_size file (file_size file) *)
               end else begin
                 try
                   let file_disk_name = file_disk_name file in
                   if Unix32.file_exists file_disk_name &&
-                    Unix32.getsize file_disk_name <> Int64.zero then begin
+                    Unix32.getsize file_disk_name false <> Int64.zero then begin
+                    (* getsize writable=false is ok because file has state FileDownloaded *)
                       lprintf "FILE DOWNLOADED\n"; 
                       
                       DonkeyOneFile.declare_completed_file file;
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/donkey/donkeyShare.ml ./src/networks/donkey/donkeyShare.ml
--- ./src/networks/donkey/donkeyShare.ml	2005-05-02 14:57:59.000000000 +0200
+++ ./src/networks/donkey/donkeyShare.ml	2005-05-24 01:18:38.000000000 +0200
@@ -215,7 +215,7 @@
                 lprintf "Shared file doesn't exist\n"; 
                 raise Not_found;
               end;
-            if Unix32.getsize sh.shared_name <> sh.shared_size then begin
+            if Unix32.getsize sh.shared_name false <> sh.shared_size then begin
                 lprintf "Bad shared file size\n" ; 
                 raise Not_found;
               end;
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/gnutella/gnutellaProtocol.ml ./src/networks/gnutella/gnutellaProtocol.ml
--- ./src/networks/gnutella/gnutellaProtocol.ml	2005-03-20 02:41:30.000000000 +0100
+++ ./src/networks/gnutella/gnutellaProtocol.ml	2005-05-24 01:18:38.000000000 +0200
@@ -511,7 +511,7 @@
           
           (fun pos upload_buffer spos rlen ->
               Unix32.read fd pos upload_buffer spos rlen),
-          Unix32.getsize64 fd, []
+          Unix32.getsize64 fd false, []
         else
           failwith (Printf.sprintf "Cannot find TigerTree [%s]" urn)
     | _ -> failwith "Cannot parse /uri-res/N2T request"
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/opennap/opennapGlobals.ml ./src/networks/opennap/opennapGlobals.ml
--- ./src/networks/opennap/opennapGlobals.ml	2005-03-20 02:41:30.000000000 +0100
+++ ./src/networks/opennap/opennapGlobals.ml	2005-05-24 01:18:38.000000000 +0200
@@ -187,7 +187,7 @@
           (Printf.sprintf "ON-%s" (Md4.to_string file_id)) in
       let t = Unix32.create_rw file_temp in
       let current_size = try
-          Unix32.getsize file_temp
+          Unix32.getsize file_temp true
         with e ->
             lprintf "Exception %s in current_size\n" (Printexc2.to_string e); 
             Int64.zero
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/networks/soulseek/slskGlobals.ml ./src/networks/soulseek/slskGlobals.ml
--- ./src/networks/soulseek/slskGlobals.ml	2004-11-01 12:23:02.000000000 +0100
+++ ./src/networks/soulseek/slskGlobals.ml	2005-05-24 01:18:38.000000000 +0200
@@ -256,7 +256,7 @@
       let file_temp = Filename.concat !!temp_directory 
           (Printf.sprintf "SK-%s" (Md4.to_string file_id)) in
       let current_size = try
-          Unix32.getsize file_temp
+          Unix32.getsize file_temp true
         with e ->
             lprintf "Exception %s in current_size\n" (Printexc2.to_string e); 
             Int64.zero
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/utils/lib/md4.ml ./src/utils/lib/md4.ml
--- ./src/utils/lib/md4.ml	2004-11-01 12:23:02.000000000 +0100
+++ ./src/utils/lib/md4.ml	2005-05-24 01:18:38.000000000 +0200
@@ -341,7 +341,7 @@
     
     let file s =
       let digest = String.create hash_length in
-      let file_size = Unix32.getsize s in
+      let file_size = Unix32.getsize s false in
       unsafe_file digest s file_size;
       digest
     
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/utils/lib/unix32.ml ./src/utils/lib/unix32.ml
--- ./src/utils/lib/unix32.ml	2005-04-13 23:52:27.000000000 +0200
+++ ./src/utils/lib/unix32.ml	2005-05-24 01:18:38.000000000 +0200
@@ -99,17 +99,21 @@
             close t
 
 
-    let local_force_fd t =
+    let local_force_fd t writable =
       check_destroyed t;
       let fd =
         match t.fd with
           None ->
             if !cache_size >= !max_cache_size then  close_one ();
             let fd =
-              try
-                Unix.openfile t.filename rw_flag rights
-              with Unix.Unix_error( (Unix.EACCES | Unix.EROFS) ,_,_) ->
+              if writable then begin
+                try
+                  Unix.openfile t.filename rw_flag rights
+                with Unix.Unix_error( (Unix.EACCES | Unix.EROFS) ,_,_) ->
                   Unix.openfile t.filename ro_flag 0o400
+                end
+              else
+                Unix.openfile t.filename ro_flag 0o400
             in
             incr cache_size;
 (*            lprintf "local_force: opening %d\n" (Obj.magic fd);  *)
@@ -134,11 +138,11 @@
 
     let ftruncate64 t len =
       check_destroyed t;
-      Unix2.c_ftruncate64 (local_force_fd t) len
+      Unix2.c_ftruncate64 (local_force_fd t true) len
 
-    let getsize64 t = 
+    let getsize64 t writable =
       check_destroyed t;
-      Unix2.c_getfdsize64 (local_force_fd t)
+      Unix2.c_getfdsize64 (local_force_fd t writable)
 
     let mtime64 t =
       check_destroyed t;
@@ -155,13 +159,18 @@
       destroy t
 
     let read file file_pos string string_pos len =
-      let fd = local_force_fd file in
+      let fd = local_force_fd file true in
+      (*
+        I know I am calling local_force_fd with writable = true
+        although we are reading here, but I had problems with
+        it like exceptions in really_write
+      *)
       let final_pos = Unix2.c_seek64 fd file_pos Unix.SEEK_SET in
       if verbose then lprintf "really_read %d\n" len;
       Unix2.really_read fd string string_pos len
 
     let write file file_pos string string_pos len =
-      let fd = local_force_fd file in
+      let fd = local_force_fd file true in
       let final_pos = Unix2.c_seek64 fd file_pos Unix.SEEK_SET in
       if verbose then lprintf "really_write %d\n" len;
       really_write fd string string_pos len
@@ -193,7 +202,7 @@
     val close : t -> unit
     val rename : t -> string -> unit
     val ftruncate64 : t -> int64 -> unit
-    val getsize64 : t -> int64
+    val getsize64 : t -> bool -> int64
     val mtime64 : t -> float
     val exists : t -> bool
     val remove : t -> unit
@@ -211,7 +220,7 @@
     let create = FDCache.create
 
     let apply_on_chunk t pos_s len_s f =
-      let fd = FDCache.local_force_fd t in
+      let fd = FDCache.local_force_fd t true in
       f fd pos_s
 
     let close = FDCache.close
@@ -321,13 +330,13 @@
             let temp_filename = Filename.concat dirname filename in
             Unix2.safe_mkdir (Filename.dirname temp_filename);
             let fd = FDCache.create temp_filename in
-            let _ = FDCache.local_force_fd fd in
+            let _ = FDCache.local_force_fd fd true in
             iter tail (pos ++ size)
             ({
                 filename = filename;
                 pos = pos;
                 len = size;
-                current_len = FDCache.getsize64 fd;
+                current_len = FDCache.getsize64 fd true;
                 fd = fd;
                 tail = [];
               } :: files2)
@@ -372,7 +381,7 @@
       let file_begin = file.pos in
       let max_current_pos = file_begin ++ file.current_len in
       if max_current_pos >= chunk_end then
-        let fd = FDCache.local_force_fd file.fd in
+        let fd = FDCache.local_force_fd file.fd true in
         f fd (chunk_begin -- file_begin)
       else
       let temp_file = Filename.temp_file "chunk" ".tmp" in
@@ -401,7 +410,7 @@
           file_pos ++ zeros
       );
       FDCache.close file_out;
-      let fd = FDCache.local_force_fd file_out in
+      let fd = FDCache.local_force_fd file_out true in
       try 
         let v = f fd zero in
         Sys.remove temp_file;
@@ -648,7 +657,7 @@
         
         let chunk = t.chunks.(index) in
         let in_chunk_pos = chunk_begin -- chunk.pos in
-        let fd = FDCache.local_force_fd chunk.fd in
+        let fd = FDCache.local_force_fd chunk.fd true in
         f fd in_chunk_pos
       
       else
@@ -688,7 +697,7 @@
       iter zero (find_read_pos t chunk_begin) chunk_begin chunk_len;
       
       FDCache.close file_out;
-      let fd = FDCache.local_force_fd file_out in
+      let fd = FDCache.local_force_fd file_out true in
       try
         let v = f fd zero in
         Sys.remove temp_file;
@@ -758,7 +767,7 @@
     let ftruncate64 t size =
       t.size <- size
 
-    let getsize64 t = t.size
+    let getsize64 t writable = t.size
 
     let mtime64 t =
       let st = Unix.LargeFile.stat t.dirname in
@@ -958,11 +967,12 @@
   | SparseFile t -> SparseFile.mtime64 t
   | Destroyed -> failwith "Unix32.mtime64 on destroyed FD"
       
-let getsize64 t =
+let getsize64 t writable =
   match t.file_kind with
-  | DiskFile t -> DiskFile.getsize64 t
+  | DiskFile t -> DiskFile.getsize64 t writable
+    (* only avoid opening rw on shared files, shared files can only be DiskFile *)
   | MultiFile t -> MultiFile.getsize64 t
-  | SparseFile t -> SparseFile.getsize64 t
+  | SparseFile t -> SparseFile.getsize64 t writable
   | Destroyed -> failwith "Unix32.getsize64 on destroyed FD"
 
 let fds_size = Unix2.c_getdtablesize ()
@@ -1198,7 +1208,7 @@
   | SparseFile t -> SparseFile.remove t
   | Destroyed -> failwith "Unix32.remove on destroyed FD"
       
-let getsize s =  getsize64 (create_ro s)
+let getsize s writable =  getsize64 (create_ro s) writable
 let mtime s =  mtime64 (create_ro s)
 
 let file_exists s = exists (create_ro s)
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/utils/lib/unix32.mli ./src/utils/lib/unix32.mli
--- ./src/utils/lib/unix32.mli	2004-11-01 12:23:02.000000000 +0100
+++ ./src/utils/lib/unix32.mli	2005-05-24 01:18:38.000000000 +0200
@@ -24,8 +24,8 @@
 (* val force_fd : t -> Unix.file_descr *)
   
 (* val seek64 : t -> int64 -> Unix.seek_command -> int64  *)
-val getsize : string -> int64
-val getsize64 : t -> int64
+val getsize : string -> bool -> int64
+val getsize64 : t -> bool -> int64
 val ftruncate64 : t -> int64 -> unit
 
 val close_all : unit -> unit
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./tools/ed2k_hash.ml ./tools/ed2k_hash.ml
--- ./tools/ed2k_hash.ml	2004-08-19 09:56:55.000000000 +0200
+++ ./tools/ed2k_hash.ml	2005-05-24 01:18:38.000000000 +0200
@@ -91,7 +91,7 @@
   let sha1 = Sha1.digest_subfile fd zero file_size in
   let tiger = TigerTree.digest_subfile fd zero file_size in
   lprintf "urn:bitprint:%s.%s\n" (Sha1.to_string sha1) (TigerTree.to_string tiger);
-  let file_size = Unix32.getsize64 fd in
+  let file_size = Unix32.getsize64 fd false in
   let nchunks = Int64.to_int (Int64.div 
         (Int64.sub file_size Int64.one) tiger_block_size) + 1 in
   let chunks = 
@@ -118,7 +118,7 @@
   
 let bitprint_filename filename partial =
   let fd = Unix32.create_rw filename in
-  let file_size = Unix32.getsize64 fd in
+  let file_size = Unix32.getsize64 fd false in
   let (sha1, tiger2) = bitprint_file fd file_size partial in
   lprintf "urn:bitprint:%s.%s\n" (Sha1.to_string sha1) (TigerTree.to_string tiger2);
   ()
@@ -159,7 +159,7 @@
 
 let sha1_hash_filename block_size filename =
   let fd = Unix32.create_rw filename in
-  let file_size = Unix32.getsize64 fd in
+  let file_size = Unix32.getsize64 fd false in
   let nchunks = Int64.to_int (Int64.div 
         (Int64.sub file_size Int64.one) block_size) + 1 in
   for i = 0 to nchunks - 1 do
@@ -180,7 +180,7 @@
   
 let ed2k_hash_filename filename partial = 
   let fd = Unix32.create_rw filename in
-  let file_size = Unix32.getsize64 fd in
+  let file_size = Unix32.getsize64 fd false in
   let md4 = ed2k_hash_file fd file_size partial in
   lprintf "ed2k://|file|%s|%Ld|%s|/\n" 
     (Filename.basename filename)
@@ -195,7 +195,7 @@
   
 let sig2dat_hash_filename filename partial =
   let fd = Unix32.create_rw filename in
-  let file_size = Unix32.getsize64 fd in
+  let file_size = Unix32.getsize64 fd false in
   let len64 = min (Int64.of_int 307200) file_size in
   let len = Int64.to_int len64 in
   let s = String.create len in
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./tools/get_range.ml ./tools/get_range.ml
--- ./tools/get_range.ml	2004-03-08 00:02:31.000000000 +0100
+++ ./tools/get_range.ml	2005-05-24 01:22:12.000000000 +0200
@@ -53,7 +53,7 @@
       "size" -> 
         if Array.length Sys.argv <> 3 then usage ();
         let filename = argv.(2) in
-        Printf.printf "[SIZE %Ld]\n" (Unix32.getsize filename)
+        Printf.printf "[SIZE %Ld]\n" (Unix32.getsize filename false)
         
     | "range" ->
         if Array.length Sys.argv <> 6 then usage ();
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./tools/make_torrent.ml ./tools/make_torrent.ml
--- ./tools/make_torrent.ml	2005-03-02 20:28:17.000000000 +0100
+++ ./tools/make_torrent.ml	2005-05-24 01:18:38.000000000 +0200
@@ -148,7 +148,7 @@
           else  Unix32.create_ro filename
         in
         
-        let length = Unix32.getsize64 t in
+        let length = Unix32.getsize64 t false in
         
         if torrent.torrent_length <> length then begin
             Printf.printf "ERROR: computed size %Ld <> torrent size %Ld"
Binärdateien ./use_tags and ./use_tags sind verschieden.
