summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2023-03-23 17:50:17 +0100
committerJes Sorensen <jes@trained-monkey.org>2023-05-08 22:23:45 +0200
commit25aa7329141c0b28d8811671627f0f5c5dc22273 (patch)
tree286fe590a0f86e4b47a9dba980cd2d32eab0e2f2 /util.c
parentmdadm: define is_devname_ignore() (diff)
downloadmdadm-25aa7329141c0b28d8811671627f0f5c5dc22273.tar.xz
mdadm-25aa7329141c0b28d8811671627f0f5c5dc22273.zip
mdadm: numbered names verification
New functions added to remove literals and make the code reusable. Use parse_num() instead of is_numer(). Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to '')
-rw-r--r--util.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/util.c b/util.c
index d70ca43b..fa378eba 100644
--- a/util.c
+++ b/util.c
@@ -974,6 +974,50 @@ dev_t devnm2devid(char *devnm)
}
/**
+ * is_devname_numbered() - helper for numbered devname verification.
+ * @devname: path or name to check.
+ * @pref: expected devname prefix.
+ * @pref_len: prefix len.
+ */
+static bool is_devname_numbered(const char *devname, const char *pref, const int pref_len)
+{
+ int val;
+
+ assert(devname && pref);
+
+ if (strncmp(devname, pref, pref_len) != 0)
+ return false;
+
+ if (parse_num(&val, devname + pref_len) != 0)
+ return false;
+
+ if (val > 127)
+ return false;
+
+ return true;
+}
+
+/**
+ * is_devname_md_numbered() - check if &devname is numbered MD device (md).
+ * @devname: path or name to check.
+ */
+bool is_devname_md_numbered(const char *devname)
+{
+ return is_devname_numbered(devname, DEV_NUM_PREF, DEV_NUM_PREF_LEN);
+}
+
+/**
+ * is_devname_md_d_numbered() - check if &devname is secondary numbered MD device (md_d).
+ * @devname: path or name to check.
+ */
+bool is_devname_md_d_numbered(const char *devname)
+{
+ static const char d_dev[] = DEV_NUM_PREF "_d";
+
+ return is_devname_numbered(devname, d_dev, sizeof(d_dev) - 1);
+}
+
+/**
* get_md_name() - Get main dev node of the md device.
* @devnm: Md device name or path.
*