bwrite, not sbwrite, needs to open for writing and write.

This commit is contained in:
Juli Mallett 2003-01-23 23:58:22 +00:00
parent 4abe79362a
commit 3ff1f264e9
2 changed files with 14 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}