pageout.c 935 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/segment.h>
  18. /**
  19. * \fn int segment_pageout(SEGMENT *SEG, int i)
  20. *
  21. * \brief Pages segment to disk.
  22. *
  23. * Finds segment value <b>i</b> in segment <b>seg</b> and pages it out
  24. * to disk.
  25. *
  26. * \param[in] seg segment
  27. * \param[in] i segment value
  28. * \return 1 if successful
  29. * \return -1 on error
  30. */
  31. int segment_pageout(SEGMENT * SEG, int i)
  32. {
  33. segment_seek(SEG, SEG->scb[i].n, 0);
  34. if (write(SEG->fd, SEG->scb[i].buf, SEG->size) != SEG->size) {
  35. G_warning("segment_pageout: %s", strerror(errno));
  36. return -1;
  37. }
  38. SEG->scb[i].dirty = 0;
  39. return 1;
  40. }