Skip to content

Commit c002f42

Browse files
NTFS: - Add disable_sparse mount option together with a per volume sparse
enable bit which is set appropriately and a per inode sparse disable bit which is preset on some system file inodes as appropriate. - Enforce that sparse support is disabled on NTFS volumes pre 3.0. Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
1 parent f40661b commit c002f42

9 files changed

Lines changed: 80 additions & 33 deletions

File tree

‎Documentation/filesystems/ntfs.txt‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Overview
2121
========
2222

2323
Linux-NTFS comes with a number of user-space programs known as ntfsprogs.
24-
These include mkntfs, a full-featured ntfs file system format utility,
24+
These include mkntfs, a full-featured ntfs filesystem format utility,
2525
ntfsundelete used for recovering files that were unintentionally deleted
2626
from an NTFS volume and ntfsresize which is used to resize an NTFS partition.
2727
See the web site for more information.
@@ -149,7 +149,14 @@ case_sensitive=<BOOL> If case_sensitive is specified, treat all file names as
149149
name, if it exists. If case_sensitive, you will need
150150
to provide the correct case of the short file name.
151151

152-
errors=opt What to do when critical file system errors are found.
152+
disable_sparse=<BOOL> If disable_sparse is specified, creation of sparse
153+
regions, i.e. holes, inside files is disabled for the
154+
volume (for the duration of this mount only). By
155+
default, creation of sparse regions is enabled, which
156+
is consistent with the behaviour of traditional Unix
157+
filesystems.
158+
159+
errors=opt What to do when critical filesystem errors are found.
153160
Following values can be used for "opt":
154161
continue: DEFAULT, try to clean-up as much as
155162
possible, e.g. marking a corrupt inode as

‎fs/ntfs/ChangeLog‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ ToDo/Notes:
5656
this only works until the data attribute becomes too big for the mft
5757
record after which we abort the write returning -EOPNOTSUPP from
5858
ntfs_prepare_write().
59+
- Add disable_sparse mount option together with a per volume sparse
60+
enable bit which is set appropriately and a per inode sparse disable
61+
bit which is preset on some system file inodes as appropriate.
62+
- Enforce that sparse support is disabled on NTFS volumes pre 3.0.
5963

6064
2.1.22 - Many bug and race fixes and error handling improvements.
6165

