GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
pageout.c
Go to the documentation of this file.
1 
2 /**
3  * \file pageout.c
4  *
5  * \brief Segment page-out routines.
6  *
7  * This program is free software under the GNU General Public License
8  * (>=v2). Read the file COPYING that comes with GRASS for details.
9  *
10  * \author GRASS GIS Development Team
11  *
12  * \date 2005-2009
13  */
14 
15 #include <stdio.h>
16 #include <unistd.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <grass/gis.h>
20 #include "local_proto.h"
21 
22 
23 /**
24  * \brief Internal use only
25  *
26  * Pages segment to disk.
27  *
28  * Finds segment value <b>i</b> in segment <b>seg</b> and pages it out
29  * to disk.
30  *
31  * \param[in] SEG segment
32  * \param[in] i segment value
33  * \return 1 if successful
34  * \return -1 on error
35  */
36 
37 int seg_pageout(SEGMENT * SEG, int i)
38 {
39  SEG->seek(SEG, SEG->scb[i].n, 0);
40  errno = 0;
41  if (write(SEG->fd, SEG->scb[i].buf, SEG->size) != SEG->size) {
42  int err = errno;
43 
44  if (err)
45  G_warning("Segment pageout: %s", strerror(err));
46  else
47  G_warning("Segment pageout: insufficient disk space?");
48  return -1;
49  }
50  SEG->scb[i].dirty = 0;
51 
52  return 1;
53 }
int fd
Definition: segment.h:44
int size
Definition: segment.h:28
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
Definition: symbol/read.c:220
char * buf
Definition: segment.h:47
char dirty
Definition: segment.h:48
void G_warning(const char *,...) __attribute__((format(printf
int(* seek)()
Definition: segment.h:41
int seg_pageout(SEGMENT *SEG, int i)
Internal use only.
Definition: pageout.c:37
struct SEGMENT::scb * scb