1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <zircon/device/block.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 __BEGIN_CDECLS
12 
13 // TODO(smklein): Rename functions to match library (prefix).
14 
15 // Format a block device to be an empty FVM.
16 zx_status_t fvm_init(int fd, size_t slice_size);
17 // Queries driver to obtain slice_size, then overwrites and unbinds an FVM
18 zx_status_t fvm_destroy(const char* path);
19 // Given the slice_size, overwrites and unbinds an FVM
20 zx_status_t fvm_overwrite(const char* path, size_t slice_size);
21 
22 // Allocates a new vpartition in the fvm, and waits for it to become
23 // accessible (by watching for a corresponding block device).
24 //
25 // Returns an open fd to the new partition on success, -1 on error.
26 int fvm_allocate_partition(int fvm_fd, const alloc_req_t* request);
27 
28 // Waits for a partition with a GUID pair to appear, and opens it.
29 //
30 // If one of the GUIDs is null, it is ignored. For example:
31 //   wait_for_partition(NULL, systemGUID, ZX_SEC(5));
32 // Waits for any partition with the corresponding system GUID to appear.
33 // At least one of the GUIDs must be non-null.
34 //
35 // Returns an open fd to the partition on success, -1 on error.
36 int open_partition(const uint8_t* uniqueGUID, const uint8_t* typeGUID,
37                    zx_duration_t timeout, char* out_path);
38 
39 // Finds and destroys the partition with the given GUID pair, if it exists.
40 zx_status_t destroy_partition(const uint8_t* uniqueGUID, const uint8_t* typeGUID);
41 
42 __END_CDECLS
43