from os.path import join
from keydb import KeyDB
from fs import ensure_dir
from fs import normalize
from fs import find_seq
from fs import parents

def __metadata_path(root):
  return join(root, ".farmfs")

def __userdata_path(mdd):
  return join(mdd, "userdata")

def __keys_path(mdd):
  return join(mdd, "keys")

def mkfs(root):
  abs_path = normalize(root)
  ensure_dir(abs_path)
  mdd = __metadata_path(abs_path)
  ensure_dir(mdd)
  ensure_dir(__userdata_path(mdd))
  ensure_dir(__keys_path(mdd))

def find_metadata_path(cwd):
  mdd = find_seq(".farmfs", parents(cwd))
  if mdd is None:
    raise ValueError("Volume not found: %s" % cwd)
  return mdd

class FarmFSVolume:
  def __init__(self, mdd):
    self.mdd = mdd
    self.keydb = KeyDB(mdd)


@@ -145,17 +145,16 @@
 ts%0A%0Adef 
-_
 _metadat
@@ -203,17 +203,16 @@
 %22)%0A%0Adef 
-_
 _userdat
@@ -260,17 +260,16 @@
 %22)%0A%0Adef 
-_
 _keys_pa
@@ -381,17 +381,16 @@
   mdd = 
-_
 _metadat
@@ -438,17 +438,16 @@
 re_dir(_
-_
 userdata
@@ -472,17 +472,16 @@
 re_dir(_
-_
 keys_pat
@@ -709,16 +709,51 @@
 d = mdd%0A
+    self.udd = _userdata_path(mdd)%0A
     self
@@ -767,14 +767,26 @@
 = KeyDB(
+_keys_path(
 mdd)
+)
 %0A%0A

Fix name mangle.