mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o dev_write
This commit is contained in:
parent
90ae9fe928
commit
0db56c6b55
@ -38,6 +38,10 @@ int dev_get_size(struct device *dev, uint64_t *size)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* FIXME: factor common code out.
|
||||||
|
*/
|
||||||
|
|
||||||
int _read(int fd, void *buf, size_t count)
|
int _read(int fd, void *buf, size_t count)
|
||||||
{
|
{
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
@ -77,9 +81,41 @@ int64_t dev_read(struct device *dev, uint64_t offset,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _write(int fd, const void *buf, size_t count)
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
int tot = 0;
|
||||||
|
|
||||||
|
while (tot < count) {
|
||||||
|
n = write(fd, buf, count - tot);
|
||||||
|
|
||||||
|
if (n <= 0)
|
||||||
|
return tot ? tot : n;
|
||||||
|
|
||||||
|
tot += n;
|
||||||
|
buf += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tot;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t dev_write(struct device *dev, uint64_t offset,
|
int64_t dev_write(struct device *dev, uint64_t offset,
|
||||||
int64_t len, void *buffer)
|
int64_t len, void *buffer)
|
||||||
{
|
{
|
||||||
// FIXME: lazy programmer
|
int64_t r;
|
||||||
|
int fd = open(dev->name, O_WRONLY);
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
log_sys_err("open");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||||
|
log_sys_err("lseek");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = _write(fd, buffer, len);
|
||||||
|
close(fd);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
|||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(_munge_formats(&data->pv))) {
|
if (!_munge_formats(&data->pv)) {
|
||||||
log_verbose("Unknown metadata version %d found on %s",
|
log_verbose("Unknown metadata version %d found on %s",
|
||||||
data->pv.version, dev->name);
|
data->pv.version, dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
|
Loading…
Reference in New Issue
Block a user