[Bug 200043] New: lseek returns negative and inconsistent positions for directories on ext4 fs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://bugzilla.kernel.org/show_bug.cgi?id=200043

            Bug ID: 200043
           Summary: lseek returns negative and inconsistent positions for
                    directories on ext4 fs
           Product: File System
           Version: 2.5
    Kernel Version: v4.17
          Hardware: All
                OS: Linux
              Tree: Mainline
            Status: NEW
          Severity: normal
          Priority: P1
         Component: ext4
          Assignee: fs_ext4@xxxxxxxxxxxxxxxxxxxx
          Reporter: anatoly.trosinenko@xxxxxxxxx
        Regression: No

When used on a directory FD residing on Ext4 FS, lseek with SEEK_END (and maybe
other whence-s) can return negative numbers and leave errno = 0. These numbers
in case of SEEK_END are (-1 - offset) and do not accumulate.

Reading the lseek(2) man page, I'm not absolutely sure it is a bug, but this
seems to be quite strange behavior.

How to reproduce:
1. Compile the following code:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>

int main(int argc, char *argv[]) {
  int fd = open(argv[1], O_RDONLY);
  printf("fd = %d\n", fd);
  int res = lseek(fd, -10, SEEK_END);
  printf("lseek returned: %d (errno = %d)\n", res, errno);
  res = lseek(fd, -1, SEEK_END);
  printf("lseek returned: %d (errno = %d)\n", res, errno);
  res = lseek(fd, 0, SEEK_END);
  printf("lseek returned: %d (errno = %d)\n", res, errno);
  res = lseek(fd, -11, SEEK_SET);
  printf("lseek returned: %d (errno = %d)\n", res, errno);
  return 0;
}

2. Run it:

# ./lseek_negative /tmp # Suppose the tmpfs is mounted there
fd = 3
lseek returned -1 (errno = 22)
lseek returned -1 (errno = 22)
lseek returned -1 (errno = 22)
lseek returned -1 (errno = 22)
# ./lseek_negative / # Suppose the / is ext4
fd = 3
lseek returned -11 (errno = 0)
lseek returned -2 (errno = 0)
lseek returned -1 (errno = 0)    <-- Look at the errno value
lseek returned -1 (errno = 22)

-- 
You are receiving this mail because:
You are watching the assignee of the bug.



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux