3
0

fgetsetversion.c 1.6 KB

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