}
}
-void xpwrite(int fd, const void *buf, size_t count, off_t offset)
+void xpwrite(int fd, const void *buf, size_t count, off_t offset, const char *msg)
{
ssize_t r = pwrite(fd, buf, count, offset);
if (r != count)
- die("write error (ret %zi err %m)", r);
+ die("error writing %s (ret %zi err %m)", msg, r);
}
struct stat xfstatat(int dirfd, const char *path, int flags)
{
char *buf = read_file_str(dirfd, path);
u64 v;
- if (kstrtou64(buf, 10, &v))
+ if (bch2_strtou64_h(buf, &v))
die("read_file_u64: error parsing %s (got %s)", path, buf);
free(buf);
return v;
return ret;
}
-/* Returns blocksize in units of 512 byte sectors: */
+/* Returns blocksize, in bytes: */
unsigned get_blocksize(const char *path, int fd)
{
struct stat statbuf = xfstat(fd);
if (!S_ISBLK(statbuf.st_mode))
- return statbuf.st_blksize >> 9;
+ return statbuf.st_blksize;
unsigned ret;
xioctl(fd, BLKPBSZGET, &ret);
- return ret >> 9;
+ return ret;
}
/* Open a block device, do magic blkid stuff to probe for existing filesystems: */
const char *fs_type = NULL, *fs_label = NULL;
size_t fs_type_len, fs_label_len;
- int fd = xopen(dev, O_RDWR|O_EXCL);
+ int fd = open(dev, O_RDWR|O_EXCL);
+ if (fd < 0)
+ die("Error opening device to format %s: %m", dev);
if (force)
return fd;
return *a_prefix ? NULL : a;
}
-unsigned hatoi_validate(const char *s, const char *msg)
-{
- u64 v;
-
- if (bch2_strtoull_h(s, &v))
- die("bad %s %s", msg, s);
-
- v /= 512;
-
- if (v > USHRT_MAX)
- die("%s too large\n", msg);
-
- if (!v)
- die("%s too small\n", msg);
-
- return v;
-}
-
/* crc32c */
static u32 crc32c_default(u32 crc, const void *buf, size_t size)