Module Name:    src
Committed By:   manu
Date:           Fri Jun 24 16:59:29 UTC 2011

Modified Files:
        src/lib/libpuffs: null.c

Log Message:
Commit fix for misc/45029.
Approved by pooka@


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libpuffs/null.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpuffs/null.c
diff -u src/lib/libpuffs/null.c:1.28 src/lib/libpuffs/null.c:1.29
--- src/lib/libpuffs/null.c:1.28	Sun Oct 18 20:14:06 2009
+++ src/lib/libpuffs/null.c	Fri Jun 24 16:59:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: null.c,v 1.28 2009/10/18 20:14:06 pooka Exp $	*/
+/*	$NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $	*/
 
 /*
  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: null.c,v 1.28 2009/10/18 20:14:06 pooka Exp $");
+__RCSID("$NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $");
 #endif /* !lint */
 
 /*
@@ -410,21 +410,36 @@
 	struct puffs_node *pn = opc;
 	int fd, rv;
 	int fflags;
+	struct stat sb;
 
 	rv = 0;
-	fd = writeableopen(PNPATH(pn));
-	if (fd == -1)
+	if (stat(PNPATH(pn), &sb) == -1)
 		return errno;
+	if (S_ISDIR(sb.st_mode)) {
+		DIR *dirp;
+		if ((dirp = opendir(PNPATH(pn))) == 0)
+			return errno;
+		fd = dirfd(dirp);
+		if (fd == -1)
+			return errno;
 
-	if (how & PUFFS_FSYNC_DATAONLY)
-		fflags = FDATASYNC;
-	else
-		fflags = FFILESYNC;
-	if (how & PUFFS_FSYNC_CACHE)
-		fflags |= FDISKSYNC;
+		if (fsync(fd) == -1)
+			rv = errno;
+	} else {
+		fd = writeableopen(PNPATH(pn));
+		if (fd == -1)
+			return errno;
 
-	if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
-		rv = errno;
+		if (how & PUFFS_FSYNC_DATAONLY)
+			fflags = FDATASYNC;
+		else
+			fflags = FFILESYNC;
+		if (how & PUFFS_FSYNC_CACHE)
+			fflags |= FDISKSYNC;
+
+		if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
+			rv = errno;
+	}
 
 	close(fd);
 

Reply via email to