ioctl

IOCTL Linux device driver [closed]

我是研究僧i 提交于 2019-11-27 16:39:23
Can anyone explain me, What is IOCTL ? What is it used for? How can I use it? Why can't I define new function that does the same work as IOCTL ? Inductiveload An ioctl , which means "input-output control" is a kind of device-specific system call. There are only a few system calls in Linux (300-400), which are not enough to express all the unique functions devices may have. So a driver can define an ioctl which allows a userspace application to send it orders. However, ioctls are not very flexible and tend to get a bit cluttered (dozens of "magic numbers" which just work... or not), and can

Sending ATA commands directly to device in Windows?

余生长醉 提交于 2019-11-27 11:42:08
问题 I’m trying to send ATA commands to a physical disk in Windows, and get the response from the device. Note: In this case I want to send the IDENTIFY DEVICE (0xEC) command. The device will respond with a 512-byte block of data. (In particular I’m interested in bit 0 of word 119 - the device’s support for the TRIM command). I know that I need to use CreateFile to open the device: handle = CreateFile( "\\.\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ, nil, // no security attributes OPEN

framebuffer绘屏

北城余情 提交于 2019-11-27 10:21:56
通过framebuffer绘制屏幕上的每一个像素点: 1.打开framebuffer设备; 2.通过ioctl取得fixed screen information;(ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) 3.通过ioctl取得variable screen information;(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) 4.通过mmap映射设备内存到进程空间;(记得区分内核空间和用户空间,用户空间是无法对物理内存直接读写的) 5.写framebuffer; 6.终止。(记得终止时一定要取消映射,并close掉句柄) 来源: https://www.cnblogs.com/yangxingsha/p/11359009.html

linux重定向串口打印到telnet ssh远程中断

六月ゝ 毕业季﹏ 提交于 2019-11-27 09:59:07
如果要实时显示printk 信息 可以参考 https://www.cnblogs.com/ChenChangXiong/p/11357416.html 有时候调试需要 但是没有串口 使用telnet ssh远程登录的时候 不能显示启动时候运行的程序的打印 这个时候需要重定向 源码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <fcntl.h> 5 #include <sys/ioctl.h> 6 #include <unistd.h> 7 8 int main(int argc, char *argv[]) 9 { 10 int tty = -1; 11 char *tty_name = NULL; 12 13 if(argc < 2) 14 { 15 printf("miss argument\n"); 16 return 0; 17 } 18 19 /* 获取当前tty名称 */ 20 tty_name = ttyname(STDOUT_FILENO); 21 printf("tty_name: %s\n", tty_name); 22 23 if(!strcmp(argv[1], "on")) 24 { 25 /* 重定向console到当前tty */ 26

ioctl giving Invalid Argument

[亡魂溺海] 提交于 2019-11-27 08:08:39
问题 I want to send a opened file descriptor between two different programs. So I am using ioctl with named pipes to do so. But there I am getting Invalid argument for ioctl. #include <stropts.h> #include "accesories.c" #include <fcntl.h> #include <errno.h> #include <string.h> #include <sys/ioctl.h> #define MSGSIZ 63 char *fifo = "fifo"; int send_err(int fd, int errcode, const char *msg) { int n; if ((n = strlen(msg)) > 0) if (write(fd, msg, n) != n) /* send the error message */ return(-1); if

Detect laptop lid closure and opening

橙三吉。 提交于 2019-11-27 07:06:33
Is it possible to detect when a laptop's lid is open or closed? From what I've read, this isn't possible, but SO has helped me with the impossible before. The only thing I've found that might be in the right direction is an MSDN blog post about IOCTLs needed to report power buttons . Is it possible to "sniff" these as the OS calls them? I'm using VB.NET, but will take suggestions in any language. Thank you for your time and advice. Edit : My software will be (eventually) overriding the actions (based on user preference) that occur when the lid is closed, so listening for suspend and other

Set IP address using SIOCSIFADDR ioctl

為{幸葍}努か 提交于 2019-11-27 05:26:29
问题 I am trying to get and set the IP address using the IOCTL interface on Linux. I am successfully able to get and set it. When I set the ip address, ifconfig eth0 shows a proper IP address, but then the system gets disconnected. i.e. System is not pingable. Here's my code for setting the IP address. Please let me know if I am missing something. struct ifreq ifr; in_addr_t in_addr; struct sockaddr_in sin; memset(&ifr, 0, sizeof(struct ifreq)); memset(&sin, 0, sizeof(struct sockaddr_in)); sockfd

Beep on Linux in C

倾然丶 夕夏残阳落幕 提交于 2019-11-27 04:51:28
I want to generate a beep sound with a specific frequency and length (for different sound signals) using the system beeper (and only the speakers if beeper is not available / accessible). I know it is possible to do this by using ioctl, but that requires root access, which I don't want. I know I could just use the "beep" command, but that would be a dependency, which, if possible, shouldn't be used (no external dependencies at all, just the basic linux libraries and C). What I currently have is the following code (but this requires superuser privileges to run): #include <stdlib.h> #include

Maximum buffer length for sendto?

被刻印的时光 ゝ 提交于 2019-11-27 01:59:41
问题 How do you get the maximum number of bytes that can be passed to a sendto(..) call for a socket opened as a UDP port? 回答1: Use getsockopt(). This site has a good breakdown of the usage and options you can retrieve. In Windows, you can do: int optlen = sizeof(int); int optval; getsockopt(socket, SOL_SOCKET, SO_MAX_MSG_SIZE, (int *)&optval, &optlen); For Linux, according to the UDP man page, the kernel will use MTU discovery (it will check what the maximum UDP packet size is between here and

How can I get to know the IP address for interfaces in C?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 01:38:32
问题 Let's say I'm running a program called IpAddresses.c. I want that program to get all IP addresses this device has according to each interface. Just like ifconfig. How can I do that? I don't know much about ioctl, but I read it might help me. 回答1: Just use getifaddrs(). Here's an example: #include <arpa/inet.h> #include <sys/socket.h> #include <ifaddrs.h> #include <stdio.h> int main () { struct ifaddrs *ifap, *ifa; struct sockaddr_in *sa; char *addr; getifaddrs (&ifap); for (ifa = ifap; ifa;