|
|
|
@ -2,6 +2,8 @@
|
|
|
|
|
|
|
|
|
|
use std::os::fd::RawFd;
|
|
|
|
|
use std::ffi::{CStr, OsString};
|
|
|
|
|
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
|
|
|
|
use std::vec;
|
|
|
|
|
use libc;
|
|
|
|
|
|
|
|
|
|
use super::native;
|
|
|
|
@ -20,36 +22,38 @@ pub struct DrmVersion {
|
|
|
|
|
|
|
|
|
|
pub fn get_drm_version(fd: RawFd) -> Option<DrmVersion> {
|
|
|
|
|
unsafe {
|
|
|
|
|
let name_vec = libc::malloc(128);
|
|
|
|
|
libc::memset(name_vec, 0, 128);
|
|
|
|
|
let date_vec = libc::malloc(128);
|
|
|
|
|
libc::memset(date_vec, 0, 128);
|
|
|
|
|
let desc_vec = libc::malloc(128);
|
|
|
|
|
libc::memset(desc_vec, 0, 128);
|
|
|
|
|
let mut name_vec = vec![0 as u8; 128];
|
|
|
|
|
let mut date_vec = vec![0 as u8; 128];
|
|
|
|
|
let mut desc_vec = vec![0 as u8; 128];
|
|
|
|
|
|
|
|
|
|
let mut version = native::drm_version {
|
|
|
|
|
version_major: 0,
|
|
|
|
|
version_minor: 0,
|
|
|
|
|
version_patchlevel: 0,
|
|
|
|
|
name: name_vec as *mut i8,
|
|
|
|
|
date: date_vec as *mut i8,
|
|
|
|
|
desc: desc_vec as *mut i8,
|
|
|
|
|
name: name_vec.as_mut_ptr() as *mut i8,
|
|
|
|
|
date: date_vec.as_mut_ptr() as *mut i8,
|
|
|
|
|
desc: desc_vec.as_mut_ptr() as *mut i8,
|
|
|
|
|
name_len: 128,
|
|
|
|
|
date_len: 128,
|
|
|
|
|
desc_len: 128,
|
|
|
|
|
};
|
|
|
|
|
let res_val = libc::ioctl(fd, native::DRM_IOCTL_VERSION, &mut version) == 0;
|
|
|
|
|
let res = if res_val {
|
|
|
|
|
let name = CStr::from_ptr(version.name).to_str().expect("Failed to convert name");
|
|
|
|
|
let date = CStr::from_ptr(version.date).to_str().expect("Failed to convert date");
|
|
|
|
|
let desc = CStr::from_ptr(version.desc).to_str().expect("Failed to convert desc");
|
|
|
|
|
name_vec.resize(CStr::from_bytes_until_nul(name_vec.as_slice()).unwrap().to_bytes().len(), 0);
|
|
|
|
|
date_vec.resize(CStr::from_bytes_until_nul(date_vec.as_slice()).unwrap().to_bytes().len(), 0);
|
|
|
|
|
desc_vec.resize(CStr::from_bytes_until_nul(desc_vec.as_slice()).unwrap().to_bytes().len(), 0);
|
|
|
|
|
|
|
|
|
|
let name = OsString::from_vec(name_vec);
|
|
|
|
|
let date = OsString::from_vec(date_vec);
|
|
|
|
|
let desc = OsString::from_vec(desc_vec);
|
|
|
|
|
|
|
|
|
|
let drm_version = DrmVersion {
|
|
|
|
|
version_major: version.version_major,
|
|
|
|
|
version_minor: version.version_minor,
|
|
|
|
|
version_patchlevel: version.version_patchlevel,
|
|
|
|
|
name: OsString::from(name.to_string()),
|
|
|
|
|
date: OsString::from(date.to_string()),
|
|
|
|
|
desc: OsString::from(desc.to_string()),
|
|
|
|
|
name: name,
|
|
|
|
|
date: date,
|
|
|
|
|
desc: desc,
|
|
|
|
|
};
|
|
|
|
|
Some(drm_version)
|
|
|
|
|
} else {None};
|
|
|
|
|