libdrm: drmGetMinorNameFromFd: Fix FreeBSD variant

Fix the FreeBSD variant by getting the node type represented by fd to deduce
the target minor name.
We then return the full /dev/dri/<minorname><id> version.

Fix: #41
Fixes: 6818a50b12
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Signed-off-by: Emmanuel Vadot <manu@FreeBSD.org>
main
Emmanuel Vadot 2020-04-28 15:26:13 +02:00
parent 5ec177b398
commit f52e2b20ed
1 changed files with 19 additions and 8 deletions

View File

@ -2947,7 +2947,7 @@ static char *drmGetMinorNameForFD(int fd, int type)
char dname[SPECNAMELEN]; char dname[SPECNAMELEN];
const char *mname; const char *mname;
char name[SPECNAMELEN]; char name[SPECNAMELEN];
int id, maj, min; int id, maj, min, nodetype, i;
if (fstat(fd, &sbuf)) if (fstat(fd, &sbuf))
return NULL; return NULL;
@ -2965,14 +2965,25 @@ static char *drmGetMinorNameForFD(int fd, int type)
* FreeBSD on amd64/i386/powerpc external kernel modules create node in * 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 * in /dev/drm/ and links in /dev/dri while a WIP in kernel driver creates
* only device nodes in /dev/dri/ */ * only device nodes in /dev/dri/ */
/* Get the node type represented by fd so we can deduce the target name */
nodetype = drmGetMinorType(maj, min);
if (nodetype == -1)
return (NULL);
mname = drmGetMinorName(type); mname = drmGetMinorName(type);
if (sscanf(dname, "drm/%d", &id) != 1) {
snprintf(name, sizeof(name), "dri/%s", mname); for (i = 0; i < SPECNAMELEN; i++) {
if (strncmp(name, dname, strlen(name)) != 0) if (isalpha(dname[i]) == 0 && dname[i] != '/')
return NULL; break;
snprintf(name, sizeof(name), "/dev/%s", dname); }
} else if (dname[i] == '\0')
snprintf(name, sizeof(name), DRM_DIR_NAME "/%s%d", mname, id); return (NULL);
id = (int)strtol(&dname[i], NULL, 10);
id -= drmGetMinorBase(nodetype);
snprintf(name, sizeof(name), DRM_DIR_NAME "/%s%d", mname,
id + drmGetMinorBase(type));
return strdup(name); return strdup(name);
#else #else
struct stat sbuf; struct stat sbuf;