summaryrefslogtreecommitdiff
path: root/xf86drm.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2009-11-23 20:51:34 -0500
committerKristian Høgsberg <krh@bitplanet.net>2009-11-23 20:51:34 -0500
commit22d46669043d38fcd16efca773f5ed5693c0fb58 (patch)
tree2a61afd66353314e6d10b4f78e7bc14ebb65ae94 /xf86drm.c
parent500f5b524000ed5930301f4303744cb4c0a19b75 (diff)
Add drmGetDeviceNameFromFd function
Determines the /dev filename of the drm fd argument.
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/xf86drm.c b/xf86drm.c
index 26dd8129..364fe17d 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2510,3 +2510,29 @@ int drmDropMaster(int fd)
ret = ioctl(fd, DRM_IOCTL_DROP_MASTER, 0);
return ret;
}
+
+char *drmGetDeviceNameFromFd(int fd)
+{
+ char name[128];
+ struct stat sbuf;
+ dev_t d;
+ int i;
+
+ /* The whole drmOpen thing is a fiasco and we need to find a way
+ * back to just using open(2). For now, however, lets just make
+ * things worse with even more ad hoc directory walking code to
+ * discover the device file name. */
+
+ fstat(fd, &sbuf);
+ d = sbuf.st_rdev;
+
+ for (i = 0; i < DRM_MAX_MINOR; i++) {
+ snprintf(name, sizeof name, DRM_DEV_NAME, DRM_DIR_NAME, i);
+ if (stat(name, &sbuf) == 0 && sbuf.st_rdev == d)
+ break;
+ }
+ if (i == DRM_MAX_MINOR)
+ return NULL;
+
+ return drmStrdup(name);
+}