aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Gray2016-11-30 22:18:39 -0600
committerEmil Velikov2016-12-05 11:52:46 -0600
commitf189011b362a2dff3ab914523e546cc96f53df39 (patch)
tree5e517e4d3e6e7ff01ff604ed099ebef68c3e758d /xf86drm.c
parent5c1c91b3d381a51ea57fb68242f8645e63d806bd (diff)
downloadexternal-libdrm-f189011b362a2dff3ab914523e546cc96f53df39.tar.gz
external-libdrm-f189011b362a2dff3ab914523e546cc96f53df39.tar.xz
external-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)
2818out_close_dir: 2818out_close_dir:
2819 closedir(sysdir); 2819 closedir(sysdir);
2820#else 2820#else
2821#warning "Missing implementation of drmGetMinorNameForFD" 2821 struct stat sbuf;
2822 char buf[PATH_MAX + 1];
2823 const char *dev_name;
2824 unsigned int maj, min;
2825 int n;
2826
2827 if (fstat(fd, &sbuf))
2828 return NULL;
2829
2830 maj = major(sbuf.st_rdev);
2831 min = minor(sbuf.st_rdev);
2832
2833 if (maj != DRM_MAJOR || !S_ISCHR(sbuf.st_mode))
2834 return NULL;
2835
2836 switch (type) {
2837 case DRM_NODE_PRIMARY:
2838 dev_name = DRM_DEV_NAME;
2839 break;
2840 case DRM_NODE_CONTROL:
2841 dev_name = DRM_CONTROL_DEV_NAME;
2842 break;
2843 case DRM_NODE_RENDER:
2844 dev_name = DRM_RENDER_DEV_NAME;
2845 break;
2846 default:
2847 return NULL;
2848 };
2849
2850 n = snprintf(buf, sizeof(buf), dev_name, DRM_DIR_NAME, min);
2851 if (n == -1 || n >= sizeof(buf))
2852 return NULL;
2853
2854 return strdup(buf);
2822#endif 2855#endif
2823 return NULL; 2856 return NULL;
2824} 2857}