aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Gray2016-12-16 23:09:52 -0600
committerEmil Velikov2016-12-24 11:06:53 -0600
commite2e766d5acdbb826f1cfe5643669db54ee86f456 (patch)
tree7508331243098b57fafcee55e79813cd60a7677e /xf86drm.c
parentd5cf3f98314c1b9d87216e00c30c9fef06ff24c3 (diff)
downloadexternal-libgbm-e2e766d5acdbb826f1cfe5643669db54ee86f456.tar.gz
external-libgbm-e2e766d5acdbb826f1cfe5643669db54ee86f456.tar.xz
external-libgbm-e2e766d5acdbb826f1cfe5643669db54ee86f456.zip
xf86drm: add a non-sysfs version of drmGetDeviceNameFromFd2
Implement a generic drmGetDeviceNameFromFd2() to use on non-linux systems without sysfs. v2: remove min < base test as requested by Emil Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Diffstat (limited to 'xf86drm.c')
-rw-r--r--xf86drm.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/xf86drm.c b/xf86drm.c
index f6850aa2..f684c017 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3627,7 +3627,47 @@ char *drmGetDeviceNameFromFd2(int fd)
3627 fclose(f); 3627 fclose(f);
3628 return device_name; 3628 return device_name;
3629#else 3629#else
3630#warning "Missing implementation of drmGetDeviceNameFromFd2" 3630 struct stat sbuf;
3631 return NULL; 3631 char node[PATH_MAX + 1];
3632 const char *dev_name;
3633 int node_type;
3634 int maj, min, n, base;
3635
3636 if (fstat(fd, &sbuf))
3637 return NULL;
3638
3639 maj = major(sbuf.st_rdev);
3640 min = minor(sbuf.st_rdev);
3641
3642 if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
3643 return NULL;
3644
3645 node_type = drmGetMinorType(min);
3646 if (node_type == -1)
3647 return NULL;
3648
3649 switch (node_type) {
3650 case DRM_NODE_PRIMARY:
3651 dev_name = DRM_DEV_NAME;
3652 break;
3653 case DRM_NODE_CONTROL:
3654 dev_name = DRM_CONTROL_DEV_NAME;
3655 break;
3656 case DRM_NODE_RENDER:
3657 dev_name = DRM_RENDER_DEV_NAME;
3658 break;
3659 default:
3660 return NULL;
3661 };
3662
3663 base = drmGetMinorBase(node_type);
3664 if (base < 0)
3665 return NULL;
3666
3667 n = snprintf(node, PATH_MAX, dev_name, DRM_DIR_NAME, min - base);
3668 if (n == -1 || n >= PATH_MAX)
3669 return NULL;
3670
3671 return strdup(node);
3632#endif 3672#endif
3633} 3673}