@@ -1062,7 +1066,7 @@ tng-0.0.8 - 08/03/2002 - Now using BitKeeper, http://linux-ntfs.bkbits.net/
10621066
- Further runlist merging work. (Richard Russon)
10631067
- Backwards compatibility for gcc-2.95. (Richard Russon)
10641068
- Update to kernel 2.5.5-pre1 and rediff the now tiny patch.
1065-
- Convert to new file system declaration using ->ntfs_get_sb() and
1069+
- Convert to new filesystem declaration using ->ntfs_get_sb() and
10661070
replacing ntfs_read_super() with ntfs_fill_super().
10671071
- Set s_maxbytes to MAX_LFS_FILESIZE to avoid page cache page index
10681072
overflow on 32-bit architectures.
@@ -1358,15 +1362,15 @@ tng-0.0.1 - The first useful version.
13581362
The driver is now actually useful! Yey. (-: It undoubtedly has got bugs
13591363
though and it doesn't implement accesssing compressed files yet. Also,
13601364
accessing files with attribute list attributes is not implemented yet
1361-
either. But for small or simple file systems it should work and allow
1365+
either. But for small or simple filesystems it should work and allow
13621366
you to list directories, use stat on directory entries and the file
13631367
system, open, read, mmap and llseek around in files. A big mile stone
13641368
has been reached!
13651369

13661370
tng-0.0.0 - Initial version tag.
13671371

13681372
Initial driver implementation. The driver can mount and umount simple
1369-
NTFS file systems (i.e. ones without attribute lists in the system
1373+
NTFS filesystems (i.e. ones without attribute lists in the system
13701374
files). If the mount fails there might be problems in the error handling
13711375
code paths, so be warned. Otherwise it seems to be loading the system
13721376
files nicely and the mft record read mapping/unmapping seems to be

‎fs/ntfs/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* dir.c - NTFS kernel directory operations. Part of the Linux-NTFS project.
33
*
4-
* Copyright (c) 2001-2004 Anton Altaparmakov
4+
* Copyright (c) 2001-2005 Anton Altaparmakov
55
* Copyright (c) 2002 Richard Russon
66
*
77
* This program/include file is free software; you can redistribute it and/or
@@ -610,7 +610,7 @@ MFT_REF ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
610610
// TODO: (AIA)
611611
// The algorithm embedded in this code will be required for the time when we
612612
// want to support adding of entries to directories, where we require correct
613-
// collation of file names in order not to cause corruption of the file system.
613+
// collation of file names in order not to cause corruption of the filesystem.
614614

615615
/**
616616
* ntfs_lookup_inode_by_name - find an inode in a directory given its name

‎fs/ntfs/inode.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* inode.c - NTFS kernel inode handling. Part of the Linux-NTFS project.
33
*
4-
* Copyright (c) 2001-2004 Anton Altaparmakov
4+
* Copyright (c) 2001-2005 Anton Altaparmakov
55
*
66
* This program/include file is free software; you can redistribute it and/or
77
* modify it under the terms of the GNU General Public License as published
@@ -1731,6 +1731,7 @@ int ntfs_read_inode_mount(struct inode *vi)
17311731
/* Setup the data attribute. It is special as it is mst protected. */
17321732
NInoSetNonResident(ni);
17331733
NInoSetMstProtected(ni);
1734+
NInoSetSparseDisabled(ni);
17341735
ni->type = AT_DATA;
17351736
ni->name = NULL;
17361737
ni->name_len = 0;
@@ -2279,6 +2280,8 @@ int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt)
22792280
seq_printf(sf, ",case_sensitive");
22802281
if (NVolShowSystemFiles(vol))
22812282
seq_printf(sf, ",show_sys_files");
2283+
if (!NVolSparseEnabled(vol))
2284+
seq_printf(sf, ",disable_sparse");
22822285
for (i = 0; on_errors_arr[i].val; i++) {
22832286
if (on_errors_arr[i].val & vol->on_errors)
22842287
seq_printf(sf, ",errors=%s", on_errors_arr[i].str);

‎fs/ntfs/inode.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* inode.h - Defines for inode structures NTFS Linux kernel driver. Part of
33
* the Linux-NTFS project.
44
*
5-
* Copyright (c) 2001-2004 Anton Altaparmakov
5+
* Copyright (c) 2001-2005 Anton Altaparmakov
66
* Copyright (c) 2002 Richard Russon
77
*
88
* This program/include file is free software; you can redistribute it and/or
@@ -166,6 +166,7 @@ typedef enum {
166166
NI_Sparse, /* 1: Unnamed data attr is sparse (f).
167167
1: Create sparse files by default (d).
168168
1: Attribute is sparse (a). */
169+
NI_SparseDisabled, /* 1: May not create sparse regions. */
169170
NI_TruncateFailed, /* 1: Last ntfs_truncate() call failed. */
170171
} ntfs_inode_state_bits;
171172

@@ -218,6 +219,7 @@ NINO_FNS(IndexAllocPresent)
218219
NINO_FNS(Compressed)
219220
NINO_FNS(Encrypted)
220221
NINO_FNS(Sparse)
222+
NINO_FNS(SparseDisabled)
221223
NINO_FNS(TruncateFailed)
222224

223225
/*

‎fs/ntfs/layout.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* layout.h - All NTFS associated on-disk structures. Part of the Linux-NTFS
33
* project.
44
*
5-
* Copyright (c) 2001-2004 Anton Altaparmakov
5+
* Copyright (c) 2001-2005 Anton Altaparmakov
66
* Copyright (c) 2002 Richard Russon
77
*
88
* This program/include file is free software; you can redistribute it and/or
@@ -834,7 +834,7 @@ enum {
834834
/* Note, this is a copy of the corresponding bit from the mft record,
835835
telling us whether this file has a view index present (eg. object id
836836
index, quota index, one of the security indexes or the encrypting
837-
file system related indexes). */
837+
filesystem related indexes). */
838838
};
839839

