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

Re: Can't scan new disk



Hi,

Mark Allums wrote:
> The disk is not mounted.

At least not from the perception of e2fsck, indeed, or else it would say
  "%s is mounted.\n"
instead of
  "%s is in use.\n"
See
  https://sources.debian.org/src/e2fsprogs/1.44.5-1/e2fsck/unix.c/?hl=269#L269
(found by
  https://codesearch.debian.net/search?q=package%3Ae2fsprogs+is+in+use
)

If i understand the code correctly, the program gets to that spot because
condition

  if ((!(ctx->mount_flags & (EXT2_MF_MOUNTED | EXT2_MF_BUSY))) ||

is not true. It says "is in use", because

  if (ctx->mount_flags & EXT2_MF_MOUNTED)

is not true. I.e. (ctx->mount_flags & EXT2_MF_BUSY) is true.

I bet that it is about open(2)/fcntl(2) flag O_EXCL, because of
  https://codesearch.debian.net/search?q=package%3Ae2fsprogs+EXT2_MF_BUSY
  https://sources.debian.org/src/e2fsprogs/1.44.5-1/lib/ext2fs/ismounted.c/?hl=415#L410
where i see 

            int fd = open(device, O_RDONLY | O_EXCL);

            if (fd >= 0)
                    close(fd);
            else if (errno == EBUSY)
                    *mount_flags |= EXT2_MF_BUSY;

O_EXCL has a special meaning with Linux device files. It works as advisory
locking with this file type only. In the context of mounting, a failure
with O_EXCL and success without that flag instructs the mounter to mount
read-only. In the context of CD burning, it tells an interested drive
groping program (except mount(8)) to leave the drive alone. Even cdrecord
joined that party.


So one should hop back to the sub-thread where open file pointers to
/dev/sdb1 were the main suspects.

fcntl(2) would be able to inquire the O_EXCL flag by command F_GETFL,
but it needs the file descriptor which is an integer number in the context
of the using process. Dunno whether it is possible to inquire this from
another process.


Have a nice day :)

Thomas


Reply to: