#endif
struct device_info *dev = c.devices + i;
+ stat_buf = malloc(sizeof(struct stat));
+ ASSERT(stat_buf);
+ if (stat(dev->path, stat_buf) < 0 ) {
+ MSG(0, "\tError: Failed to get the device stat!\n");
+ free(stat_buf);
+ return -1;
+ }
+
if (c.sparse_mode) {
- fd = open((char *)dev->path, O_RDWR | O_CREAT | O_BINARY, 0644);
+ fd = open(dev->path, O_RDWR | O_CREAT | O_BINARY, 0644);
} else {
- fd = open((char *)dev->path, O_RDWR);
+ if (S_ISBLK(stat_buf->st_mode))
+ fd = open(dev->path, O_RDWR | O_EXCL);
+ else
+ fd = open(dev->path, O_RDWR);
}
if (fd < 0) {
MSG(0, "\tError: Failed to open the device!\n");
+ free(stat_buf);
return -1;
}
dev->fd = fd;
if (c.sparse_mode) {
- if (f2fs_init_sparse_file())
+ if (f2fs_init_sparse_file()) {
+ free(stat_buf);
return -1;
+ }
}
if (c.kd == -1) {
}
}
- stat_buf = malloc(sizeof(struct stat));
- if (fstat(fd, stat_buf) < 0 ) {
- MSG(0, "\tError: Failed to get the device stat!\n");
- free(stat_buf);
- return -1;
- }
-
if (c.sparse_mode) {
dev->total_sectors = c.device_size / dev->sector_size;
} else if (S_ISREG(stat_buf->st_mode)) {