]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - sysfs.c
Add reading SATA encryption information
[thirdparty/mdadm.git] / sysfs.c
diff --git a/sysfs.c b/sysfs.c
index 4ded1672f95c6571d4ed3b55feedf8318c8ff6c8..20fe1e9efaeda3c9de931a0a21d5c78751aee7ad 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -1121,3 +1121,32 @@ void sysfsline(char *line)
        sr->next = sysfs_rules;
        sysfs_rules = sr;
 }
+
+/**
+ * sysfs_is_libata_allow_tpm_enabled() - check if libata allow_tmp is enabled.
+ * @verbose: verbose flag.
+ *
+ * Check if libata allow_tmp flag is set, this is required for SATA Opal Security commands to work.
+ *
+ * Return: true if allow_tpm enable, false otherwise.
+ */
+bool sysfs_is_libata_allow_tpm_enabled(const int verbose)
+{
+       const char *path = "/sys/module/libata/parameters/allow_tpm";
+       const char *expected_value = "1";
+       int fd = open(path, O_RDONLY);
+       char buf[3];
+
+       if (!is_fd_valid(fd)) {
+               pr_vrb("Failed open file descriptor to %s. Cannot check libata allow_tpm param.\n",
+                      path);
+               return false;
+       }
+
+       sysfs_fd_get_str(fd, buf, sizeof(buf));
+       close(fd);
+
+       if (strncmp(buf, expected_value, 1) == 0)
+               return true;
+       return false;
+}