usnjrnl.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * usnjrnl.h - NTFS kernel transaction log ($UsnJrnl) handling. Part of the
  4. * Linux-NTFS project.
  5. *
  6. * Copyright (c) 2005 Anton Altaparmakov
  7. */
  8. #ifdef NTFS_RW
  9. #include <linux/fs.h>
  10. #include <linux/highmem.h>
  11. #include <linux/mm.h>
  12. #include "aops.h"
  13. #include "debug.h"
  14. #include "endian.h"
  15. #include "time.h"
  16. #include "types.h"
  17. #include "usnjrnl.h"
  18. #include "volume.h"
  19. /**
  20. * ntfs_stamp_usnjrnl - stamp the transaction log ($UsnJrnl) on an ntfs volume
  21. * @vol: ntfs volume on which to stamp the transaction log
  22. *
  23. * Stamp the transaction log ($UsnJrnl) on the ntfs volume @vol and return
  24. * 'true' on success and 'false' on error.
  25. *
  26. * This function assumes that the transaction log has already been loaded and
  27. * consistency checked by a call to fs/ntfs/super.c::load_and_init_usnjrnl().
  28. */
  29. bool ntfs_stamp_usnjrnl(ntfs_volume *vol)
  30. {
  31. ntfs_debug("Entering.");
  32. if (likely(!NVolUsnJrnlStamped(vol))) {
  33. sle64 stamp;
  34. struct page *page;
  35. USN_HEADER *uh;
  36. page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0);
  37. if (IS_ERR(page)) {
  38. ntfs_error(vol->sb, "Failed to read from "
  39. "$UsnJrnl/$DATA/$Max attribute.");
  40. return false;
  41. }
  42. uh = (USN_HEADER*)page_address(page);
  43. stamp = get_current_ntfs_time();
  44. ntfs_debug("Stamping transaction log ($UsnJrnl): old "
  45. "journal_id 0x%llx, old lowest_valid_usn "
  46. "0x%llx, new journal_id 0x%llx, new "
  47. "lowest_valid_usn 0x%llx.",
  48. (long long)sle64_to_cpu(uh->journal_id),
  49. (long long)sle64_to_cpu(uh->lowest_valid_usn),
  50. (long long)sle64_to_cpu(stamp),
  51. i_size_read(vol->usnjrnl_j_ino));
  52. uh->lowest_valid_usn =
  53. cpu_to_sle64(i_size_read(vol->usnjrnl_j_ino));
  54. uh->journal_id = stamp;
  55. flush_dcache_page(page);
  56. set_page_dirty(page);
  57. ntfs_unmap_page(page);
  58. /* Set the flag so we do not have to do it again on remount. */
  59. NVolSetUsnJrnlStamped(vol);
  60. }
  61. ntfs_debug("Done.");
  62. return true;
  63. }
  64. #endif /* NTFS_RW */