From 22d46669043d38fcd16efca773f5ed5693c0fb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 23 Nov 2009 20:51:34 -0500 Subject: Add drmGetDeviceNameFromFd function Determines the /dev filename of the drm fd argument. --- xf86drm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'xf86drm.c') 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); +} -- cgit v1.2.3