     /// Helper function for getting the command wrapper from the delegate context.
     static fileprivate func toCommandWrapper(_ context: UnsafeMutableRawPointer) -> CommandWrapper {
         return Unmanaged<CommandWrapper>.fromOpaque(UnsafeRawPointer(context)).takeUnretainedValue()
+    }
+
+    private func fsGetFileContents(_ path: String, _ data: UnsafeMutablePointer<llb_data_t>) -> Bool {
+        let fs = delegate.fs!
+
+        // Get the contents for the file.
+        guard let contents = fs.readFileContents(path) else {
+            return false
+        }
+
+        data.pointee = copiedDataFromBytes(contents)
+
+        return true
+    }
+
+    private func fsGetFileInfo(_ path: String, _ info: UnsafeMutablePointer<llb_fs_file_info_t>) {
+        // Ignore invalid paths.
+        guard path.first == "/" else {
+            info.pointee = llb_fs_file_info_t()
+            return
+        }
+
+        // If the path doesn't exist, it is missing.
+        let fs = delegate.fs!
+        guard let s = try? fs.getFileInfo(path).statBuf else {
+            info.pointee = llb_fs_file_info_t()
+            return
+        }
+
+        // Otherwise, we have some kind of file.
+        info.pointee.device = UInt64(s.st_dev)
+        info.pointee.inode = UInt64(s.st_ino)
+        info.pointee.mode = UInt64(s.st_mode)
+        info.pointee.size = UInt64(s.st_size)
+        info.pointee.mod_time.seconds = UInt64(s.st_mtimespec.tv_sec)
+        info.pointee.mod_time.nanoseconds = UInt64(s.st_mtimespec.tv_nsec)
+    }
+
+    private func fsGetLinkInfo(_ path: String, _ info: UnsafeMutablePointer<llb_fs_file_info_t>) {
+        // FIXME: We do not support this natively, yet.
+        return fsGetFileInfo(path, info)
     }
 
     /// The owning list of all created tools.

    }
}

/// Delegate interface for use with the build system.
public protocol BuildSystemDelegate {
    /// Called in response to requests for new tools.
    ///
    /// The client should return an appropriate tool implementation if recognized.

        llb_buildsystem_destroy(_system)
    }

    /// Build the default target, or optionally a single node.
    ///
    /// The client is responsible for ensuring only one build is ever executing concurrently.
    ///
    /// - parameter node: Optional path to a single node to build.
    /// - returns: True if the build was successful, false otherwise.
    public func build(node: String? = nil) -> Bool {
        if let node = node {
            var data = copiedDataFromBytes([UInt8](node.utf8))
            return llb_buildsystem_build_node(_system, &data)
        } else {
            var data = llb_data_t(length: 0, data: nil)
            return llb_buildsystem_build(_system, &data)
        }
    }

    /// Cancel any running build.
