.sector = offset >> 9,
.nr_sectors = length >> 9,
};
+ int fd, ret = 0;
+
+ /* If the file is not yet opened, open it for this function. */
+ fd = f->fd;
+ if (fd < 0) {
+ fd = open(f->file_name, O_RDWR | O_LARGEFILE);
+ if (fd < 0)
+ return -errno;
+ }
- if (ioctl(f->fd, BLKRESETZONE, &zr) < 0)
- return -errno;
+ if (ioctl(fd, BLKRESETZONE, &zr) < 0)
+ ret = -errno;
- return 0;
+ if (f->fd < 0)
+ close(fd);
+
+ return ret;
}