}
/**
+ * Open the DRM device with specified type of specified framebuffer.
+ *
+ * Looks up the associated DRM device with specified type of the
+ * specified framebuffer and opens it.
+ *
+ * \param fb the index of framebuffer.
+ * \param type the device node type to open, PRIMARY, CONTROL or RENDER
+ *
+ * \return a file descriptor on success, or a negative value on error.
+ *
+ */
+drm_public int drmOpenByFB(int fb, int type)
+{
+#ifdef __linux__
+ DIR *sysdir;
+ struct dirent *ent;
+ char buf[64];
+ const char *name = drmGetMinorName(type);
+ int fd = -1, len = strlen(name);
+
+ snprintf(buf, sizeof(buf), "/sys/class/graphics/fb%d/device/drm", fb);
+ sysdir = opendir(buf);
+ if (!sysdir)
+ return -errno;
+
+ while ((ent = readdir(sysdir))) {
+ if (!strncmp(ent->d_name, name, len)) {
+ snprintf(buf, sizeof(buf), "%s/%s", DRM_DIR_NAME, ent->d_name);
+ fd = open(buf, O_RDWR | O_CLOEXEC, 0);
+ break;
+ }
+ }
+
+ closedir(sysdir);
+ return fd;
+#else
+#warning "Missing implementation of drmOpenByFB"
+ return -EINVAL;
+#endif
+}
+
+/**
* Free the version information returned by drmGetVersion().
*
* \param v pointer to the version information.
extern int drmOpenControl(int minor);
extern int drmOpenRender(int minor);
+extern int drmOpenByFB(int fb, int type);
extern int drmClose(int fd);
extern drmVersionPtr drmGetVersion(int fd);
extern drmVersionPtr drmGetLibVersion(int fd);