+ (* Don't allow large numbers of disks. *)
+ if nr_disks > max_disks then (
+ eprintf (f_"diskzip: maximum number of disk images is limited by the current image format to %d") nr_disks;
+ exit 2
+ );
+ let names = List.map (
+ fun { Diskimage.d_name = name } ->
+ let name =
+ try
+ let i = 1 + String.rindex name '/' in
+ String.sub name i (String.length name - i)
+ with
+ Invalid_string | Not_found -> name in
+
+ let contains_dotdot =
+ try ignore (String.find name ".."); true
+ with Invalid_string | Not_found -> false in
+ if contains_dotdot then (
+ prerr_endline (s_"diskzip: disk image names cannot contain \"..\"");
+ exit 2
+ );
+
+ (* Don't allow very long names. *)
+ if String.length name > max_image_name then (
+ eprintf (f_"diskzip: maximum length of disk image name is limited by the current image format to %d bytes") max_image_name;
+ exit 2
+ );
+
+ name
+ ) disks in
+
+ (* Header followed by names. *)
+ let header =
+ let header =
+ let bs = BITSTRING {
+ 0xD152 : 16; 0x01 : 8; 0x00 : 8; (* file magic, version 1.0 *)
+ nr_disks : 8 (* number of disks being packed *)
+ } in
+ let len = Bitmatch.bitstring_length bs in
+ assert (len land 7 = 0);
+ Bitmatch.string_of_bitstring bs in
+ let names = List.map (
+ fun name ->
+ let bs =
+ BITSTRING {
+ String.length name : 16;
+ name : -1 : string
+ } in
+ let len = Bitmatch.bitstring_length bs in
+ assert (len land 7 = 0);
+ Bitmatch.string_of_bitstring bs
+ ) names in
+
+ (* Construct the final header. *)
+ header ^ String.concat "" names in
+
+ ignore (write stdout header 0 (String.length header))
+
+(*