ioctl

DeviceIoControl for SCSI INQUIRY command returns error 50

徘徊边缘 提交于 2019-12-11 18:25:54
问题 I am trying to access a USB scanner through the IOCTL commands. This is on Windows 7. I did not deal with IOCTL coding before, so I first tried the following snippet based on what I could find with a quick search. #include "stdafx.h" #include <stddef.h> #include <Windows.h> #include <ntddscsi.h> #include <usbscan.h> typedef struct { SCSI_PASS_THROUGH spt; BYTE sense[18]; BYTE data[36]; } SPTSD; LPTSTR ErrorMessage(DWORD error) { LPTSTR errorText = NULL; FormatMessage( FORMAT_MESSAGE_FROM

IOCTL Driver SystemBuffer always NULL

≯℡__Kan透↙ 提交于 2019-12-11 15:59:30
问题 I have a simple struct which I would like to pass to my driver. Here is the struct: typedef struct readStruct { ... } ReadStruct, *pRreadStruct; Here is my usermode application: DWORD dwReturn; readStruct reader{ ... }; WriteFile(hDriver, (LPCVOID)&reader, sizeof(ReadStruct), &dwReturn, NULL); Here is my driver code, it always returns NULL to the readStruct. What am I doing wrong? PIO_STACK_LOCATION pIoStackIrp = NULL; pRreadStruct readStruct; pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);

Linux: ioctl/FIONREAD returning 0 bytes available at /dev/random?

谁说我不能喝 提交于 2019-12-11 09:03:51
问题 After opening the file descriptor fd and other sanity checks for /dev/random, I am attempting to read how many bytes are readable from the device so I can pull this amount if it is required by my program. My basic code is this: if (fd = open("/dev/random", O_RDONLY) < 0) { perror("open"); return 1; } ... if(ioctl(fd, FIONREAD, &n) < 0) { //file descriptor, call, unsigned int perror("ioctl"); return 1; } printf("%d bytes available for reading.\n", n); return 0; No matter what the scenario (as

Linux equivalent of I_PUSH

为君一笑 提交于 2019-12-11 08:18:28
问题 This question is related to pty terminal packet mode TIOCPKT What the linux way of enabling packet mode ? I could not find I_PUSH working when passed in ioctl function. 回答1: TIOCPKT is exactly what you want, according to the tty_ioctl(4) man page: the argument is a pointer to an integer which is non-zero to enable packet mode, or zero to disable it. 来源: https://stackoverflow.com/questions/7614618/linux-equivalent-of-i-push

FBIOPUT_VSCREENINFO and modelines

谁说胖子不能爱 提交于 2019-12-11 04:45:53
问题 I am trying to change the screen configuration with FBIOPUT_VSCREENINFO, but I do not have a clue how to compute: __u32 pixclock; /* pixel clock in ps (pico seconds) */ __u32 left_margin; /* time from sync to picture */ __u32 right_margin; /* time from picture to sync */ __u32 upper_margin; /* time from sync to picture */ __u32 lower_margin; __u32 hsync_len; /* length of horizontal sync */ __u32 vsync_len; (see: http://lxr.free-electrons.com/source/include/linux/fb.h#L245 ) for the fb_var

Passing struct to device driver through IOCTL

假装没事ソ 提交于 2019-12-10 22:18:08
问题 I am trying to pass a struct from user space to kernel space. I had been trying for many hours and it isn't working. Here is what I have done so far.. int device_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg){ int ret, SIZE; switch(cmd){ case PASS_STRUCT_ARRAY_SIZE: SIZE = (int *)arg; if(ret < 0){ printk("Error in PASS_STRUCT_ARRAY_SIZE\n"); return -1; } printk("Struct Array Size : %d\n",SIZE); break; case PASS_STRUCT: struct mesg{ int pIDs[SIZE]; int

IOCTL call and checking return value

孤人 提交于 2019-12-10 19:43:15
问题 if((err = ioctl(fd, IOC_CARD_LOCK, &lock)) < 0) { printf("ioctl failed and returned errno %d \n",err); } Is the above code correct and a good programming practice? It does compile on my PC. i.e does it populate err with the return value of ioctl and check if err is < 0 Is the above method a standard way to return "err" returned by IOCTL. There seem to be some standard variable called errno? what is it? Will that be the same as above? 回答1: I found out a better way to do this. if(ioctl(fd, IOC

SIOCETHTOOL vs SIOCGMIIPHY vs SIOCGIFFLAGS

a 夏天 提交于 2019-12-10 18:57:20
问题 After some search on the Internet,I came to know that, following are the list of options available to get/set parameters to the ethernet interface. SIOCETHTOOL SIOCGMIIPHY SIOCGIFFLAGS I even saw some 'stackoverflow' questions regarding the usage of SIOCETHTOOL. But the questions I have are: Comparison of these three interfaces (means API's) in terms of the features they offer and support in multiple kernels. When should one of these options should be preferred over the others. I hardly find

How can I determine the amount of write/output buffer space left on a linux serial port?

我是研究僧i 提交于 2019-12-10 17:15:40
问题 You can determine how much data is available to read from a serial port under linux using an ioctl. Is it possible to determine how much buffer space remains for the serial port when writing to it? Effectively I want to write a block of data to a serial port, succeeding only if it can all be offloaded in one go, or failing if it would have to be chunked. The writes and reads to the ports are non-blocking. I'm not expecting this to be the UARTs buffer, but the kernels memory buffer ahead of

porting ioctl() calls from unix to linux, error with FIONBIO

白昼怎懂夜的黑 提交于 2019-12-10 15:28:46
问题 i want to use ioctl() to get the number of bytes ready to be read the way I did it is: mysocket=socket(....); ioctl(mysocket, FIONBIO, &zero); connect(.....); ioctl( mysocket, FIONREAD, &numBytes ); read(mysocket, buffer, numBytes); this was working fine in unix, now i have to port it to linux i keep getting ERROR error: 'FIONBIO' was not declared in this scope Is there some header file specific for linux? or 'FIOBIO' doesnt work at all in linux? I have following headers included: #include