Re: [PATCH 1/2] btrfs-progs: multidevice support for check_mounted

Karel Zak
2009-11-23T09:01:43Z

On Sun, Nov 22, 2009 at 02:33:13PM +0100, Andi Drebes wrote:
> In the new patch below, is_pseudo_fs() is replaced by
> is_existing_blk_or_reg_file(). We ignore entries associated with an
> invalid path or paths that don't point to a regular or block file.
> However, if a path used in a pseudo-filesystem entry points to the
> file that is being checked, check_mounted() returns 1. In my eyes,
> this is extremely unlikely.
...
> +/* Checks if a file exists and is a block or regular file*/
> +int is_existing_blk_or_reg_file(const char* filename)
> +{
> + struct stat st_buf;
> +
> + if(stat(filename, &st_buf) < 0) {
> + if(errno == ENOENT)
> + return 0;
> + else
> + return -errno;
> + }
> +
> + return (S_ISBLK(st_buf.st_mode) || S_ISREG(st_buf.st_mode));
> +}

Yes, this looks better.

Karel

--
Karel Zak <kzak@redhat.com>