diff -a -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/commonSwarming.ml ./src/daemon/common/commonSwarming.ml
--- ./src/daemon/common/commonSwarming.ml	2006-05-12 00:17:07.000000000 +0200
+++ ./src/daemon/common/commonSwarming.ml	2006-04-27 11:15:43.000000000 +0200
@@ -159,6 +159,7 @@
     mutable s_strategy : strategy;
 
     mutable s_verified_bitmap : string;
+    mutable s_priorities_bitmap : string;
     mutable s_availability : int array;
     mutable s_nuploading : int array;
 (*    mutable s_last_seen : int array; *)
@@ -345,6 +346,7 @@
     s_range_size = zero;
     s_strategy = AdvancedStrategy;
     s_verified_bitmap = "";
+    s_priorities_bitmap = "";
     s_blocks = [||];
     s_block_pos = [||];
     s_availability = [||];
@@ -405,6 +407,7 @@
           s_strategy = AdvancedStrategy;
 
           s_verified_bitmap = String.make nchunks '0';
+          s_priorities_bitmap = String.make nchunks '1'; (*JAVE init all prios to 1, thus all chunks will be downloaded as usual*)
           s_blocks = Array.create nchunks EmptyBlock ;
           s_block_pos = Array.create nchunks zero;
           s_availability = Array.create nchunks 0;
@@ -671,6 +674,7 @@
 
   s.s_blocks <- Array.create nblocks EmptyBlock;
   s.s_verified_bitmap <- String.make nblocks '0';
+  s.s_priorities_bitmap <- String.make nblocks '1';
   s.s_block_pos <- Array.create nblocks zero;
   s.s_availability <- Array.create nblocks 0; (* not preserved ? *)
   s.s_nuploading <- Array.create nblocks 0; (* not preserved ? *)
@@ -1729,6 +1733,7 @@
     let t = up.up_t in
     let s = t.t_s in
     (* priority bitmap <> 0 here ? *)
+    if s.s_priorities_bitmap.[b] == '0' then iter_partial up else
     match s.s_blocks.(b) with
     | CompleteBlock | VerifiedBlock ->
         iter_partial up
@@ -1746,6 +1751,7 @@
       let t = up.up_t in
       let s = t.t_s in
       (* priority bitmap <> 0 here ? *)
+      if s.s_priorities_bitmap.[b] ==  '0' then iter_complete up else
       match s.s_blocks.(b) with
       | CompleteBlock | VerifiedBlock ->
           iter_complete up
@@ -1907,7 +1913,7 @@
 
 	let best_choices = array_fold_lefti (fun n acc b ->
 	  (* priority bitmap <> 0 here ? *)
-	  if not (should_download_block s b) then acc else
+	  if s.s_priorities_bitmap.[b]== '0' or  not (should_download_block s b) then acc else
 	    let nchunk = my_t.t_chunk_of_block.(b) in
 	    let block_begin = compute_block_begin s b in
 	    let block_end = compute_block_end s b in
@@ -1919,9 +1925,7 @@
 	    let nuploaders = s.s_nuploading.(b) in
 	    let this_choice = {
 	      choice_num = n;
-	      choice_user_priority = (* priority bitmap here instead ? *)
-		if block_begin < preview_beginning then 3 else
-		  if block_end > preview_end then 2 else 1;
+              choice_user_priority = Char.code s.s_priorities_bitmap.[b] ;  (* priority bitmap here instead ? *)
 	      choice_nuploaders = nuploaders;
 	      choice_size = size;
 	      choice_remaining = remaining;
@@ -1938,8 +1942,8 @@
 		let cmp = compare_choices this_choice h in
 		if cmp > 0 then [this_choice]
 		else if cmp < 0 then acc
-		else this_choice :: acc
-	) [] up.up_complete_blocks in
+		else this_choice :: acc)
+          [] up.up_complete_blocks in
 	(* what about up_partial_blocks ? 
 	   currently they're taken care of by linear_select_block
 	   fallback below *)
