On Sat, Oct 31, 2015 at 07:21:19PM +0000, Sami Kerola wrote: > +int open_blkdev_or_file(const char *name, const int oflag) > +{ > + int fd; > + struct stat ftype; > + > + if (stat(name, &ftype) < 0) > + return -1; > + if (S_ISBLK(ftype.st_mode)) { > + fd = open(name, oflag | O_EXCL); > + } else > + fd = open(name, oflag); > + if (-1 < fd && !is_same_inode(fd, name)) { > + close(fd); > + errno = EBADFD; > + return -1; > + } > + if (-1 < fd && S_ISBLK(ftype.st_mode) && blkdev_is_misaligned(fd)) > + warnx(_("warning: %s is misaligned"), name); > + return fd; > +} Hmmm... this abstraction introduces extra stat() calls. Would be enough to use is_same_inode() directly in the code to reuse struct stat? Karel -- Karel Zak <kzak@xxxxxxxxxx> http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html