840840
typedef le32 FILE_ATTR_FLAGS;

‎fs/ntfs/super.c‎

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* super.c - NTFS kernel super block handling. Part of the Linux-NTFS project.
33
*
4-
* Copyright (c) 2001-2004 Anton Altaparmakov
4+
* Copyright (c) 2001-2005 Anton Altaparmakov
55
* Copyright (c) 2001,2002 Richard Russon
66
*
77
* This program/include file is free software; you can redistribute it and/or
@@ -41,7 +41,7 @@
4141
#include "malloc.h"
4242
#include "ntfs.h"
4343

44-
/* Number of mounted file systems which have compression enabled. */
44+
/* Number of mounted filesystems which have compression enabled. */
4545
static unsigned long ntfs_nr_compression_users;
4646

4747
/* A global default upcase table and a corresponding reference count. */
@@ -102,7 +102,7 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
102102
gid_t gid = (gid_t)-1;
103103
mode_t fmask = (mode_t)-1, dmask = (mode_t)-1;
104104
int mft_zone_multiplier = -1, on_errors = -1;
105-
int show_sys_files = -1, case_sensitive = -1;
105+
int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1;
106106
struct nls_table *nls_map = NULL, *old_nls;
107107

108108
/* I am lazy... (-8 */
@@ -162,6 +162,7 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
162162
else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
163163
else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
164164
else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
165+
else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse)
165166
else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
166167
on_errors_arr)
167168
else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes"))
@@ -291,6 +292,21 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
291292
else
292293
NVolClearCaseSensitive(vol);
293294
}
295+
if (disable_sparse != -1) {
296+
if (disable_sparse)
297+
NVolClearSparseEnabled(vol);
298+
else {
299+
if (!NVolSparseEnabled(vol) &&
300+
vol->major_ver && vol->major_ver < 3)
301+
ntfs_warning(vol->sb, "Not enabling sparse "
302+
"support due to NTFS volume "
303+
"version %i.%i (need at least "
304+
"version 3.0).", vol->major_ver,
305+
vol->minor_ver);
306+
else
307+
NVolSetSparseEnabled(vol);
308+
}
309+
}
294310
return TRUE;
295311
needs_arg:
296312
ntfs_error(vol->sb, "The %s option requires an argument.", p);
@@ -967,6 +983,7 @@ static BOOL load_and_init_mft_mirror(ntfs_volume *vol)
967983
tmp_ni = NTFS_I(tmp_ino);
968984
/* The $MFTMirr, like the $MFT is multi sector transfer protected. */
969985
NInoSetMstProtected(tmp_ni);
986+
NInoSetSparseDisabled(tmp_ni);
970987
/*
971988
* Set up our little cheat allowing us to reuse the async read io
972989
* completion handler for directories.
@@ -1122,6 +1139,7 @@ static BOOL load_and_check_logfile(ntfs_volume *vol)
11221139
/* ntfs_check_logfile() will have displayed error output. */
11231140
return FALSE;
11241141
}
1142+
NInoSetSparseDisabled(NTFS_I(tmp_ino));
11251143
vol->logfile_ino = tmp_ino;
11261144
ntfs_debug("Done.");
11271145
return TRUE;
@@ -1220,6 +1238,7 @@ static BOOL load_and_init_attrdef(ntfs_volume *vol)
12201238
iput(ino);
12211239
goto failed;
12221240
}
1241+
NInoSetSparseDisabled(NTFS_I(ino));
12231242
/* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */
12241243
i_size = i_size_read(ino);
12251244
if (i_size <= 0 || i_size > 0x7fffffff)
@@ -1439,6 +1458,7 @@ static BOOL load_system_files(ntfs_volume *vol)
14391458
iput(vol->lcnbmp_ino);
14401459
goto bitmap_failed;
14411460
}
1461+
NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino));
14421462
if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) {
14431463
iput(vol->lcnbmp_ino);
14441464
bitmap_failed:
@@ -1490,6 +1510,12 @@ static BOOL load_system_files(ntfs_volume *vol)
14901510
unmap_mft_record(NTFS_I(vol->vol_ino));
14911511
printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver,
14921512
vol->minor_ver);
1513+
if (vol->major_ver < 3 && NVolSparseEnabled(vol)) {
1514+
ntfs_warning(vol->sb, "Disabling sparse support due to NTFS "
1515+
"volume version %i.%i (need at least version "
1516+
"3.0).", vol->major_ver, vol->minor_ver);
1517+
NVolClearSparseEnabled(vol);
1518+
}
14931519
#ifdef NTFS_RW
14941520
/* Make sure that no unsupported volume flags are set. */
14951521
if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
@@ -2033,7 +2059,7 @@ static s64 get_nr_free_clusters(ntfs_volume *vol)
20332059
/**
20342060
* __get_nr_free_mft_records - return the number of free inodes on a volume
20352061
* @vol: ntfs volume for which to obtain free inode count
2036-
* @nr_free: number of mft records in file system
2062+
* @nr_free: number of mft records in filesystem
20372063
* @max_index: maximum number of pages containing set bits
20382064
*
20392065
* Calculate the number of free mft records (inodes) on the mounted NTFS
@@ -2138,13 +2164,13 @@ static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs)
21382164
/* Optimal transfer block size. */
21392165
sfs->f_bsize = PAGE_CACHE_SIZE;
21402166
/*
2141-
* Total data blocks in file system in units of f_bsize and since
2167+
* Total data blocks in filesystem in units of f_bsize and since
21422168
* inodes are also stored in data blocs ($MFT is a file) this is just
21432169
* the total clusters.
21442170
*/
21452171
sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >>
21462172
PAGE_CACHE_SHIFT;
2147-
/* Free data blocks in file system in units of f_bsize. */
2173+
/* Free data blocks in filesystem in units of f_bsize. */
21482174
size = get_nr_free_clusters(vol) << vol->cluster_size_bits >>
21492175
PAGE_CACHE_SHIFT;
21502176
if (size < 0LL)
@@ -2163,7 +2189,7 @@ static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs)
21632189
max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits)
21642190
+ 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
21652191
read_unlock_irqrestore(&mft_ni->size_lock, flags);
2166-
/* Number of inodes in file system (at this point in time). */
2192+
/* Number of inodes in filesystem (at this point in time). */
21672193
sfs->f_files = size;
21682194
/* Free inodes in fs (based on current total count). */
21692195
sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index);
@@ -2172,8 +2198,8 @@ static int ntfs_statfs(struct super_block *sb, struct kstatfs *sfs)
21722198
* File system id. This is extremely *nix flavour dependent and even
21732199
* within Linux itself all fs do their own thing. I interpret this to
21742200
* mean a unique id associated with the mounted fs and not the id
2175-
* associated with the file system driver, the latter is already given
2176-
* by the file system type in sfs->f_type. Thus we use the 64-bit
2201+
* associated with the filesystem driver, the latter is already given
2202+
* by the filesystem type in sfs->f_type. Thus we use the 64-bit
21772203
* volume serial number splitting it into two 32-bit parts. We enter
21782204
* the least significant 32-bits in f_fsid[0] and the most significant
21792205
* 32-bits in f_fsid[1].
@@ -2259,18 +2285,18 @@ static struct export_operations ntfs_export_ops = {
22592285
};
22602286

