# # # patch "lib/device/dev-io.c" # from [6fe1a5df58858e89f37691a84082aef19dd4c081] # to [e8234288b52608df48a1370e0ea49a9b834e4000] # ============================================================ --- lib/device/dev-io.c 6fe1a5df58858e89f37691a84082aef19dd4c081 +++ lib/device/dev-io.c e8234288b52608df48a1370e0ea49a9b834e4000 @@ -36,6 +36,10 @@ # ifndef BLKGETSIZE64 /* fs.h out-of-date */ # define BLKGETSIZE64 _IOR(0x12, 114, size_t) # endif /* BLKGETSIZE64 */ +#elif __NetBSD__ +# include +# include +# include #else # include # define BLKBSZGET DKIOCGETBLOCKSIZE @@ -51,7 +55,11 @@ # endif #endif +#ifdef __NetBSD__ +static struct list _open_devices = { &(_open_devices), &(_open_devices) }; /* inline expand the LIST_INIT macro, as it clashes with the one in */ +#else static LIST_INIT(_open_devices); +#endif /*----------------------------------------------------------------- * The standard io loop that keeps submitting an io until it's @@ -125,12 +133,22 @@ static int _get_block_size(struct device static int _get_block_size(struct device *dev, unsigned int *size) { const char *name = dev_name(dev); +#ifdef __NetBSD__ + struct disklabel lab; +#endif if ((dev->block_size == -1)) { +#ifdef __NetBSD__ + if (ioctl(dev_fd(dev), DIOCGDINFO, &lab) < 0) { + dev->block_size = DEV_BSIZE; + } else + dev->block_size = lab.d_secsize; +#else if (ioctl(dev_fd(dev), BLKBSZGET, &dev->block_size) < 0) { log_sys_error("ioctl BLKBSZGET", name); return 0; } +#endif log_debug("%s: block size is %u bytes", name, dev->block_size); } @@ -240,12 +258,35 @@ static int _dev_get_size_dev(const struc { int fd; const char *name = dev_name(dev); +#ifdef __NetBSD__ + struct disklabel lab; + struct dkwedge_info dkw; +#endif if ((fd = open(name, O_RDONLY)) < 0) { log_sys_error("open", name); return 0; + } + +#ifdef __NetBSD__ + if ((*size = lseek (fd, 0, SEEK_END)) < 0) { + log_sys_error("lseek SEEK_END", name); + close(fd); + return 0; } + if (ioctl(fd, DIOCGDINFO, &lab) < 0) { + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) < 0) { + log_sys_error("ioctl DIOCGWEDGEINFO", name); + close(fd); + return 0; + } else + if (dkw.dkw_size) + *size = dkw.dkw_size; + } else + if (lab.d_secsize) + *size /= lab.d_secsize; +#else if (ioctl(fd, BLKGETSIZE64, size) < 0) { log_sys_error("ioctl BLKGETSIZE64", name); if (close(fd)) @@ -254,6 +295,7 @@ static int _dev_get_size_dev(const struc } *size >>= BLKSIZE_SHIFT; /* Convert to sectors */ +#endif if (close(fd)) log_sys_error("close", name); @@ -306,8 +348,10 @@ void dev_flush(struct device *dev) void dev_flush(struct device *dev) { +#ifdef __linux__ if (!(dev->flags & DEV_REGULAR) && ioctl(dev->fd, BLKFLSBUF, 0) >= 0) return; +#endif if (fsync(dev->fd) >= 0) return;