ioctl

linux内核之dmaengine

可紊 提交于 2019-11-29 00:01:27
dmaengine framwork主要分为两部分:DMA controller 和DMA engine API。涉及内核相关文档:Documentation/damengine目录、Documentation/devicetree/bindings/dma/、Documentation/DAM-API-HOWTO.txt\DMA-API.txt\DMA-attributes.txt 1、dma controller(provider的角度) 基于DMA的硬件地址使用的是总线地址而不是物理地址,总线地址是从设备角度看到的内存地址,物理地址是从CPU mmu控制器外围角度上看到的内存地址。在pc上,对于ISA和PCI而言,总系地址即为物理地址,但并不是每个平台都是如此。接口总线通过桥接电路连接,桥接电路会将I/O地址映射为不同的物理地址,例如在PREP(PowerPC Reference Platform)系统中,物理地址0在设备端看起来是0x80000000,而0通常又被映射为虚拟地址0xC0000000,所以同一个地址就具备了三重身份:物理地址0,总线地址0x80000000及虚拟地址0xC0000000。 (1)重要数据结构之struct dma_device 该结构体抽象了dma controller,部分成员说明如下: channels:一个链表头

Sending ATA commands directly to device in Windows?

一曲冷凌霜 提交于 2019-11-28 18:50:24
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_EXISTING, 0, // flags and attributes nil // no template file ); But after this I’m stymied about what to do.

使用WinDbg内核调试

好久不见. 提交于 2019-11-28 18:32:55
看雪学院,笨笨翻译《 使用WinDbg内核调试 》。很有用的资料,由于太长,加上很多图片,偷懒,留个链接在这里。这里简要做一些我测试时候的笔记: 首先你要配置好测试环境:参考 VMware+Windgb+Win7 内核驱动调试 在你的主机上配置Symbols 配置sympath,C:\Users\Admin\Desktop\first\objchk_win7_x86\i386是你编译好的sys目录: SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols;C:\Users\Admin\Desktop\first\objchk_win7_x86\i386 配置Source search path假设文件放在C:\Users\Admin\Desktop\first]: C:\Users\Admin\Desktop\first 然后在命令行中输入:.reload 打开源文件:Ctrl+O 接着检查是否已经加载sys.dbg,命令为: kd> !lmi ndislwf Loaded Module Info: [nt] Module: ntoskrnl Base Address: 80a02000 Symbol Type: PDB – Symbols loaded successfully from symbol server. d

Physical disk size not correct (IoCtlDiskGetDriveGeometry)

懵懂的女人 提交于 2019-11-28 09:28:09
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 long Cylinders; public int MediaType; public int TracksPerCylinder; public int SectorsPerTrack; public int

获取网络接口信息——ioctl()函数与结构体struct ifreq、 struct ifconf (获取或设置 网卡 IP 子网掩码 本地广播地址)

岁酱吖の 提交于 2019-11-28 07:14:56
Linux 下 可以使用ioctl()函数 以及 结构体 struct ifreq 结构体struct ifconf来获取网络接口的各种信息。 ioctl 首先看ioctl()用法 ioctl()原型如下: #include <sys/ioctl.h> int ioctl(int fd, int request, ...); 参数: fd : 文件描述符 request: 表示要请求的信息。如IP地址、网络掩码等 ... : 后面的可变参数根据request而定 比如我们请求所有网络接口的清单: struct ifconf IoCtlReq; ... ioctl( Sock, SIOCGIFCONF, &IoCtlReq ) 其中IoCtlReq 是一个 与接口相关的request如下表所示(来源: <http://baike.baidu.com/view/1081282.htm?fr=aladdin>): 关于ioctl的详细解释清查阅本博其它博文 struct ifreq 结构体 struct ifreq用来保存某个接口的信息。 // if.h /* * Interface request structure used for socket * ioctl's. All interface ioctl's must have parameter * definitions

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 06:58:23
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. 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; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family==AF_INET) { sa = (struct sockaddr_in *) ifa->ifa_addr;

“inappropriate ioctl for device”

爷,独闯天下 提交于 2019-11-28 06:42:09
I have a Perl script running in an AIX box. The script tries to open a file from a certain directory and it fails to read the file because file has no read permission, but I get a different error saying inappropriate ioctl for device . Shouldn't it say something like no read permissions for file or something similar? What does this inappropriate ioctl for device message mean? How can I fix it? EDIT: This is what I found when I did strace . open("/local/logs/xxx/xxxxServer.log", O_WRONLY|O_CREAT|O_APPEND|O_LARGEFILE, 0666) = 4 _llseek(4, 0, [77146], SEEK_END) = 0 ioctl(4, SNDCTL_TMR_TIMEBASE or

ioctl操作

随声附和 提交于 2019-11-28 05:14:17
  在本书中有两个地方都对这个函数进行了介绍,其实还有很多地方需要这个函数。ioclt函数传统上一直作为纳西而不适合归入其他精细定义类别的特性的系统接口。网络程序(特别是服务器程序)经常在程序启动执行后使用ioctl获取所在主机全部网络接口的信心,包括:接口地址、是否支持广播、是否支持多播。 #include <unistd.h> int ioctl(int fd,int request,...../* void *arg /); //返回:若成功则为0.失败则我-1 套接字操作 文件操作 接口操作 ARP高速缓存操作 路由表操作 流系统   不但某些ioclt操作和某些fcntl操作功能重叠(譬如把套接字设置为非阻塞),而且某些操作可以使用ioctl以不止一种方式制定(譬如设置套接字的进程组属主)。下表列出了网络相关ioctl请求的request参数以及arg地址必须指向的数据类型。 套接字操作   明确要求套接字ioctl请求有三个,它们都要求ioctl的第三个参数是指向某个整数的一个指针。 SIOCATMARK:如果本套接字的读指针当前位于带外标记,那就通过由第三个参数指向的帧数放回一个非0值,否则返回一个0值。 SIOCGPGRP:通过由第三个参数指向的整数返回本套接字的进程ID或进程组ID,该ID指定针对本套接字的SIGIO或SIGURG信号的接受进程。 SIOCSPGR

Set IP address using SIOCSIFADDR ioctl

泄露秘密 提交于 2019-11-28 05:08:58
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 = socket(AF_INET, SOCK_STREAM, 0); sprintf(ifr.ifr_name, "eth0"); in_addr = inet_addr("192.168.101.17")

ioctl is not called if cmd = 2

一曲冷凌霜 提交于 2019-11-27 17:55:44
问题 I am developing a kernel module that uses unlocked_ioctl. I tested it with kernel version 2.6.24-23-generic and it works perfectly. Now I tried it with kernel version 3.3.1-1-ARCH and something weird happens: the ioctl function is not executed when the request value (cmd) is 2. It returns 0, but the function is not executed. In order to check that it is not executed I did the following: static long midriver_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { printk("Called with