Page MenuHomeFreeBSD

D24508.id70794.diff
No OneTemporary

D24508.id70794.diff

Index: sbin/newfs_msdos/mkfs_msdos.c
===================================================================
--- sbin/newfs_msdos/mkfs_msdos.c
+++ sbin/newfs_msdos/mkfs_msdos.c
@@ -243,8 +243,9 @@
struct bsx *bsx;
struct de *de;
u_int8_t *img;
+ u_int8_t *physbuf, *physbuf_end;
const char *bname;
- ssize_t n;
+ ssize_t n, tailsize;
time_t now;
u_int fat, bss, rds, cls, dir, lsn, x, x1, x2;
u_int extra_res, alignment, saved_x, attempts=0;
@@ -252,7 +253,7 @@
int fd, fd1, rv;
struct msdos_options o = *op;
- img = NULL;
+ physbuf = NULL;
rv = -1;
fd = fd1 = -1;
@@ -622,10 +623,14 @@
}
- if (!(img = malloc(bpb.bpbBytesPerSec))) {
+ physbuf = malloc(MAXPHYS);
+ if (physbuf == NULL) {
warn(NULL);
goto done;
}
+ physbuf_end = physbuf + MAXPHYS;
+ img = physbuf;
+
dir = bpb.bpbResSectors + (bpb.bpbFATsecs ? bpb.bpbFATsecs :
bpb.bpbBigFATsecs) * bpb.bpbFATs;
memset(&si_sa, 0, sizeof(si_sa));
@@ -750,19 +755,28 @@
(u_int)tm->tm_mday;
mk2(de->deMDate, x);
}
- if ((n = write(fd, img, bpb.bpbBytesPerSec)) == -1) {
- warn("%s", fname);
- goto done;
- }
- if ((unsigned)n != bpb.bpbBytesPerSec) {
- warnx("%s: can't write sector %u", fname, lsn);
- goto done;
+ img += bpb.bpbBytesPerSec;
+ if (img >= physbuf_end) {
+ n = write(fd, physbuf, MAXPHYS);
+ if (n != MAXPHYS) {
+ warnx("%s: can't write sector %u", fname, lsn);
+ goto done;
+ }
+ img = physbuf;
}
}
+ if (img != physbuf) {
+ tailsize = img - physbuf;
+ n = write(fd, physbuf, tailsize);
+ if (n != tailsize) {
+ warnx("%s: can't write sector %u", fname, lsn);
+ goto done;
+ }
+ }
}
rv = 0;
done:
- free(img);
+ free(physbuf);
if (fd != -1)
close(fd);
if (fd1 != -1)

File Metadata

Mime Type
text/plain
Expires
Mon, Jan 13, 1:58 AM (17 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15774915
Default Alt Text
D24508.id70794.diff (1 KB)

Event Timeline