libdrm: drmGetDeviceNameFromFd: Add FreeBSD variant

Get the major/minor via fstat and after checking that this is a drm node
construct the full device node name using devname.
Note that we should be able to use fdevname to avoid calling fstat + devname
but for some reason it doesn't work on drm node (probably due to how the device
node are created in the linux compat code for drm on FreeBSD).

Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
main
Emmanuel Vadot 2020-01-21 17:50:15 +01:00 committed by Emmanuel Vadot
parent c55a1e564c
commit 6818a50b12
1 changed files with 24 additions and 0 deletions

View File

@ -117,6 +117,8 @@ struct drm_pciinfo {
static drmServerInfoPtr drm_server_info;
static bool drmNodeIsDRM(int maj, int min);
drm_public void drmSetServerInfo(drmServerInfoPtr info)
{
drm_server_info = info;
@ -2768,6 +2770,27 @@ drm_public int drmIsMaster(int fd)
drm_public char *drmGetDeviceNameFromFd(int fd)
{
#ifdef __FreeBSD__
struct stat sbuf;
char dname[SPECNAMELEN];
char name[SPECNAMELEN];
int maj, min;
if (fstat(fd, &sbuf))
return NULL;
maj = major(sbuf.st_rdev);
min = minor(sbuf.st_rdev);
if (!drmNodeIsDRM(maj, min) || !S_ISCHR(sbuf.st_mode))
return NULL;
if (!devname_r(sbuf.st_rdev, S_IFCHR, dname, sizeof(dname)))
return NULL;
snprintf(name, sizeof(name), "/dev/%s", dname);
return strdup(name);
#else
char name[128];
struct stat sbuf;
dev_t d;
@ -2790,6 +2813,7 @@ drm_public char *drmGetDeviceNameFromFd(int fd)
return NULL;
return strdup(name);
#endif
}
static bool drmNodeIsDRM(int maj, int min)