OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS 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 * Interface for root device discovery via sysfs with optional |
| 6 * bells and whistles. |
| 7 */ |
| 8 #ifndef ROOTDEV_ROOTDEV_H_ |
| 9 #define ROOTDEV_ROOTDEV_H_ |
| 10 |
| 11 #include <stdbool.h> |
| 12 #include <sys/types.h> |
| 13 |
| 14 #ifdef __cplusplus |
| 15 extern "C" { |
| 16 #endif |
| 17 |
| 18 /** |
| 19 * rootdev: returns the path to the root device in @path |
| 20 * @path: pre-allocated char array the result will be written to |
| 21 * @size: size of @path |
| 22 * @full: whether to try to do full resolution. E.g., device-mapper |
| 23 * @strip: whether to remove the partition # or not. |
| 24 * |
| 25 * Returns 0 on success, non-zero on error. |
| 26 */ |
| 27 int rootdev(char *path, size_t size, bool full, bool strip); |
| 28 |
| 29 /* All interface below this point will most definitely be C specific. If |
| 30 * we rewrite this as a C++ class, only the above generic interface should |
| 31 * still be provided. |
| 32 */ |
| 33 |
| 34 /** |
| 35 * rootdev_wrapper: rootdev equivalent with paths can be substituted. |
| 36 */ |
| 37 int rootdev_wrapper(char *path, size_t size, |
| 38 bool full, bool strip, |
| 39 dev_t *dev, |
| 40 const char *search, const char *dev_path); |
| 41 /** |
| 42 * rootdev_get_device: finds the /dev path for @dev |
| 43 * @dst: destination char array |
| 44 * @size: size of @dst |
| 45 * @dev: dev_t specifying the known root device |
| 46 * @search: path to search under. NULL for default. |
| 47 * |
| 48 * Returns 0 on success, non-zero on error. |
| 49 * |
| 50 * The name of the devices is placed in @dst. It will not |
| 51 * be qualified with /dev/ by default. |
| 52 */ |
| 53 int rootdev_get_device(char *dst, size_t size, dev_t dev, |
| 54 const char *search); |
| 55 |
| 56 /** |
| 57 * rootdev_get_device_slave: returns the first device under @device/slaves |
| 58 * @slave: destination char array for storing the result |
| 59 * @size: size of @slave |
| 60 * @dev: pointer to a dev_t to populate |
| 61 * @device: name of the device to probe, like "sdb" |
| 62 * @search: path to search under. NULL for default. |
| 63 * |
| 64 * Returns 0 on success, non-zero on failure. |
| 65 * It is safe for @device == @slave. |
| 66 */ |
| 67 int rootdev_get_device_slave(char *slave, size_t size, dev_t *dev, |
| 68 const char *device, const char *search); |
| 69 |
| 70 /** |
| 71 * rootdev_get_path: converts a device name to a path in the device tree |
| 72 * @path: char array to store the path |
| 73 * @size: size of @devpath |
| 74 * @device: name of the device |
| 75 * @dev: optional expected dev_t of the node. |
| 76 * @dev_path: path to dev tree. NULL for default (/dev) |
| 77 * |
| 78 * A @dev of 0 is ignored. |
| 79 * |
| 80 * @path is populated for all return codes. |
| 81 * Returns 0 on success and non-zero on error: |
| 82 * -1 on unexpected errors (@path may be invalid) |
| 83 * 1 on no existing @path |
| 84 * 2 @path exists but the dev_t value is mismatched. |
| 85 * |
| 86 * Nb, this function does NOT search /dev for a match. It performs a normal |
| 87 * string concatenation and probes for the existence. If udev has moved, |
| 88 * or otherwise renamed, the device, a positive value is returned. |
| 89 * The caller may then use the dev_t and @path to create the node with |
| 90 * mknod(2). |
| 91 */ |
| 92 int rootdev_get_path(char *path, size_t size, const char *device, dev_t dev, |
| 93 const char *dev_path); |
| 94 |
| 95 const char *rootdev_get_partition(const char *dst, size_t len); |
| 96 void rootdev_strip_partition(char *dst, size_t len); |
| 97 int rootdev_symlink_active(const char *path); |
| 98 int rootdev_create_devices(const char *name, dev_t dev, bool symlink); |
| 99 |
| 100 #ifdef __cplusplus |
| 101 } /* extern "C" */ |
| 102 #endif |
| 103 |
| 104 #endif /* ROOTDEV_ROOTDEV_H_ */ |
OLD | NEW |