Why does lseek() return ESPIPE, when driver doesn't provide implementation?
1
vote
1
answer
251
views
Linux Device Drivers, 3rd Edition states:
> if the llseek method is missing from the device's operations, the
> default implementation in the kernel performs seeks by modifying
> filp->f_pos
Yet I have a character device for which driver doesn't implement lseek. Here are file op definitions for this device type:
https://github.com/Xilinx/dma_ip_drivers/blob/master/XDMA/linux-kernel/xdma/cdev_ctrl.c
But attempting lseek on this device returns ESPIPE:
-c
#include
#include
#include
#include
#include
#include
int main(int argc, char** argv) {
uint32_t val=0x12345678;
int fid=open("/dev/xdma0_user", O_RDWR);
off_t lseek_ret=lseek(fid, 0x8ul, SEEK_SET);
if (lseek_ret <0)
fprintf(stderr, "Seek result: %d, errno: %s (%d)\n", lseek_ret, strerror(errno), errno );
unsigned int c=write(fid, &val, sizeof(val));
printf("written %u bytes\n", c);
close(fid);
return (0);
}
Output:
Seek result: -1, errno: Illegal seek (29)
written 4 bytes
I can't understand how this comes about. It can't stem from the driver: ESPIPE isn't even mentioned anywhere in it, so it must come from the kernel, which contradicts the quote above.
Has the default behaviour been altered? Can it be somehow configured? How can be seen what kernel actually does (ideally source code)?
Kernel version is 5.10 (Debian 11).
Asked by Andrey Pro
(179 rep)
Sep 19, 2024, 11:00 PM
Last activity: Sep 20, 2024, 09:52 AM
Last activity: Sep 20, 2024, 09:52 AM