[GRASS-SVN] r71648 - grass/trunk/lib/segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Nov 8 08:24:02 PST 2017
Author: mmetz
Date: 2017-11-08 08:24:02 -0800 (Wed, 08 Nov 2017)
New Revision: 71648
Modified:
grass/trunk/lib/segment/format.c
grass/trunk/lib/segment/pagein.c
Log:
segment lib: fix for Segment_format_nofill()
Modified: grass/trunk/lib/segment/format.c
===================================================================
--- grass/trunk/lib/segment/format.c 2017-11-08 14:57:59 UTC (rev 71647)
+++ grass/trunk/lib/segment/format.c 2017-11-08 16:24:02 UTC (rev 71648)
@@ -26,6 +26,7 @@
static int write_int(int, int);
static int write_off_t(int, off_t);
static int zero_fill(int, off_t);
+static int seek_only(int, off_t);
/* fd must be open for write */
@@ -158,13 +159,17 @@
|| !write_int(fd, len))
return -1;
- if (!fill)
- return 1;
-
/* calculate total number of segments */
nbytes = spr * ((nrows + srows - 1) / srows);
nbytes *= size;
+ if (!fill) {
+ /* only seek and write a zero byte to the end */
+ if (seek_only(fd, nbytes) < 0)
+ return -1;
+ return 1;
+ }
+
/* fill segment file with zeros */
/* NOTE: this could be done faster using lseek() by seeking
* ahead nbytes and then writing a single byte of 0,
@@ -239,10 +244,16 @@
}
return 1;
#else
+ return seek_only(fd, nbytes);
+#endif
+}
+
+static int seek_only(int fd, off_t nbytes)
+{
/* Using lseek (faster upon initialization).
NOTE: This version doesn't allocate disk storage for the file; storage will
be allocated dynamically as blocks are actually written. This could
- result in zero_fill() succeeding but a subsequent call to write() failing
+ result in seek_only() succeeding but a subsequent call to write() failing
with ENOSPC ("No space left on device").
*/
@@ -268,5 +279,4 @@
}
return 1;
-#endif
}
Modified: grass/trunk/lib/segment/pagein.c
===================================================================
--- grass/trunk/lib/segment/pagein.c 2017-11-08 14:57:59 UTC (rev 71647)
+++ grass/trunk/lib/segment/pagein.c 2017-11-08 16:24:02 UTC (rev 71648)
@@ -93,14 +93,20 @@
SEG->seek(SEG, SEG->scb[cur].n, 0);
read_result = read(SEG->fd, SEG->scb[cur].buf, SEG->size);
- if (read_result != SEG->size) {
+
+ if (read_result == 0) {
+ /* this can happen if the file was not zero-filled,
+ * i.e. formatted with Segment_format_nofill() or
+ * Segment_format() used lseek for file initialization */
+ G_debug(1, "Segment pagein: zero read");
+ memset(SEG->scb[cur].buf, 0, SEG->size);
+ }
+ else if (read_result != SEG->size) {
G_debug(2, "Segment pagein: read_result=%d SEG->size=%d",
read_result, SEG->size);
if (read_result < 0)
G_warning("Segment pagein: %s", strerror(errno));
- else if (read_result == 0)
- G_warning("Segment pagein: read EOF");
else
G_warning
("Segment pagein: short count during read(), got %d, expected %d",
More information about the grass-commit
mailing list