1// Copyright 2017 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 <inttypes.h>
8#include <stdlib.h>
9
10#include <zircon/compiler.h>
11#include <zircon/device/ramdisk.h>
12#include <zircon/types.h>
13
14__BEGIN_CDECLS
15
16// Wait for a device at "path" to become available.
17//
18// Returns ZX_OK if the device is ready to be opened, or ZX_ERR_TIMED_OUT if
19// the device is not available after "timeout" has elapsed.
20int wait_for_device(const char* path, zx_duration_t timeout);
21
22// Creates a ramdisk  returns the full path to the ramdisk in ramdisk_path_out.
23// This path should be at least PATH_MAX characters long.
24//
25// Return 0 on success, -1 on error.
26int create_ramdisk(uint64_t blk_size, uint64_t blk_count, char* out_path);
27
28// Creates a ramdisk  returns the full path to the ramdisk in ramdisk_path_out.
29// This path should be at least PATH_MAX characters long.
30//
31// Return 0 on success, -1 on error.
32int create_ramdisk_with_guid(uint64_t blk_size, uint64_t blk_count, const uint8_t* type_guid,
33                             size_t guid_len, char* out_path);
34
35// Same but uses an existing VMO as the ramdisk.
36// The handle is always consumed, and must be the only handle to this VMO.
37int create_ramdisk_from_vmo(zx_handle_t vmo, char* out_path);
38
39// Puts the ramdisk at |ramdisk_path| to sleep after |blk_count| blocks written.
40// After this, transactions will no longer be immediately persisted to disk.
41// If the |RAMDISK_FLAG_RESUME_ON_WAKE| flag has been set, transactions will
42// be processed when |wake_ramdisk| is called, otherwise they will fail immediately.
43int sleep_ramdisk(const char* ramdisk_path, uint64_t blk_count);
44
45// Wake the ramdisk at |ramdisk_path| from a sleep state.
46int wake_ramdisk(const char* ramdisk_path);
47
48// Returns the ramdisk's current failed, successful, and total block counts as |counts|.
49int get_ramdisk_blocks(const char* ramdisk_path, ramdisk_blk_counts_t* counts);
50
51// Destroys a ramdisk, given the "ramdisk_path" returned from "create_ramdisk".
52//
53// Return 0 on success, -1 on error.
54int destroy_ramdisk(const char* ramdisk_path);
55
56__END_CDECLS
57