ioctl

Physical disk size not correct (IoCtlDiskGetDriveGeometry)

℡╲_俬逩灬. 提交于 2019-12-17 19:11:15
问题 I use the code below to get the physical disk size , but the size returned is not correct. I've checked the size with other tools. The code below reports Total disk space: 8.249.955.840 bytes and it should be Total disk space: 8.254.390.272 bytes How can I retrieve the actual/correct physical disk size? Tested on USB drives and normal hard drives. The code is long, here separate it in parts to show. The structure: [StructLayout(LayoutKind.Sequential)] internal struct DiskGeometry { public

主题:ioctl函数详细说明

好久不见. 提交于 2019-12-16 19:04:22
ioctl 函数 本函数影响由 fd 参数引用的一个打开的文件。 #include<unistd.h> int ioctl ( int fd, int request, .../* void *arg */ ); 返回 0 :成功 -1 :出错 第三个参数总是一个指针,但指针的类型依赖于 request 参数。 我们可以把和网络相关的请求划分为 6 类: 套接口操作 文件操作 接口操作 ARP 高速缓存操作 路由表操作 流系统 下表列出了网络相关 ioctl 请求的 request 参数以及 arg 地址必须指向的数据类型: 类别 Request 说明 数据类型 套 接 口 SIOCATMARK SIOCSPGRP SIOCGPGRP 是否位于带外标记 设置套接口的进程 ID 或进程组 ID 获取套接口的进程 ID 或进程组 ID int int int 文 件 FIONBIN FIOASYNC FIONREAD FIOSETOWN FIOGETOWN 设置 / 清除非阻塞 I/O 标志 设置 / 清除信号驱动异步 I/O 标志 获取接收缓存区中的字节数 设置文件的进程 ID 或进程组 ID 获取文件的进程 ID 或进程组 ID int int int int int 接 口 SIOCGIFCONF SIOCSIFADDR SIOCGIFADDR SIOCSIFFLAGS

Qemu 模拟器

穿精又带淫゛_ 提交于 2019-12-14 21:46:06
一、Qemu 架构 Qemu 是纯软件实现的虚拟化模拟器 ,几乎可以模拟任何硬件设备,我们最熟悉的就是能够模拟一台能够独立运行操作系统的虚拟机,虚拟机认为自己和硬件打交道,但其实是和 Qemu 模拟出来的硬件打交道,Qemu 将这些指令转译给真正的硬件。 正因为 Qemu 是纯软件实现的,所有的指令都要经 Qemu 过一手,性能非常低,所以,在生产环境中,大多数的做法都是配合 KVM 来完成虚拟化工作,因为 KVM 是硬件辅助的虚拟化技术,主要负责 比较繁琐的 CPU 和内存虚拟化,而 Qemu 则负责 I/O 虚拟化,两者合作各自发挥自身的优势,相得益彰。 qemu 从本质上看,虚拟出的每个虚拟机对应 host 上的一个 Qemu 进程,而虚拟机的执行线程(如 CPU 线程、I/O 线程等)对应 Qemu 进程的一个线程。下面通过一个虚拟机启动过程看看 Qemu 是如何与 KVM 交互的。 // 第一步,获取到 KVM 句柄 kvmfd = open("/dev/kvm", O_RDWR); // 第二步,创建虚拟机,获取到虚拟机句柄。 vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0); // 第三步,为虚拟机映射内存,还有其他的 PCI,信号处理的初始化。ioctl(kvmfd, KVM_SET_USER_MEMORY_REGION, &mem); /

Linux kernel module - IOCTL usage returns ENOTTY

ε祈祈猫儿з 提交于 2019-12-14 01:13:12
问题 Im working on little kernel module. Im trying to use IOCTL (in ioctl_add), but I get ENOTTY when I call it, which is checked in switch, on the bottom of main. The code is below. Has anyone got any idea what am I doing wrong? user.c: #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <unistd.h> #include <sys/types.h> #include <sys/ioctl.h> #include <linux/ioctl.h> #include <sys/stat.h> #include <sys/poll.h> #include <fcntl.h> #include <string.h> #include <errno.h> #define

What does FIONREAD of UDP (datagram) sockets return? [duplicate]

為{幸葍}努か 提交于 2019-12-14 00:53:52
问题 This question already has answers here : How do I get amount of queued data for UDP socket? (2 answers) Closed last year . Which one does ioctl of FIONREAD return, the next packet's length, or the length of all data in the buffer? Suppose there is a UDP server that receives 2 packets from a client 1 and another 2 packets from client 2 after client 1's packet. Then, what is the value of ioctl of FIONREAD , and what does readfrom return in that case? Client 1 : v two packets ++UDP Server got 4

ws_xpixel and ws_ypixel

半世苍凉 提交于 2019-12-12 18:17:22
问题 Here is the code I am using to print the resolution in pixels of the current terminal. #include <sys/ioctl.h> #include <stdio.h> #include <unistd.h> int main (int argc, char *argv[]) { struct winsize ww; ioctl(STDOUT_FILENO, TIOCGWINSZ, &ww); printf ("x-pixels %d\n", ww.ws_xpixel); printf ("y-pixels %d\n", ww.ws_ypixel); return 0; } I used this as winsize reference. But the code prints only zeros. If I use ws_col or ws_row it works fine. Please help, thanks ! 回答1: If you look at the source

Retrieval of the error counters via TIOCGICOUNT returns always error (-1)

青春壹個敷衍的年華 提交于 2019-12-12 12:19:16
问题 I have come across a show stopping problem when developing an interface application for a USB to RS422 converter module. I need to retrieve the UART error counters for framing, overrun, parity and break errors. But the call to ioctl always returns -1 and the counter values from the retrieved struct are jumping to very big numbers. The code i am using to retrieve the counters is the following: struct serial_icounter_struct counters; int ret = ioctl(portDescriptor, TIOCGICOUNT, &counters); To

Android ioctl - root permissions and usage

你说的曾经没有我的故事 提交于 2019-12-12 11:31:05
问题 I'm working on some routing functionality in an Android app, and need to access ioctls. Since apps that use ioctls need root permission to run, the only way I've been able to call them is linking a separate executable and calling that from Java with Runtime.getRuntime().exec() . Is there a way to access root permissions from JNI in Android without building a separate executable? Is building an executable the best approach to access an ioctl? 回答1: There is no means for a non-root process to

How to properly convert a C ioctl call to a python fcntl.ioctl call?

牧云@^-^@ 提交于 2019-12-12 08:28:48
问题 Following an example on resetting a serial port in Linux I wanted to translate the following snippet fd = open(filename, O_WRONLY); ioctl(fd, USBDEVFS_RESET, 0); close(fd); into valid python code. Here is what I have tried so far file_handler = open(self._port, 'w') fcntl.ioctl(file_handler, termios.USBDEVFS_RESET) file_handler.close() which ends with an error 'module' object has no attribute 'USBDEVFS_RESET' . The termios documentation is not very helpful in this point, as it does not list

ioctl to block operation

蓝咒 提交于 2019-12-12 02:28:19
问题 I am using ioctl function to access framebuffer The problem is that for each frame, I am writing framebuffer three times For instance, each frame, I first fill frame with Red color, do some computation, fill Green, then do another computation, then fill Blue. In other words, each frame, I have three layers, Red as the bottom, Green, then Blue as the top. Therefore, Red and Green is invisible and all I can see is the Blue. Now, my question is that when I use ioctl call, it seems like it can't