summaryrefslogtreecommitdiff
path: root/ufs
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2000-03-03 21:48:33 +0000
committerRoland McGrath <roland@gnu.org>2000-03-03 21:48:33 +0000
commitf62fbb2b36d3ba2406fe9b4216082f726188ccc3 (patch)
treeed2b0e521014eececee3049791092a806f4b154d /ufs
parent9cf5495d262557397b24d722634ba2beb8d82ebb (diff)
2000-03-03 Roland McGrath <roland@baalperazim.frob.com>
* dir.c (diskfs_get_directs): Don't allocate buffer for *DATA until after scanning for ENTRY and possibly returning EOF.
Diffstat (limited to 'ufs')
-rw-r--r--ufs/dir.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ufs/dir.c b/ufs/dir.c
index 304c8a44..8077234c 100644
--- a/ufs/dir.c
+++ b/ufs/dir.c
@@ -1,5 +1,5 @@
/* Directory management routines
- Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999 Free Software Foundation
+ Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -856,15 +856,6 @@ diskfs_get_directs (struct node *dp,
dp->dn->dirents[i] = -1;
}
- /* Allocate enough space to hold the maximum we might return */
- if (!bufsiz || bufsiz > dp->dn_stat.st_size)
- allocsize = round_page (dp->dn_stat.st_size);
- else
- allocsize = round_page (bufsiz);
-
- if (allocsize > *datacnt)
- *data = mmap (0, allocsize, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
-
/* Scan through the entries to find ENTRY. If we encounter
a -1 in the process then stop to fill it. When we run
off the end, ENTRY is too big. */
@@ -891,11 +882,23 @@ diskfs_get_directs (struct node *dp,
if (blkno == nblks)
{
+ /* We reached the end of the directory without seeing ENTRY.
+ This is treated as an EOF condition, meaning we return
+ success with empty results. */
*datacnt = 0;
*amt = 0;
return 0;
}
+ /* Allocate enough space to hold the maximum we might return */
+ if (!bufsiz || bufsiz > dp->dn_stat.st_size)
+ allocsize = round_page (dp->dn_stat.st_size);
+ else
+ allocsize = round_page (bufsiz);
+
+ if (allocsize > *datacnt)
+ *data = mmap (0, allocsize, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+
/* Set bufp appropriately */
bufp = buf;
if (curentry != entry)