 (defn- id->file
   "Determine the filesystem path for a block of content with the given hash
   identifier."
-  ^java.io.File
-  [root id]
-  (let [hex (multihash/hex id)]
-    (io/file
-      root
-      (subs hex 0 dir-prefix-length)
-      (subs hex dir-prefix-length))))
+  ^File
+  [^File root id]
+  (let [hex (multihash/hex id)
+        len (min (dec (count hex)) prefix-length)
+        subdir (subs hex 0 len)
+        fragment (subs hex len)]
+    (io/file (blocks-dir root) subdir fragment)))
 
 
 (defn- file->id
   "Reconstruct the hash identifier represented by the given file path. Returns
   nil if the file is not a proper block."
-  [root ^File file]
-  (let [root (str root)
-        path (.getPath file)]
-    (cond
-      (= meta-properties-file (.getName file))
-      nil
-
-      (not (str/starts-with? path root))
-      (log/warnf "File %s is not a child of root directory %s" file root)
-
-      :else
-      (let [hex (str/replace (subs path (inc (count root))) "/" "")]
-        (if (re-matches #"[0-9a-fA-F]+" hex)
-          (multihash/decode (hex/parse hex))
-          (log/warnf "File %s did not form valid hex entry: %s" file hex))))))
+  [^File root ^File file]
+  (let [prefix (str (blocks-dir root))
+        path (.getPath file)
+        hex (str/replace (subs path (inc (count prefix))) "/" "")]
+    (if (re-matches #"[0-9a-fA-F]+" hex)
+      (multihash/decode (hex/parse hex))
+      (log/warnf "File %s did not form valid hex entry: %s" file hex))))
 
 
 (defn- file->block




;; ## File Block Functions

(def ^:private dir-prefix-length
  "Number of characters to use as a prefix for top-level directory names."
  8)


(defn- file-stats


  (start
    [this]
    ; TODO: auto-migrate v0 layouts?
    (let [properties (or (read-meta-properties root)
                         (write-meta-properties root))
          version (:version properties)]
      (when (not= layout-version version)
        (throw (ex-info
                 (str "Unknown storage layout version " (pr-str version)
                      " does not match supported version "
                      (pr-str layout-version))
                 {:supported layout-version
                  :properties properties})))
      (log/debug "Using storage layout version" version)
      (assoc this :version version)))

