1
0
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:
Joe Thornber 2001-10-10 13:03:10 +00:00
parent 90ae9fe928
commit 0db56c6b55
2 changed files with 41 additions and 5 deletions

View File

@ -38,6 +38,10 @@ int dev_get_size(struct device *dev, uint64_t *size)
return 1;
}
/*
* FIXME: factor common code out.
*/
int _read(int fd, void *buf, size_t count)
{
size_t n = 0;
@ -77,9 +81,41 @@ int64_t dev_read(struct device *dev, uint64_t offset,
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 len, void *buffer)
{
// FIXME: lazy programmer
return 0;
int64_t r;
int fd = open(dev->name, O_WRONLY);
if (fd < 0) {
log_sys_err("open");
return 0;
}
if (lseek(fd, offset, SEEK_SET) < 0) {
log_sys_err("lseek");
return 0;
}
r = _write(fd, buffer, len);
close(fd);
return r;
}

View File

@ -239,9 +239,9 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
goto bad;
}
if (!(_munge_formats(&data->pv))) {
if (!_munge_formats(&data->pv)) {
log_verbose("Unknown metadata version %d found on %s",
data->pv.version, dev->name);
data->pv.version, dev->name);
goto bad;
}
@ -250,7 +250,7 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
*/
if (data->pv.vg_name == '\0') {
log_very_verbose("%s is not a member of any VG",
dev->name);
dev->name);
return data;
}