The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=88a8c68298dbc86370d9a7eff06314da398829cb

commit 88a8c68298dbc86370d9a7eff06314da398829cb
Author:     Warner Losh <[email protected]>
AuthorDate: 2022-11-30 22:10:11 +0000
Commit:     Warner Losh <[email protected]>
CommitDate: 2022-11-30 22:30:33 +0000

    ofw/disk: Add parsedev support
    
    Add a parsedev support for OpenFirmware disks. We must look at
    characteristics of the OFW node to know if we match this device (so
    supply a match routine) or not. Add a parsing routine to allocate
    devdesc for OpenFirmware disks as well.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D37558
---
 stand/libofw/ofw_disk.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/stand/libofw/ofw_disk.c b/stand/libofw/ofw_disk.c
index 67da8cbeb310..ae2776ee4689 100644
--- a/stand/libofw/ofw_disk.c
+++ b/stand/libofw/ofw_disk.c
@@ -50,7 +50,8 @@ static int    ofwd_close(struct open_file *f);
 static int     ofwd_ioctl(struct open_file *f, u_long cmd, void *data);
 static int     ofwd_print(int verbose);
 static char *  ofwd_fmtdev(struct devdesc *);
-
+static int     ofwd_parsedev(struct devdesc **, const char *, const char **);
+static bool    ofwd_match(struct devsw *, const char *);
 
 struct devsw ofwdisk = {
        .dv_name = "block",
@@ -62,7 +63,9 @@ struct devsw ofwdisk = {
        .dv_ioctl = ofwd_ioctl,
        .dv_print = ofwd_print,
        .dv_cleanup = nullsys,
+       .dv_match = ofwd_match,
        .dv_fmtdev = ofwd_fmtdev,
+       .dv_parsedev = ofwd_parsedev,
 };
 
 /*
@@ -210,6 +213,16 @@ ofwd_print(int verbose __unused)
 
        return (0);
 }
+
+
+static bool
+ofwd_match(struct devsw *devsw, const char *devspec)
+{
+       const char *path;
+
+       return (ofw_path_to_handle(devspec, devsw->dv_name, &path) != -1);
+}
+
 static char *
 ofwd_fmtdev(struct devdesc *idev)
 {
@@ -217,3 +230,25 @@ ofwd_fmtdev(struct devdesc *idev)
 
        return (dev->d_path);
 }
+
+static int
+ofwd_parsedev(struct devdesc **dev, const char *devspec, const char **path)
+{
+       const char *rem_path;
+       struct ofw_devdesc *idev;
+
+       if (ofw_path_to_handle(devspec, ofwdisk.dv_name, &rem_path) == -1)
+               return (ENOENT);
+       idev = malloc(sizeof(struct ofw_devdesc));
+       if (idev == NULL) {
+               printf("ofw_parsedev: malloc failed\n");
+               return ENOMEM;
+       };
+       strlcpy(idev->d_path, devspec, min(rem_path - devspec + 1,
+               sizeof(idev->d_path)));
+       if (dev != NULL)
+               *dev = &idev->dd;
+       if (path != NULL)
+               *path = rem_path;
+       return 0;
+}

Reply via email to