ioctl

How to issue a READ CD command to a CD-ROM drive in Windows?

非 Y 不嫁゛ 提交于 2020-01-02 07:29:22
问题 I'm working on an application that needs to issue raw SCSI commands to a CD-ROM drive. Currently, I'm struggling with sending a READ CD ( 0xBE ) command to the drive and getting back the data from a given sector of the CD. Consider the following code : #include <windows.h> #include <winioctl.h> #include <ntddcdrm.h> #include <ntddscsi.h> #include <stddef.h> int main(void) { HANDLE fh; DWORD ioctl_bytes; BOOL ioctl_rv; const UCHAR cdb[] = { 0xBE, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 }; UCHAR buf

What is the point of using the linux macro access_ok()

谁都会走 提交于 2020-01-01 09:17:15
问题 I've been doing some research and I'm a little confused about this macro. Hopefully someone can give me some guidance. I have some ioctl code (which I've inherited, not written) and the first thing it does if check if access_ok() before moving on to copying data over from user space: #define __lddk_copy_from_user(a,b,c) copy_from_user(a,b,c) #define __lddk_copy_to_user(a,b,c) copy_to_user(a,b,c) long can_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { switch(cmd) { case

HDD serial number flipped every 2 bytes in Windows XP, Vista and 7 but not in Windows 8

荒凉一梦 提交于 2020-01-01 08:26:08
问题 I need to get HDD serial number to use it as a key for licensing a software. I used diskid32 code in this url: http://www.winsim.com/diskid32/diskid32.html It used the DeviceIoControl Win32 API with the IO control code of IOCTL_STORAGE_QUERY_PROPERTY . It worked. However, when I double check with the actual serial number printed on the HDD itself, I found that every 2 bytes of the number was flipped. A simple solution could be to simply flip the bytes back. It worked in Windows XP, Vista and

关于ioctl的cmd值如何解析...

瘦欲@ 提交于 2019-12-28 13:41:01
遇到ioctl内核中未定义, 打印log [ 739.108300] No such IOCTL, cmd is -1071625723 cmd is -1071625723 这个cmd如何解释呢...? ioctl原型 SYNOPSIS #include <sys/ioctl.h> int ioctl(int d, int request, ...); 其中request/cmd是一个32位整数。 那这个整数是如何定义的呢?? 可参考内核文档 ./Documentation/ioctl/ioctl-decoding.txt ./Documentation/ioctl/ioctl-number.txt 以上cmd数字的解析规则: 1 To decode a hex IOCTL code: 2 3 Most architectures use this generic format, but check 4 include/ARCH/ioctl.h for specifics, e.g. powerpc 5 uses 3 bits to encode read/write and 13 bits for size. 6 7 bits meaning 8 31-30› 00 - no parameters: uses _IO macro 9 › 10 - read: _IOR 10 ›

“inappropriate ioctl for device”

你离开我真会死。 提交于 2019-12-28 11:48:53
问题 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

Linux驱动开发——gpio(3)

坚强是说给别人听的谎言 提交于 2019-12-28 03:43:54
文章目录 linux内核字符设备硬件操作接口之ioctl ioctl系统调用函数的使用 使用参考: 对应的底层驱动的ioctl接口 LED灯使用示例: 操作流程: linux内核字符设备硬件操作接口之ioctl ioctl系统调用函数的使用 对于ioctl这个系统调用接口,Linux的创始人在2.0版本之前并没有进行添加,仅有write和read两个接口,但是后来发现当需要去控制文件的某些操作的时候,很显然这两个接口根本不够用。所以才有了这个万能控制接口ioctl,但是作为Linux的创始人Linus本人一直排斥该接口,因为这个ioctl接口的在内核中的使用相当于对应用层开设了一个能够直接交互的窗口,很影响内核整体的权限控制,不过由于目前还暂时没有更好可以替代的方法,所以还是继续保留了这个接口的使用。 对应驱动开发来说,ioctl的接口使用真的很方便,能够帮助我们解决很多同设备或者驱动在应用层或者用户态下调用的问题。 ioctl函数原型: int ioctl(int fd, int request, …) 函数功能: 1.向硬件设备发送控制命令 2.还可以和硬件设备进行读或者写操作 参数: fd:文件描述符 request:给硬件设备发送的控制命令,此命令有驱动开发者自行定义,例如我们在LED驱动下可以定义: #define LED_ON 0x100001 #define LED

How to use ioctl to read and write to a chardev?

天大地大妈咪最大 提交于 2019-12-25 07:04:57
问题 I am trying to build a kernel module with a simple ioctl function that reads and writes to a chardev. Here is the code for my module: #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> #include <asm/uaccess.h> #define MY_MACIG 'G' #define READ_IOCTL _IOR(MY_MACIG, 0, int) #define WRITE_IOCTL _IOW(MY_MACIG, 1, int) static int major; static char msg[200]; static ssize_t device_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset) { printk("I am in

(十)Linux 网络编程之ioctl函数

旧街凉风 提交于 2019-12-25 03:12:26
1.介绍 Linux网络程序与内核交互的方法是通过ioctl来实现的,ioctl与网络协议栈进行交互,可得到网络接口的信息,网卡设备的映射属性和配置网络接口.并且还能够查看,修改,删除ARP高速缓存的信息,所以,我们有必要了解一下ioctl函数的具体实现. 2.相关结构体与相关函数 #include int ioctl(int d,int request,....); 参数: d-文件描述符,这里是对网络套接字操作,显然是套接字描述符 request-请求码 省略的部分对应不同的内存缓冲区,而具体的内存缓冲区是由请求码request来决定的,下面看一下具体都有哪些相关缓冲区。 (1)网络接口请求结构ifreq struct ifreq{ #define IFHWADDRLEN 6 //6个字节的硬件地址,即MAC union{ char ifrn_name[IFNAMESIZ];//网络接口名称 }ifr_ifrn; union{ struct sockaddr ifru_addr;//本地IP地址 struct sockaddr ifru_dstaddr;//目标IP地址 struct sockaddr ifru_broadaddr;//广播IP地址 struct sockaddr ifru_netmask;//本地子网掩码地址 struct sockaddr ifru

How do I get width and height of my terminal with ioctl?

大兔子大兔子 提交于 2019-12-24 00:55:53
问题 What do I have to change to make this work? #!/usr/bin/perl use 5.012; use warnings; require "/usr/lib/perl5/vendor_perl/5.12.1/x86_64-linux-thread-multi/sys/ioctl.ph"; my ($rows, $cols, $xpix, $ypix); my $winsize = "\0" x 8; my $TIOCGWINSZ = 0x40087468; # should be require sys/ioctl.pl if (ioctl(STDOUT, $TIOCGWINSZ, $winsize)) { ($rows, $cols, $xpix, $ypix) = unpack('S4', $winsize); } else { say "something didn't work" and exit; } Inspired by tchrist's answer in From column to row. 回答1: This

What's different between compiling in 32bit mode and 64bit mode on 64bit os about execution of ioctl function?

自作多情 提交于 2019-12-23 20:26:08
问题 I have a 64 bit Enterprice SuSE 11 I have an application which open a HIDRAW device and operate an ioctl function on it to get raw info from this device like below: struct hidraw_devinfo devinfo; int fd = open("/dev/hidraw0", 0); int ret = ioctl(fd, HIDIOCGRAWINFO, &devinfo); ... If I compile this program in 64 bit mode there is no error and no problem and when I execute the application the ioctl function works properly. g++ main.cpp If I complie this program in 32 bit mode there is also no