aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ntfs/ChangeLog10
-rw-r--r--fs/ntfs/layout.h9
-rw-r--r--fs/ntfs/lcnalloc.c31
-rw-r--r--fs/ntfs/lcnalloc.h27
-rw-r--r--fs/ntfs/logfile.c30
-rw-r--r--fs/ntfs/logfile.h2
-rw-r--r--fs/ntfs/mft.c2
7 files changed, 67 insertions, 44 deletions
diff --git a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog
index c7e9237379c2..83f3322765cd 100644
--- a/fs/ntfs/ChangeLog
+++ b/fs/ntfs/ChangeLog
@@ -29,7 +29,8 @@ ToDo/Notes:
29 The Windows boot will run chkdsk and then reboot. The user can then 29 The Windows boot will run chkdsk and then reboot. The user can then
30 immediately boot into Linux rather than having to do a full Windows 30 immediately boot into Linux rather than having to do a full Windows
31 boot first before rebooting into Linux and we will recognize such a 31 boot first before rebooting into Linux and we will recognize such a
32 journal and empty it as it is clean by definition. 32 journal and empty it as it is clean by definition. Note, this only
33 works if chkdsk left the journal in an obviously clean state.
33 - Support journals ($LogFile) with only one restart page as well as 34 - Support journals ($LogFile) with only one restart page as well as
34 journals with two different restart pages. We sanity check both and 35 journals with two different restart pages. We sanity check both and
35 either use the only sane one or the more recent one of the two in the 36 either use the only sane one or the more recent one of the two in the
@@ -94,6 +95,13 @@ ToDo/Notes:
94 my ways. 95 my ways.
95 - Fix various bugs in the runlist merging code. (Based on libntfs 96 - Fix various bugs in the runlist merging code. (Based on libntfs
96 changes by Richard Russon.) 97 changes by Richard Russon.)
98 - Fix sparse warnings that have crept in over time.
99 - Change ntfs_cluster_free() to require a write locked runlist on entry
100 since we otherwise get into a lock reversal deadlock if a read locked
101 runlist is passed in. In the process also change it to take an ntfs
102 inode instead of a vfs inode as parameter.
103 - Fix the definition of the CHKD ntfs record magic. It had an off by
104 two error causing it to be CHKB instead of CHKD.
97 105
982.1.23 - Implement extension of resident files and make writing safe as well as 1062.1.23 - Implement extension of resident files and make writing safe as well as
99 many bug fixes, cleanups, and enhancements... 107 many bug fixes, cleanups, and enhancements...
diff --git a/fs/ntfs/layout.h b/fs/ntfs/layout.h
index 609ad1728ce4..d5491de6abf4 100644
--- a/fs/ntfs/layout.h
+++ b/fs/ntfs/layout.h
@@ -123,7 +123,7 @@ enum {
123 magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */ 123 magic_RCRD = const_cpu_to_le32(0x44524352), /* Log record page. */
124 124
125 /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */ 125 /* Found in $LogFile/$DATA. (May be found in $MFT/$DATA, also?) */
126 magic_CHKD = const_cpu_to_le32(0x424b4843), /* Modified by chkdsk. */ 126 magic_CHKD = const_cpu_to_le32(0x444b4843), /* Modified by chkdsk. */
127 127
128 /* Found in all ntfs record containing records. */ 128 /* Found in all ntfs record containing records. */
129 magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector 129 magic_BAAD = const_cpu_to_le32(0x44414142), /* Failed multi sector
@@ -317,12 +317,13 @@ typedef u64 MFT_REF;
317typedef le64 leMFT_REF; 317typedef le64 leMFT_REF;
318 318
319#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \ 319#define MK_MREF(m, s) ((MFT_REF)(((MFT_REF)(s) << 48) | \
320 ((MFT_REF)(m) & MFT_REF_MASK_CPU))) 320 ((MFT_REF)(m) & (u64)MFT_REF_MASK_CPU)))
321#define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s)) 321#define MK_LE_MREF(m, s) cpu_to_le64(MK_MREF(m, s))
322 322
323#define MREF(x) ((unsigned long)((x) & MFT_REF_MASK_CPU)) 323#define MREF(x) ((unsigned long)((x) & (u64)MFT_REF_MASK_CPU))
324#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff)) 324#define MSEQNO(x) ((u16)(((x) >> 48) & 0xffff))
325#define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & MFT_REF_MASK_CPU)) 325#define MREF_LE(x) ((unsigned long)(le64_to_cpu(x) & \
326 (u64)MFT_REF_MASK_CPU))
326#define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff)) 327#define MSEQNO_LE(x) ((u16)((le64_to_cpu(x) >> 48) & 0xffff))
327 328
328#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0) 329#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0)
diff --git a/fs/ntfs/lcnalloc.c b/fs/ntfs/lcnalloc.c
index 7b5934290685..5af3bf0b7eee 100644
--- a/fs/ntfs/lcnalloc.c
+++ b/fs/ntfs/lcnalloc.c
@@ -779,14 +779,13 @@ out:
779 779
780/** 780/**
781 * __ntfs_cluster_free - free clusters on an ntfs volume 781 * __ntfs_cluster_free - free clusters on an ntfs volume
782 * @vi: vfs inode whose runlist describes the clusters to free 782 * @ni: ntfs inode whose runlist describes the clusters to free
783 * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters 783 * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters
784 * @count: number of clusters to free or -1 for all clusters 784 * @count: number of clusters to free or -1 for all clusters
785 * @write_locked: true if the runlist is locked for writing
786 * @is_rollback: true if this is a rollback operation 785 * @is_rollback: true if this is a rollback operation
787 * 786 *
788 * Free @count clusters starting at the cluster @start_vcn in the runlist 787 * Free @count clusters starting at the cluster @start_vcn in the runlist
789 * described by the vfs inode @vi. 788 * described by the vfs inode @ni.
790 * 789 *
791 * If @count is -1, all clusters from @start_vcn to the end of the runlist are 790 * If @count is -1, all clusters from @start_vcn to the end of the runlist are
792 * deallocated. Thus, to completely free all clusters in a runlist, use 791 * deallocated. Thus, to completely free all clusters in a runlist, use
@@ -801,31 +800,28 @@ out:
801 * Return the number of deallocated clusters (not counting sparse ones) on 800 * Return the number of deallocated clusters (not counting sparse ones) on
802 * success and -errno on error. 801 * success and -errno on error.
803 * 802 *
804 * Locking: - The runlist described by @vi must be locked on entry and is 803 * Locking: - The runlist described by @ni must be locked for writing on entry
805 * locked on return. Note if the runlist is locked for reading the 804 * and is locked on return. Note the runlist may be modified when
806 * lock may be dropped and reacquired. Note the runlist may be 805 * needed runlist fragments need to be mapped.
807 * modified when needed runlist fragments need to be mapped.
808 * - The volume lcn bitmap must be unlocked on entry and is unlocked 806 * - The volume lcn bitmap must be unlocked on entry and is unlocked
809 * on return. 807 * on return.
810 * - This function takes the volume lcn bitmap lock for writing and 808 * - This function takes the volume lcn bitmap lock for writing and
811 * modifies the bitmap contents. 809 * modifies the bitmap contents.
812 */ 810 */
813s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count, 811s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, s64 count,
814 const BOOL write_locked, const BOOL is_rollback) 812 const BOOL is_rollback)
815{ 813{
816 s64 delta, to_free, total_freed, real_freed; 814 s64 delta, to_free, total_freed, real_freed;
817 ntfs_inode *ni;
818 ntfs_volume *vol; 815 ntfs_volume *vol;
819 struct inode *lcnbmp_vi; 816 struct inode *lcnbmp_vi;
820 runlist_element *rl; 817 runlist_element *rl;
821 int err; 818 int err;
822 819
823 BUG_ON(!vi); 820 BUG_ON(!ni);
824 ntfs_debug("Entering for i_ino 0x%lx, start_vcn 0x%llx, count " 821 ntfs_debug("Entering for i_ino 0x%lx, start_vcn 0x%llx, count "
825 "0x%llx.%s", vi->i_ino, (unsigned long long)start_vcn, 822 "0x%llx.%s", ni->mft_no, (unsigned long long)start_vcn,
826 (unsigned long long)count, 823 (unsigned long long)count,
827 is_rollback ? " (rollback)" : ""); 824 is_rollback ? " (rollback)" : "");
828 ni = NTFS_I(vi);
829 vol = ni->vol; 825 vol = ni->vol;
830 lcnbmp_vi = vol->lcnbmp_ino; 826 lcnbmp_vi = vol->lcnbmp_ino;
831 BUG_ON(!lcnbmp_vi); 827 BUG_ON(!lcnbmp_vi);
@@ -843,7 +839,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
843 839
844 total_freed = real_freed = 0; 840 total_freed = real_freed = 0;
845 841
846 rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, write_locked); 842 rl = ntfs_attr_find_vcn_nolock(ni, start_vcn, TRUE);
847 if (IS_ERR(rl)) { 843 if (IS_ERR(rl)) {
848 if (!is_rollback) 844 if (!is_rollback)
849 ntfs_error(vol->sb, "Failed to find first runlist " 845 ntfs_error(vol->sb, "Failed to find first runlist "
@@ -897,7 +893,7 @@ s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, s64 count,
897 893
898 /* Attempt to map runlist. */ 894 /* Attempt to map runlist. */
899 vcn = rl->vcn; 895 vcn = rl->vcn;
900 rl = ntfs_attr_find_vcn_nolock(ni, vcn, write_locked); 896 rl = ntfs_attr_find_vcn_nolock(ni, vcn, TRUE);
901 if (IS_ERR(rl)) { 897 if (IS_ERR(rl)) {
902 err = PTR_ERR(rl); 898 err = PTR_ERR(rl);
903 if (!is_rollback) 899 if (!is_rollback)
@@ -965,8 +961,7 @@ err_out:
965 * If rollback fails, set the volume errors flag, emit an error 961 * If rollback fails, set the volume errors flag, emit an error
966 * message, and return the error code. 962 * message, and return the error code.
967 */ 963 */
968 delta = __ntfs_cluster_free(vi, start_vcn, total_freed, write_locked, 964 delta = __ntfs_cluster_free(ni, start_vcn, total_freed, TRUE);
969 TRUE);
970 if (delta < 0) { 965 if (delta < 0) {
971 ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving " 966 ntfs_error(vol->sb, "Failed to rollback (error %i). Leaving "
972 "inconsistent metadata! Unmount and run " 967 "inconsistent metadata! Unmount and run "
diff --git a/fs/ntfs/lcnalloc.h b/fs/ntfs/lcnalloc.h
index e4d7fb98d685..a6a8827882e7 100644
--- a/fs/ntfs/lcnalloc.h
+++ b/fs/ntfs/lcnalloc.h
@@ -2,7 +2,7 @@
2 * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the 2 * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the
3 * Linux-NTFS project. 3 * Linux-NTFS project.
4 * 4 *
5 * Copyright (c) 2004 Anton Altaparmakov 5 * Copyright (c) 2004-2005 Anton Altaparmakov
6 * 6 *
7 * This program/include file is free software; you can redistribute it and/or 7 * This program/include file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published 8 * modify it under the terms of the GNU General Public License as published
@@ -28,6 +28,7 @@
28#include <linux/fs.h> 28#include <linux/fs.h>
29 29
30#include "types.h" 30#include "types.h"
31#include "inode.h"
31#include "runlist.h" 32#include "runlist.h"
32#include "volume.h" 33#include "volume.h"
33 34
@@ -42,18 +43,17 @@ extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
42 const VCN start_vcn, const s64 count, const LCN start_lcn, 43 const VCN start_vcn, const s64 count, const LCN start_lcn,
43 const NTFS_CLUSTER_ALLOCATION_ZONES zone); 44 const NTFS_CLUSTER_ALLOCATION_ZONES zone);
44 45
45extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn, 46extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
46 s64 count, const BOOL write_locked, const BOOL is_rollback); 47 s64 count, const BOOL is_rollback);
47 48
48/** 49/**
49 * ntfs_cluster_free - free clusters on an ntfs volume 50 * ntfs_cluster_free - free clusters on an ntfs volume
50 * @vi: vfs inode whose runlist describes the clusters to free 51 * @ni: ntfs inode whose runlist describes the clusters to free
51 * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters 52 * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters
52 * @count: number of clusters to free or -1 for all clusters 53 * @count: number of clusters to free or -1 for all clusters
53 * @write_locked: true if the runlist is locked for writing
54 * 54 *
55 * Free @count clusters starting at the cluster @start_vcn in the runlist 55 * Free @count clusters starting at the cluster @start_vcn in the runlist
56 * described by the vfs inode @vi. 56 * described by the ntfs inode @ni.
57 * 57 *
58 * If @count is -1, all clusters from @start_vcn to the end of the runlist are 58 * If @count is -1, all clusters from @start_vcn to the end of the runlist are
59 * deallocated. Thus, to completely free all clusters in a runlist, use 59 * deallocated. Thus, to completely free all clusters in a runlist, use
@@ -65,19 +65,18 @@ extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn,
65 * Return the number of deallocated clusters (not counting sparse ones) on 65 * Return the number of deallocated clusters (not counting sparse ones) on
66 * success and -errno on error. 66 * success and -errno on error.
67 * 67 *
68 * Locking: - The runlist described by @vi must be locked on entry and is 68 * Locking: - The runlist described by @ni must be locked for writing on entry
69 * locked on return. Note if the runlist is locked for reading the 69 * and is locked on return. Note the runlist may be modified when
70 * lock may be dropped and reacquired. Note the runlist may be 70 * needed runlist fragments need to be mapped.
71 * modified when needed runlist fragments need to be mapped.
72 * - The volume lcn bitmap must be unlocked on entry and is unlocked 71 * - The volume lcn bitmap must be unlocked on entry and is unlocked
73 * on return. 72 * on return.
74 * - This function takes the volume lcn bitmap lock for writing and 73 * - This function takes the volume lcn bitmap lock for writing and
75 * modifies the bitmap contents. 74 * modifies the bitmap contents.
76 */ 75 */
77static inline s64 ntfs_cluster_free(struct inode *vi, const VCN start_vcn, 76static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
78 s64 count, const BOOL write_locked) 77 s64 count)
79{ 78{
80 return __ntfs_cluster_free(vi, start_vcn, count, write_locked, FALSE); 79 return __ntfs_cluster_free(ni, start_vcn, count, FALSE);
81} 80}
82 81
83extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol, 82extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
diff --git a/fs/ntfs/logfile.c b/fs/ntfs/logfile.c
index 0173e95500d9..0fd70295cca6 100644
--- a/fs/ntfs/logfile.c
+++ b/fs/ntfs/logfile.c
@@ -51,7 +51,8 @@ static BOOL ntfs_check_restart_page_header(struct inode *vi,
51 RESTART_PAGE_HEADER *rp, s64 pos) 51 RESTART_PAGE_HEADER *rp, s64 pos)
52{ 52{
53 u32 logfile_system_page_size, logfile_log_page_size; 53 u32 logfile_system_page_size, logfile_log_page_size;
54 u16 usa_count, usa_ofs, usa_end, ra_ofs; 54 u16 ra_ofs, usa_count, usa_ofs, usa_end = 0;
55 BOOL have_usa = TRUE;
55 56
56 ntfs_debug("Entering."); 57 ntfs_debug("Entering.");
57 /* 58 /*
@@ -86,6 +87,14 @@ static BOOL ntfs_check_restart_page_header(struct inode *vi,
86 (int)sle16_to_cpu(rp->minor_ver)); 87 (int)sle16_to_cpu(rp->minor_ver));
87 return FALSE; 88 return FALSE;
88 } 89 }
90 /*
91 * If chkdsk has been run the restart page may not be protected by an
92 * update sequence array.
93 */
94 if (ntfs_is_chkd_record(rp->magic) && !le16_to_cpu(rp->usa_count)) {
95 have_usa = FALSE;
96 goto skip_usa_checks;
97 }
89 /* Verify the size of the update sequence array. */ 98 /* Verify the size of the update sequence array. */
90 usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); 99 usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS);
91 if (usa_count != le16_to_cpu(rp->usa_count)) { 100 if (usa_count != le16_to_cpu(rp->usa_count)) {
@@ -102,6 +111,7 @@ static BOOL ntfs_check_restart_page_header(struct inode *vi,
102 "inconsistent update sequence array offset."); 111 "inconsistent update sequence array offset.");
103 return FALSE; 112 return FALSE;
104 } 113 }
114skip_usa_checks:
105 /* 115 /*
106 * Verify the position of the restart area. It must be: 116 * Verify the position of the restart area. It must be:
107 * - aligned to 8-byte boundary, 117 * - aligned to 8-byte boundary,
@@ -109,7 +119,8 @@ static BOOL ntfs_check_restart_page_header(struct inode *vi,
109 * - within the system page size. 119 * - within the system page size.
110 */ 120 */
111 ra_ofs = le16_to_cpu(rp->restart_area_offset); 121 ra_ofs = le16_to_cpu(rp->restart_area_offset);
112 if (ra_ofs & 7 || ra_ofs < usa_end || 122 if (ra_ofs & 7 || (have_usa ? ra_ofs < usa_end :
123 ra_ofs < sizeof(RESTART_PAGE_HEADER)) ||
113 ra_ofs > logfile_system_page_size) { 124 ra_ofs > logfile_system_page_size) {
114 ntfs_error(vi->i_sb, "$LogFile restart page specifies " 125 ntfs_error(vi->i_sb, "$LogFile restart page specifies "
115 "inconsistent restart area offset."); 126 "inconsistent restart area offset.");
@@ -402,8 +413,12 @@ static int ntfs_check_and_load_restart_page(struct inode *vi,
402 idx++; 413 idx++;
403 } while (to_read > 0); 414 } while (to_read > 0);
404 } 415 }
405 /* Perform the multi sector transfer deprotection on the buffer. */ 416 /*
406 if (post_read_mst_fixup((NTFS_RECORD*)trp, 417 * Perform the multi sector transfer deprotection on the buffer if the
418 * restart page is protected.
419 */
420 if ((!ntfs_is_chkd_record(trp->magic) || le16_to_cpu(trp->usa_count))
421 && post_read_mst_fixup((NTFS_RECORD*)trp,
407 le32_to_cpu(rp->system_page_size))) { 422 le32_to_cpu(rp->system_page_size))) {
408 /* 423 /*
409 * A multi sector tranfer error was detected. We only need to 424 * A multi sector tranfer error was detected. We only need to
@@ -615,11 +630,16 @@ is_empty:
615 * Otherwise just throw it away. 630 * Otherwise just throw it away.
616 */ 631 */
617 if (rstr2_lsn > rstr1_lsn) { 632 if (rstr2_lsn > rstr1_lsn) {
633 ntfs_debug("Using second restart page as it is more "
634 "recent.");
618 ntfs_free(rstr1_ph); 635 ntfs_free(rstr1_ph);
619 rstr1_ph = rstr2_ph; 636 rstr1_ph = rstr2_ph;
620 /* rstr1_lsn = rstr2_lsn; */ 637 /* rstr1_lsn = rstr2_lsn; */
621 } else 638 } else {
639 ntfs_debug("Using first restart page as it is more "
640 "recent.");
622 ntfs_free(rstr2_ph); 641 ntfs_free(rstr2_ph);
642 }
623 rstr2_ph = NULL; 643 rstr2_ph = NULL;
624 } 644 }
625 /* All consistency checks passed. */ 645 /* All consistency checks passed. */
diff --git a/fs/ntfs/logfile.h b/fs/ntfs/logfile.h
index 42388f95ea6d..a51f3dd0e9eb 100644
--- a/fs/ntfs/logfile.h
+++ b/fs/ntfs/logfile.h
@@ -113,7 +113,7 @@ typedef struct {
113 */ 113 */
114enum { 114enum {
115 RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002), 115 RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
116 RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */ 116 RESTART_SPACE_FILLER = const_cpu_to_le16(0xffff), /* gcc: Force enum bit width to 16. */
117} __attribute__ ((__packed__)); 117} __attribute__ ((__packed__));
118 118
119typedef le16 RESTART_AREA_FLAGS; 119typedef le16 RESTART_AREA_FLAGS;
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
index 2c32b84385a8..247586d1d5dc 100644
--- a/fs/ntfs/mft.c
+++ b/fs/ntfs/mft.c
@@ -1953,7 +1953,7 @@ restore_undo_alloc:
1953 a = ctx->attr; 1953 a = ctx->attr;
1954 a->data.non_resident.highest_vcn = cpu_to_sle64(old_last_vcn - 1); 1954 a->data.non_resident.highest_vcn = cpu_to_sle64(old_last_vcn - 1);
1955undo_alloc: 1955undo_alloc:
1956 if (ntfs_cluster_free(vol->mft_ino, old_last_vcn, -1, TRUE) < 0) { 1956 if (ntfs_cluster_free(mft_ni, old_last_vcn, -1) < 0) {
1957 ntfs_error(vol->sb, "Failed to free clusters from mft data " 1957 ntfs_error(vol->sb, "Failed to free clusters from mft data "
1958 "attribute.%s", es); 1958 "attribute.%s", es);
1959 NVolSetErrors(vol); 1959 NVolSetErrors(vol);