bwrite, not sbwrite, needs to open for writing and write.
This commit is contained in:
parent
4abe79362a
commit
3ff1f264e9
@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <ufs/ffs/fs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -74,14 +75,26 @@ ssize_t
|
||||
bwrite(struct uufsd *disk, ufs2_daddr_t blockno, const void *data, size_t size)
|
||||
{
|
||||
ssize_t cnt;
|
||||
int rofd;
|
||||
|
||||
ERROR(disk, NULL);
|
||||
|
||||
rofd = disk->d_fd;
|
||||
|
||||
disk->d_fd = open(disk->d_name, O_WRONLY);
|
||||
if (disk->d_fd < 0) {
|
||||
ERROR(disk, "failed to open disk for writing");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cnt = pwrite(disk->d_fd, data, size, (off_t)(blockno * disk->d_bsize));
|
||||
if (cnt != size) {
|
||||
ERROR(disk, "short write to block device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(disk->d_fd);
|
||||
disk->d_fd = rofd;
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <ufs/ffs/fs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -94,18 +93,12 @@ int
|
||||
sbwrite(struct uufsd *disk, int all)
|
||||
{
|
||||
struct fs *fs;
|
||||
int i, rofd;
|
||||
int i;
|
||||
|
||||
ERROR(disk, NULL);
|
||||
|
||||
fs = &disk->d_fs;
|
||||
|
||||
rofd = disk->d_fd;
|
||||
disk->d_fd = open(disk->d_name, O_WRONLY);
|
||||
if (disk->d_fd < 0) {
|
||||
ERROR(disk, "failed to open disk");
|
||||
return -1;
|
||||
}
|
||||
if (bwrite(disk, disk->d_sblock, fs, SBLOCKSIZE) == -1) {
|
||||
ERROR(disk, "failed to write superblock");
|
||||
return -1;
|
||||
@ -118,7 +111,5 @@ sbwrite(struct uufsd *disk, int all)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
close(disk->d_fd);
|
||||
disk->d_fd = rofd;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user