dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH libdrm 1/5] xf86drm: implement drmGetMinorNameForFD for non-sysfs
@ 2016-11-26  0:40 Jonathan Gray
  2016-11-26  0:40 ` [PATCH libdrm 2/5] xf86drm: implement drmParseSubsystemType for OpenBSD Jonathan Gray
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Jonathan Gray @ 2016-11-26  0:40 UTC (permalink / raw)
  To: dri-devel; +Cc: emil.l.velikov

Implement drmGetMinorNameForFD for systems without sysfs by
adapting drm_get_device_name_for_fd() from the Mesa loader.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
---
 xf86drm.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/xf86drm.c b/xf86drm.c
index ed924a7..216220c 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2818,7 +2818,25 @@ static char *drmGetMinorNameForFD(int fd, int type)
 out_close_dir:
     closedir(sysdir);
 #else
-#warning "Missing implementation of drmGetMinorNameForFD"
+    struct stat sbuf;
+    unsigned int maj, min;
+    char buf[PATH_MAX + 1];
+    int n;
+
+    if (fstat(fd, &sbuf))
+        return NULL;
+
+    maj = major(sbuf.st_rdev);
+    min = minor(sbuf.st_rdev);
+
+    if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
+        return NULL;
+
+    n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, min);
+    if (n == -1 || n >= sizeof(buf))
+        return NULL;
+
+    return strdup(buf);
 #endif
     return NULL;
 }
-- 
2.10.2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-11-30 16:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-26  0:40 [PATCH libdrm 1/5] xf86drm: implement drmGetMinorNameForFD for non-sysfs Jonathan Gray
2016-11-26  0:40 ` [PATCH libdrm 2/5] xf86drm: implement drmParseSubsystemType for OpenBSD Jonathan Gray
2016-11-29 19:46   ` Emil Velikov
2016-11-30  0:23     ` Jonathan Gray
2016-11-30 16:23       ` Emil Velikov
2016-11-26  0:40 ` [PATCH libdrm 3/5] xf86drm: implement drmParsePciDeviceInfo " Jonathan Gray
2016-11-29 19:55   ` Emil Velikov
2016-11-30  0:38     ` Jonathan Gray
2016-11-30 16:11       ` Emil Velikov
2016-11-26  0:40 ` [PATCH libdrm 4/5] xf86drm: implement drmParsePciBusInfo " Jonathan Gray
2016-11-26  0:40 ` [PATCH libdrm 5/5] xf86drm: implement an OpenBSD specific drmGetDevice Jonathan Gray
2016-11-29 20:03   ` Emil Velikov
2016-11-30  0:00     ` Jonathan Gray
2016-11-30 16:32       ` Emil Velikov
2016-11-29 19:22 ` [PATCH libdrm 1/5] xf86drm: implement drmGetMinorNameForFD for non-sysfs Emil Velikov
2016-11-30  0:15   ` Jonathan Gray
2016-11-30 16:16     ` Emil Velikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox