aboutsummaryrefslogtreecommitdiff
path: root/stand
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-11-30 22:08:36 +0000
committerWarner Losh <imp@FreeBSD.org>2023-01-24 21:49:38 +0000
commite29ff543be64de4f0c3c8008a1b6d762b553a6da (patch)
tree0f59b092cf31ebecfc574f0c895aa5b4f4de9ee1 /stand
parent9fd7cf55e6fff04b049bfda70da48b2c9d4b57b3 (diff)
downloadsrc-e29ff543be64de4f0c3c8008a1b6d762b553a6da.tar.gz
src-e29ff543be64de4f0c3c8008a1b6d762b553a6da.zip
stand: Introduce new dv_parsedev routine
Allow device classes to define a parsing routine. Most device classes already have these routines, but there's much duplication in their use. Define an interface for a common routine to parse an individual device. By convetion, files have the form "[device:]/path/to/file" where device is optional (filled in to be the value of currdev) and it starts with the dv_name field of the device, with the rest of the name up to the device (typically a unit number, but disks add partition inforation, and other devices may do artibtrary otehr things). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37337 (cherry picked from commit a0aad69f9556221283b8f6ddcd332329b50463e4)
Diffstat (limited to 'stand')
-rw-r--r--stand/libsa/libsa.332
-rw-r--r--stand/libsa/stand.h1
2 files changed, 32 insertions, 1 deletions
diff --git a/stand/libsa/libsa.3 b/stand/libsa/libsa.3
index 7bd7a848cd3d..f732595bc647 100644
--- a/stand/libsa/libsa.3
+++ b/stand/libsa/libsa.3
@@ -710,7 +710,9 @@ struct devsw {
int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
int (*dv_print)(int verbose);
void (*dv_cleanup)(void);
- void (*dv_fmtdev)(struct devdesc *);
+ char * (*dv_fmtdev)(struct devdesc *);
+ int (*dv_parsedev)(struct devdesc **dev, const char *devpart,
+ const char **path);
};
.Ed
.Bl -tag -width ".Fn dv_strategy"
@@ -751,6 +753,34 @@ Cleans up any memory used by the device before the next stage is run.
.It Fn dv_fmtdev
Converts the specified devdesc to the canonical string representation
for that device.
+.It Fn dv_parsedev
+Parses the device portion of a file path.
+The
+.Dv devpart
+will point to the
+.Sq tail
+of device name, possibly followed by a colon and a path within the device.
+The
+.Sq tail
+is, by convention, the part of the device specification that follows the
+.Fa dv_name
+part of the string.
+So when parsing the string
+.Dq disk3p5:/xxx
+.Dv devpart
+will point to the
+.Sq 3
+in that string.
+The parsing routine is expected to allocate a new
+.Dv struct devdesc
+or subclass and return it in
+.Dv dev
+when successful.
+This routine should set
+.Dv path
+to point to the portion of the string after device specification, or
+.Dq /xxx
+in the earlier example.
.El
.Sh HISTORY
The
diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h
index 3b2627355ed6..716486107b27 100644
--- a/stand/libsa/stand.h
+++ b/stand/libsa/stand.h
@@ -160,6 +160,7 @@ struct devsw {
int (*dv_print)(int verbose); /* print device information */
void (*dv_cleanup)(void);
char * (*dv_fmtdev)(struct devdesc *);
+ int (*dv_parsedev)(struct devdesc **, const char *, const char **);
};
/*