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. 20 zx_status_t 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 zx_status_t create_ramdisk(uint64_t blk_size, uint64_t blk_count, char* out_path); 25 26 // Creates a ramdisk returns the full path to the ramdisk in ramdisk_path_out. 27 // This path should be at least PATH_MAX characters long. 28 zx_status_t create_ramdisk_with_guid(uint64_t blk_size, uint64_t blk_count, 29 const uint8_t* type_guid, size_t guid_len, char* out_path); 30 31 // Same but uses an existing VMO as the ramdisk. 32 // The handle is always consumed, and must be the only handle to this VMO. 33 zx_status_t create_ramdisk_from_vmo(zx_handle_t vmo, char* out_path); 34 35 // Puts the ramdisk at |ramdisk_path| to sleep after |blk_count| blocks written. 36 // After this, transactions will no longer be immediately persisted to disk. 37 // If the |RAMDISK_FLAG_RESUME_ON_WAKE| flag has been set, transactions will 38 // be processed when |wake_ramdisk| is called, otherwise they will fail immediately. 39 zx_status_t sleep_ramdisk(const char* ramdisk_path, uint64_t blk_count); 40 41 // Wake the ramdisk at |ramdisk_path| from a sleep state. 42 zx_status_t wake_ramdisk(const char* ramdisk_path); 43 44 // Returns the ramdisk's current failed, successful, and total block counts as |counts|. 45 zx_status_t get_ramdisk_blocks(const char* ramdisk_path, ramdisk_blk_counts_t* counts); 46 47 // Destroys a ramdisk, given the "ramdisk_path" returned from "create_ramdisk". 48 zx_status_t destroy_ramdisk(const char* ramdisk_path); 49 50 __END_CDECLS 51