Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F171119240
D59422.id185866.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D59422.id185866.diff
View Options
diff --git a/stand/libsa/dev.c b/stand/libsa/dev.c
--- a/stand/libsa/dev.c
+++ b/stand/libsa/dev.c
@@ -64,7 +64,7 @@
}
/* NB: devspec points to the remainder of the device name after dv_name */
-static int
+int
default_parsedev(struct devdesc **dev, const char *devspec,
const char **path)
{
@@ -102,6 +102,69 @@
return (err);
}
+/*
+ * Helper for URI-syntax devices. NB: like default_parsedev(), devspec is
+ * the remainder after dv_name. Parses "[N]://host[:port][/path]"; EINVAL
+ * if devspec doesn't match that pattern.
+ */
+int
+parse_uri(const char *devspec, int *unitp, char **hostp, int *portp,
+ const char **pathp)
+{
+ const char *cp, *p;
+ char *end;
+ int unit;
+
+ cp = devspec;
+ unit = 0;
+ if (*cp != '\0' && *cp != ':') {
+ errno = 0;
+ unit = strtol(cp, &end, 0);
+ if (errno != 0 || end == cp)
+ return (EINVAL);
+ cp = end;
+ }
+ if (strncmp(cp, "://", 3) != 0)
+ return (EINVAL);
+ cp += 3;
+
+ p = cp;
+ while (*p != '\0' && *p != '/' && *p != ':')
+ p++;
+ if (p == cp)
+ return (EINVAL); /* empty host */
+
+ *hostp = malloc(p - cp + 1);
+ if (*hostp == NULL)
+ return (ENOMEM);
+ memcpy(*hostp, cp, p - cp);
+ (*hostp)[p - cp] = '\0';
+
+ *portp = 0;
+ if (*p == ':') {
+ p++;
+ errno = 0;
+ *portp = strtol(p, &end, 10);
+ if (errno != 0 || end == p) {
+ free(*hostp);
+ *hostp = NULL;
+ return (EINVAL);
+ }
+ p = end;
+ }
+
+ if (*p != '\0' && *p != '/') {
+ free(*hostp);
+ *hostp = NULL;
+ return (EINVAL);
+ }
+
+ *unitp = unit;
+ if (pathp != NULL)
+ *pathp = p;
+ return (0);
+}
+
/* NB: devspec points to the whole device spec, and possible trailing path */
int
devparse(struct devdesc **dev, const char *devspec, const char **path)
diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h
--- a/stand/libsa/stand.h
+++ b/stand/libsa/stand.h
@@ -196,6 +196,8 @@
char *devformat(struct devdesc *d);
int devparse(struct devdesc **, const char *, const char **);
+int default_parsedev(struct devdesc **, const char *, const char **);
+int parse_uri(const char *, int *, char **, int *, const char **);
int devinit(void);
void dev_cleanup(void);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Sep 9, 7:59 PM (15 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38478655
Default Alt Text
D59422.id185866.diff (2 KB)
Attached To
Mode
D59422: libsa: Add a generic URI-syntax devspec parser
Attached
Detach File
Event Timeline
Log In to Comment