blob: aacfaf085ae4554b4125e5d9efe6ca1f4a3ec781 [file] [log] [blame]
Will Drewry80fbc6c2010-08-30 10:13:34 -05001/* 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
15extern "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 */
27int 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 */
37int 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 */
53int 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 *
Will Drewry80fbc6c2010-08-30 10:13:34 -050064 * It is safe for @device == @slave.
65 */
Paul Taysomc9880282012-08-30 08:33:32 -070066void rootdev_get_device_slave(char *slave, size_t size, dev_t *dev,
67 const char *device, const char *search);
Will Drewry80fbc6c2010-08-30 10:13:34 -050068
69/**
70 * rootdev_get_path: converts a device name to a path in the device tree
71 * @path: char array to store the path
72 * @size: size of @devpath
73 * @device: name of the device
Will Drewry80fbc6c2010-08-30 10:13:34 -050074 * @dev_path: path to dev tree. NULL for default (/dev)
75 *
76 * A @dev of 0 is ignored.
77 *
78 * @path is populated for all return codes.
79 * Returns 0 on success and non-zero on error:
80 * -1 on unexpected errors (@path may be invalid)
Will Drewry80fbc6c2010-08-30 10:13:34 -050081 *
82 * Nb, this function does NOT search /dev for a match. It performs a normal
Bertrand SIMONNET9d44d9d2015-09-22 13:29:25 -070083 * string concatenation.
84 * We can't check if the device actually exists as vendors may create an
85 * SELinux context we don't know about for it (in which case, this function
86 * would always fail).
Will Drewry80fbc6c2010-08-30 10:13:34 -050087 */
Bertrand SIMONNET9d44d9d2015-09-22 13:29:25 -070088int rootdev_get_path(char *path, size_t size, const char *device,
Will Drewry80fbc6c2010-08-30 10:13:34 -050089 const char *dev_path);
90
91const char *rootdev_get_partition(const char *dst, size_t len);
92void rootdev_strip_partition(char *dst, size_t len);
93int rootdev_symlink_active(const char *path);
94int rootdev_create_devices(const char *name, dev_t dev, bool symlink);
95
96#ifdef __cplusplus
97} /* extern "C" */
98#endif
99
100#endif /* ROOTDEV_ROOTDEV_H_ */