ioctl

SPI_IOC_MESSAGE(N) macro giving me fits

余生长醉 提交于 2019-12-05 18:43:25
I'm having trouble getting a SPI program I'm working on to behave correctly and it seems to be some issue with the SPI_IOC_MESSAGE(N) macro. Here's sample code that DOESN'T work (ioctl returns EINVAL (22) ): std::vector<spi_ioc_transfer> tr; <code that fills tr with 1+ transfers> // Hand the transmission(s) off to the SPI driver if (tr.size() > 0) { int ret = ioctl(fd, SPI_IOC_MESSAGE(tr.size()), tr.data()); if (ret < 1) { int err = errno; } } My test code right now is creating a vector of length 1. If I explicitly change the code to: int ret = ioctl(fd, SPI_IOC_MESSAGE( 1 ), tr.data()); ..

ioctl操作

拥有回忆 提交于 2019-12-05 17:52:00
  在本书中有两个地方都对这个函数进行了介绍,其实还有很多地方需要这个函数。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

How to set the terminal's size?

99封情书 提交于 2019-12-05 13:43:19
How do I get the terminal size in Go. In C it would look like this: struct ttysize ts; ioctl(0, TIOCGWINSZ, &ts); But how to i access TIOCGWINSZ in Go The cgo compiler can't handle variable arguments in a c function and macros in c header files at present, so you can't do a simple // #include <sys/ioctl.h> // typedef struct ttysize ttysize; import "C" func GetWinSz() { var ts C.ttysize; C.ioctl(0,C.TIOCGWINSZ,&ts) } To get around the macros use a constant, so // #include <sys/ioctl.h> // typedef struct ttysize ttysize; import "C" const TIOCGWINSZ C.ulong = 0x5413; // Value from Jed Smith's

How does iwlist() command scans the wireless networks?

大城市里の小女人 提交于 2019-12-05 08:11:36
I want to know how iwlist command scans the wireless networks available, in linux. I read its source code and there was an ioctl call using SIOCSIWSCAN to trigger the scan and SIOCGIWSCAN to get the scan results. But how the beacon frames are captured and analyzed by these system calls? iwlist(8) and the other wireless tools provide a common front end to different wireless device drivers that support Linux Wireless Extensions (WEXT). Each driver will register handlers with WEXT that implement the device specific operations defined by this interface. For scanning, the two handlers are trigger

Can someone help me replace “lock_kernel” on a block device driver?

那年仲夏 提交于 2019-12-05 07:26:50
Thank you for looking at this post. I am trying to patch up a network block device driver. If you need to see the sources they are at http : / / code.ximeta.com. I noticed that lock_kernel() seems deprecated as of linux 2.6.37. I read "The new way of ioctl()" and found that device drivers now should perform a specific lock before operating. So I would like some advice replacing this if possible. I have found two sections in the current code that I think are related, in the block folder section. Source block->io.c ->ctrldev.c I put snippets from each for your consideration. io.c contains one

Check for extra characters in Linux terminal buffer

♀尐吖头ヾ 提交于 2019-12-05 07:22:46
问题 I try to implement getch() function in Python, which should also return list of chars for special keys like F1-F12 and arrow keys. These special keys generate several chars in a sequence. Therefore getch() reads one char in blocking mode and then should check if there are extra chars in input buffer to fetch them too. I am using ioctl call together with termios.FIONREAD to get the number of bytes in the input buffer. It catches non-special key presses stacked in buffer, but misses extra

Where are ioctl parameters (such as 0x1268 / BLKSSZGET) actually specified?

点点圈 提交于 2019-12-05 05:35:16
This question was migrated from Unix & Linux Stack Exchange because it can be answered on Stack Overflow. Migrated 6 years ago . I am looking for a definitive specification describing the expected arguments and behavior of ioctl 0x1268 (BLKSSZGET). This number is declared in many places (none of which contain a definitive reference source), such as linux/fs.h , but I can find no specification for it. Surely, somebody at some point in the past decided that 0x1268 would get the physical sector size of a device and documented that somewhere. Where does this information come from and where can I

How to set errno in Linux device driver?

一世执手 提交于 2019-12-05 01:37:02
I am designing a Linux character device driver. I want to set errno when error occurs in ioctl() system call. long my_own_ioctl(struct file *file, unsigned int req, unsigned long arg) { long ret = 0; BOOL isErr = FALSE; // some operation // ... if (isErr) { // set errno // ... <--- What should I do? ret = -1; } return ret; } What should I do to achieve that? Thank you at advance! Please allow me to explain my application with more detail. My device is located in /dev/myCharDev. My user space application is like this: #define _COMMAND (1) #define _ERROR_COMMAND_PARAMETER (-1) int main() { int

Linux Framebuffer适配层释疑

北慕城南 提交于 2019-12-04 14:41:52
Linux Framebuffer对应的源文件在linux/drivers/video/目录下。在这个目录下还有与各种显卡驱动相关的源文件。 Linux FrameBuffer适配层有以下两个文件非常重要的文件。 1. linux/include/linux/fb.h ,包含了几个非常重要的数据结构 fb_var_screeninfo 描述了对应的framebuffer当前的配置状况,应用程序可以通过ioctl直接对fb_var_screeninfo中的某些参数进行调整,例如xres、yres、height、width等等。 fb_fix_screeninfo 描述了对应的framebuffer当前的特性,这些特性不能通过ioctl直接修改,只能通过修改fb_var_screeninfo中的某些参数间接调整fb_fix_screeninfo中描述的特性,其中经常关注的特性包括:smem_start、smem_len、line_length,从事QT开发的工程师尤其要注意line_length的值,否则UI界面会出现"诡异"的花屏。 fb_cmap 描述设备无关的颜色映射信息,和调色板的配置相关,若使用DirectFB图形引擎,尤其要考究这个结构的使用,可以通过FBIOGETCMAP 和 FBIOPUTCMAP 对应的ioctl操作设定或获取颜色映射信息。 fb_info

How to check if interface is up

泄露秘密 提交于 2019-12-04 11:42:46
问题 Title pretty much says it all. If I run ifconfig , I get this: eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet -snip- netmask 255.255.255.0 broadcast -snip- ... Using this, I can know if it's up or not ( <UP,... ), but I want to be able to do this in C (or C++, if there is a simpler solution there) without relying on parsing external processes. Here is what I've got so far (doesn't work): bool is_interface_online(std::string interface) { struct ifreq ifr; int sock = socket(PF