Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs/tmpfs tmpfs_alloc_node: it is less error-prone to sto...
details: https://anonhg.NetBSD.org/src/rev/0cb945cef727
branches: trunk
changeset: 791014:0cb945cef727
user: rmind <rmind%NetBSD.org@localhost>
date: Thu Oct 31 00:59:17 2013 +0000
description:
tmpfs_alloc_node: it is less error-prone to store the link path with
the NIL terminator included. Adjust tmpfs_readlink() to exclude NIL.
Also, remove the check for zero-length and add some asserts.
diffstat:
sys/fs/tmpfs/tmpfs_subr.c | 14 +++++++-------
sys/fs/tmpfs/tmpfs_vnops.c | 11 ++++++-----
2 files changed, 13 insertions(+), 12 deletions(-)
diffs (76 lines):
diff -r 7555a587a000 -r 0cb945cef727 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Thu Oct 31 00:30:14 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Thu Oct 31 00:59:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_subr.c,v 1.80 2013/10/04 15:14:11 rmind Exp $ */
+/* $NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 rmind Exp $ */
/*
* Copyright (c) 2005-2011 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.80 2013/10/04 15:14:11 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.81 2013/10/31 00:59:17 rmind Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@@ -166,13 +166,13 @@
break;
case VLNK:
/* Symbolic link. Target specifies the file name. */
- KASSERT(target && strlen(target) < MAXPATHLEN);
+ KASSERT(target != NULL);
nnode->tn_size = strlen(target);
- if (nnode->tn_size == 0) {
- nnode->tn_spec.tn_lnk.tn_link = NULL;
- break;
- }
+ KASSERT(nnode->tn_size > 0);
+ KASSERT(nnode->tn_size < MAXPATHLEN);
+ nnode->tn_size++; /* include the NIL */
+
nnode->tn_spec.tn_lnk.tn_link =
tmpfs_strname_alloc(tmp, nnode->tn_size);
if (nnode->tn_spec.tn_lnk.tn_link == NULL) {
diff -r 7555a587a000 -r 0cb945cef727 sys/fs/tmpfs/tmpfs_vnops.c
--- a/sys/fs/tmpfs/tmpfs_vnops.c Thu Oct 31 00:30:14 2013 +0000
+++ b/sys/fs/tmpfs/tmpfs_vnops.c Thu Oct 31 00:59:17 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_vnops.c,v 1.103 2013/10/04 15:14:11 rmind Exp $ */
+/* $NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.103 2013/10/04 15:14:11 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.104 2013/10/31 00:59:17 rmind Exp $");
#include <sys/param.h>
#include <sys/dirent.h>
@@ -1030,16 +1030,17 @@
} */ *ap = v;
vnode_t *vp = ap->a_vp;
struct uio *uio = ap->a_uio;
- tmpfs_node_t *node;
+ tmpfs_node_t *node = VP_TO_TMPFS_NODE(vp);
int error;
KASSERT(VOP_ISLOCKED(vp));
KASSERT(uio->uio_offset == 0);
KASSERT(vp->v_type == VLNK);
+ KASSERT(node->tn_size > 0);
- node = VP_TO_TMPFS_NODE(vp);
+ /* Note: readlink(2) returns the path without NIL. */
error = uiomove(node->tn_spec.tn_lnk.tn_link,
- MIN(node->tn_size, uio->uio_resid), uio);
+ MIN(node->tn_size - 1, uio->uio_resid), uio);
node->tn_status |= TMPFS_NODE_ACCESSED;
return error;
Home |
Main Index |
Thread Index |
Old Index