blob: 018189eff55a58099287e50a9150adf9b1c3dfc7 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:zircon/zircon.dart';
import 'package:fidl_fuchsia_io/fidl_async.dart';
import 'pseudo_file.dart';
/// Specifies how a VMO wrapped by [VmoFile] may be shared.
enum VmoSharingMode {
/// The VMO may not be shared, the VMO file appears as a regular file.
/// A duplicate of the VMO is shared.
// TODO(crjohns): Support cloning.
/// A node which wraps a VMO that can be duplicated when opened.
/// Reads when opening a [VmoFile] as a file are buffered, and repeated reads
/// will obtain the same information unless the connection is closed between
/// reads.
/// A duplicate of the underlying VMO is exposed through [Node.Describe] when
/// [VmoSharingMode] is [shareDuplicate].
class VmoFile extends PseudoFile {
final Vmo _vmo;
final VmoSharingMode _sharingMode;
/// Constructor for read-only [Vmo]
VmoFile.readOnly(this._vmo, this._sharingMode)
: assert(_vmo != null),
super.readOnly(() {
int size = _vmo.getSize().size;
}) {
if (_vmo == null) {
throw Exception('Vmo cannot be null');
// TODO(crjohns): Support writable vmo files.
/// Describes this node. Returns null on error.
NodeInfo describe() {
if (_sharingMode == VmoSharingMode.shareDuplicate) {
final Vmo duplicatedVmo =
if (duplicatedVmo == null) {
return null;
return NodeInfo.withVmofile(new Vmofile(
vmo: duplicatedVmo, offset: 0, length: _vmo.getSize().size));
return NodeInfo.withFile(FileObject(event: null));