pageout.c 1.0 KB

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