[blobfs] End friendship between VnodeBlob and Blobfs

It's a sad falling-out, but it makes the interfaces more isolated.

Test: blobfs-integration-tests, blobfs-unit-tests

Change-Id: I4362373992e98e2f4257e25614e7ee37cb7ffad7
diff --git a/system/ulib/blobfs/include/blobfs/blobfs.h b/system/ulib/blobfs/include/blobfs/blobfs.h
index dc934ad..1fef26e 100644
--- a/system/ulib/blobfs/include/blobfs/blobfs.h
+++ b/system/ulib/blobfs/include/blobfs/blobfs.h
@@ -114,7 +114,6 @@
                public fs::TransactionHandler, public SpaceManager {
 public:
     DISALLOW_COPY_ASSIGN_AND_MOVE(Blobfs);
-    friend class VnodeBlob;
 
     ////////////////
     // fs::ManagedVfs interface.
@@ -167,6 +166,10 @@
         return AllocatedExtentIterator(allocator_.get(), node_index);
     }
 
+    Allocator* GetAllocator() {
+        return allocator_.get();
+    }
+
     Inode* GetNode(uint32_t node_index) {
         return allocator_->GetNode(node_index);
     }
@@ -267,6 +270,12 @@
     // no strong references.
     void VnodeReleaseSoft(VnodeBlob* vn) __TA_EXCLUDES(hash_lock_);
 
+    // Writes node data to the inode table and updates disk.
+    void PersistNode(WritebackWork* wb, uint32_t node_index);
+
+    // Adds reserved blocks to allocated bitmap and writes the bitmap out to disk.
+    void PersistBlocks(WritebackWork* wb, const ReservedExtent& extent);
+
 private:
     friend class BlobfsChecker;
 
@@ -294,9 +303,6 @@
     // Precondition: The Vnode must not exist in |open_hash_|.
     fbl::RefPtr<VnodeBlob> VnodeUpgradeLocked(const uint8_t* key) __TA_REQUIRES(hash_lock_);
 
-    // Adds reserved blocks to allocated bitmap and writes the bitmap out to disk.
-    void PersistBlocks(WritebackWork* wb, const ReservedExtent& extent);
-
     // Frees blocks from the allocated map (if allocated) and updates disk if necessary.
     void FreeExtent(WritebackWork* wb, const Extent& extent);
 
@@ -309,9 +315,6 @@
     // disk.
     void FreeInode(WritebackWork* wb, uint32_t node_index);
 
-    // Writes node data to the inode table and updates disk.
-    void PersistNode(WritebackWork* wb, uint32_t node_index);
-
     // Given a contiguous number of blocks after a starting block,
     // write out the bitmap to disk for the corresponding blocks.
     // Should only be called by PersistBlocks and FreeExtent.
diff --git a/system/ulib/blobfs/vnode.cpp b/system/ulib/blobfs/vnode.cpp
index 36293d1..7be661b 100644
--- a/system/ulib/blobfs/vnode.cpp
+++ b/system/ulib/blobfs/vnode.cpp
@@ -187,8 +187,8 @@
     auto detach =
         fbl::MakeAutoCall([this, &compressed_vmoid]() { blobfs_->DetachVmo(compressed_vmoid); });
 
-    const uint64_t kDataStart = DataStartBlock(blobfs_->info_);
-    AllocatedExtentIterator extent_iter(blobfs_->allocator_.get(), GetMapIndex());
+    const uint64_t kDataStart = DataStartBlock(blobfs_->Info());
+    AllocatedExtentIterator extent_iter(blobfs_->GetAllocator(), GetMapIndex());
     BlockIterator block_iter(&extent_iter);
 
     // Read the uncompressed merkle tree into the start of the blob's VMO.
@@ -248,7 +248,7 @@
                    inode_.block_count);
     fs::Ticker ticker(blobfs_->LocalMetrics().Collecting());
     fs::ReadTxn txn(blobfs_);
-    AllocatedExtentIterator extent_iter(blobfs_->allocator_.get(), GetMapIndex());
+    AllocatedExtentIterator extent_iter(blobfs_->GetAllocator(), GetMapIndex());
     BlockIterator block_iter(&extent_iter);
     // Read both the uncompressed merkle tree and data.
     const uint64_t blob_data_blocks = BlobDataBlocks(inode_);
@@ -257,7 +257,7 @@
         return ZX_ERR_IO_DATA_INTEGRITY;
     }
     const uint32_t length = static_cast<uint32_t>(blob_data_blocks + merkle_blocks);
-    const uint64_t data_start = DataStartBlock(blobfs_->info_);
+    const uint64_t data_start = DataStartBlock(blobfs_->Info());
     zx_status_t status = StreamBlocks(
         &block_iter, length, [&](uint64_t vmo_offset, uint64_t dev_offset, uint32_t length) {
             txn.Enqueue(vmoid_, vmo_offset, dev_offset + data_start, length);
@@ -465,7 +465,7 @@
 
         Inode* mapped_inode = blobfs_->GetNode(map_index_);
         *mapped_inode = inode_;
-        NodePopulator populator(blobfs_->allocator_.get(), std::move(write_info_->extents),
+        NodePopulator populator(blobfs_->GetAllocator(), std::move(write_info_->extents),
                                 std::move(write_info_->node_indices));
         ZX_ASSERT(populator.Walk(on_node, on_extent) == ZX_OK);
 
@@ -475,7 +475,7 @@
         // Special case: Empty node.
         ZX_DEBUG_ASSERT(write_info_->node_indices.size() == 1);
         const ReservedNode& node = write_info_->node_indices[0];
-        blobfs_->allocator_->MarkInodeAllocated(node);
+        blobfs_->GetAllocator()->MarkInodeAllocated(node);
         blobfs_->PersistNode(wb.get(), node.index());
     }
 
@@ -954,10 +954,10 @@
     info->max_filename_size = Digest::kLength * 2;
     info->fs_type = VFS_TYPE_BLOBFS;
     info->fs_id = blobfs_->GetFsId();
-    info->total_bytes = blobfs_->info_.data_block_count * blobfs_->info_.block_size;
-    info->used_bytes = blobfs_->info_.alloc_block_count * blobfs_->info_.block_size;
-    info->total_nodes = blobfs_->info_.inode_count;
-    info->used_nodes = blobfs_->info_.alloc_inode_count;
+    info->total_bytes = blobfs_->Info().data_block_count * blobfs_->Info().block_size;
+    info->used_bytes = blobfs_->Info().alloc_block_count * blobfs_->Info().block_size;
+    info->total_nodes = blobfs_->Info().inode_count;
+    info->used_nodes = blobfs_->Info().alloc_inode_count;
     strlcpy(reinterpret_cast<char*>(info->name), kFsName, fuchsia_io_MAX_FS_NAME_BUFFER);
     return ZX_OK;
 }