22612287
/**
2262-
* ntfs_fill_super - mount an ntfs files system
2263-
* @sb: super block of ntfs file system to mount
2288+
* ntfs_fill_super - mount an ntfs filesystem
2289+
* @sb: super block of ntfs filesystem to mount
22642290
* @opt: string containing the mount options
22652291
* @silent: silence error output
22662292
*
22672293
* ntfs_fill_super() is called by the VFS to mount the device described by @sb
2268-
* with the mount otions in @data with the NTFS file system.
2294+
* with the mount otions in @data with the NTFS filesystem.
22692295
*
22702296
* If @silent is true, remain silent even if errors are detected. This is used
2271-
* during bootup, when the kernel tries to mount the root file system with all
2272-
* registered file systems one after the other until one succeeds. This implies
2273-
* that all file systems except the correct one will quite correctly and
2297+
* during bootup, when the kernel tries to mount the root filesystem with all
2298+
* registered filesystems one after the other until one succeeds. This implies
2299+
* that all filesystems except the correct one will quite correctly and
22742300
* expectedly return an error, but nobody wants to see error messages when in
22752301
* fact this is what is supposed to happen.
22762302
*
@@ -2330,6 +2356,9 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
23302356

23312357
unlock_kernel();
23322358

2359+
/* By default, enable sparse support. */
2360+
NVolSetSparseEnabled(vol);
2361+
23332362
/* Important to get the mount options dealt with now. */
23342363
if (!parse_options(vol, (char*)opt))
23352364
goto err_out_now;
@@ -2711,7 +2740,7 @@ static int __init init_ntfs_fs(void)
27112740
ntfs_debug("NTFS driver registered successfully.");
27122741
return 0; /* Success! */
27132742
}
2714-
printk(KERN_CRIT "NTFS: Failed to register NTFS file system driver!\n");
2743+
printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n");
27152744

