summaryrefslogtreecommitdiffstats
path: root/lib/utils_devpath.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lib/utils_devpath.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/lib/utils_devpath.c b/lib/utils_devpath.c
index dc5a5bb..5e7e13e 100644
--- a/lib/utils_devpath.c
+++ b/lib/utils_devpath.c
@@ -3,8 +3,8 @@
*
* Copyright (C) 2004 Jana Saout <jana@saout.de>
* Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2009-2023 Red Hat, Inc. All rights reserved.
- * Copyright (C) 2009-2023 Milan Broz
+ * Copyright (C) 2009-2024 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2024 Milan Broz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -210,6 +210,24 @@ static int _path_get_uint64(const char *sysfs_path, uint64_t *value, const char
return _read_uint64(path, value);
}
+int crypt_dev_get_partition_number(const char *dev_path)
+{
+ uint64_t partno;
+ struct stat st;
+
+ if (stat(dev_path, &st) < 0)
+ return 0;
+
+ if (!S_ISBLK(st.st_mode))
+ return 0;
+
+ if (!_sysfs_get_uint64(major(st.st_rdev), minor(st.st_rdev),
+ &partno, "partition"))
+ return -EINVAL;
+
+ return (int)partno;
+}
+
int crypt_dev_is_rotational(int major, int minor)
{
uint64_t val;
@@ -220,6 +238,16 @@ int crypt_dev_is_rotational(int major, int minor)
return val ? 1 : 0;
}
+int crypt_dev_is_dax(int major, int minor)
+{
+ uint64_t val;
+
+ if (!_sysfs_get_uint64(major, minor, &val, "queue/dax"))
+ return 0; /* if failed, expect non-DAX device */
+
+ return val ? 1 : 0;
+}
+
int crypt_dev_is_partition(const char *dev_path)
{
uint64_t val;
@@ -253,6 +281,7 @@ uint64_t crypt_dev_partition_offset(const char *dev_path)
&val, "start"))
return 0;
+ /* coverity[tainted_data_return:FALSE] */
return val;
}