@@ -3041,3 +3045,25 @@
   with _ -> false
 
 
+(*functions for priority bitmask*)
+
+let file_swarmer f =
+  HS.find swarmers_by_name { dummy_swarmer with s_filename = file_disk_name f }
+
+(** set the priority bitmask for each chunk in a file*)
+let set_swarmer_chunk_priorities f priobitmap = 
+  let s = file_swarmer f in
+    if String.length priobitmap ==  String.length s.s_verified_bitmap then 
+      s.s_priorities_bitmap <- priobitmap
+
+
+(** get the priority bitmask for a file*)
+let get_swarmer_chunk_priorities f = 
+  let s = file_swarmer f in
+    s.s_priorities_bitmap
+
+let get_swarmer_chunk_verified f = 
+  let s = file_swarmer f in
+    s.s_verified_bitmap
+
+(* JAVE maybe export compute_block_num ?*)
diff -a -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/driverCommands.ml ./src/daemon/driver/driverCommands.ml
--- ./src/daemon/driver/driverCommands.ml	2006-05-12 00:16:49.000000000 +0200
+++ ./src/daemon/driver/driverCommands.ml	2006-05-11 23:50:53.000000000 +0200
@@ -2996,6 +2996,93 @@
 let _ =
   register_commands "Driver/Xpert"
     [
+      
+      "debug_set_download_prio", Arg_two 
+        (fun arg priostring  o ->
+           let num = int_of_string arg in
+           let file = file_find num in
+             CommonSwarming.set_swarmer_chunk_priorities file priostring;
+             "set prio"
+               
+        ), ":\t\t\t\t\tset block download priorities for a file. 0=never download, >0=download largest prio first";
+      
+      "debug_get_download_prio", Arg_one 
+        (fun arg o ->
+           let num = int_of_string arg in
+           let file = file_find num in
+           let swarmer = CommonSwarming.file_swarmer file in
+           let prio=CommonSwarming.get_swarmer_chunk_priorities file in
+           let downloaded = CommonSwarming.get_swarmer_chunk_verified file in
+             Printf.bprintf o.conn_buf
+               "prio      :%s\ndownloaded:%s\n" prio downloaded;
+             Unix32.subfile_tree_map (file_fd file)
+               (fun fname start length current_length ->
+                  let stop = if length <> 0L then (start++length -- 1L)else start in
+                  let blockstart = try (CommonSwarming.compute_block_num swarmer start) with _ -> 0 in
+                  let blockend =  try  (CommonSwarming.compute_block_num swarmer stop) with _ -> 0 in
+                    
+                    Printf.bprintf o.conn_buf "sf:%5Ld ef:%5Ld l:%Ld cl:%Ld > sc:%5d ec:%5d filename:%-30s \n" 
+                      start
+                      stop
+                      length
+                      current_length
+                      blockstart
+                      blockend
+                      fname;
+                    
+                    (*make a chunk downloaded status string for a subfile*)
+                    try 
+                      let i=ref blockstart in
+                        while !i <=  blockend do
+                          Buffer.add_char  o.conn_buf  downloaded.[!i];
+                          i := !i + 1;
+                        done;
+                        Printf.bprintf o.conn_buf "\n";
+
+                    with _ -> ();
+                   ;()
+               );
+              "";
+    ), ":\t\t\t\t\tget file block priorities for a file, and show subfile completion status";
+
+
+    "debug_set_subfile_prio", Arg_multiple 
+      (fun args o ->
+
+         let filenum = int_of_string (List.nth args 0) in
+         let priochar =  (List.nth args 1).[0] in
+         let subfilestart = int_of_string (List.nth args 2) in
+         let subfileend = if (List.length args) == 4 then int_of_string (List.nth args 3) else subfilestart in
+
+         let file = file_find filenum in
+         let swarmer = CommonSwarming.file_swarmer file in
+         let priostring=CommonSwarming.get_swarmer_chunk_priorities file in
+
+         let subfile1=Unix32.find_file_index (file_fd file) subfilestart in (*subfilestart is subfile number, not a yte index, so is buggy*) 
+         let subfile2=Unix32.find_file_index (file_fd file) subfileend in
+         let my2 x=match x with (_,y,_) -> y in
+         let my3 x=match x with (_,_,y) -> y in
+         let start =  my2 subfile1 in
+         let stop =  my2 subfile2 ++  my3 subfile2 -- if   my3 subfile2 > 0L then 1L else 0L in
+         let blockstart = (CommonSwarming.compute_block_num swarmer start) in
+         let blockend = (CommonSwarming.compute_block_num swarmer stop) in
+           let i= ref blockstart in (* use String.fill instead *)
+             while !i <= blockend do
+               priostring.[!i] <- priochar;
+               i := !i + 1;
+               ();
+             done;
+           Printf.bprintf o.conn_buf
+             "start:%Ld stop:%Ld bs:%d be:%d\npriostring:%s\n" 
+             start stop blockstart blockend priostring
+           ;
+
+           CommonSwarming.set_swarmer_chunk_priorities file priostring;
+           ();
+        _s "done"
+    ), "debug_set_subfile_prio <download id> <prio> <1st subfile> <optional last subfile>";
+
+
 
     "reload_messages", Arg_none (fun o ->
         CommonMessages.load_message_file ();
diff -a -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	2006-04-14 01:55:25.000000000 +0200
+++ ./src/utils/lib/unix32.ml	2006-04-27 11:07:16.000000000 +0200
@@ -442,6 +442,14 @@
           find_file
             (if file_pos < pos then tree1 else tree2) file_pos
 
+    let rec subfile_tree_map indent tree f=
+      match tree with
+          Leaf file -> 
+            f file.filename file.pos file.len file.current_len
+        | Node (pos, tree1, tree2) ->
+            subfile_tree_map (indent ^ "  ") tree1 f;
+            subfile_tree_map (indent ^ "  ") tree2 f
+              
     let rec print_tree indent tree =
       match tree with
         Leaf file -> lprintf_nl "%s  - %s (%Ld,%Ld)"
@@ -1642,7 +1650,29 @@
       let shared_end = shared_begin ++ shared_len in
       ()
 *)      
-  end
+end
+
+(* subfile tree map function*)
+let subfile_tree_map t f =
+  match t.file_kind with
+    | MultiFile t ->  MultiFile.subfile_tree_map "" t.MultiFile.tree f; ()
+    | _ -> ()
+        
+
+let find_file t chunk_begin = 
+  match t.file_kind with
+    | MultiFile t ->  
+        let (sf,tail)=(MultiFile.find_file t chunk_begin) in
+          (sf.MultiFile.filename, sf.MultiFile.pos , sf.MultiFile.len)
+    | _ -> ("unimplemeted" , 0L, 0L)
+
+let find_file_index t index = 
+  match t.file_kind with
+    | MultiFile t ->  
+        let sf=List.nth t.MultiFile.files index in
+          (sf.MultiFile.filename, sf.MultiFile.pos , sf.MultiFile.len)
+    | _ -> ("unimplemeted" , 0L, 0L)
+
 type t = file
 
 (*
diff -a -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	2006-03-06 19:02:16.000000000 +0100
+++ ./src/utils/lib/unix32.mli	2006-04-27 11:07:16.000000000 +0200
@@ -101,3 +101,6 @@
 val percentused : string -> int option
 val percentfree : string -> int option
 val filesystem : string -> string
+val subfile_tree_map : t -> (string -> int64 -> int64 -> int64-> unit)  ->  unit
+val find_file : t -> int64 -> (string * int64 * int64)
+val find_file_index : t -> int -> (string * int64 * int64)

