Re: Automated fsck on boot

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

 



Max Vozeler wrote:
> Does the attached version do the right thing in this regard? It
> works for me and takes the normal code path if lo_file_name doesn't
> match the loopfile that was given in *spec.

Your version compared device (or file) names. Comparing names is problematic
because they may be truncated or they may use relative paths (not begin with
slash). I changed it to compare device number and inode number of the block
special file (or normal file) to those recorded in loop device.

# losetup /dev/loop6
/dev/loop6: [0902]:213045 (/dev/md5) offset=4096 encryption=AES128 multi-key-v3
             ^^^^  ^^^^^^
              |      |
              |    Inode number inside my root file system where static
              |    block special node /dev/md5 happens to reside.
              |
             Device number of my root file system where static
             block special node /dev/md5 happens to reside.


I merged your patch, but now the code looks like this:

int is_loop_active(const char *dev, const char *backdev)
{
	int fd;
	int ret = 0;
	struct stat statbuf;
	struct loop_info64 loopinfo;
	if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
		fd = open (dev, O_RDONLY);
		if (fd < 0)
			return 0;
		if ((loop_get_status64_ioctl(fd, &loopinfo) == 0)
		    && (stat (backdev, &statbuf) == 0)
		    && (statbuf.st_dev == loopinfo.lo_device)
		    && (statbuf.st_ino == loopinfo.lo_inode))
			ret = 1; /* backing device matches */
		memset(&loopinfo, 0, sizeof(loopinfo));
		close(fd);
	}
	return ret;
}

-- 
Jari Ruusu  1024R/3A220F51 5B 4B F9 BB D3 3F 52 E9  DB 1D EB E3 24 0E A9 DD

-
Linux-crypto:  cryptography in and on the Linux system
Archive:       http://mail.nl.linux.org/linux-crypto/


[Index of Archives]     [Kernel]     [Linux Crypto]     [Gnu Crypto]     [Gnu Classpath]     [Netfilter]     [Bugtraq]
  Powered by Linux