Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/newfs - use calloc to zero memory
details: https://anonhg.NetBSD.org/src/rev/439ec5857beb
branches: trunk
changeset: 337815:439ec5857beb
user: christos <christos%NetBSD.org@localhost>
date: Wed Apr 29 01:49:25 2015 +0000
description:
- use calloc to zero memory
- pass the proper buffer to mkdir
- fix for apple ufs
diffstat:
sbin/newfs/mkfs.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diffs (100 lines):
diff -r d10333c509f2 -r 439ec5857beb sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Tue Apr 28 19:59:14 2015 +0000
+++ b/sbin/newfs/mkfs.c Wed Apr 29 01:49:25 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkfs.c,v 1.123 2015/04/28 15:15:53 christos Exp $ */
+/* $NetBSD: mkfs.c,v 1.124 2015/04/29 01:49:25 christos Exp $ */
/*
* Copyright (c) 1980, 1989, 1993
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: mkfs.c,v 1.123 2015/04/28 15:15:53 christos Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.124 2015/04/29 01:49:25 christos Exp $");
#endif
#endif /* not lint */
@@ -110,7 +110,8 @@
static void initcg(int, const struct timeval *);
static int fsinit(const struct timeval *, mode_t, uid_t, gid_t);
-static int makedir(struct direct *, int);
+union Buffer;
+static int makedir(union Buffer *, struct direct *, int);
static daddr_t alloc(int, int);
static void iput(union dinode *, ino_t);
static void rdfs(daddr_t, int, void *);
@@ -199,9 +200,9 @@
exit(12);
}
#endif
- if ((fsun = mkfs_malloc(sizeof(*fsun))) == NULL)
+ if ((fsun = calloc(1, sizeof(*fsun))) == NULL)
exit(12);
- if ((cgun = mkfs_malloc(sizeof(*cgun))) == NULL)
+ if ((cgun = calloc(1, sizeof(*cgun))) == NULL)
exit(12);
fsi = fi;
@@ -1054,12 +1055,12 @@
*/
memset(&node, 0, sizeof(node));
if (Oflag == 0) {
- (void)makedir((struct direct *)olost_found_dir, 2);
+ (void)makedir(&buf, (struct direct *)olost_found_dir, 2);
for (i = dirblksiz; i < sblock.fs_bsize; i += dirblksiz)
copy_dir((struct direct*)&olost_found_dir[2],
(struct direct*)&buf[i]);
} else {
- (void)makedir(lost_found_dir, 2);
+ (void)makedir(&buf, lost_found_dir, 2);
for (i = dirblksiz; i < sblock.fs_bsize; i += dirblksiz)
copy_dir(&lost_found_dir[2], (struct direct*)&buf[i]);
}
@@ -1125,10 +1126,10 @@
}
node.dp1.di_nlink = PREDEFDIR;
if (Oflag == 0)
- node.dp1.di_size = makedir((struct direct *)oroot_dir,
- PREDEFDIR);
+ node.dp1.di_size = makedir(&buf,
+ (struct direct *)oroot_dir, PREDEFDIR);
else
- node.dp1.di_size = makedir(root_dir, PREDEFDIR);
+ node.dp1.di_size = makedir(&buf, root_dir, PREDEFDIR);
node.dp1.di_db[0] = alloc(sblock.fs_fsize, node.dp1.di_mode);
if (node.dp1.di_db[0] == 0)
return (0);
@@ -1155,7 +1156,7 @@
node.dp2.di_birthtime = tv->tv_sec;
node.dp2.di_birthnsec = tv->tv_usec * 1000;
node.dp2.di_nlink = PREDEFDIR;
- node.dp2.di_size = makedir(root_dir, PREDEFDIR);
+ node.dp2.di_size = makedir(&buf, root_dir, PREDEFDIR);
node.dp2.di_db[0] = alloc(sblock.fs_fsize, node.dp2.di_mode);
if (node.dp2.di_db[0] == 0)
return (0);
@@ -1260,18 +1261,17 @@
* return size of directory.
*/
int
-makedir(struct direct *protodir, int entries)
+makedir(union Buffer *buf, struct direct *protodir, int entries)
{
char *cp;
- union Buffer buf;
int i, spcleft;
int dirblksiz = UFS_DIRBLKSIZ;
if (isappleufs)
dirblksiz = APPLEUFS_DIRBLKSIZ;
- memset(&buf, 0, UFS_DIRBLKSIZ);
+ memset(buf, 0, dirblksiz);
spcleft = dirblksiz;
- for (cp = buf.data, i = 0; i < entries - 1; i++) {
+ for (cp = buf->data, i = 0; i < entries - 1; i++) {
protodir[i].d_reclen = UFS_DIRSIZ(Oflag == 0, &protodir[i], 0);
copy_dir(&protodir[i], (struct direct*)cp);
cp += protodir[i].d_reclen;
Home |
Main Index |
Thread Index |
Old Index