@@ -809,6 +809,29 @@ static ssize_t btrfs_checksum_show(struct kobject *kobj,
BTRFS_ATTR(, checksum, btrfs_checksum_show);
+/*
+ * Match the %golden in the %given. Ignore the leading and trailing whitespaces
+ * if any.
+ */
+static int btrfs_strmatch(const char *given, const char *golden)
+{
+ size_t len = strlen(golden);
+ char *stripped;
+
+ /* strip leading whitespace */
+ stripped = skip_spaces(given);
+
+ if (strncmp(stripped, golden, len) == 0) {
+ /* strip trailing whitespace */
+ if (strlen(skip_spaces(stripped + len)))
+ return -EINVAL;
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static const struct attribute *btrfs_attrs[] = {
BTRFS_ATTR_PTR(, label),
BTRFS_ATTR_PTR(, nodesize),
Add a generic helper to match the golden-string in the given-string, and ignore the leading and trailing whitespaces if any. Signed-off-by: Anand Jain <anand.jain@oracle.com> Suggested-by: David Sterba <dsterba@suse.com> --- v5: born fs/btrfs/sysfs.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)