libdrm: drmGetMinorNameForFD: Add FreeBSD variant

Use the FreeBSD variant function to obtain the minor name and the
device node.
Return the correct path based on where the node is (drm/ versus dri/).

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:53:07 +01:00 committed by Emmanuel Vadot
parent 6818a50b12
commit 57c50cfc45
1 changed files with 32 additions and 0 deletions

View File

@ -2938,6 +2938,38 @@ static char *drmGetMinorNameForFD(int fd, int type)
closedir(sysdir);
return NULL;
#elif __FreeBSD__
struct stat sbuf;
char dname[SPECNAMELEN];
const char *mname;
char name[SPECNAMELEN];
int id, 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;
/* Handle both /dev/drm and /dev/dri
* FreeBSD on amd64/i386/powerpc external kernel modules create node in
* in /dev/drm/ and links in /dev/dri while a WIP in kernel driver creates
* only device nodes in /dev/dri/ */
mname = drmGetMinorName(type);
if (sscanf(dname, "drm/%d", &id) != 1) {
snprintf(name, sizeof(name), "dri/%s", mname);
if (strncmp(name, dname, strlen(name)) != 0)
return NULL;
snprintf(name, sizeof(name), "/dev/%s", dname);
} else
snprintf(name, sizeof(name), DRM_DIR_NAME "/%s%d", mname, id);
return strdup(name);
#else
struct stat sbuf;
char buf[PATH_MAX + 1];