Module Name: src
Committed By: christos
Date: Sun Jan 27 20:05:47 UTC 2013
Modified Files:
src/usr.sbin/makefs: Makefile ffs.c msdos.c
src/usr.sbin/makefs/ffs: buf.c buf.h ffs_alloc.c ffs_balloc.c
src/usr.sbin/makefs/msdos: msdosfs_vfsops.c msdosfs_vnops.c
Log Message:
This works well enough to populate plain files in the root dir. creating
directories fails.
To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/makefs/Makefile
cvs rdiff -u -r1.54 -r1.55 src/usr.sbin/makefs/ffs.c
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/makefs/msdos.c
cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/makefs/ffs/buf.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/makefs/ffs/buf.h
cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/makefs/ffs/ffs_alloc.c
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/makefs/ffs/ffs_balloc.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/makefs/msdos/msdosfs_vfsops.c
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/makefs/msdos/msdosfs_vnops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.sbin/makefs/Makefile
diff -u src/usr.sbin/makefs/Makefile:1.34 src/usr.sbin/makefs/Makefile:1.35
--- src/usr.sbin/makefs/Makefile:1.34 Fri Jan 25 19:31:49 2013
+++ src/usr.sbin/makefs/Makefile Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.34 2013/01/26 00:31:49 christos Exp $
+# $NetBSD: Makefile,v 1.35 2013/01/27 20:05:46 christos Exp $
#
WARNS?= 5
@@ -18,7 +18,7 @@ MKNODSRC= ${NETBSDSRCDIR}/sbin/mknod
MTREESRC= ${NETBSDSRCDIR}/usr.sbin/mtree
CPPFLAGS+= -I${.CURDIR} -I${MKNODSRC} -I${MTREESRC} -DMAKEFS
-CPPFLAGS+= -DMSDOSFS_DEBUG
+#CPPFLAGS+= -DMSDOSFS_DEBUG
.PATH: ${MKNODSRC} ${MTREESRC}
.include "${.CURDIR}/cd9660/Makefile.inc"
Index: src/usr.sbin/makefs/ffs.c
diff -u src/usr.sbin/makefs/ffs.c:1.54 src/usr.sbin/makefs/ffs.c:1.55
--- src/usr.sbin/makefs/ffs.c:1.54 Fri Jan 25 19:19:39 2013
+++ src/usr.sbin/makefs/ffs.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs.c,v 1.54 2013/01/26 00:19:39 christos Exp $ */
+/* $NetBSD: ffs.c,v 1.55 2013/01/27 20:05:46 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -71,7 +71,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs.c,v 1.54 2013/01/26 00:19:39 christos Exp $");
+__RCSID("$NetBSD: ffs.c,v 1.55 2013/01/27 20:05:46 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -945,7 +945,6 @@ ffs_write_file(union dinode *din, uint32
errno = bwrite(bp);
if (errno != 0)
goto bad_ffs_write_file;
- brelse(bp, 0);
if (!isfile)
p += chunk;
}
Index: src/usr.sbin/makefs/msdos.c
diff -u src/usr.sbin/makefs/msdos.c:1.7 src/usr.sbin/makefs/msdos.c:1.8
--- src/usr.sbin/makefs/msdos.c:1.7 Sun Jan 27 10:35:45 2013
+++ src/usr.sbin/makefs/msdos.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: msdos.c,v 1.7 2013/01/27 15:35:45 christos Exp $ */
+/* $NetBSD: msdos.c,v 1.8 2013/01/27 20:05:46 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: msdos.c,v 1.7 2013/01/27 15:35:45 christos Exp $");
+__RCSID("$NetBSD: msdos.c,v 1.8 2013/01/27 20:05:46 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -162,7 +162,6 @@ msdos_makefs(const char *image, const ch
vp.fd = open(image, O_RDWR);
vp.fs = msdos_opt;
- vp.offset = 0;
if ((pmp = msdosfs_mount(&vp, 0)) == NULL)
err(1, "msdosfs_mount");
@@ -237,7 +236,7 @@ msdos_populate_dir(const char *path, str
continue;
}
if (msdosfs_mkfile(pbuf, dir, cur) == NULL)
- err(1, "msdosfs_mkfile");
+ err(1, "msdosfs_mkfile %s", pbuf);
}
return 0;
}
Index: src/usr.sbin/makefs/ffs/buf.c
diff -u src/usr.sbin/makefs/ffs/buf.c:1.14 src/usr.sbin/makefs/ffs/buf.c:1.15
--- src/usr.sbin/makefs/ffs/buf.c:1.14 Sun Jan 27 09:10:03 2013
+++ src/usr.sbin/makefs/ffs/buf.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.14 2013/01/27 14:10:03 christos Exp $ */
+/* $NetBSD: buf.c,v 1.15 2013/01/27 20:05:46 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -41,7 +41,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: buf.c,v 1.14 2013/01/27 14:10:03 christos Exp $");
+__RCSID("$NetBSD: buf.c,v 1.15 2013/01/27 20:05:46 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -148,6 +148,7 @@ bwrite(struct buf *bp)
if (debug & DEBUG_BUF_BWRITE)
printf("bwrite: write %ld (offset %lld) returned %lld\n",
bp->b_bcount, (long long)offset, (long long)rv);
+ brelse(bp, 0);
if (rv == bp->b_bcount)
return (0);
else if (rv == -1) /* write error */
@@ -189,7 +190,6 @@ getblk(struct vnode *vp, daddr_t blkno,
int fd = vp->fd;
struct fs *fs = vp->fs;
- // blkno += vp->offset;
assert (fs != NULL);
if (debug & DEBUG_BUF_GETBLK)
printf("getblk: blkno %lld size %d\n", (long long)blkno, size);
Index: src/usr.sbin/makefs/ffs/buf.h
diff -u src/usr.sbin/makefs/ffs/buf.h:1.5 src/usr.sbin/makefs/ffs/buf.h:1.6
--- src/usr.sbin/makefs/ffs/buf.h:1.5 Sun Jan 27 09:10:22 2013
+++ src/usr.sbin/makefs/ffs/buf.h Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.5 2013/01/27 14:10:22 christos Exp $ */
+/* $NetBSD: buf.h,v 1.6 2013/01/27 20:05:46 christos Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -58,7 +58,6 @@ struct vnode {
int fd;
void *fs;
void *v_data;
- int offset;
};
#define vput(a) ((void)(a))
Index: src/usr.sbin/makefs/ffs/ffs_alloc.c
diff -u src/usr.sbin/makefs/ffs/ffs_alloc.c:1.21 src/usr.sbin/makefs/ffs/ffs_alloc.c:1.22
--- src/usr.sbin/makefs/ffs/ffs_alloc.c:1.21 Fri Jan 25 19:19:39 2013
+++ src/usr.sbin/makefs/ffs/ffs_alloc.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_alloc.c,v 1.21 2013/01/26 00:19:39 christos Exp $ */
+/* $NetBSD: ffs_alloc.c,v 1.22 2013/01/27 20:05:46 christos Exp $ */
/* From: NetBSD: ffs_alloc.c,v 1.50 2001/09/06 02:16:01 lukem Exp */
/*
@@ -47,7 +47,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs_alloc.c,v 1.21 2013/01/26 00:19:39 christos Exp $");
+__RCSID("$NetBSD: ffs_alloc.c,v 1.22 2013/01/27 20:05:46 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -304,14 +304,13 @@ ffs_alloccg(struct inode *ip, int cg, da
int error, frags, allocsiz, i;
struct fs *fs = ip->i_fs;
const int needswap = UFS_FSNEEDSWAP(fs);
- struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 };
+ struct vnode vp = { ip->i_fd, ip->i_fs, NULL };
if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
return (0);
error = bread(&vp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,
NULL, 0, &bp);
if (error) {
- brelse(bp, 0);
return (0);
}
cgp = (struct cg *)bp->b_data;
@@ -322,7 +321,7 @@ ffs_alloccg(struct inode *ip, int cg, da
}
if (size == fs->fs_bsize) {
bno = ffs_alloccgblk(ip, bp, bpref);
- bdwrite(bp);
+ bwrite(bp);
return (bno);
}
/*
@@ -440,7 +439,7 @@ ffs_blkfree(struct inode *ip, daddr_t bn
int i, error, cg, blk, frags, bbase;
struct fs *fs = ip->i_fs;
const int needswap = UFS_FSNEEDSWAP(fs);
- struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 };
+ struct vnode vp = { ip->i_fd, ip->i_fs, NULL };
if (size > fs->fs_bsize || fragoff(fs, size) != 0 ||
fragnum(fs, bno) + numfrags(fs, size) > fs->fs_frag) {
Index: src/usr.sbin/makefs/ffs/ffs_balloc.c
diff -u src/usr.sbin/makefs/ffs/ffs_balloc.c:1.15 src/usr.sbin/makefs/ffs/ffs_balloc.c:1.16
--- src/usr.sbin/makefs/ffs/ffs_balloc.c:1.15 Fri Jan 25 19:19:39 2013
+++ src/usr.sbin/makefs/ffs/ffs_balloc.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ffs_balloc.c,v 1.15 2013/01/26 00:19:39 christos Exp $ */
+/* $NetBSD: ffs_balloc.c,v 1.16 2013/01/27 20:05:46 christos Exp $ */
/* From NetBSD: ffs_balloc.c,v 1.25 2001/08/08 08:36:36 lukem Exp */
/*
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(__lint)
-__RCSID("$NetBSD: ffs_balloc.c,v 1.15 2013/01/26 00:19:39 christos Exp $");
+__RCSID("$NetBSD: ffs_balloc.c,v 1.16 2013/01/27 20:05:46 christos Exp $");
#endif /* !__lint */
#include <sys/param.h>
@@ -95,7 +95,7 @@ ffs_balloc_ufs1(struct inode *ip, off_t
int32_t *allocblk, allociblk[UFS_NIADDR + 1];
int32_t *allocib;
const int needswap = UFS_FSNEEDSWAP(fs);
- struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 };
+ struct vnode vp = { ip->i_fd, ip->i_fs, NULL };
lbn = lblkno(fs, offset);
size = blkoff(fs, offset) + bufsize;
@@ -346,7 +346,7 @@ ffs_balloc_ufs2(struct inode *ip, off_t
int64_t *allocblk, allociblk[UFS_NIADDR + 1];
int64_t *allocib;
const int needswap = UFS_FSNEEDSWAP(fs);
- struct vnode vp = { ip->i_fd, ip->i_fs, NULL, 0 };
+ struct vnode vp = { ip->i_fd, ip->i_fs, NULL };
lbn = lblkno(fs, offset);
size = blkoff(fs, offset) + bufsize;
Index: src/usr.sbin/makefs/msdos/msdosfs_vfsops.c
diff -u src/usr.sbin/makefs/msdos/msdosfs_vfsops.c:1.4 src/usr.sbin/makefs/msdos/msdosfs_vfsops.c:1.5
--- src/usr.sbin/makefs/msdos/msdosfs_vfsops.c:1.4 Sun Jan 27 10:35:45 2013
+++ src/usr.sbin/makefs/msdos/msdosfs_vfsops.c Sun Jan 27 15:05:46 2013
@@ -50,7 +50,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.4 2013/01/27 15:35:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.5 2013/01/27 20:05:46 christos Exp $");
#include <sys/param.h>
@@ -301,6 +301,12 @@ msdosfs_mount(struct vnode *devvp, int f
pmp->pm_crbomask = pmp->pm_bpcluster - 1;
pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
+ DPRINTF(("%s(fatmask=%lu, fatmult=%u, fatdiv=%u, fatblocksize=%lu, "
+ "fatblocksec=%lu, bnshift=%lu, pbcluster=%lu, crbomask=%lu, "
+ "cnshift=%lu)\n",
+ __func__, pmp->pm_fatmask, pmp->pm_fatmult, pmp->pm_fatdiv,
+ pmp->pm_fatblocksize, pmp->pm_fatblocksec, pmp->pm_bnshift,
+ pmp->pm_bpcluster, pmp->pm_crbomask, pmp->pm_cnshift));
/*
* Check for valid cluster size
* must be a power of 2
Index: src/usr.sbin/makefs/msdos/msdosfs_vnops.c
diff -u src/usr.sbin/makefs/msdos/msdosfs_vnops.c:1.8 src/usr.sbin/makefs/msdos/msdosfs_vnops.c:1.9
--- src/usr.sbin/makefs/msdos/msdosfs_vnops.c:1.8 Sun Jan 27 11:03:15 2013
+++ src/usr.sbin/makefs/msdos/msdosfs_vnops.c Sun Jan 27 15:05:46 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: msdosfs_vnops.c,v 1.8 2013/01/27 16:03:15 christos Exp $ */
+/* $NetBSD: msdosfs_vnops.c,v 1.9 2013/01/27 20:05:46 christos Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@@ -51,7 +51,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.8 2013/01/27 16:03:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.9 2013/01/27 20:05:46 christos Exp $");
#include <sys/param.h>
#include <sys/mman.h>
@@ -70,6 +70,11 @@ __KERNEL_RCSID(0, "$NetBSD: msdosfs_vnop
#include "makefs.h"
#include "msdos.h"
+#ifdef MSDOSFS_DEBUG
+#define DPRINTF(a) printf a
+#else
+#define DPRINTF(a)
+#endif
/*
* Some general notes:
*
@@ -169,9 +174,7 @@ msdosfs_findslot(struct denode *dp, stru
* case it doesn't already exist.
*/
slotcount = 0;
-#ifdef MSDOSFS_DEBUG
- printf("%s(): dos filename: %s\n", __func__, dosfilename);
-#endif
+ DPRINTF(("%s(): dos filename: %s\n", __func__, dosfilename));
/*
* Search the directory pointed at by vdp for the name pointed at
* by cnp->cn_nameptr.
@@ -264,10 +267,8 @@ msdosfs_findslot(struct denode *dp, stru
chksum = -1;
continue;
}
-#ifdef MSDOSFS_DEBUG
- printf("%s(): match blkoff %d, diroff %d\n",
- __func__, blkoff, diroff);
-#endif
+ DPRINTF(("%s(): match blkoff %d, diroff %d\n",
+ __func__, blkoff, diroff));
/*
* Remember where this directory
* entry came from for whoever did
@@ -296,10 +297,8 @@ notfound:
* that's ok if we are creating or renaming and are at the end of
* the pathname and the directory hasn't been removed.
*/
-#ifdef MSDOSFS_DEBUG
- printf("%s(): refcnt %ld, slotcount %d, slotoffset %d\n",
- __func__, dp->de_refcnt, slotcount, slotoffset);
-#endif
+ DPRINTF(("%s(): refcnt %ld, slotcount %d, slotoffset %d\n",
+ __func__, dp->de_refcnt, slotcount, slotoffset));
/*
* Fixup the slot description to point to the place where
* we might put the new DOS direntry (putting the Win95
@@ -351,10 +350,8 @@ msdosfs_mkfile(const char *path, struct
cn.cn_nameptr = node->name;
cn.cn_namelen = strlen(node->name);
-#ifdef MSDOSFS_DEBUG
- printf("msdosfs_create(name %s, mode 0%o size %zu\n", node->name,
- st->st_mode, (size_t)st->st_size);
-#endif
+ DPRINTF(("%s(name %s, mode 0%o size %zu)\n", __func__, node->name,
+ st->st_mode, (size_t)st->st_size));
/*
* If this is the root directory and there is no space left we
@@ -398,6 +395,21 @@ bad:
errno = error;
return NULL;
}
+static int
+msdosfs_updatede(struct denode *dep)
+{
+ struct buf *bp;
+ struct direntry *dirp;
+ int error;
+
+ dep->de_flag &= ~DE_MODIFIED;
+ error = readde(dep, &bp, &dirp);
+ if (error)
+ return error;
+ DE_EXTERNALIZE(dirp, dep);
+ error = bwrite(bp);
+ return error;
+}
/*
* Write data to a file or directory.
@@ -409,16 +421,12 @@ msdosfs_wfile(const char *path, struct d
size_t osize = dep->de_FileSize;
struct stat *st = &node->inode->st;
size_t nsize;
- size_t offs = 0;
struct msdosfsmount *pmp = dep->de_pmp;
struct buf *bp;
char *dat;
- u_long cn;
-#ifdef MSDOSFS_DEBUG
- printf("%s(diroff %lu, dirclust %lu, startcluster %lu)\n", __func__,
- dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
-#endif
+ DPRINTF(("%s(diroff %lu, dirclust %lu, startcluster %lu)\n", __func__,
+ dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster));
if (st->st_size == 0)
return 0;
@@ -429,11 +437,16 @@ msdosfs_wfile(const char *path, struct d
}
nsize = st->st_size;
+ DPRINTF(("%s(nsize=%zu, osize=%zu)\n", __func__, nsize, osize));
if (nsize > osize) {
if ((error = deextend(dep, nsize, NULL)) != 0) {
errno = error;
return -1;
}
+ if ((error = msdosfs_updatede(dep)) != 0) {
+ errno = error;
+ return -1;
+ }
}
if ((fd = open(path, O_RDONLY)) == -1)
@@ -441,35 +454,37 @@ msdosfs_wfile(const char *path, struct d
if ((dat = mmap(0, nsize, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0))
== MAP_FAILED) {
- fprintf(stderr, "mmap %s", node->name);
+ DPRINTF(("%s: mmap %s %s", __func__, node->name,
+ strerror(errno)));
+ close(fd);
goto out;
}
close(fd);
- for (cn = 0;; cn++) {
+ for (size_t offs = 0; offs < nsize;) {
int blsize, cpsize;
daddr_t bn;
- if ((error = pcbmap(dep, cn, &bn, 0, &blsize)) != 0) {
- fprintf(stderr, "pcbmap %ld\n", cn);
+ u_long lbn = dep->de_StartCluster;
+ u_long on = offs & pmp->pm_crbomask;
+
+ if (lbn == MSDOSFSROOT) {
+ DPRINTF(("%s: bad lbn %lu", __func__, lbn));
goto out;
}
-#ifdef MSDOSFS_DEBUG
- printf("%s(cn=%lu, bn=%llu/%llu, blsize=%d)\n", __func__, cn,
- (unsigned long long)bn,
- (unsigned long long)de_bn2kb(pmp, bn), blsize);
-#endif
+ bn = cntobn(pmp, lbn);
+ blsize = pmp->pm_bpcluster;
+ DPRINTF(("%s(lbn=%lu, bn=%llu/%llu, blsize=%d)\n", __func__,
+ lbn, (unsigned long long)bn,
+ (unsigned long long)de_bn2kb(pmp, bn), blsize));
if ((error = bread(pmp->pm_devvp, de_bn2kb(pmp, bn), blsize,
NULL, 0, &bp)) != 0) {
- fprintf(stderr, "bread %d\n", error);
+ DPRINTF(("bread %d\n", error));
goto out;
}
- cpsize = MIN((int)(nsize - offs), blsize);
- memcpy(bp->b_data, dat + offs, cpsize);
+ cpsize = MIN((nsize - offs), blsize - on);
+ memcpy((char *)bp->b_data + on, dat + offs, cpsize);
bwrite(bp);
- brelse(bp, 0);
- offs += blsize;
- if (offs >= nsize)
- break;
+ offs += cpsize;
}
munmap(dat, nsize);