summaryrefslogtreecommitdiff
path: root/xf86drm.c
diff options
context:
space:
mode:
authorJonathan Gray <jsg@jsg.id.au>2016-12-01 15:18:39 +1100
committerEmil Velikov <emil.l.velikov@gmail.com>2016-12-05 17:52:46 +0000
commitf189011b362a2dff3ab914523e546cc96f53df39 (patch)
tree5e517e4d3e6e7ff01ff604ed099ebef68c3e758d /xf86drm.c
parent5c1c91b3d381a51ea57fb68242f8645e63d806bd (diff)
downloadlibdrm-f189011b362a2dff3ab914523e546cc96f53df39.tar.gz
libdrm-f189011b362a2dff3ab914523e546cc96f53df39.tar.bz2
libdrm-f189011b362a2dff3ab914523e546cc96f53df39.zip
xf86drm: implement drmGetMinorNameForFD for non-sysfs
Implement drmGetMinorNameForFD for systems without sysfs by adapting drm_get_device_name_for_fd() from the Mesa loader. v2: use type parameter to select dev name instead of always using DRM_DEV_NAME Signed-off-by: Jonathan Gray <jsg@jsg.id.au> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/xf86drm.c b/xf86drm.c
index a886768e..65764de4 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -2818,7 +2818,40 @@ static char *drmGetMinorNameForFD(int fd, int type)
out_close_dir:
closedir(sysdir);
#else
-#warning "Missing implementation of drmGetMinorNameForFD"
+ struct stat sbuf;
+ char buf[PATH_MAX + 1];
+ const char *dev_name;
+ unsigned int maj, min;
+ 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;
+
+ switch (type) {
+ case DRM_NODE_PRIMARY:
+ dev_name = DRM_DEV_NAME;
+ break;
+ case DRM_NODE_CONTROL:
+ dev_name = DRM_CONTROL_DEV_NAME;
+ break;
+ case DRM_NODE_RENDER:
+ dev_name = DRM_RENDER_DEV_NAME;
+ break;
+ default:
+ return NULL;
+ };
+
+ n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min);
+ if (n == -1 || n >= sizeof(buf))
+ return NULL;
+
+ return strdup(buf);
#endif
return NULL;
}