Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2080)

Unified Diff: rootdev.h

Issue 3141038: rootdev: fix -d, add -c and -r. ifdefs for so use (Closed) Base URL: http://src.chromium.org/git/rootdev.git
Patch Set: integrated feedback; added functional tests Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « main.c ('k') | rootdev.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rootdev.h
diff --git a/rootdev.h b/rootdev.h
new file mode 100644
index 0000000000000000000000000000000000000000..03b8bd807c04f1f38b1362f1397aec62b7479249
--- /dev/null
+++ b/rootdev.h
@@ -0,0 +1,104 @@
+/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Interface for root device discovery via sysfs with optional
+ * bells and whistles.
+ */
+#ifndef ROOTDEV_ROOTDEV_H_
+#define ROOTDEV_ROOTDEV_H_
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * rootdev: returns the path to the root device in @path
+ * @path: pre-allocated char array the result will be written to
+ * @size: size of @path
+ * @full: whether to try to do full resolution. E.g., device-mapper
+ * @strip: whether to remove the partition # or not.
+ *
+ * Returns 0 on success, non-zero on error.
+ */
+int rootdev(char *path, size_t size, bool full, bool strip);
+
+/* All interface below this point will most definitely be C specific. If
+ * we rewrite this as a C++ class, only the above generic interface should
+ * still be provided.
+ */
+
+/**
+ * rootdev_wrapper: rootdev equivalent with paths can be substituted.
+ */
+int rootdev_wrapper(char *path, size_t size,
+ bool full, bool strip,
+ dev_t *dev,
+ const char *search, const char *dev_path);
+/**
+ * rootdev_get_device: finds the /dev path for @dev
+ * @dst: destination char array
+ * @size: size of @dst
+ * @dev: dev_t specifying the known root device
+ * @search: path to search under. NULL for default.
+ *
+ * Returns 0 on success, non-zero on error.
+ *
+ * The name of the devices is placed in @dst. It will not
+ * be qualified with /dev/ by default.
+ */
+int rootdev_get_device(char *dst, size_t size, dev_t dev,
+ const char *search);
+
+/**
+ * rootdev_get_device_slave: returns the first device under @device/slaves
+ * @slave: destination char array for storing the result
+ * @size: size of @slave
+ * @dev: pointer to a dev_t to populate
+ * @device: name of the device to probe, like "sdb"
+ * @search: path to search under. NULL for default.
+ *
+ * Returns 0 on success, non-zero on failure.
+ * It is safe for @device == @slave.
+ */
+int rootdev_get_device_slave(char *slave, size_t size, dev_t *dev,
+ const char *device, const char *search);
+
+/**
+ * rootdev_get_path: converts a device name to a path in the device tree
+ * @path: char array to store the path
+ * @size: size of @devpath
+ * @device: name of the device
+ * @dev: optional expected dev_t of the node.
+ * @dev_path: path to dev tree. NULL for default (/dev)
+ *
+ * A @dev of 0 is ignored.
+ *
+ * @path is populated for all return codes.
+ * Returns 0 on success and non-zero on error:
+ * -1 on unexpected errors (@path may be invalid)
+ * 1 on no existing @path
+ * 2 @path exists but the dev_t value is mismatched.
+ *
+ * Nb, this function does NOT search /dev for a match. It performs a normal
+ * string concatenation and probes for the existence. If udev has moved,
+ * or otherwise renamed, the device, a positive value is returned.
+ * The caller may then use the dev_t and @path to create the node with
+ * mknod(2).
+ */
+int rootdev_get_path(char *path, size_t size, const char *device, dev_t dev,
+ const char *dev_path);
+
+const char *rootdev_get_partition(const char *dst, size_t len);
+void rootdev_strip_partition(char *dst, size_t len);
+int rootdev_symlink_active(const char *path);
+int rootdev_create_devices(const char *name, dev_t dev, bool symlink);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ROOTDEV_ROOTDEV_H_ */
« no previous file with comments | « main.c ('k') | rootdev.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698