27162745
sysctl_err_out:
27172746
kmem_cache_destroy(ntfs_big_inode_cache);
@@ -2725,7 +2754,7 @@ static int __init init_ntfs_fs(void)
27252754
kmem_cache_destroy(ntfs_index_ctx_cache);
27262755
ictx_err_out:
27272756
if (!err) {
2728-
printk(KERN_CRIT "NTFS: Aborting NTFS file system driver "
2757+
printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver "
27292758
"registration...\n");
27302759
err = -ENOMEM;
27312760
}
@@ -2765,7 +2794,7 @@ static void __exit exit_ntfs_fs(void)
27652794
}
27662795

27672796
MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>");
2768-
MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2004 Anton Altaparmakov");
2797+
MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2005 Anton Altaparmakov");
27692798
MODULE_VERSION(NTFS_VERSION);
27702799
MODULE_LICENSE("GPL");
27712800
#ifdef DEBUG

‎fs/ntfs/sysctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* the Linux-NTFS project. Adapted from the old NTFS driver,
44
* Copyright (C) 1997 Martin von Löwis, Régis Duchesne
55
*
6-
* Copyright (c) 2002-2004 Anton Altaparmakov
6+
* Copyright (c) 2002-2005 Anton Altaparmakov
77
*
88
* This program/include file is free software; you can redistribute it and/or
99
* modify it under the terms of the GNU General Public License as published
@@ -67,7 +67,7 @@ int ntfs_sysctl(int add)
6767
return -ENOMEM;
6868
#ifdef CONFIG_PROC_FS
6969
/*
70-
* If the proc file system is in use and we are a module, need
70+
* If the proc filesystem is in use and we are a module, need
7171
* to set the owner of our proc entry to our module. In the
7272
* non-modular case, THIS_MODULE is NULL, so this is ok.
7373
*/

0 commit comments

Comments
 (0)