3
0

fgetsetversion.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fgetversion.c - Get a file version on an ext2 file system
  4. * fsetversion.c - Set a file version on an ext2 file system
  5. *
  6. *
  7. * Copyright (C) 1993, 1994 Remy Card <card@masi.ibp.fr>
  8. * Laboratoire MASI, Institut Blaise Pascal
  9. * Universite Pierre et Marie Curie (Paris VI)
  10. *
  11. * This file can be redistributed under the terms of the GNU Library General
  12. * Public License
  13. */
  14. /*
  15. * History:
  16. * 93/10/30 - Creation
  17. */
  18. #ifdef HAVE_ERRNO_H
  19. #include <errno.h>
  20. #endif
  21. #ifdef HAVE_UNISTD_H
  22. #include <unistd.h>
  23. #endif
  24. #include <fcntl.h>
  25. #include <sys/ioctl.h>
  26. #include "e2p.h"
  27. #ifdef O_LARGEFILE
  28. #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE)
  29. #else
  30. #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK)
  31. #endif
  32. /*
  33. To do fsetversion: unsigned long *ptr_version must be set to NULL.
  34. and unsigned long version must be set to a value
  35. To do fgetversion: unsigned long *ptr_version must NOT be set to NULL
  36. and unsigned long version is ignored.
  37. TITO.
  38. */
  39. int fgetsetversion (const char * name, unsigned long * get_version, unsigned long set_version)
  40. {
  41. #ifdef HAVE_EXT2_IOCTLS
  42. int fd, r, ver, save_errno = 0;
  43. fd = open (name, OPEN_FLAGS);
  44. if (fd == -1)
  45. return -1;
  46. if (!get_version) {
  47. ver = (int) set_version;
  48. r = ioctl (fd, EXT2_IOC_SETVERSION, &ver);
  49. } else {
  50. r = ioctl (fd, EXT2_IOC_GETVERSION, &ver);
  51. *get_version = ver;
  52. }
  53. if (r == -1)
  54. save_errno = errno;
  55. close (fd);
  56. if (save_errno)
  57. errno = save_errno;
  58. return r;
  59. #else /* ! HAVE_EXT2_IOCTLS */
  60. errno = EOPNOTSUPP;
  61. return -1;
  62. #endif /* ! HAVE_EXT2_IOCTLS */
  63. }