Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * usnjrnl.h - NTFS kernel transaction log ($UsnJrnl) handling.  Part of the
0004  *         Linux-NTFS project.
0005  *
0006  * Copyright (c) 2005 Anton Altaparmakov
0007  */
0008 
0009 #ifdef NTFS_RW
0010 
0011 #include <linux/fs.h>
0012 #include <linux/highmem.h>
0013 #include <linux/mm.h>
0014 
0015 #include "aops.h"
0016 #include "debug.h"
0017 #include "endian.h"
0018 #include "time.h"
0019 #include "types.h"
0020 #include "usnjrnl.h"
0021 #include "volume.h"
0022 
0023 /**
0024  * ntfs_stamp_usnjrnl - stamp the transaction log ($UsnJrnl) on an ntfs volume
0025  * @vol:    ntfs volume on which to stamp the transaction log
0026  *
0027  * Stamp the transaction log ($UsnJrnl) on the ntfs volume @vol and return
0028  * 'true' on success and 'false' on error.
0029  *
0030  * This function assumes that the transaction log has already been loaded and
0031  * consistency checked by a call to fs/ntfs/super.c::load_and_init_usnjrnl().
0032  */
0033 bool ntfs_stamp_usnjrnl(ntfs_volume *vol)
0034 {
0035     ntfs_debug("Entering.");
0036     if (likely(!NVolUsnJrnlStamped(vol))) {
0037         sle64 stamp;
0038         struct page *page;
0039         USN_HEADER *uh;
0040 
0041         page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0);
0042         if (IS_ERR(page)) {
0043             ntfs_error(vol->sb, "Failed to read from "
0044                     "$UsnJrnl/$DATA/$Max attribute.");
0045             return false;
0046         }
0047         uh = (USN_HEADER*)page_address(page);
0048         stamp = get_current_ntfs_time();
0049         ntfs_debug("Stamping transaction log ($UsnJrnl): old "
0050                 "journal_id 0x%llx, old lowest_valid_usn "
0051                 "0x%llx, new journal_id 0x%llx, new "
0052                 "lowest_valid_usn 0x%llx.",
0053                 (long long)sle64_to_cpu(uh->journal_id),
0054                 (long long)sle64_to_cpu(uh->lowest_valid_usn),
0055                 (long long)sle64_to_cpu(stamp),
0056                 i_size_read(vol->usnjrnl_j_ino));
0057         uh->lowest_valid_usn =
0058                 cpu_to_sle64(i_size_read(vol->usnjrnl_j_ino));
0059         uh->journal_id = stamp;
0060         flush_dcache_page(page);
0061         set_page_dirty(page);
0062         ntfs_unmap_page(page);
0063         /* Set the flag so we do not have to do it again on remount. */
0064         NVolSetUsnJrnlStamped(vol);
0065     }
0066     ntfs_debug("Done.");
0067     return true;
0068 }
0069 
0070 #endif /* NTFS_RW */