Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/newfs_msdos don't truncate the file if an offset is given.



details:   https://anonhg.NetBSD.org/src/rev/1e79c9752ec5
branches:  trunk
changeset: 784595:1e79c9752ec5
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 03 03:21:42 2013 +0000

description:
don't truncate the file if an offset is given.

diffstat:

 sbin/newfs_msdos/mkfs_msdos.c |  9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diffs (37 lines):

diff -r c42bdfd89a2e -r 1e79c9752ec5 sbin/newfs_msdos/mkfs_msdos.c
--- a/sbin/newfs_msdos/mkfs_msdos.c     Sun Feb 03 03:21:21 2013 +0000
+++ b/sbin/newfs_msdos/mkfs_msdos.c     Sun Feb 03 03:21:42 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs_msdos.c,v 1.6 2013/01/27 21:56:26 christos Exp $  */
+/*     $NetBSD: mkfs_msdos.c,v 1.7 2013/02/03 03:21:42 christos Exp $  */
 
 /*
  * Copyright (c) 1998 Robert Nordier
@@ -37,7 +37,7 @@
 static const char rcsid[] =
   "$FreeBSD: src/sbin/newfs_msdos/newfs_msdos.c,v 1.15 2000/10/10 01:49:37 wollman Exp $";
 #else
-__RCSID("$NetBSD: mkfs_msdos.c,v 1.6 2013/01/27 21:56:26 christos Exp $");
+__RCSID("$NetBSD: mkfs_msdos.c,v 1.7 2013/02/03 03:21:42 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -263,6 +263,7 @@
     u_int bss, rds, cls, dir, lsn, x, x1, x2;
     int ch, fd, fd1;
     struct msdos_options o = *op;
+    int oflags = O_RDWR | O_CREAT;
 
     if (o.block_size && o.sectors_per_cluster) {
        warnx("Cannot specify both block size and sectors per cluster");
@@ -278,7 +279,9 @@
            warnx("create (-C) is incompatible with -N");
            return -1;
        }
-       fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0644);
+       if (o.offset == 0)
+               oflags |= O_TRUNC;
+       fd = open(fname, oflags, 0644);
        if (fd == -1) {
            warnx("failed to create %s", fname);
            return -1;



Home | Main Index | Thread Index | Old Index