From 6818a50b1215081d6a7b7b710f504a6b182320c8 Mon Sep 17 00:00:00 2001 From: Emmanuel Vadot Date: Tue, 21 Jan 2020 17:50:15 +0100 Subject: libdrm: drmGetDeviceNameFromFd: Add FreeBSD variant Get the major/minor via fstat and after checking that this is a drm node construct the full device node name using devname. Note that we should be able to use fdevname to avoid calling fstat + devname but for some reason it doesn't work on drm node (probably due to how the device node are created in the linux compat code for drm on FreeBSD). Signed-off-by: Emmanuel Vadot Reviewed-by: Eric Engestrom Reviewed-by: Emil Velikov --- xf86drm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'xf86drm.c') diff --git a/xf86drm.c b/xf86drm.c index 9644bd57..e6f6a890 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -117,6 +117,8 @@ struct drm_pciinfo { static drmServerInfoPtr drm_server_info; +static bool drmNodeIsDRM(int maj, int min); + drm_public void drmSetServerInfo(drmServerInfoPtr info) { drm_server_info = info; @@ -2768,6 +2770,27 @@ drm_public int drmIsMaster(int fd) drm_public char *drmGetDeviceNameFromFd(int fd) { +#ifdef __FreeBSD__ + struct stat sbuf; + char dname[SPECNAMELEN]; + char name[SPECNAMELEN]; + int maj, min; + + if (fstat(fd, &sbuf)) + return NULL; + + maj = major(sbuf.st_rdev); + min = minor(sbuf.st_rdev); + + if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode)) + return NULL; + + if (!devname_r(sbuf.st_rdev, S_IFCHR, dname, sizeof(dname))) + return NULL; + + snprintf(name, sizeof(name), "/dev/%s", dname); + return strdup(name); +#else char name[128]; struct stat sbuf; dev_t d; @@ -2790,6 +2813,7 @@ drm_public char *drmGetDeviceNameFromFd(int fd) return NULL; return strdup(name); +#endif } static bool drmNodeIsDRM(int maj, int min) -- cgit v1.2.3