Commit 3c51ba14 authored by Anton Altaparmakov's avatar Anton Altaparmakov

Integrate ntfs tng with kernel now that the old driver had been removed.

parent 7ff0cd43
NTFS Overview
=============
To mount an NTFS 1.2/3.x (Windows NT4/2000/XP) volume, use the filesystem
type 'ntfs'. The driver currently works only in read-only mode, with no
fault-tolerance supported.
For ftdisk support, limited success was reported with volume sets on top of
the md driver, although mirror and stripe sets should work as well - if the
md driver can be talked into using the same layout as Windows NT. However,
using the md driver will fail if any of your NTFS partitions have an odd
number of sectors.
Supported mount options
=======================
nls=name Character set to use when returning file names.
Unlike VFAT, NTFS suppresses names that contain
unconvertible characters. Note that most character
sets contain insufficient characters to represent all
possible Unicode characters that can exist on NTFS. To
be sure you are not missing any files, you are advised
to use nls=utf8 which is capable of representing all
Unicode characters.
uid=
gid=
umask= Provide default owner, group, and access mode mask.
These options work as documented in mount(8). By
default, the files are owned by root and are not
readable by anyone else.
fmask=
dmask= Instead of specifying umask which applies both to
files and directories, fmask applies only to files and
dmask only to directories.
sloppy=<BOOL> If sloppy is specified, ignore unknown mount options.
Otherwise the default behaviour is to abort mount if
any unknown options are found.
errors=opt What to do when critical file system errors are found.
Following values can be used for "opt":
continue: DEFAULT, try to clean-up as much as
possible, e.g. marking a corrupt inode as
bad so it is no longer accessed.
recover: At present only supported is recovery of
the boot sector from the backup copy. If a
read-only mount, the recovery is done in
memory only and not written to disk.
show_inodes=opt Allows choice of which types of inode names readdir()
returns, i.e. this affects what "ls" shows. Following
values can be used for "opt":
system: show system files
win32: long file names (includes POSIX) [DEFAULT]
long: same as win32
dos: short file names only (excludes POSIX)
short: same as dos
posix: same as both win32 and dos
all: all file names
Note that the options are additive, i.e. specifying:
show_inodes=system,show_inodes=win32,show_inodes=dos
is the same as specifying:
show_inodes=all
Note that the "posix" and "all" options will show all
directory names, BUT the link count on each directory
inode entry is set to 1, due to Linux not supporting
directory hard links. This may well confuse some
userspace applications, since the directory names will
have the same inode numbers. Thus it is NOT advisable
to use the "posix" and "all" options. We provide them
only for completeness sake.
Further, note that the "system" option will not show
"$MFT" due to bugs/mis-features in glibc. Even though
it does not show, you can specifically "ls" it:
ls -l \$MFT
And of course you can stat it, too.
Further, note that irrespective of what show_inodes
option(s) you use, all files are accessible when you
specify the correct name, even though they may not be
shown in a normal "ls", i.e. you can always access the
system files and both the short and long file names of
files and directories.
Finally, note that win32 and dos file names are not
case sensitive and can be accessed using any
combination of lower and upper case, while POSIX file
names are case sensitive and they can only be accessed
given the correct case.
mft_zone_multiplier= Set the MFT zone multiplier for the volume (this
setting is not persistent across mounts and can be
changed from mount to mount but cannot be changed on
remount). Values of 1 to 4 are allowed, 1 being the
default. The MFT zone multiplier determines how much
space is reserved for the MFT on the volume. If all
other space is used up, then the MFT zone will be
shrunk dynamically, so this has no impact on the
amount of free space. However, it can have an impact
on performance by affecting fragmentation of the MFT.
In general use the default. If you have a lot of small
files then use a higher value. The values have the
following meaning:
Value MFT zone size (% of volume size)
1 12.5%
2 25%
3 37.5%
4 50%
Note this option is irrelevant for read-only mounts.
Features
========
- Implementation of NTFS read support functionally equivalent to the old ntfs
driver.
Known bugs and (mis-)features
=============================
- None
Please send bug reports/comments/feedback/abuse to the Linux-NTFS development
list at sourceforge: linux-ntfs-dev@lists.sourceforge.net
ChangeLog
=========
Note that a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog.
TNG-0.0.8:
- Started ChangeLog.
......@@ -576,6 +576,37 @@ CONFIG_HPFS_FS
say M here and read <file:Documentation/modules.txt>. If unsure,
say N.
CONFIG_NTFS_FS
NTFS is the file system of Microsoft Windows NT/2000/XP. For more
information see <file:Documentation/filesystems/ntfs.txt>. Saying Y
here would allow you to read from NTFS partitions.
This file system is also available as a module ( = code which can be
inserted in and removed from the running kernel whenever you want).
The module will be called ntfs.o. If you want to compile it as a
module, say M here and read <file:Documentation/modules.txt>. If you
are not using Windows NT/2000/XP in addition to Linux on your computer
it is safe to say N.
CONFIG_NTFS_DEBUG
If you are experiencing any problems with the NTFS file system, say
Y here. This will result in additional consistency checks to be
performed by the driver as well as additional debugging messages to
be written to the system log. Note that debugging messages are
disabled by default. To enable them, supply the option debug_msgs=1
at the kernel command line when booting the kernel or as an option
to insmod when loading the ntfs module. Once the driver is active,
you can enable debugging messages by doing (as root):
echo 1 > /proc/sys/fs/ntfs-debug
Replacing the "1" with "0" would disable debug messages.
If you leave debugging messages disable, this results in little
overhead, but enabling debug messages results in very significant
slowdown of the system.
When reporting bugs, please try to have available a full dump of
debugging messages while the misbehaviour was occurring.
CONFIG_SYSV_FS
SCO, Xenix and Coherent are commercial Unix systems for Intel
machines, and Version 7 was used on the DEC PDP-11. Saying Y
......
......@@ -62,6 +62,9 @@ tristate 'Minix fs support' CONFIG_MINIX_FS
tristate 'FreeVxFS file system support (VERITAS VxFS(TM) compatible)' CONFIG_VXFS_FS
tristate 'NTFS file system support (read only)' CONFIG_NTFS_FS
dep_mbool ' NTFS debugging support' CONFIG_NTFS_DEBUG $CONFIG_NTFS_FS
tristate 'OS/2 HPFS file system support' CONFIG_HPFS_FS
bool '/proc file system support' CONFIG_PROC_FS
......
......@@ -52,6 +52,7 @@ subdir-$(CONFIG_SYSV_FS) += sysv
subdir-$(CONFIG_SMB_FS) += smbfs
subdir-$(CONFIG_NCP_FS) += ncpfs
subdir-$(CONFIG_HPFS_FS) += hpfs
subdir-$(CONFIG_NTFS_FS) += ntfs
subdir-$(CONFIG_UFS_FS) += ufs
subdir-$(CONFIG_EFS_FS) += efs
subdir-$(CONFIG_JFFS_FS) += jffs
......
......@@ -33,7 +33,7 @@ ToDo:
in between. Either need different type of optimization as above or
need to change the read/write spinlock to a read/write semaphore.
tng-0.0.8 - Work in progress.
tng-0.0.8 - 08/03/2002 - BitKeeper ChangeSet 1.457
- Replace bdevname(sb->s_dev) with sb->s_id.
- Remove now superfluous new-line characters in all callers of
......@@ -108,6 +108,16 @@ tng-0.0.8 - Work in progress.
- Check for lowest_vcn != 0 in ntfs_read_inode() and mark the inode as
bad if found.
- Update to 2.5.6-pre2 changes in struct address_space.
- Import Sourceforge CVS repository into BitKeeper repository:
http://linux-ntfs.bkbits.net/ntfs-tng-2.5
- Update fs/Makefile, fs/Config.help, fs/Config.in, and
Documentation/filesystems/ntfs.txt for NTFS TNG.
- Create kernel configuration option controlling whether debugging
is enabled or not.
- Add the required export of end_buffer_io_sync() from the patches
directory to the kernel code.
- Update inode.c::ntfs_show_options() with show_inodes mount option.
- Update errors mount option.
tng-0.0.7 - 13/02/2002 - The driver is now feature complete for read-only!
......
......@@ -9,8 +9,9 @@ obj-m := $(O_TARGET)
EXTRA_CFLAGS = -DNTFS_VERSION=\"TNG-0.0.8\"
# Uncomment this to enable debugging code.
ifeq ($(CONFIG_NTFS_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
include $(TOPDIR)/Rules.make
/*
* compaops.c - NTFS kernel compressed attributes handling.
* Part of the Linux-NTFS project.
*
* Copyright (c) 2001 Anton Altaparmakov.
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/ntfs_fs.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
#include <linux/locks.h>
/*
* We start off with ntfs_read_compressed() from the old NTFS driver and with
* fs/isofs/compress.c::zisofs_readpage().
*
* The aim of the exercise is to have the usual page cache of a compressed
* inode as the uncompressed data. The
*/
/**
* ntfs_file_read_compressed_block - read a compressed block into the page cache
* page: locked page in the compression block(s) we need to read
*
* When we are called the page has already been verified to be locked and the
* attribute is known to be non-resident, not encrypted, but compressed.
*
* 1. Determine which compression block(s) @page is in.
* 2. Get hold of all pages corresponding to this/these compression block(s).
* 3. Read the (first) compression block.
* 4. Decompress it into the corresponding pages.
* 5. Throw the compressed data away and proceed to 3. for the next compression
* block or return success if no more compression blocks left.
*
* Warning: We have to be careful what we do about existing pages. They might
* have been written to so that we would lose data if we were to just overwrite
* them with the out-of-date uncompressed data.
*
* Note: As an efficiency/latency improvement, it might be a nice idea to
* create a kernel thread as soon as we have filled @page with data. We can
* then read the remaining pages at our leisure in the background. However,
* creation of a kernel thread might actually impact performance so much as to
* lose all the benefits of returning early... Even further so because when we
* reach that stage we probably have the whole compression block already in
* memory, unless we read the block in little chunks and handle each chunk on
* its own.
*/
int ntfs_file_read_compressed_block(struct page *page)
{
/* For the moment this will do... */
UnlockPage(page);
return -EOPNOTSUPP;
}
#if 0
// From the old NTFS driver:
/* Process compressed attributes. */
int ntfs_read_compressed(ntfs_inode *ino, ntfs_attribute *attr, __s64 offset,
ntfs_io *dest)
{
int error = 0;
int clustersizebits;
int s_vcn, rnum, vcn, got, l1;
__s64 copied, len, chunk, offs1, l, chunk2;
ntfs_cluster_t cluster, cl1;
char *comp = 0, *comp1;
char *decomp = 0;
ntfs_io io;
ntfs_runlist *rl;
l = dest->size;
clustersizebits = ino->vol->cluster_size_bits;
/* Starting cluster of potential chunk. There are three situations:
a) In a large uncompressible or sparse chunk, s_vcn is in the middle
of a run.
b) s_vcn is right on a run border.
c) When several runs make a chunk, s_vcn is before the chunks. */
s_vcn = offset >> clustersizebits;
/* Round down to multiple of 16. */
s_vcn &= ~15;
rl = attr->d.r.runlist;
for (rnum = vcn = 0; rnum < attr->d.r.len && vcn + rl->len <= s_vcn;
rnum++, rl++)
vcn += rl->len;
if (rnum == attr->d.r.len) {
/* Beyond end of file. */
/* FIXME: Check allocated / initialized. */
dest->size = 0;
return 0;
}
io.do_read = 1;
io.fn_put = ntfs_put;
io.fn_get = 0;
cluster = rl->lcn;
len = rl->len;
copied = 0;
while (l) {
chunk = 0;
if (cluster == (ntfs_cluster_t)-1) {
/* Sparse cluster. */
__s64 ll;
if ((len - (s_vcn - vcn)) & 15)
ntfs_error("Unexpected sparse chunk size.");
ll = ((__s64)(vcn + len) << clustersizebits) - offset;
if (ll > l)
ll = l;
chunk = ll;
error = ntfs_read_zero(dest, ll);
if (error)
goto out;
} else if (dest->do_read) {
if (!comp) {
comp = ntfs_malloc(16 << clustersizebits);
if (!comp) {
error = -ENOMEM;
goto out;
}
}
got = 0;
/* We might need to start in the middle of a run. */
cl1 = cluster + s_vcn - vcn;
comp1 = comp;
do {
int delta;
io.param = comp1;
delta = s_vcn - vcn;
if (delta < 0)
delta = 0;
l1 = len - delta;
if (l1 > 16 - got)
l1 = 16 - got;
io.size = (__s64)l1 << clustersizebits;
error = ntfs_getput_clusters(ino->vol, cl1, 0,
&io);
if (error)
goto out;
if (l1 + delta == len) {
rnum++;
rl++;
vcn += len;
cluster = cl1 = rl->lcn;
len = rl->len;
}
got += l1;
comp1 += (__s64)l1 << clustersizebits;
} while (cluster != (ntfs_cluster_t)-1 && got < 16);
/* Until empty run. */
chunk = 16 << clustersizebits;
if (cluster != (ntfs_cluster_t)-1 || got == 16)
/* Uncompressible */
comp1 = comp;
else {
if (!decomp) {
decomp = ntfs_malloc(16 <<
clustersizebits);
if (!decomp) {
error = -ENOMEM;
goto out;
}
}
/* Make sure there are null bytes after the
* last block. */
*(ntfs_u32*)comp1 = 0;
ntfs_decompress(decomp, comp, chunk);
comp1 = decomp;
}
offs1 = offset - ((__s64)s_vcn << clustersizebits);
chunk2 = (16 << clustersizebits) - offs1;
if (chunk2 > l)
chunk2 = l;
if (chunk > chunk2)
chunk = chunk2;
dest->fn_put(dest, comp1 + offs1, chunk);
}
l -= chunk;
copied += chunk;
offset += chunk;
s_vcn = (offset >> clustersizebits) & ~15;
if (l && offset >= ((__s64)(vcn + len) << clustersizebits)) {
rnum++;
rl++;
vcn += len;
cluster = rl->lcn;
len = rl->len;
}
}
out:
if (comp)
ntfs_free(comp);
if (decomp)
ntfs_free(decomp);
dest->size = copied;
return error;
}
/*
* When decompressing, we typically obtain more than one page
* per reference. We inject the additional pages into the page
* cache as a form of readahead.
*/
static int zisofs_readpage(struct file *file, struct page *page)
{
struct inode *inode = file->f_dentry->d_inode;
struct address_space *mapping = inode->i_mapping;
unsigned int maxpage, xpage, fpage, blockindex;
unsigned long offset;
unsigned long blockptr, blockendptr, cstart, cend, csize;
struct buffer_head *bh, *ptrbh[2];
unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
unsigned int bufshift = ISOFS_BUFFER_BITS(inode);
unsigned long bufmask = bufsize - 1;
int err = -EIO;
int i;
unsigned int header_size = inode->u.isofs_i.i_format_parm[0];
unsigned int zisofs_block_shift = inode->u.isofs_i.i_format_parm[1];
/* unsigned long zisofs_block_size = 1UL << zisofs_block_shift; */
unsigned int zisofs_block_page_shift = zisofs_block_shift-PAGE_CACHE_SHIFT;
unsigned long zisofs_block_pages = 1UL << zisofs_block_page_shift;
unsigned long zisofs_block_page_mask = zisofs_block_pages-1;
struct page *pages[zisofs_block_pages];
unsigned long index = page->index;
int indexblocks;
/* We have already been given one page, this is the one
we must do. */
xpage = index & zisofs_block_page_mask;
pages[xpage] = page;
/* The remaining pages need to be allocated and inserted */
offset = index & ~zisofs_block_page_mask;
blockindex = offset >> zisofs_block_page_shift;
maxpage = (inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
maxpage = min(zisofs_block_pages, maxpage-offset);
for ( i = 0 ; i < maxpage ; i++, offset++ ) {
if ( i != xpage ) {
pages[i] = grab_cache_page_nowait(mapping, offset);
}
page = pages[i];
if ( page ) {
ClearPageError(page);
kmap(page);
}
}
/* This is the last page filled, plus one; used in case of abort. */
fpage = 0;
/* Find the pointer to this specific chunk */
/* Note: we're not using isonum_731() here because the data is known aligned */
/* Note: header_size is in 32-bit words (4 bytes) */
blockptr = (header_size + blockindex) << 2;
blockendptr = blockptr + 4;
indexblocks = ((blockptr^blockendptr) >> bufshift) ? 2 : 1;
ptrbh[0] = ptrbh[1] = 0;
if ( isofs_get_blocks(inode, blockptr >> bufshift, ptrbh, indexblocks) != indexblocks ) {
if ( ptrbh[0] ) brelse(ptrbh[0]);
printk(KERN_DEBUG "zisofs: Null buffer on reading block table, inode = %lu, block = %lu\n",
inode->i_ino, blockptr >> bufshift);
goto eio;
}
ll_rw_block(READ, indexblocks, ptrbh);
bh = ptrbh[0];
if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
printk(KERN_DEBUG "zisofs: Failed to read block table, inode = %lu, block = %lu\n",
inode->i_ino, blockptr >> bufshift);
if ( ptrbh[1] )
brelse(ptrbh[1]);
goto eio;
}
cstart = le32_to_cpu(*(u32 *)(bh->b_data + (blockptr & bufmask)));
if ( indexblocks == 2 ) {
/* We just crossed a block boundary. Switch to the next block */
brelse(bh);
bh = ptrbh[1];
if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
printk(KERN_DEBUG "zisofs: Failed to read block table, inode = %lu, block = %lu\n",
inode->i_ino, blockendptr >> bufshift);
goto eio;
}
}
cend = le32_to_cpu(*(u32 *)(bh->b_data + (blockendptr & bufmask)));
brelse(bh);
csize = cend-cstart;
/* Now page[] contains an array of pages, any of which can be NULL,
and the locks on which we hold. We should now read the data and
release the pages. If the pages are NULL the decompressed data
for that particular page should be discarded. */
if ( csize == 0 ) {
/* This data block is empty. */
for ( fpage = 0 ; fpage < maxpage ; fpage++ ) {
if ( (page = pages[fpage]) != NULL ) {
memset(page_address(page), 0, PAGE_CACHE_SIZE);
flush_dcache_page(page);
SetPageUptodate(page);
kunmap(page);
UnlockPage(page);
if ( fpage == xpage )
err = 0; /* The critical page */
else
page_cache_release(page);
}
}
} else {
/* This data block is compressed. */
z_stream stream;
int bail = 0, left_out = -1;
int zerr;
int needblocks = (csize + (cstart & bufmask) + bufmask) >> bufshift;
int haveblocks;
struct buffer_head *bhs[needblocks+1];
struct buffer_head **bhptr;
/* Because zlib is not thread-safe, do all the I/O at the top. */
blockptr = cstart >> bufshift;
memset(bhs, 0, (needblocks+1)*sizeof(struct buffer_head *));
haveblocks = isofs_get_blocks(inode, blockptr, bhs, needblocks);
ll_rw_block(READ, haveblocks, bhs);
bhptr = &bhs[0];
bh = *bhptr++;
/* First block is special since it may be fractional.
We also wait for it before grabbing the zlib
semaphore; odds are that the subsequent blocks are
going to come in in short order so we don't hold
the zlib semaphore longer than necessary. */
if ( !bh || (wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
printk(KERN_DEBUG "zisofs: Hit null buffer, fpage = %d, xpage = %d, csize = %ld\n",
fpage, xpage, csize);
goto b_eio;
}
stream.next_in = bh->b_data + (cstart & bufmask);
stream.avail_in = min(bufsize-(cstart & bufmask), csize);
csize -= stream.avail_in;
stream.workspace = zisofs_zlib_workspace;
down(&zisofs_zlib_semaphore);
zerr = zlib_fs_inflateInit(&stream);
if ( zerr != Z_OK ) {
if ( err && zerr == Z_MEM_ERROR )
err = -ENOMEM;
printk(KERN_DEBUG "zisofs: zisofs_inflateInit returned %d\n",
zerr);
goto z_eio;
}
while ( !bail && fpage < maxpage ) {
page = pages[fpage];
if ( page )
stream.next_out = page_address(page);
else
stream.next_out = (void *)&zisofs_sink_page;
stream.avail_out = PAGE_CACHE_SIZE;
while ( stream.avail_out ) {
int ao, ai;
if ( stream.avail_in == 0 && left_out ) {
if ( !csize ) {
printk(KERN_WARNING "zisofs: ZF read beyond end of input\n");
bail = 1;
break;
} else {
bh = *bhptr++;
if ( !bh ||
(wait_on_buffer(bh), !buffer_uptodate(bh)) ) {
/* Reached an EIO */
printk(KERN_DEBUG "zisofs: Hit null buffer, fpage = %d, xpage = %d, csize = %ld\n",
fpage, xpage, csize);
bail = 1;
break;
}
stream.next_in = bh->b_data;
stream.avail_in = min(csize,bufsize);
csize -= stream.avail_in;
}
}
ao = stream.avail_out; ai = stream.avail_in;
zerr = zlib_fs_inflate(&stream, Z_SYNC_FLUSH);
left_out = stream.avail_out;
if ( zerr == Z_BUF_ERROR && stream.avail_in == 0 )
continue;
if ( zerr != Z_OK ) {
/* EOF, error, or trying to read beyond end of input */
if ( err && zerr == Z_MEM_ERROR )
err = -ENOMEM;
if ( zerr != Z_STREAM_END )
printk(KERN_DEBUG "zisofs: zisofs_inflate returned %d, inode = %lu, index = %lu, fpage = %d, xpage = %d, avail_in = %d, avail_out = %d, ai = %d, ao = %d\n",
zerr, inode->i_ino, index,
fpage, xpage,
stream.avail_in, stream.avail_out,
ai, ao);
bail = 1;
break;
}
}
if ( stream.avail_out && zerr == Z_STREAM_END ) {
/* Fractional page written before EOF. This may
be the last page in the file. */
memset(stream.next_out, 0, stream.avail_out);
stream.avail_out = 0;
}
if ( !stream.avail_out ) {
/* This page completed */
if ( page ) {
flush_dcache_page(page);
SetPageUptodate(page);
kunmap(page);
UnlockPage(page);
if ( fpage == xpage )
err = 0; /* The critical page */
else
page_cache_release(page);
}
fpage++;
}
}
zlib_fs_inflateEnd(&stream);
z_eio:
up(&zisofs_zlib_semaphore);
b_eio:
for ( i = 0 ; i < haveblocks ; i++ ) {
if ( bhs[i] )
brelse(bhs[i]);
}
}
eio:
/* Release any residual pages, do not SetPageUptodate */
while ( fpage < maxpage ) {
page = pages[fpage];
if ( page ) {
flush_dcache_page(page);
if ( fpage == xpage )
SetPageError(page);
kunmap(page);
UnlockPage(page);
if ( fpage != xpage )
page_cache_release(page);
}
fpage++;
}
/* At this point, err contains 0 or -EIO depending on the "critical" page */
return err;
}
#endif
......@@ -1349,6 +1349,13 @@ void ntfs_clear_big_inode(struct inode *vi)
return;
}
static const option_t si_readdir_opts_arr[] = {
{ SHOW_SYSTEM, "system" },
{ SHOW_WIN32, "win32" },
{ SHOW_DOS, "dos" },
{ 0, NULL }
};
/**
* ntfs_show_options - show mount options in /proc/mounts
* @sf: seq_file in which to write our mount options
......@@ -1363,6 +1370,7 @@ int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt)
{
ntfs_volume *vol = NTFS_SB(mnt->mnt_sb);
int i;
char *s;
seq_printf(sf, ",uid=%i", vol->uid);
seq_printf(sf, ",gid=%i", vol->gid);
......@@ -1372,14 +1380,26 @@ int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt)
seq_printf(sf, ",fmask=0%o", vol->fmask);
seq_printf(sf, ",dmask=0%o", vol->dmask);
}
seq_printf(sf, ",mft_zone_multiplier=%i", vol->mft_zone_multiplier);
seq_printf(sf, ",nls=%s", vol->nls_map->charset);
for (i = 0; on_errors_arr[i].val; i++) {
if (on_errors_arr[i].val == vol->on_errors) {
seq_printf(sf, ",errors=%s", on_errors_arr[i].str);
switch (vol->readdir_opts) {
case SHOW_ALL:
seq_printf(sf, ",show_inodes=all");
break;
case SHOW_POSIX:
seq_printf(sf, ",show_inodes=posix");
break;
default:
for (i = 0; si_readdir_opts_arr[i].val; i++) {
if (si_readdir_opts_arr[i].val & vol->readdir_opts)
seq_printf(sf, ",show_inodes=%s",
si_readdir_opts_arr[i].str);
}
}
for (i = 0; on_errors_arr[i].val; i++) {
if (on_errors_arr[i].val & vol->on_errors)
seq_printf(sf, ",errors=%s", on_errors_arr[i].str);
}
seq_printf(sf, ",mft_zone_multiplier=%i", vol->mft_zone_multiplier);
return 0;
}
......@@ -36,9 +36,11 @@ static unsigned long ntfs_nr_compression_users = 0;
/* Error constants/strings used in inode.c::ntfs_show_options(). */
typedef enum {
/* One of these must be present, default is ON_ERRORS_CONTINUE. */
ON_ERRORS_PANIC = 0x01,
ON_ERRORS_REMOUNT_RO = 0x02,
ON_ERRORS_CONTINUE = 0x04,
/* Optional, can be combined with any of the above. */
ON_ERRORS_RECOVER = 0x10,
} ON_ERRORS_ACTIONS;
......@@ -47,9 +49,6 @@ const option_t on_errors_arr[] = {
{ ON_ERRORS_REMOUNT_RO, "remount-ro", },
{ ON_ERRORS_CONTINUE, "continue", },
{ ON_ERRORS_RECOVER, "recover" },
{ ON_ERRORS_RECOVER | ON_ERRORS_PANIC, "recover_or_panic" },
{ ON_ERRORS_RECOVER | ON_ERRORS_REMOUNT_RO, "recover_or_remount-ro" },
{ ON_ERRORS_RECOVER | ON_ERRORS_CONTINUE, "recover_or_continue" },
{ 0, NULL }
};
......@@ -288,8 +287,8 @@ static BOOL parse_options(ntfs_volume *vol, char *opt)
vol->mft_zone_multiplier = 1;
if (on_errors != -1)
vol->on_errors = on_errors;
if (!vol->on_errors)
vol->on_errors = ON_ERRORS_CONTINUE;
if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER)
vol->on_errors |= ON_ERRORS_CONTINUE;
if (uid != (uid_t)-1)
vol->uid = uid;
if (gid != (gid_t)-1)
......@@ -1837,7 +1836,7 @@ static int __init init_ntfs_fs(void)
#ifdef MODULE
" MODULE"
#endif
"]. Copyright (c) 2001 Anton Altaparmakov.\n");
"]. Copyright (c) 2001,2002 Anton Altaparmakov.\n");
ntfs_debug("Debug messages are enabled.");
......
/*
* ntfs_fs.h - Defines for NTFS Linux kernel driver. Part of the Linux-NTFS
* project.
*
* Copyright (c) 2001 Anton Altaparmakov.
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_NTFS_FS_H
#define _LINUX_NTFS_FS_H
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/ntfs_layout.h>
#include <linux/vmalloc.h> /* For __vmalloc() and PAGE_KERNEL. */
#include <linux/nls.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
typedef enum {
NTFS_BLOCK_SIZE = 512,
NTFS_BLOCK_SIZE_BITS = 9,
NTFS_SB_MAGIC = 0x5346544e, /* 'NTFS' */
NTFS_MAX_NAME_LEN = 255,
} NTFS_CONSTANTS;
typedef enum {
FALSE = 0,
TRUE = 1
} BOOL;
typedef enum {
LCN_HOLE = -1,
LCN_RL_NOT_MAPPED = -2,
LCN_ENOENT = -3,
LCN_EINVAL = -4,
} LCN_SPECIAL_VALUES;
typedef enum {
CASE_SENSITIVE = 0,
IGNORE_CASE = 1,
} IGNORE_CASE_BOOL;
/*
* Defined bits for the state field in the ntfs_inode_info structure.
* (f) = files only, (d) = directories only
*/
typedef enum {
NI_Dirty, /* 1: Mft record needs to be written to disk. */
NI_AttrList, /* 1: Mft record contains an attribute list. */
NI_NonResident, /* 1: Unnamed data attr is non-resident (f).
1: $I30 index alloc attr is present (d). */
NI_Compressed, /* 1: Unnamed data attr is compressed (f). */
NI_Encrypted, /* 1: Unnamed data attr is encrypted (f). */
NI_BmpNonResident, /* 1: $I30 bitmap attr is non resident (d). */
} ntfs_inode_state_bits;
/*
* NOTE: We should be adding dirty mft records to a list somewhere and they
* should be independent of the (ntfs/vfs) inode structure so that an inode can
* be removed but the record can be left dirty for syncing later.
*/
#define NInoDirty(n_ino) test_bit(NI_Dirty, &(n_ino)->state)
#define NInoSetDirty(n_ino) set_bit(NI_Dirty, &(n_ino)->state)
#define NInoClearDirty(n_ino) clear_bit(NI_Dirty, &(n_ino)->state)
#define NInoAttrList(n_ino) test_bit(NI_AttrList, &(n_ino)->state)
#define NInoNonResident(n_ino) test_bit(NI_NonResident, &(n_ino)->state)
#define NInoIndexAllocPresent(n_ino) test_bit(NI_NonResident, &(n_ino)->state)
#define NInoCompressed(n_ino) test_bit(NI_Compressed, &(n_ino)->state)
#define NInoEncrypted(n_ino) test_bit(NI_Encrypted, &(n_ino)->state)
#define NInoBmpNonResident(n_ino) test_bit(NI_Encrypted, &(n_ino)->state)
/* Global variables. */
/* Slab cache of Unicode name strings (from super.c). */
extern kmem_cache_t *ntfs_name_cache;
/* The little endian Unicode string $I30 as a global constant. */
extern const uchar_t $I30[5];
/* The various operations structs defined throughout the driver files. */
extern struct super_operations ntfs_sops;
extern struct file_operations ntfs_file_ops;
extern struct inode_operations ntfs_file_inode_ops;
extern struct address_space_operations ntfs_file_aops;
extern struct file_operations ntfs_dir_ops;
extern struct inode_operations ntfs_dir_inode_ops;
extern struct address_space_operations ntfs_dir_aops;
extern struct file_operations ntfs_empty_file_ops;
extern struct inode_operations ntfs_empty_inode_ops;
extern struct address_space_operations ntfs_empty_aops;
extern struct address_space_operations ntfs_mftbmp_aops;
/* The classical max and min macros. */
#ifndef max
#define max(a, b) ((a) >= (b) ? (a): (b))
#endif
#ifndef min
#define min(a, b) ((a) <= (b) ? (a): (b))
#endif
/* Generic macro to convert pointers to values for comparison purposes. */
#ifndef p2n
#define p2n(p) ((ptrdiff_t)((ptrdiff_t*)(p)))
#endif
/**
* vmalloc_nofs - allocate any pages but don't allow calls into fs layer
* @size: number of bytes to allocate
*
* Allocate any pages but don't allow calls into fs layer.
*/
static inline void *vmalloc_nofs(unsigned long size)
{
return __vmalloc(size, GFP_NOFS | __GFP_HIGHMEM, PAGE_KERNEL);
}
/**
* NTFS_SB - return the ntfs super block given a vfs super block
* @sb: VFS super block
*
* NTFS_SB() returns the ntfs super block associated with the VFS super block
* @sb. This function is here in case it is decided to get rid of the big union
* in the struct super_block definition in include/linux/fs.h in favour of using
* the generic_sbp field (or whatever).
*/
static inline struct ntfs_sb_info *NTFS_SB(struct super_block *sb)
{
return &sb->u.ntfs_sb;
}
/**
* NTFS_I - return the ntfs inode given a vfs inode
* @inode: VFS inode
*
* NTFS_I() returns the ntfs inode associated with the VFS @inode. This
* function is here in case it is decided to get rid of the big union in the
* struct inode definition in include/linux/fs.h in favour of using the
* generic_ip field (or whatever).
*/
static inline struct ntfs_inode_info *NTFS_I(struct inode *inode)
{
return &inode->u.ntfs_i;
}
#if 0 /* Fool kernel-doc since it doesn't do macros yet */
/**
* ntfs_debug - write a debug level message to syslog
* @f: a printf format string containing the message
* @...: the variables to substitute into @f
*
* ntfs_debug() writes a DEBUG level message to the syslog but only if the
* driver was compiled with -DDEBUG. Otherwise, the call turns into a NOP.
*/
static void ntfs_debug(const char *f, ...);
#endif
#ifdef DEBUG
#define ntfs_debug(f, a...) \
do { \
printk(KERN_DEBUG "NTFS-fs DEBUG (%s, %d): %s: ", \
__FILE__, __LINE__, __FUNCTION__); \
printk(f, ##a); \
} while (0)
#else /* !DEBUG */
#define ntfs_debug(f, a...) do {} while (0)
#endif /* !DEBUG */
/*
* Signed endianness conversion defines.
*/
#define sle16_to_cpu(x) ((__s16)__le16_to_cpu((__s16)(x)))
#define sle32_to_cpu(x) ((__s32)__le32_to_cpu((__s32)(x)))
#define sle64_to_cpu(x) ((__s64)__le64_to_cpu((__s64)(x)))
#define sle16_to_cpup(x) ((__s16)__le16_to_cpu(*(__s16*)(x)))
#define sle32_to_cpup(x) ((__s32)__le32_to_cpu(*(__s32*)(x)))
#define sle64_to_cpup(x) ((__s64)__le64_to_cpu(*(__s64*)(x)))
#define cpu_to_sle16(x) ((__s16)__cpu_to_le16((__s16)(x)))
#define cpu_to_sle32(x) ((__s32)__cpu_to_le32((__s32)(x)))
#define cpu_to_sle64(x) ((__s64)__cpu_to_le64((__s64)(x)))
#define cpu_to_sle16p(x) ((__s16)__cpu_to_le16(*(__s16*)(x)))
#define cpu_to_sle32p(x) ((__s32)__cpu_to_le32(*(__s32*)(x)))
#define cpu_to_sle64p(x) ((__s64)__cpu_to_le64(*(__s64*)(x)))
/**
* ntfs_unmap_page - release a page that was mapped using ntfs_map_page()
* @page: the page to release
*
* Unpin, unmap and release a page that was obtained from ntfs_map_page().
*/
static inline void ntfs_unmap_page(struct page *page)
{
kunmap(page);
page_cache_release(page);
}
/**
* ntfs_map_page - map a page into accessible memory, reading it if necessary
* @mapping: address space for which to obtain the page
* @index: index into the page cache for @mapping of the page to map
*
* Read a page from the page cache of the address space @mapping at position
* @index, where @index is in units of PAGE_CACHE_SIZE, and not in bytes.
*
* If the page is not in memory it is loaded from disk first using the readpage
* method defined in the address space operations of @mapping and the page is
* added to the page cache of @mapping in the process.
*
* If the page is in high memory it is mapped into memory directly addressible
* by the kernel.
*
* Finally the page count is incremented, thus pinning the page into place.
*
* The above means that page_address(page) can be used on all pages obtained
* with ntfs_map_page() to get the kernel virtual address of the page.
*
* When finished with the page, the caller has to call ntfs_unmap_page() to
* unpin, unmap and release the page.
*
* Note this does not grant exclusive access. If such is desired, the caller
* must provide it independently of the ntfs_{un}map_page() calls by using
* a {rw_}semaphore or other means of serialization. A spin lock cannot be
* used as ntfs_map_page() can block.
*
* The unlocked and uptodate page is returned on success or an encoded error
* on failure. Caller has to test for error using the IS_ERR() macro on the
* return value. If that evaluates to TRUE, the negative error code can be
* obtained using PTR_ERR() on the return value of ntfs_map_page().
*/
static inline struct page *ntfs_map_page(struct address_space *mapping,
unsigned long index)
{
struct page *page = read_cache_page(mapping, index,
(filler_t*)mapping->a_ops->readpage, NULL);
if (!IS_ERR(page)) {
wait_on_page(page);
kmap(page);
if (Page_Uptodate(page) && !PageError(page))
return page;
ntfs_unmap_page(page);
return ERR_PTR(-EIO);
}
return page;
}
/**
* attr_search_context - used in attribute search functions
* @mrec: buffer containing mft record to search
* @attr: attribute record in @mrec where to begin/continue search
* @is_first: if true lookup_attr() begins search with @attr, else after @attr
*
* Structure must be initialized to zero before the first call to one of the
* attribute search functions. Initialize @mrec to point to the mft record to
* search, and @attr to point to the first attribute within @mrec (not necessary
* if calling the _first() functions), and set @is_first to TRUE (not necessary
* if calling the _first() functions).
*
* If @is_first is TRUE, the search begins with @attr. If @is_first is FALSE,
* the search begins after @attr. This is so that, after the first call to one
* of the search attribute functions, we can call the function again, without
* any modification of the search context, to automagically get the next
* matching attribute.
*/
typedef struct {
MFT_RECORD *mrec;
ATTR_RECORD *attr;
BOOL is_first;
} attr_search_context;
/* Declarations of functions and global variables. */
/* From fs/ntfs/aops.c */
extern int ntfs_file_get_block(struct inode *vfs_ino, const long blk,
struct buffer_head *bh, const int create);
/* From fs/ntfs/compaops.c */
extern int ntfs_file_read_compressed_block(struct page *page);
/* From fs/ntfs/super.c */
#define default_upcase_len 0x10000
extern wchar_t *default_upcase;
extern unsigned long ntfs_nr_upcase_users;
extern unsigned long ntfs_nr_mounts;
extern struct semaphore ntfs_lock;
/* From fs/ntfs/mst.c */
extern inline void __post_read_mst_fixup(NTFS_RECORD *b, const __u32 size);
extern int post_read_mst_fixup(NTFS_RECORD *b, const __u32 size);
extern int pre_write_mst_fixup(NTFS_RECORD *b, const __u32 size);
/* From fs/ntfs/time.c */
extern inline __s64 utc2ntfs(const time_t time);
extern inline __s64 get_current_ntfs_time(void);
extern inline time_t ntfs2utc(const __s64 time);
/* From fs/ntfs/debug.c */
void ntfs_warning(const struct super_block *sb, const char *fmt, ...);
void ntfs_error(const struct super_block *sb, const char *fmt, ...);
/* From fs/ntfs/inode.c */
void ntfs_read_inode(struct inode *vfs_ino);
void ntfs_read_inode_mount(struct inode *vfs_ino);
void ntfs_dirty_inode(struct inode *vfs_ino);
void ntfs_clear_inode(struct inode *vfs_ino);
/* From fs/ntfs/dir.c */
__u64 ntfs_lookup_ino_by_name(struct inode *dir_ino, const uchar_t *uname,
const int uname_len);
/* From fs/ntfs/attrib.c */
run_list *decompress_mapping_pairs(const ATTR_RECORD *attr, run_list *run_list);
LCN vcn_to_lcn(const run_list *rl, const VCN vcn);
BOOL find_attr(const ATTR_TYPES type, const uchar_t *name, const __u32 name_len,
const IGNORE_CASE_BOOL ic, const uchar_t *upcase,
const __u32 upcase_len, const __u8 *val, const __u32 val_len,
attr_search_context *ctx);
extern inline BOOL find_first_attr(const ATTR_TYPES type, const uchar_t *name,
const __u32 name_len, const IGNORE_CASE_BOOL ic,
const uchar_t *upcase, const __u32 upcase_len,
const __u8 *val, const __u32 val_len, attr_search_context *ctx);
/* From fs/ntfs/mft.c */
int format_mft_record(struct inode *vfs_ino, MFT_RECORD *m);
int format_mft_record2(struct super_block *vfs_sb, const unsigned long inum,
MFT_RECORD *m);
MFT_RECORD *map_mft_record_for_read(struct inode *vfs_ino);
MFT_RECORD *map_mft_record_for_read2(struct super_block *vfs_sb,
const unsigned long inum, struct inode **vfs_ino);
MFT_RECORD *map_mft_record_for_write(struct inode *vfs_ino);
MFT_RECORD *map_mft_record_for_write2(struct super_block *vfs_sb,
const unsigned long inum, struct inode **vfs_ino);
void unmap_mft_record_from_read(struct inode *vfs_ino);
void unmap_mft_record_from_write(struct inode *vfs_ino);
/* From fs/ntfs/unistr.c */
BOOL ntfs_are_names_equal(const uchar_t *s1, size_t s1_len,
const uchar_t *s2, size_t s2_len,
const IGNORE_CASE_BOOL ic,
const uchar_t *upcase, const __u32 upcase_size);
int ntfs_collate_names(const uchar_t *name1, const __u32 name1_len,
const uchar_t *name2, const __u32 name2_len,
const int err_val, const IGNORE_CASE_BOOL ic,
const uchar_t *upcase, const __u32 upcase_len);
int ntfs_ucsncmp(const uchar_t *s1, const uchar_t *s2, size_t n);
int ntfs_ucsncasecmp(const uchar_t *s1, const uchar_t *s2, size_t n,
const uchar_t *upcase, const __u32 upcase_size);
void ntfs_upcase_name(uchar_t *name, __u32 name_len, const uchar_t *upcase,
const __u32 upcase_len);
void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
const uchar_t *upcase, const __u32 upcase_len);
int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
FILE_NAME_ATTR *file_name_attr2,
const int err_val, const IGNORE_CASE_BOOL ic,
const uchar_t *upcase, const __u32 upcase_len);
int ntfs_nlstoucs(const struct ntfs_sb_info *vol, const char *ins,
const int ins_len, uchar_t **outs);
int ntfs_ucstonls(const struct ntfs_sb_info *vol, const uchar_t *ins,
const int ins_len, unsigned char **outs, int outs_len);
/* From fs/ntfs/upcase.c */
uchar_t *generate_default_upcase(void);
#endif /* _LINUX_NTFS_FS_H */
#ifndef _LINUX_NTFS_FS_I_H
#define _LINUX_NTFS_FS_I_H
/*
* Clusters are signed 64-bit values on NTFS volumes. We define two types, LCN
* and VCN, to allow for type checking and better code readability.
*/
typedef __s64 VCN;
typedef __s64 LCN;
/**
* run_list - in memory vcn to lcn mapping array
* @vcn: starting vcn of the current array element
* @lcn: starting lcn of the current array element
* @length: length in clusters of the current array element
*
* The last vcn (in fact the last vcn + 1) is reached when length == 0.
*
* When lcn == -1 this means that the count vcns starting at vcn are not
* physically allocated (i.e. this is a hole / data is sparse).
*/
typedef struct { /* In memory vcn to lcn mapping structure element. */
VCN vcn; /* vcn = Starting virtual cluster number. */
LCN lcn; /* lcn = Starting logical cluster number. */
__s64 length; /* Run length in clusters. */
} run_list;
/*
* The NTFS in-memory inode structure. It is just used as an extension to the
* fields already provided in the VFS inode.
*/
struct ntfs_inode_info {
struct inode *inode; /* Pointer to the inode structure of this
ntfs_inode_info structure. */
unsigned long state; /* NTFS specific flags describing this inode.
See fs/ntfs/ntfs.h:ntfs_inode_state_bits. */
run_list *run_list; /* If state has the NI_NonResident bit set,
the run list of the unnamed data attribute
(if a file) or of the index allocation
attribute (directory). If run_list is NULL,
the run list has not been read in or has
been unmapped. If NI_NonResident is clear,
the unnamed data attribute is resident (file)
or there is no $I30 index allocation
attribute (directory). In that case run_list
is always NULL.*/
__s32 nr_extents; /* The number of extents[], if this is a base
mft record, -1 if this is an extent record,
and 0 if there are no extents. */
struct rw_semaphore mrec_lock; /* Lock for serializing access to the
mft record belonging to this inode. */
struct page *page; /* The page containing the mft record of the
inode. This should only be touched by the
(un)map_mft_record_for_*() functions. Do NOT
touch from anywhere else or the ntfs divil
will appear and take your heart out with a
blunt spoon! You have been warned. (-8 */
union {
struct { /* It is a directory. */
__u32 index_block_size; /* Size of an index block. */
__u8 index_block_size_bits; /* Log2 of the size of an
an index block. */
__s64 bmp_size; /* Size of the $I30 bitmap. */
run_list *bmp_rl; /* Run list for the $I30 bitmap
if it is non-resident. */
};
struct { /* It is a compressed file. */
__u32 compression_block_size; /* Size of a compression
block (cb). */
__u8 compression_block_size_bits; /* Log2 of the size
of a cb. */
__u8 compression_block_clusters; /* Number of clusters
per compression
block. */
};
};
union { /* This union is only used if nr_extents != 0. */
struct { /* nr_extents > 0 */
__s64 i_ino; /* The inode number of the
extent mft record. */
__u32 i_generation; /* The i_generation of the
extent mft record. */
} *extents; /* The currently known of extents, sorted in
ascending order. */
struct { /* nr_exents == -1 */
__s64 i_ino; /* The inode number of the base
mft record of this extent. */
__u32 i_generation; /* The i_generation of the base
mft record. */
} base; /* The base mft record of this extent. */
};
};
#endif /* _LINUX_NTFS_FS_I_H */
#ifndef _LINUX_NTFS_FS_SB_H
#define _LINUX_NTFS_FS_SB_H
/* 2-byte Unicode character type. */
typedef __u16 uchar_t;
/*
* The NTFS in memory super block structure.
*/
struct ntfs_sb_info {
/*
* FIXME: Reorder to have commonly used together element within the
* same cache line, aiming at a cache line size of 32 bytes. Aim for
* 64 bytes for less commonly used together elements. Put most commonly
* used elements to front of structure. Obviously do this only when the
* structure has stabilized... (AIA)
*/
/* Device specifics. */
struct super_block *sb; /* Pointer back to the super_block,
so we don't have to get the offset
every time. */
LCN nr_blocks; /* Number of NTFS_BLOCK_SIZE bytes
sized blocks on the device. */
/* Configuration provided by user at mount time. */
uid_t uid; /* uid that files will be mounted as. */
gid_t gid; /* gid that files will be mounted as. */
mode_t fmask; /* The mask for file permissions. */
mode_t dmask; /* The mask for directory
permissions. */
__u8 mft_zone_multiplier; /* Initial mft zone multiplier. */
__u8 on_errors; /* What to do on file system errors. */
/* NTFS bootsector provided information. */
__u16 sector_size; /* in bytes */
__u8 sector_size_bits; /* log2(sector_size) */
__u32 cluster_size; /* in bytes */
__u32 cluster_size_mask; /* cluster_size - 1 */
__u8 cluster_size_bits; /* log2(cluster_size) */
__u32 mft_record_size; /* in bytes */
__u32 mft_record_size_mask; /* mft_record_size - 1 */
__u8 mft_record_size_bits; /* log2(mft_record_size) */
__u32 index_record_size; /* in bytes */
__u32 index_record_size_mask; /* index_record_size - 1 */
__u8 index_record_size_bits; /* log2(index_record_size) */
union {
LCN nr_clusters; /* Volume size in clusters. */
LCN nr_lcn_bits; /* Number of bits in lcn bitmap. */
};
LCN mft_lcn; /* Cluster location of mft data. */
LCN mftmirr_lcn; /* Cluster location of copy of mft. */
__u64 serial_no; /* The volume serial number. */
/* Mount specific NTFS information. */
__u32 upcase_len; /* Number of entries in upcase[]. */
uchar_t *upcase; /* The upcase table. */
LCN mft_zone_start; /* First cluster of the mft zone. */
LCN mft_zone_end; /* First cluster beyond the mft zone. */
struct inode *mft_ino; /* The VFS inode of $MFT. */
struct rw_semaphore mftbmp_lock; /* Lock for serializing accesses to the
mft record bitmap ($MFT/$BITMAP). */
union {
__s64 nr_mft_records; /* Number of records in the mft. */
__s64 nr_mft_bits; /* Number of bits in mft bitmap. */
};
struct address_space mftbmp_mapping; /* Page cache for $MFT/$BITMAP. */
run_list *mftbmp_rl; /* Run list for $MFT/$BITMAP. */
struct inode *mftmirr_ino; /* The VFS inode of $MFTMirr. */
struct inode *lcnbmp_ino; /* The VFS inode of $Bitmap. */
struct rw_semaphore lcnbmp_lock; /* Lock for serializing accesses to the
cluster bitmap ($Bitmap/$DATA). */
struct inode *vol_ino; /* The VFS inode of $Volume. */
unsigned long vol_flags; /* Volume flags (VOLUME_*). */
__u8 major_ver; /* Ntfs major version of volume. */
__u8 minor_ver; /* Ntfs minor version of volume. */
struct inode *root_ino; /* The VFS inode of the root
directory. */
struct inode *secure_ino; /* The VFS inode of $Secure (NTFS3.0+
only, otherwise NULL). */
struct nls_table *nls_map;
};
#endif /* _LINUX_NTFS_FS_SB_H */
/*
* ntfs_layout.h - All NTFS associated on-disk structures. Part of the
* Linux-NTFS project.
*
* Copyright (c) 2001 Anton Altaparmakov.
*
* This program/include file is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program/include file is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_NTFS_LAYOUT_H
#define _LINUX_NTFS_LAYOUT_H
#include <linux/types.h>
#include <linux/bitops.h>
#include <linux/list.h>
#include <asm/byteorder.h>
/*
* Constant endianness conversion defines.
*/
#define const_le16_to_cpu(x) __constant_le16_to_cpu(x)
#define const_le32_to_cpu(x) __constant_le32_to_cpu(x)
#define const_le64_to_cpu(x) __constant_le64_to_cpu(x)
#define const_cpu_to_le16(x) __constant_cpu_to_le16(x)
#define const_cpu_to_le32(x) __constant_cpu_to_le32(x)
#define const_cpu_to_le64(x) __constant_cpu_to_le64(x)
/* The NTFS oem_id */
#define magicNTFS const_cpu_to_le64(0x202020205346544e) /* "NTFS " */
/*
* Location of bootsector on partition:
* The standard NTFS_BOOT_SECTOR is on sector 0 of the partition.
* On NT4 and above there is one backup copy of the boot sector to
* be found on the last sector of the partition (not normally accessible
* from within Windows as the bootsector contained number of sectors
* value is one less than the actual value!).
* On versions of NT 3.51 and earlier, the backup copy was located at
* number of sectors/2 (integer divide), i.e. in the middle of the volume.
*/
/*
* BIOS parameter block (bpb) structure.
*/
typedef struct {
__u16 bytes_per_sector; /* Size of a sector in bytes. */
__u8 sectors_per_cluster; /* Size of a cluster in sectors. */
__u16 reserved_sectors; /* zero */
__u8 fats; /* zero */
__u16 root_entries; /* zero */
__u16 sectors; /* zero */
__u8 media_type; /* 0xf8 = hard disk */
__u16 sectors_per_fat; /* zero */
__u16 sectors_per_track; /* irrelevant */
__u16 heads; /* irrelevant */
__u32 hidden_sectors; /* zero */
__u32 large_sectors; /* zero */
} __attribute__ ((__packed__)) BIOS_PARAMETER_BLOCK;
/*
* NTFS boot sector structure.
*/
typedef struct {
__u8 jump[3]; /* Irrelevant (jump to boot up code).*/
__u64 oem_id; /* Magic "NTFS ". */
BIOS_PARAMETER_BLOCK bpb; /* See BIOS_PARAMETER_BLOCK. */
__u8 unused[4]; /* zero */
__s64 number_of_sectors; /* Number of sectors in volume. Gives
maximum volume size of 2^63 sectors.
Assuming standard sector size of 512
bytes, the maximum byte size is
approx. 4.7x10^21 bytes. (-; */
__s64 mft_lcn; /* Cluster location of mft data. */
__s64 mftmirr_lcn; /* Cluster location of copy of mft. */
__s8 clusters_per_mft_record; /* Mft record size in clusters. */
__u8 reserved0[3]; /* zero */
__s8 clusters_per_index_record;/* Index block size in clusters. */
__u8 reserved1[3]; /* zero */
__u64 volume_serial_number; /* Irrelevant (serial number). */
__u32 checksum; /* Boot sector checksum. */
__u8 bootstrap[426]; /* Irrelevant (boot up code). */
__u16 end_of_sector_marker; /* End of bootsector magic. Always is
0xaa55 in little endian. */
} __attribute__ ((__packed__)) NTFS_BOOT_SECTOR;
/*
* Magic identifiers present at the beginning of all ntfs record containing
* records (like mft records for example).
*/
typedef enum {
magic_BAAD = const_cpu_to_le32(0x44414142), /* BAAD == corrupt record */
magic_CHKD = const_cpu_to_le32(0x424b4843), /* CHKD == chkdsk ??? */
magic_FILE = const_cpu_to_le32(0x454c4946), /* FILE == mft entry */
magic_HOLE = const_cpu_to_le32(0x454c4f48), /* HOLE == ? (NTFS 3.0+?) */
magic_INDX = const_cpu_to_le32(0x58444e49), /* INDX == index buffer */
} NTFS_RECORD_TYPES;
/*
* Generic magic comparison macros. Finally found a use for the ## preprocessor
* operator! (-8
*/
#define is_magic(x, m) ( (__u32)(x) == magic_##m )
#define is_magicp(p, m) ( *(__u32*)(p) == magic_##m )
/*
* Specialised magic comparison macros.
*/
#define is_baad_record(x) ( is_magic (x, BAAD) )
#define is_baad_recordp(p) ( is_magicp(p, BAAD) )
#define is_chkd_record(x) ( is_magic (x, CHKD) )
#define is_chkd_recordp(p) ( is_magicp(p, CHKD) )
#define is_file_record(x) ( is_magic (x, FILE) )
#define is_file_recordp(p) ( is_magicp(p, FILE) )
#define is_hole_record(x) ( is_magic (x, HOLE) )
#define is_hole_recordp(p) ( is_magicp(p, HOLE) )
#define is_indx_record(x) ( is_magic (x, INDX) )
#define is_indx_recordp(p) ( is_magicp(p, INDX) )
#define is_mft_record(x) ( is_file_record(x) )
#define is_mft_recordp(p) ( is_file_recordp(p) )
/*
* The Update Sequence Array (usa) is an array of the __u16 values which belong
* to the end of each sector protected by the update sequence record in which
* this array is contained. Note that the first entry is the Update Sequence
* Number (usn), a cyclic counter of how many times the protected record has
* been written to disk. The values 0 and -1 (ie. 0xffff) are not used. All
* last __u16's of each sector have to be equal to the usn (during reading) or
* are set to it (during writing). If they are not, an incomplete multi sector
* transfer has occured when the data was written.
* The maximum size for the update sequence array is fixed to:
* maximum size = usa_ofs + (usa_count * 2) = 510 bytes
* The 510 bytes comes from the fact that the last __u16 in the array has to
* (obviously) finish before the last __u16 of the first 512-byte sector.
* This formula can be used as a consistency check in that usa_ofs +
* (usa_count * 2) has to be less than or equal to 510.
*/
typedef struct {
NTFS_RECORD_TYPES magic; /* A four-byte magic identifying the
record type and/or status. */
__u16 usa_ofs; /* Offset to the Update Sequence Array (usa)
from the start of the ntfs record. */
__u16 usa_count; /* Number of __u16 sized entries in the usa
including the Update Sequence Number (usn),
thus the number of fixups is the usa_count
minus 1. */
} __attribute__ ((__packed__)) NTFS_RECORD;
/*
* System files mft record numbers. All these files are always marked as used
* in the bitmap attribute of the mft; presumably in order to avoid accidental
* allocation for random other mft records. Also, the sequence number for each
* of the system files is always equal to their mft record number and it is
* never modified.
*/
typedef enum {
FILE_MFT = 0, /* Master file table (mft). Data attribute
contains the entries and bitmap attribute
records which ones are in use (bit==1). */
FILE_MFTMirr = 1, /* Mft mirror (copy of first four mft records)
in data attribute. */
FILE_LogFile = 2, /* Journalling log in data attribute. */
FILE_Volume = 3, /* Volume name attribute and volume information
attribute (flags and ntfs version). Windows
refers to this file as volume DASD (Direct
Access Storage Device). */
FILE_AttrDef = 4, /* Array of attribute definitions in data
attribute. */
FILE_root = 5, /* Root directory. */
FILE_Bitmap = 6, /* Allocation bitmap of all clusters (lcns) in
data attribute. */
FILE_Boot = 7, /* Boot sector (always at cluster 0) in data
attribute. */
FILE_BadClus = 8, /* Contains all bad clusters in the non-resident
data attribute. */
FILE_Secure = 9, /* Shared security descriptors in data attribute
and two indexes into the descriptors.
Appeared in Windows 2000. Before that, this
file was named $Quota but was unused. */
FILE_UpCase = 10, /* Uppercase equivalents of all 65536 Unicode
characters in data attribute. */
FILE_Extend = 11, /* Directory containing other system files (eg.
$ObjId, $Quota, $Reparse and $UsnJrnl). This
is new to NTFS3.0. */
FILE_reserved12 = 12, /* Reserved for future use (records 12-15). */
FILE_reserved13 = 13,
FILE_reserved14 = 14,
FILE_reserved15 = 15,
FILE_first_user = 16, /* First user file, used as test limit for
whether to allow opening a file or not. */
} NTFS_SYSTEM_FILES;
/*
* These are the so far known MFT_RECORD_* flags (16-bit) which contain
* information about the mft record in which they are present.
*/
typedef enum {
MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001),
MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002),
MFT_REC_SPACE_FILLER = 0xffff /* Just to make flags 16-bit. */
} __attribute__ ((__packed__)) MFT_RECORD_FLAGS;
/*
* mft references (aka file references or file record segment references) are
* used whenever a structure needs to refer to a record in the mft.
*
* A reference consists of a 48-bit index into the mft and a 16-bit sequence
* number used to detect stale references.
*
* For error reporting purposes we treat the 48-bit index as a signed quantity.
*
* The sequence number is a circular counter (skipping 0) describing how many
* times the referenced mft record has been (re)used. This has to match the
* sequence number of the mft record being referenced, otherwise the reference
* is considered stale and removed (FIXME: only ntfsck or the driver itself?).
*
* If the sequence number is zero it is assumed that no sequence number
* consistency checking should be performed.
*
* FIXME: Since inodes are 32-bit as of now, the driver needs to always check
* for high_part being 0 and if not either BUG(), cause a panic() or handle
* the situation in some other way. This shouldn't be a problem as a volume has
* to become HUGE in order to need more than 32-bits worth of mft records.
* Assuming the standard mft record size of 1kb only the records (never mind
* the non-resident attributes, etc.) would require 4Tb of space on their own
* for the first 32 bits worth of records. This is only if some strange person
* doesn't decide to foul play and make the mft sparse which would be a really
* horrible thing to do as it would trash our current driver implementation. )-:
* Do I hear screams "we want 64-bit inodes!" ?!? (-;
*
* FIXME: The mft zone is defined as the first 12% of the volume. This space is
* reserved so that the mft can grow contiguously and hence doesn't become
* fragmented. Volume free space includes the empty part of the mft zone and
* when the volume's free 88% are used up, the mft zone is shrunk by a factor
* of 2, thus making more space available for more files/data. This process is
* repeated everytime there is no more free space except for the mft zone until
* there really is no more free space.
*/
/*
* Typedef the MFT_REF as a 64-bit value for easier handling.
* Also define two unpacking macros to get to the reference (MREF) and
* sequence number (MSEQNO) respectively.
* The _LE versions are to be applied on little endian MFT_REFs.
* Note: The _LE versions will return a CPU endian formatted value!
*/
typedef enum {
MFT_REF_MASK_CPU = 0x0000ffffffffffffULL,
MFT_REF_MASK_LE = const_cpu_to_le64(0x0000ffffffffffffULL),
} MFT_REF_CONSTS;
typedef __u64 MFT_REF;
#define MREF(x) ((__u64)((x) & MFT_REF_MASK_CPU))
#define MSEQNO(x) ((__u16)(((x) >> 48) & 0xffff))
#define MREF_LE(x) ((__u64)(const_le64_to_cpu(x) & MFT_REF_MASK_CPU))
#define MSEQNO_LE(x) ((__u16)((const_le64_to_cpu(x) >> 48) & 0xffff))
#define IS_ERR_MREF(x) (((x) & 0x0000800000000000ULL) ? 1 : 0)
#define ERR_MREF(x) ((__u64)((__s64)(x)))
#define MREF_ERR(x) ((int)((__s64)(x)))
/*
* The mft record header present at the beginning of every record in the mft.
* This is followed by a sequence of variable length attribute records which
* is terminated by an attribute of type $END which is a truncated attribute
* in that it only consists of the attribute type code $END and none of the
* other members of the attribute structure are present.
*/
typedef struct {
/*Ofs*/
/* 0*/ NTFS_RECORD; /* Usually the magic is "FILE". */
/* 8*/ __u64 lsn; /* $LogFile sequence number for this record.
Changed every time the record is modified. */
/* 16*/ __u16 sequence_number; /* Number of times this mft record has been
reused. (See description for MFT_REF
above.) NOTE: The increment (skipping zero)
is done when the file is deleted. NOTE: If
this is zero it is left zero. */
/* 18*/ __u16 link_count; /* Number of hard links, i.e. the number of
directory entries referencing this record.
NOTE: Only used in mft base records.
NOTE: When deleting a directory entry we
check the link_count and if it is 1 we
delete the file. Otherwise we delete the
FILE_NAME_ATTR being referenced by the
directory entry from the mft record and
decrement the link_count.
FIXME: Careful with Win32 + DOS names! */
/* 20*/ __u16 attrs_offset; /* Byte offset to the first attribute in this
mft record from the start of the mft record.
NOTE: Must be aligned to 8-byte boundary. */
/* 22*/ MFT_RECORD_FLAGS flags; /* Bit array of MFT_RECORD_FLAGS. When a file
is deleted, the MFT_RECORD_IN_USE flag is
set to zero. */
/* 24*/ __u32 bytes_in_use; /* Number of bytes used in this mft record.
NOTE: Must be aligned to 8-byte boundary. */
/* 28*/ __u32 bytes_allocated; /* Number of bytes allocated for this mft
record. This should be equal to the mft
record size. */
/* 32*/ MFT_REF base_mft_record; /* This is zero for base mft records.
When it is not zero it is a mft reference
pointing to the base mft record to which
this record belongs (this is then used to
locate the attribute list attribute present
in the base record which describes this
extension record and hence might need
modification when the extension record
itself is modified, also locating the
attribute list also means finding the other
potential extents, belonging to the non-base
mft record). */
/* 40*/ __u16 next_attr_instance; /* The instance number that will be
assigned to the next attribute added to this
mft record. NOTE: Incremented each time
after it is used. NOTE: Every time the mft
record is reused this number is set to zero.
NOTE: The first instance number is always 0.
*/
/* sizeof() = 42 bytes */
/* NTFS 3.1+ (Windows XP and above) introduce the following additions. */
/* 42*/ //__u16 reserved; /* Reserved/alignment. */
/* 44*/ //__u32 mft_record_number; /* Number of this mft record. */
/* sizeof() = 48 bytes */
/*
* When (re)using the mft record, we place the update sequence array at this
* offset, i.e. before we start with the attributes. This also makes sense,
* otherwise we could run into problems with the update sequence array
* containing in itself the last two bytes of a sector which would mean that
* multi sector transfer protection wouldn't work. As you can't protect data
* by overwriting it since you then can't get it back...
* When reading we obviously use the data from the ntfs record header.
*/
} __attribute__ ((__packed__)) MFT_RECORD;
/*
* System defined attributes (32-bit). Each attribute type has a corresponding
* attribute name (Unicode string of maximum 64 character length) as described
* by the attribute definitions present in the data attribute of the $AttrDef
* system file. On NTFS 3.0 volumes the names are just as the types are named
* in the below enum. Note: All system attribute names start with a dollar sign.
* If that isn't a revealing choice of symbol... (-;
*/
typedef enum {
$UNUSED = const_cpu_to_le32( 0),
$STANDARD_INFORMATION = const_cpu_to_le32( 0x10),
$ATTRIBUTE_LIST = const_cpu_to_le32( 0x20),
$FILE_NAME = const_cpu_to_le32( 0x30),
$OBJECT_ID = const_cpu_to_le32( 0x40),
$SECURITY_DESCRIPTOR = const_cpu_to_le32( 0x50),
$VOLUME_NAME = const_cpu_to_le32( 0x60),
$VOLUME_INFORMATION = const_cpu_to_le32( 0x70),
$DATA = const_cpu_to_le32( 0x80),
$INDEX_ROOT = const_cpu_to_le32( 0x90),
$INDEX_ALLOCATION = const_cpu_to_le32( 0xa0),
$BITMAP = const_cpu_to_le32( 0xb0),
$REPARSE_POINT = const_cpu_to_le32( 0xc0),
$EA_INFORMATION = const_cpu_to_le32( 0xd0),
$EA = const_cpu_to_le32( 0xe0),
$PROPERTY_SET = const_cpu_to_le32( 0xf0),
$LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100),
$FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000),
$END = const_cpu_to_le32(0xffffffff),
} ATTR_TYPES;
/*
* The collation rules for sorting views/indexes/etc (32-bit).
*
* COLLATION_UNICODE_STRING - Collate Unicode strings by comparing their binary
* Unicode values, except that when a character can be uppercased, the
* upper case value collates before the lower case one.
* COLLATION_FILE_NAME - Collate file names as Unicode strings. The collation
* is done very much like COLLATION_UNICODE_STRING. In fact I have no idea
* what the difference is. Perhaps the difference is that file names
* would treat some special characters in an odd way (see
* unistr.c::ntfs_collate_names() and unistr.c::legal_ansi_char_array[]
* for what I mean but COLLATION_UNICODE_STRING would not give any special
* treatment to any characters at all, but this is speculation.
* COLLATION_NTOFS_ULONG - Sorting is done according to ascending __u32 key
* values. E.g. used for $SII index in FILE_Secure, which sorts by
* security_id (__u32).
* COLLATION_NTOFS_SID - Sorting is done according to ascending SID values.
* E.g. used for $O index in FILE_Extend/$Quota.
* COLLATION_NTOFS_SECURITY_HASH - Sorting is done first by ascending hash
* values and second by ascending security_id values. E.g. used for $SDH
* index in FILE_Secure.
* COLLATION_NTOFS_ULONGS - Sorting is done according to a sequence of ascending
* __u32 key values. E.g. used for $O index in FILE_Extend/$ObjId, which
* sorts by object_id (16-byte), by splitting up the object_id in four
* __u32 values and using them as individual keys. E.g. take the following
* two security_ids, stored as follows on disk:
* 1st: a1 61 65 b7 65 7b d4 11 9e 3d 00 e0 81 10 42 59
* 2nd: 38 14 37 d2 d2 f3 d4 11 a5 21 c8 6b 79 b1 97 45
* To compare them, they are split into four __u32 values each, like so:
* 1st: 0xb76561a1 0x11d47b65 0xe0003d9e 0x59421081
* 2nd: 0xd2371438 0x11d4f3d2 0x6bc821a5 0x4597b179
* Now, it is apparent why the 2nd object_id collates after the 1st: the
* first __u32 value of the 1st object_id is less than the first __u32 of
* the 2nd object_id. If the first __u32 values of both object_ids were
* equal then the second __u32 values would be compared, etc.
*/
typedef enum {
COLLATION_BINARY = const_cpu_to_le32(0), /* Collate by binary
compare where the first byte is most
significant. */
COLLATION_FILE_NAME = const_cpu_to_le32(1), /* Collate file names
as Unicode strings. */
COLLATION_UNICODE_STRING = const_cpu_to_le32(2), /* Collate Unicode
strings by comparing their binary
Unicode values, except that when a
character can be uppercased, the upper
case value collates before the lower
case one. */
COLLATION_NTOFS_ULONG = const_cpu_to_le32(16),
COLLATION_NTOFS_SID = const_cpu_to_le32(17),
COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(18),
COLLATION_NTOFS_ULONGS = const_cpu_to_le32(19),
} COLLATION_RULES;
/*
* The flags (32-bit) describing attribute properties in the attribute
* definition structure. FIXME: This information is from Regis's information
* and, according to him, it is not certain and probably incomplete.
* The INDEXABLE flag is fairly certainly correct as only the file name
* attribute has this flag set and this is the only attribute indexed in NT4.
*/
typedef enum {
INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be
indexed. */
NEED_TO_REGENERATE = const_cpu_to_le32(0x40), /* Need to regenerate
during regeneration
phase. */
CAN_BE_NON_RESIDENT = const_cpu_to_le32(0x80), /* Attribute can be
non-resident. */
} ATTR_DEF_FLAGS;
/*
* The data attribute of FILE_AttrDef contains a sequence of attribute
* definitions for the NTFS volume. With this, it is supposed to be safe for an
* older NTFS driver to mount a volume containing a newer NTFS version without
* damaging it (that's the theory. In practice it's: not damaging it too much).
* Entries are sorted by attribute type. The flags describe whether the
* attribute can be resident/non-resident and possibly other things, but the
* actual bits are unknown.
*/
typedef struct {
/*hex ofs*/
/* 0*/ uchar_t name[0x40]; /* Unicode name of the attribute. Zero
terminated. */
/* 80*/ ATTR_TYPES type; /* Type of the attribute. */
/* 84*/ __u32 display_rule; /* Default display rule.
FIXME: What does it mean? (AIA) */
/* 88*/ COLLATION_RULES collation_rule; /* Default collation rule. */
/* 8c*/ ATTR_DEF_FLAGS flags; /* Flags describing the attribute. */
/* 90*/ __u64 min_size; /* Optional minimum attribute size. */
/* 98*/ __u64 max_size; /* Maximum size of attribute. */
/* sizeof() = 0xa0 or 160 bytes */
} __attribute__ ((__packed__)) ATTR_DEF;
/*
* Attribute flags (16-bit).
*/
typedef enum {
ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001),
ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression
method mask. Also, first
illegal value. */
ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000),
ATTR_IS_SPARSE = const_cpu_to_le16(0x8000),
} __attribute__ ((__packed__)) ATTR_FLAGS;
/*
* Attribute compression.
*
* Only the data attribute is ever compressed in the current ntfs driver in
* Windows. Further, compression is only applied when the data attribute is
* non-resident. Finally, to use compression, the maximum allowed cluster size
* on a volume is 4kib.
*
* The compression method is based on independently compressing blocks of X
* clusters, where X is determined from the compression_unit value found in the
* non-resident attribute record header (more precisely: X = 2^compression_unit
* clusters). On Windows NT/2k, X always is 16 clusters (compression_unit = 4).
*
* There are three different cases of how a compression block of X clusters
* can be stored:
*
* 1) The data in the block is all zero (a sparse block):
* This is stored as a sparse block in the run list, i.e. the run list
* entry has length = X and lcn = -1. The mapping pairs array actually
* uses a delta_lcn value length of 0, i.e. delta_lcn is not present at
* all, which is then interpreted by the driver as lcn = -1.
* NOTE: Even uncompressed files can be sparse on NTFS 3.0 volumes, then
* the same principles apply as above, except that the length is not
* restricted to being any particular value.
*
* 2) The data in the block is not compressed:
* This happens when compression doesn't reduce the size of the block
* in clusters. I.e. if compression has a small effect so that the
* compressed data still occupies X clusters, then the uncompressed data
* is stored in the block.
* This case is recognised by the fact that the run list entry has
* length = X and lcn >= 0. The mapping pairs array stores this as
* normal with a run length of X and some specific delta_lcn, i.e.
* delta_lcn has to be present.
*
* 3) The data in the block is compressed:
* The common case. This case is recognised by the fact that the run
* list entry has length L < X and lcn >= 0. The mapping pairs array
* stores this as normal with a run length of X and some specific
* delta_lcn, i.e. delta_lcn has to be present. This run list entry is
* immediately followed by a sparse entry with length = X - L and
* lcn = -1. The latter entry is to make up the vcn counting to the
* full compression block size X.
*
* In fact, life is more complicated because adjacent entries of the same type
* can be coalesced. This means that one has to keep track of the number of
* clusters handled and work on a basis of X clusters at a time being one
* block. An example: if length L > X this means that this particular run list
* entry contains a block of length X and part of one or more blocks of length
* L - X. Another example: if length L < X, this does not necessarily mean that
* the block is compressed as it might be that the lcn changes inside the block
* and hence the following run list entry describes the continuation of the
* potentially compressed block. The block would be compressed if the
* following run list entry describes at least X - L sparse clusters, thus
* making up the compression block length as described in point 3 above. (Of
* course, there can be several run list entries with small lengths so that the
* sparse entry does not follow the first data containing entry with
* length < X.)
*
* NOTE: At the end of the compressed attribute value, there most likely is not
* just the right amount of data to make up a compression block, thus this data
* is not even attempted to be compressed. It is just stored as is, unless
* the number of clusters it occupies is reduced when compressed in which case
* it is stored as a compressed compression block, complete with sparse
* clusters at the end.
*/
/*
* Flags of resident attributes (8-bit).
*/
typedef enum {
RESIDENT_ATTR_IS_INDEXED = 0x01, /* Attribute is referenced in an index
(has implications for deleting and
modifying the attribute). */
} __attribute__ ((__packed__)) RESIDENT_ATTR_FLAGS;
/*
* Attribute record header. Always aligned to 8-byte boundary.
*/
typedef struct {
/*Ofs*/
/* 0*/ ATTR_TYPES type; /* The (32-bit) type of the attribute. */
/* 4*/ __u32 length; /* Byte size of the resident part of the
attribute (aligned to 8-byte boundary).
Used to get to the next attribute. */
/* 8*/ __u8 non_resident; /* If 0, attribute is resident.
If 1, attribute is non-resident. */
/* 9*/ __u8 name_length; /* Unicode character size of name of attribute.
0 if unnamed. */
/* 10*/ __u16 name_offset; /* If name_length != 0, the byte offset to the
beginning of the name from the attribute
record. Note that the name is stored as a
Unicode string. When creating, place offset
just at the end of the record header. Then,
follow with attribute value or mapping pairs
array, resident and non-resident attributes
respectively, aligning to an 8-byte
boundary. */
/* 12*/ ATTR_FLAGS flags; /* Flags describing the attribute. */
/* 14*/ __u16 instance; /* The instance of this attribute record. This
number is unique within this mft record (see
MFT_RECORD/next_attribute_instance notes in
in mft.h for more details). */
/* 16*/ union {
/* Resident attributes. */
struct {
/* 16 */ __u32 value_length; /* Byte size of attribute value. */
/* 20 */ __u16 value_offset; /* Byte offset of the attribute
value from the start of the
attribute record. When creating,
align to 8-byte boundary if we
have a name present as this might
not have a length of a multiple
of 8-bytes. */
/* 22 */ RESIDENT_ATTR_FLAGS resident_flags; /* See above. */
/* 23 */ __s8 reservedR; /* Reserved/alignment to 8-byte
boundary. */
} __attribute__ ((__packed__));
/* Non-resident attributes. */
struct {
/* 16*/ VCN lowest_vcn; /* Lowest valid virtual cluster number
for this portion of the attribute value or
0 if this is the only extent (usually the
case). - Only when an attribute list is used
does lowest_vcn != 0 ever occur. */
/* 24*/ VCN highest_vcn; /* Highest valid vcn of this extent of
the attribute value. - Usually there is only one
portion, so this usually equals the attribute
value size in clusters minus 1. Can be -1 for
zero length files. Can be 0 for "single extent"
attributes. */
/* 32*/ __u16 mapping_pairs_offset; /* Byte offset from the
beginning of the structure to the mapping pairs
array which contains the mappings between the
vcns and the logical cluster numbers (lcns).
When creating, place this at the end of this
record header aligned to 8-byte boundary. */
/* 34*/ __u8 compression_unit; /* The compression unit expressed
as the log to the base 2 of the number of
clusters in a compression unit. 0 means not
compressed. (This effectively limits the
compression unit size to be a power of two
clusters.) WinNT4 only uses a value of 4. */
/* 35*/ __u8 reserved1[5]; /* Align to 8-byte boundary. */
/* The sizes below are only used when lowest_vcn is zero, as otherwise it would
be difficult to keep them up-to-date.*/
/* 40*/ __s64 allocated_size; /* Byte size of disk space
allocated to hold the attribute value. Always
is a multiple of the cluster size. When a file
is compressed, this field is a multiple of the
compression block size (2^compression_unit) and
it represents the logically allocated space
rather than the actual on disk usage. For this
use the compressed_size (see below). */
/* 48*/ __s64 data_size; /* Byte size of the attribute
value. Can be larger than allocated_size if
attribute value is compressed or sparse. */
/* 56*/ __s64 initialized_size; /* Byte size of initialized
portion of the attribute value. Usually equals
data_size. */
/* sizeof(uncompressed attr) = 64*/
/* 64*/ __s64 compressed_size; /* Byte size of the attribute
value after compression. Only present when
compressed. Always is a multiple of the
cluster size. Represents the actual amount of
disk space being used on the disk. */
/* sizeof(compressed attr) = 72*/
} __attribute__ ((__packed__));
} __attribute__ ((__packed__));
} __attribute__ ((__packed__)) ATTR_RECORD;
typedef ATTR_RECORD ATTR_REC;
/*
* File attribute flags (32-bit).
*/
typedef enum {
/*
* These flags are only presnt in the STANDARD_INFORMATION attribute
* (in the field file_attributes).
*/
FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001),
FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002),
FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004),
/* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */
FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010),
/* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved
for the DOS SUBDIRECTORY flag. */
FILE_ATTR_ARCHIVE = const_cpu_to_le32(0x00000020),
FILE_ATTR_DEVICE = const_cpu_to_le32(0x00000040),
FILE_ATTR_NORMAL = const_cpu_to_le32(0x00000080),
FILE_ATTR_TEMPORARY = const_cpu_to_le32(0x00000100),
FILE_ATTR_SPARSE_FILE = const_cpu_to_le32(0x00000200),
FILE_ATTR_REPARSE_POINT = const_cpu_to_le32(0x00000400),
FILE_ATTR_COMPRESSED = const_cpu_to_le32(0x00000800),
FILE_ATTR_OFFLINE = const_cpu_to_le32(0x00001000),
FILE_ATTR_NOT_CONTENT_INDEXED = const_cpu_to_le32(0x00002000),
FILE_ATTR_ENCRYPTED = const_cpu_to_le32(0x00004000),
FILE_ATTR_VALID_FLAGS = const_cpu_to_le32(0x00007fb7),
/* FILE_ATTR_VALID_FLAGS masks out the old DOS VolId and the
FILE_ATTR_DEVICE and preserves everything else. This mask
is used to obtain all flags that are valid for reading. */
FILE_ATTR_VALID_SET_FLAGS = const_cpu_to_le32(0x000031a7),
/* FILE_ATTR_VALID_SET_FLAGS masks out the old DOS VolId, the
F_A_DEVICE, F_A_DIRECTORY, F_A_SPARSE_FILE, F_A_REPARSE_POINT,
F_A_COMPRESSED and F_A_ENCRYPTED and preserves the rest. This mask
is used to to obtain all flags that are valid for setting. */
/*
* These flags are only present in the FILE_NAME attribute (in the
* field file_attributes).
*/
FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT = const_cpu_to_le32(0x10000000),
/* This is a copy of the corresponding bit from the mft record, telling
us whether this is a directory or not, i.e. whether it has an
index root attribute or not. */
FILE_ATTR_DUP_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000),
/* This is a copy of the corresponding bit from the mft record, telling
us whether this file has a view index present (eg. object id index,
quota index, one of the security indexes or the encrypting file
system related indexes). */
} FILE_ATTR_FLAGS;
/*
* NOTE on times in NTFS: All times are in MS standard time format, i.e. they
* are the number of 100-nanosecond intervals since 1st January 1601, 00:00:00
* universal coordinated time (UTC). (In Linux time starts 1st January 1970,
* 00:00:00 UTC and is stored as the number of 1-second intervals since then.)
*/
/*
* Attribute: Standard information (0x10).
*
* NOTE: Always resident.
* NOTE: Present in all base file records on a volume.
* NOTE: There is conflicting information about the meaning of each of the time
* fields but the meaning as defined below has been verified to be
* correct by practical experimentation on Windows NT4 SP6a and is hence
* assumed to be the one and only correct interpretation.
*/
typedef struct {
/*Ofs*/
/* 0*/ __s64 creation_time; /* Time file was created. Updated when
a filename is changed(?). */
/* 8*/ __s64 last_data_change_time; /* Time the data attribute was last
modified. */
/* 16*/ __s64 last_mft_change_time; /* Time this mft record was last
modified. */
/* 24*/ __s64 last_access_time; /* Approximate time when the file was
last accessed (obviously this is not
updated on read-only volumes). In
Windows this is only updated when
accessed if some time delta has
passed since the last update. Also,
last access times updates can be
disabled altogether for speed. */
/* 32*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
/* 36*/ union {
/* NTFS 1.2 (and previous, presumably) */
/* 36 */ __u8 reserved12[12]; /* Reserved/alignment to 8-byte
boundary. */
/* sizeof() = 48 bytes */
/* NTFS 3.0 */
struct {
/*
* If a volume has been upgraded from a previous NTFS version, then these
* fields are present only if the file has been accessed since the upgrade.
* Recognize the difference by comparing the length of the resident attribute
* value. If it is 48, then the following fields are missing. If it is 72 then
* the fields are present. Maybe just check like this:
* if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) {
* Assume NTFS 1.2- format.
* If (volume version is 3.0+)
* Upgrade attribute to NTFS 3.0 format.
* else
* Use NTFS 1.2- format for access.
* } else
* Use NTFS 3.0 format for access.
* Only problem is that it might be legal to set the length of the value to
* arbitrarily large values thus spoiling this check. - But chkdsk probably
* views that as a corruption, assuming that it behaves like this for all
* attributes.
*/
/* 36*/ __u32 maximum_versions; /* Maximum allowed versions for
file. Zero if version numbering is disabled. */
/* 40*/ __u32 version_number; /* This file's version (if any).
Set to zero if maximum_versions is zero. */
/* 44*/ __u32 class_id; /* Class id from bidirectional
class id index (?). */
/* 48*/ __u32 owner_id; /* Owner_id of the user owning
the file. Translate via $Q index in FILE_Extend
/$Quota to the quota control entry for the user
owning the file. Zero if quotas are disabled. */
/* 52*/ __u32 security_id; /* Security_id for the file.
Translate via $SII index and $SDS data stream
in FILE_Secure to the security descriptor. */
/* 56*/ __u64 quota_charged; /* Byte size of the charge to
the quota for all streams of the file. Note: Is
zero if quotas are disabled. */
/* 64*/ __u64 usn; /* Last update sequence number
of the file. This is a direct index into the
change (aka usn) journal file. It is zero if
the usn journal is disabled.
NOTE: To disable the journal need to delete
the journal file itself and to then walk the
whole mft and set all Usn entries in all mft
records to zero! (This can take a while!)
The journal is FILE_Extend/$UsnJrnl. Win2k
will recreate the journal and initiate
logging if necessary when mounting the
partition. This, in contrast to disabling the
journal is a very fast process, so the user
won't even notice it. */
};
};
/* sizeof() = 72 bytes (NTFS 3.0) */
} __attribute__ ((__packed__)) STANDARD_INFORMATION;
/*
* Attribute: Attribute list (0x20).
*
* - Can be either resident or non-resident.
* - Value consists of a sequence of variable length, 8-byte aligned,
* ATTR_LIST_ENTRY records.
* - The attribute list attribute contains one entry for each attribute of
* the file in which the list is located, except for the list attribute
* itself. The list is sorted: first by attribute type, second by attribute
* name (if present), third by instance number. The extents of one
* non-resident attribute (if present) immediately follow after the initial
* extent. They are ordered by lowest_vcn and have their instace set to zero.
* It is not allowed to have two attributes with all sorting keys equal.
* - Further restrictions:
* - If not resident, the vcn to lcn mapping array has to fit inside the
* base mft record.
* - The attribute list attribute value has a maximum size of 256kb. This
* is imposed by the Windows cache manager.
* - Attribute lists are only used when the attributes of mft record do not
* fit inside the mft record despite all attributes (that can be made
* non-resident) having been made non-resident. This can happen e.g. when:
* - File has a large number of hard links (lots of file name
* attributes present).
* - The mapping pairs array of some non-resident attribute becomes so
* large due to fragmentation that it overflows the mft record.
* - The security descriptor is very complex (not applicable to
* NTFS 3.0 volumes).
* - There are many named streams.
*/
typedef struct {
/*Ofs*/
/* 0*/ ATTR_TYPES type; /* Type of referenced attribute. */
/* 4*/ __u16 length; /* Byte size of this entry. */
/* 6*/ __u8 name_length; /* Size in Unicode chars of the name of the
attribute or 0 if unnamed. */
/* 7*/ __u8 name_offset; /* Byte offset to beginning of attribute name
(always set this to where the name would
start even if unnamed). */
/* 8*/ VCN lowest_vcn; /* Lowest virtual cluster number of this portion
of the attribute value. This is usually 0. It
is non-zero for the case where one attribute
does not fit into one mft record and thus
several mft records are allocated to hold
this attribute. In the latter case, each mft
record holds one extent of the attribute and
there is one attribute list entry for each
extent. NOTE: This is DEFINITELY a signed
value! The windows driver uses cmp, followed
by jg when comparing this, thus it treats it
as signed. */
/* 16*/ MFT_REF mft_reference; /* The reference of the mft record holding
the ATTR_RECORD for this portion of the
attribute value. */
/* 24*/ __u16 instance; /* If lowest_vcn = 0, the instance of the
attribute being referenced; otherwise 0. */
/* 26*/ uchar_t name[0]; /* Use when creating only. When reading use
name_offset to determine the location of the
name. */
/* sizeof() = 26 + (attribute_name_length * 2) bytes */
} __attribute__ ((__packed__)) ATTR_LIST_ENTRY;
/*
* The maximum allowed length for a file name.
*/
#define MAXIMUM_FILE_NAME_LENGTH 255
/*
* Possible namespaces for filenames in ntfs (8-bit).
*/
typedef enum {
FILE_NAME_POSIX = 0x00,
/* This is the largest namespace. It is case sensitive and
allows all Unicode characters except for: '\0' and '/'.
Beware that in WinNT/2k files which eg have the same name
except for their case will not be distinguished by the
standard utilities and thus a "del filename" will delete
both "filename" and "fileName" without warning. */
FILE_NAME_WIN32 = 0x01,
/* The standard WinNT/2k NTFS long filenames. Case insensitive.
All Unicode chars except: '\0', '"', '*', '/', ':', '<',
'>', '?', '\' and '|'. Further, names cannot end with a '.'
or a space. */
FILE_NAME_DOS = 0x02,
/* The standard DOS filenames (8.3 format). Uppercase only.
All 8-bit characters greater space, except: '"', '*', '+',
',', '/', ':', ';', '<', '=', '>', '?' and '\'. */
FILE_NAME_WIN32_AND_DOS = 0x03,
/* 3 means that both the Win32 and the DOS filenames are
identical and hence have been saved in this single filename
record. */
} __attribute__ ((__packed__)) FILE_NAME_TYPE_FLAGS;
/*
* Attribute: Filename (0x30).
*
* NOTE: Always resident.
* NOTE: All fields, except the parent_directory, are only updated when the
* filename is changed. Until then, they just become out of sync with
* reality and the more up to date values are present in the standard
* information attribute.
* NOTE: There is conflicting information about the meaning of each of the time
* fields but the meaning as defined below has been verified to be
* correct by practical experimentation on Windows NT4 SP6a and is hence
* assumed to be the one and only correct interpretation.
*/
typedef struct {
/*hex ofs*/
/* 0*/ MFT_REF parent_directory; /* Directory this filename is
referenced from. */
/* 8*/ __s64 creation_time; /* Time file was created. */
/* 10*/ __s64 last_data_change_time; /* Time the data attribute was last
modified. */
/* 18*/ __s64 last_mft_change_time; /* Time this mft record was last
modified. */
/* 20*/ __s64 last_access_time; /* Last time this mft record was
accessed. */
/* 28*/ __s64 allocated_size; /* Byte size of allocated space for the
data attribute. NOTE: Is a multiple
of the cluster size. */
/* 30*/ __s64 data_size; /* Byte size of actual data in data
attribute. NOTE: Only present when
lowest_vcn is 0. */
/* 38*/ FILE_ATTR_FLAGS file_attributes; /* Flags describing the file. */
/* 3c*/ union {
/* 3c*/ struct {
/* 3c*/ __u16 packed_ea_size; /* Size of the buffer needed to
pack the extended attributes
(EAs), if such are present.*/
/* 3e*/ __u16 reserved; /* Reserved for alignment. */
} __attribute__ ((__packed__));
/* 3c*/ __u32 reparse_point_tag; /* Type of reparse point,
present only in reparse
points and only if there are
no EAs. */
} __attribute__ ((__packed__));
/* 40*/ __u8 file_name_length; /* Length of file name in
(Unicode) characters. */
/* 41*/ FILE_NAME_TYPE_FLAGS file_name_type; /* Namespace of the file name.*/
/* 42*/ uchar_t file_name[0]; /* File name in Unicode. */
} __attribute__ ((__packed__)) FILE_NAME_ATTR;
/*
* GUID structures store globally unique identifiers (GUID). A GUID is a
* 128-bit value consisting of one group of eight hexadecimal digits, followed
* by three groups of four hexadecimal digits each, followed by one group of
* twelve hexadecimal digits. GUIDs are Microsoft's implementation of the
* distributed computing environment (DCE) universally unique identifier (UUID).
* Example of a GUID:
* 1F010768-5A73-BC91-0010A52216A7
*/
typedef struct {
__u32 data1; /* The first eight hexadecimal digits of the GUID. */
__u16 data2; /* The first group of four hexadecimal digits. */
__u16 data3; /* The second group of four hexadecimal digits. */
__u8 data4[8]; /* The first two bytes are the third group of four
hexadecimal digits. The remaining six bytes are the
final 12 hexadecimal digits. */
} __attribute__ ((__packed__)) GUID;
/*
* FILE_Extend/$ObjId contains an index named $O. This index contains all
* object_ids present on the volume as the index keys and the corresponding
* mft_record numbers as the index entry data parts. The data part (defined
* below) also contains three other object_ids:
* birth_volume_id - object_id of FILE_Volume on which the file was first
* created. Optional (i.e. can be zero).
* birth_object_id - object_id of file when it was first created. Usually
* equals the object_id. Optional (i.e. can be zero).
* domain_id - Reserved (always zero).
*/
typedef struct {
MFT_REF mft_reference; /* Mft record containing the object_id in
the index entry key. */
union {
struct {
GUID birth_volume_id;
GUID birth_object_id;
GUID domain_id;
} __attribute__ ((__packed__));
__u8 extended_info[48];
} __attribute__ ((__packed__));
} __attribute__ ((__packed__)) OBJ_ID_INDEX_DATA;
/*
* Attribute: Object id (NTFS 3.0+) (0x40).
*
* NOTE: Always resident.
*/
typedef struct {
GUID object_id; /* Unique id assigned to the
file.*/
/* The following fields are optional. The attribute value size is 16
bytes, i.e. sizeof(GUID), if these are not present at all. Note,
the entries can be present but one or more (or all) can be zero
meaning that that particular value(s) is(are) not defined. */
union {
struct {
GUID birth_volume_id; /* Unique id of volume on which
the file was first created.*/
GUID birth_object_id; /* Unique id of file when it was
first created. */
GUID domain_id; /* Reserved, zero. */
} __attribute__ ((__packed__));
__u8 extended_info[48];
} __attribute__ ((__packed__));
} __attribute__ ((__packed__)) OBJECT_ID_ATTR;
/*
* The pre-defined IDENTIFIER_AUTHORITIES used as SID_IDENTIFIER_AUTHORITY in
* the SID structure (see below).
*/
//typedef enum { /* SID string prefix. */
// SECURITY_NULL_SID_AUTHORITY = {0, 0, 0, 0, 0, 0}, /* S-1-0 */
// SECURITY_WORLD_SID_AUTHORITY = {0, 0, 0, 0, 0, 1}, /* S-1-1 */
// SECURITY_LOCAL_SID_AUTHORITY = {0, 0, 0, 0, 0, 2}, /* S-1-2 */
// SECURITY_CREATOR_SID_AUTHORITY = {0, 0, 0, 0, 0, 3}, /* S-1-3 */
// SECURITY_NON_UNIQUE_AUTHORITY = {0, 0, 0, 0, 0, 4}, /* S-1-4 */
// SECURITY_NT_SID_AUTHORITY = {0, 0, 0, 0, 0, 5}, /* S-1-5 */
//} IDENTIFIER_AUTHORITIES;
/*
* These relative identifiers (RIDs) are used with the above identifier
* authorities to make up universal well-known SIDs.
*
* Note: The relative identifier (RID) refers to the portion of a SID, which
* identifies a user or group in relation to the authority that issued the SID.
* For example, the universal well-known SID Creator Owner ID (S-1-3-0) is
* made up of the identifier authority SECURITY_CREATOR_SID_AUTHORITY (3) and
* the relative identifier SECURITY_CREATOR_OWNER_RID (0).
*/
typedef enum { /* Identifier authority. */
SECURITY_NULL_RID = 0, /* S-1-0 */
SECURITY_WORLD_RID = 0, /* S-1-1 */
SECURITY_LOCAL_RID = 0, /* S-1-2 */
SECURITY_CREATOR_OWNER_RID = 0, /* S-1-3 */
SECURITY_CREATOR_GROUP_RID = 1, /* S-1-3 */
SECURITY_CREATOR_OWNER_SERVER_RID = 2, /* S-1-3 */
SECURITY_CREATOR_GROUP_SERVER_RID = 3, /* S-1-3 */
SECURITY_DIALUP_RID = 1,
SECURITY_NETWORK_RID = 2,
SECURITY_BATCH_RID = 3,
SECURITY_INTERACTIVE_RID = 4,
SECURITY_SERVICE_RID = 6,
SECURITY_ANONYMOUS_LOGON_RID = 7,
SECURITY_PROXY_RID = 8,
SECURITY_ENTERPRISE_CONTROLLERS_RID=9,
SECURITY_SERVER_LOGON_RID = 9,
SECURITY_PRINCIPAL_SELF_RID = 0xa,
SECURITY_AUTHENTICATED_USER_RID = 0xb,
SECURITY_RESTRICTED_CODE_RID = 0xc,
SECURITY_TERMINAL_SERVER_RID = 0xd,
SECURITY_LOGON_IDS_RID = 5,
SECURITY_LOGON_IDS_RID_COUNT = 3,
SECURITY_LOCAL_SYSTEM_RID = 0x12,
SECURITY_NT_NON_UNIQUE = 0x15,
SECURITY_BUILTIN_DOMAIN_RID = 0x20,
/*
* Well-known domain relative sub-authority values (RIDs).
*/
/* Users. */
DOMAIN_USER_RID_ADMIN = 0x1f4,
DOMAIN_USER_RID_GUEST = 0x1f5,
DOMAIN_USER_RID_KRBTGT = 0x1f6,
/* Groups. */
DOMAIN_GROUP_RID_ADMINS = 0x200,
DOMAIN_GROUP_RID_USERS = 0x201,
DOMAIN_GROUP_RID_GUESTS = 0x202,
DOMAIN_GROUP_RID_COMPUTERS = 0x203,
DOMAIN_GROUP_RID_CONTROLLERS = 0x204,
DOMAIN_GROUP_RID_CERT_ADMINS = 0x205,
DOMAIN_GROUP_RID_SCHEMA_ADMINS = 0x206,
DOMAIN_GROUP_RID_ENTERPRISE_ADMINS= 0x207,
DOMAIN_GROUP_RID_POLICY_ADMINS = 0x208,
/* Aliases. */
DOMAIN_ALIAS_RID_ADMINS = 0x220,
DOMAIN_ALIAS_RID_USERS = 0x221,
DOMAIN_ALIAS_RID_GUESTS = 0x222,
DOMAIN_ALIAS_RID_POWER_USERS = 0x223,
DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224,
DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225,
DOMAIN_ALIAS_RID_PRINT_OPS = 0x226,
DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227,
DOMAIN_ALIAS_RID_REPLICATOR = 0x228,
DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229,
DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a,
} RELATIVE_IDENTIFIERS;
/*
* The universal well-known SIDs:
*
* NULL_SID S-1-0-0
* WORLD_SID S-1-1-0
* LOCAL_SID S-1-2-0
* CREATOR_OWNER_SID S-1-3-0
* CREATOR_GROUP_SID S-1-3-1
* CREATOR_OWNER_SERVER_SID S-1-3-2
* CREATOR_GROUP_SERVER_SID S-1-3-3
*
* (Non-unique IDs) S-1-4
*
* NT well-known SIDs:
*
* NT_AUTHORITY_SID S-1-5
* DIALUP_SID S-1-5-1
*
* NETWORD_SID S-1-5-2
* BATCH_SID S-1-5-3
* INTERACTIVE_SID S-1-5-4
* SERVICE_SID S-1-5-6
* ANONYMOUS_LOGON_SID S-1-5-7 (aka null logon session)
* PROXY_SID S-1-5-8
* SERVER_LOGON_SID S-1-5-9 (aka domain controller account)
* SELF_SID S-1-5-10 (self RID)
* AUTHENTICATED_USER_SID S-1-5-11
* RESTRICTED_CODE_SID S-1-5-12 (running restricted code)
* TERMINAL_SERVER_SID S-1-5-13 (running on terminal server)
*
* (Logon IDs) S-1-5-5-X-Y
*
* (NT non-unique IDs) S-1-5-0x15-...
*
* (Built-in domain) S-1-5-0x20
*/
/*
* The SID_IDENTIFIER_AUTHORITY is a 48-bit value used in the SID structure.
*/
typedef union {
struct {
__u32 low_part; /* Low 32-bits. */
__u16 high_part; /* High 16-bits. */
} __attribute__ ((__packed__));
__u8 value[6]; /* Value as individual bytes. */
} __attribute__ ((__packed__)) SID_IDENTIFIER_AUTHORITY;
/*
* The SID structure is a variable-length structure used to uniquely identify
* users or groups. SID stands for security identifier.
*
* The standard textual representation of the SID is of the form:
* S-R-I-S-S...
* Where:
* - The first "S" is the literal character 'S' identifying the following
* digits as a SID.
* - R is the revision level of the SID expressed as a sequence of digits
* either in decimal or hexadecimal (if the later, prefixed by "0x").
* - I is the 48-bit identifier_authority, expressed as digits as R above.
* - S... is one or more sub_authority values, expressed as digits as above.
*
* Example SID; the domain-relative SID of the local Administrators group on
* Windows NT/2k:
* S-1-5-32-544
* This translates to a SID with:
* revision = 1,
* sub_authority_count = 2,
* identifier_authority = {0,0,0,0,0,5}, // SECURITY_NT_AUTHORITY
* sub_authority[0] = 32, // SECURITY_BUILTIN_DOMAIN_RID
* sub_authority[1] = 544 // DOMAIN_ALIAS_RID_ADMINS
*/
typedef struct {
__u8 revision;
__u8 sub_authority_count;
SID_IDENTIFIER_AUTHORITY identifier_authority;
__u32 sub_authority[1]; /* At least one sub_authority. */
} __attribute__ ((__packed__)) SID;
/*
* Current constants for SIDs.
*/
typedef enum {
SID_REVISION = 1, /* Current revision level. */
SID_MAX_SUB_AUTHORITIES = 15, /* Maximum number of those. */
SID_RECOMMENDED_SUB_AUTHORITIES = 1, /* Will change to around 6 in
a future revision. */
} SID_CONSTANTS;
/*
* The predefined ACE types (8-bit, see below).
*/
typedef enum {
ACCESS_MIN_MS_ACE_TYPE = 0,
ACCESS_ALLOWED_ACE_TYPE = 0,
ACCESS_DENIED_ACE_TYPE = 1,
SYSTEM_AUDIT_ACE_TYPE = 2,
SYSTEM_ALARM_ACE_TYPE = 3, /* Not implemented as of Win2k. */
ACCESS_MAX_MS_V2_ACE_TYPE = 3,
ACCESS_ALLOWED_COMPOUND_ACE_TYPE= 4,
ACCESS_MAX_MS_V3_ACE_TYPE = 4,
/* The following are Win2k only. */
ACCESS_MIN_MS_OBJECT_ACE_TYPE = 5,
ACCESS_ALLOWED_OBJECT_ACE_TYPE = 5,
ACCESS_DENIED_OBJECT_ACE_TYPE = 6,
SYSTEM_AUDIT_OBJECT_ACE_TYPE = 7,
SYSTEM_ALARM_OBJECT_ACE_TYPE = 8,
ACCESS_MAX_MS_OBJECT_ACE_TYPE = 8,
ACCESS_MAX_MS_V4_ACE_TYPE = 8,
/* This one is for WinNT&2k. */
ACCESS_MAX_MS_ACE_TYPE = 8,
} __attribute__ ((__packed__)) ACE_TYPES;
/*
* The ACE flags (8-bit) for audit and inheritance (see below).
*
* SUCCESSFUL_ACCESS_ACE_FLAG is only used with system audit and alarm ACE
* types to indicate that a message is generated (in Windows!) for successful
* accesses.
*
* FAILED_ACCESS_ACE_FLAG is only used with system audit and alarm ACE types
* to indicate that a message is generated (in Windows!) for failed accesses.
*/
typedef enum {
/* The inheritance flags. */
OBJECT_INHERIT_ACE = 0x01,
CONTAINER_INHERIT_ACE = 0x02,
NO_PROPAGATE_INHERIT_ACE = 0x04,
INHERIT_ONLY_ACE = 0x08,
INHERITED_ACE = 0x10, /* Win2k only. */
VALID_INHERIT_FLAGS = 0x1f,
/* The audit flags. */
SUCCESSFUL_ACCESS_ACE_FLAG = 0x40,
FAILED_ACCESS_ACE_FLAG = 0x80,
} __attribute__ ((__packed__)) ACE_FLAGS;
/*
* An ACE is an access-control entry in an access-control list (ACL).
* An ACE defines access to an object for a specific user or group or defines
* the types of access that generate system-administration messages or alarms
* for a specific user or group. The user or group is identified by a security
* identifier (SID).
*
* Each ACE starts with an ACE_HEADER structure (aligned on 4-byte boundary),
* which specifies the type and size of the ACE. The format of the subsequent
* data depends on the ACE type.
*/
typedef struct {
ACE_TYPES type; /* Type of the ACE. */
ACE_FLAGS flags; /* Flags describing the ACE. */
__u16 size; /* Size in bytes of the ACE. */
} __attribute__ ((__packed__)) ACE_HEADER;
/*
* The access mask (32-bit). Defines the access rights.
*/
typedef enum {
/*
* The specific rights (bits 0 to 15). Depend on the type of the
* object being secured by the ACE.
*/
/* Specific rights for files and directories are as follows: */
/* Right to read data from the file. (FILE) */
FILE_READ_DATA = const_cpu_to_le32(0x00000001),
/* Right to list contents of a directory. (DIRECTORY) */
FILE_LIST_DIRECTORY = const_cpu_to_le32(0x00000001),
/* Right to write data to the file. (FILE) */
FILE_WRITE_DATA = const_cpu_to_le32(0x00000002),
/* Right to create a file in the directory. (DIRECTORY) */
FILE_ADD_FILE = const_cpu_to_le32(0x00000002),
/* Right to append data to the file. (FILE) */
FILE_APPEND_DATA = const_cpu_to_le32(0x00000004),
/* Right to create a subdirectory. (DIRECTORY) */
FILE_ADD_SUBDIRECTORY = const_cpu_to_le32(0x00000004),
/* Right to read extended attributes. (FILE/DIRECTORY) */
FILE_READ_EA = const_cpu_to_le32(0x00000008),
/* Right to write extended attributes. (FILE/DIRECTORY) */
FILE_WRITE_EA = const_cpu_to_le32(0x00000010),
/* Right to execute a file. (FILE) */
FILE_EXECUTE = const_cpu_to_le32(0x00000020),
/* Right to traverse the directory. (DIRECTORY) */
FILE_TRAVERSE = const_cpu_to_le32(0x00000020),
/*
* Right to delete a directory and all the files it contains (its
* children), even if the files are read-only. (DIRECTORY)
*/
FILE_DELETE_CHILD = const_cpu_to_le32(0x00000040),
/* Right to read file attributes. (FILE/DIRECTORY) */
FILE_READ_ATTRIBUTES = const_cpu_to_le32(0x00000080),
/* Right to change file attributes. (FILE/DIRECTORY) */
FILE_WRITE_ATTRIBUTES = const_cpu_to_le32(0x00000100),
/*
* The standard rights (bits 16 to 23). Are independent of the type of
* object being secured.
*/
/* Right to delete the object. */
DELETE = const_cpu_to_le32(0x00010000),
/*
* Right to read the information in the object's security descriptor,
* not including the information in the SACL. I.e. right to read the
* security descriptor and owner.
*/
READ_CONTROL = const_cpu_to_le32(0x00020000),
/* Right to modify the DACL in the object's security descriptor. */
WRITE_DAC = const_cpu_to_le32(0x00040000),
/* Right to change the owner in the object's security descriptor. */
WRITE_OWNER = const_cpu_to_le32(0x00080000),
/*
* Right to use the object for synchronization. Enables a process to
* wait until the object is in the signalled state. Some object types
* do not support this access right.
*/
SYNCHRONIZE = const_cpu_to_le32(0x00100000),
/*
* The following STANDARD_RIGHTS_* are combinations of the above for
* convenience and are defined by the Win32 API.
*/
/* These are currently defined to READ_CONTROL. */
STANDARD_RIGHTS_READ = const_cpu_to_le32(0x00020000),
STANDARD_RIGHTS_WRITE = const_cpu_to_le32(0x00020000),
STANDARD_RIGHTS_EXECUTE = const_cpu_to_le32(0x00020000),
/* Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access. */
STANDARD_RIGHTS_REQUIRED = const_cpu_to_le32(0x000f0000),
/*
* Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and
* SYNCHRONIZE access.
*/
STANDARD_RIGHTS_ALL = const_cpu_to_le32(0x001f0000),
/*
* The access system ACL and maximum allowed access types (bits 24 to
* 25, bits 26 to 27 are reserved).
*/
ACCESS_SYSTEM_SECURITY = const_cpu_to_le32(0x01000000),
MAXIMUM_ALLOWED = const_cpu_to_le32(0x02000000),
/*
* The generic rights (bits 28 to 31). These map onto the standard and
* specific rights.
*/
/* Read, write, and execute access. */
GENERIC_ALL = const_cpu_to_le32(0x10000000),
/* Execute access. */
GENERIC_EXECUTE = const_cpu_to_le32(0x20000000),
/*
* Write access. For files, this maps onto:
* FILE_APPEND_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_DATA |
* FILE_WRITE_EA | STANDARD_RIGHTS_WRITE | SYNCHRONIZE
* For directories, the mapping has the same numberical value. See
* above for the descriptions of the rights granted.
*/
GENERIC_WRITE = const_cpu_to_le32(0x40000000),
/*
* Read access. For files, this maps onto:
* FILE_READ_ATTRIBUTES | FILE_READ_DATA | FILE_READ_EA |
* STANDARD_RIGHTS_READ | SYNCHRONIZE
* For directories, the mapping has the same numberical value. See
* above for the descriptions of the rights granted.
*/
GENERIC_READ = const_cpu_to_le32(0x80000000),
} ACCESS_MASK;
/*
* The generic mapping array. Used to denote the mapping of each generic
* access right to a specific access mask.
*
* FIXME: What exactly is this and what is it for? (AIA)
*/
typedef struct {
ACCESS_MASK generic_read;
ACCESS_MASK generic_write;
ACCESS_MASK generic_execute;
ACCESS_MASK generic_all;
} __attribute__ ((__packed__)) GENERIC_MAPPING;
/*
* The predefined ACE type structures are as defined below.
*/
/*
* ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE
*/
typedef struct {
ACE_HEADER; /* The ACE header. */
ACCESS_MASK mask; /* Access mask associated with the ACE. */
SID sid; /* The SID associated with the ACE. */
} __attribute__ ((__packed__)) ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE,
SYSTEM_AUDIT_ACE, SYSTEM_ALARM_ACE;
/*
* The object ACE flags (32-bit).
*/
typedef enum {
ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1),
ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2),
} OBJECT_ACE_FLAGS;
typedef struct {
ACE_HEADER; /* The ACE_HEADER. */
ACCESS_MASK mask; /* Access mask associated with the ACE. */
OBJECT_ACE_FLAGS flags; /* Flags describing the object ACE. */
GUID object_type;
GUID inherited_object_type;
SID sid; /* The SID associated with the ACE. */
} __attribute__ ((__packed__)) ACCESS_ALLOWED_OBJECT_ACE,
ACCESS_DENIED_OBJECT_ACE,
SYSTEM_AUDIT_OBJECT_ACE,
SYSTEM_ALARM_OBJECT_ACE;
/*
* An ACL is an access-control list (ACL).
* An ACL starts with an ACL header structure, which specifies the size of
* the ACL and the number of ACEs it contains. The ACL header is followed by
* zero or more access control entries (ACEs). The ACL as well as each ACE
* are aligned on 4-byte boundaries.
*/
typedef struct {
__u8 revision; /* Revision of this ACL. */
__u8 alignment1;
__u16 size; /* Allocated space in bytes for ACL. Includes this
header, the ACEs and the remaining free space. */
__u16 ace_count;/* Number of ACEs in the ACL. */
__u16 alignment2;
/* sizeof() = 8 bytes */
} __attribute__ ((__packed__)) ACL;
/*
* Current constants for ACLs.
*/
typedef enum {
/* Current revision. */
ACL_REVISION = 2,
ACL_REVISION_DS = 4,
/* History of revisions. */
ACL_REVISION1 = 1,
MIN_ACL_REVISION = 2,
ACL_REVISION2 = 2,
ACL_REVISION3 = 3,
ACL_REVISION4 = 4,
MAX_ACL_REVISION = 4,
} ACL_CONSTANTS;
/*
* The security descriptor control flags (16-bit).
*
* SE_OWNER_DEFAULTED - This boolean flag, when set, indicates that the
* SID pointed to by the Owner field was provided by a
* defaulting mechanism rather than explicitly provided by the
* original provider of the security descriptor. This may
* affect the treatment of the SID with respect to inheritence
* of an owner.
*
* SE_GROUP_DEFAULTED - This boolean flag, when set, indicates that the
* SID in the Group field was provided by a defaulting mechanism
* rather than explicitly provided by the original provider of
* the security descriptor. This may affect the treatment of
* the SID with respect to inheritence of a primary group.
*
* SE_DACL_PRESENT - This boolean flag, when set, indicates that the
* security descriptor contains a discretionary ACL. If this
* flag is set and the Dacl field of the SECURITY_DESCRIPTOR is
* null, then a null ACL is explicitly being specified.
*
* SE_DACL_DEFAULTED - This boolean flag, when set, indicates that the
* ACL pointed to by the Dacl field was provided by a defaulting
* mechanism rather than explicitly provided by the original
* provider of the security descriptor. This may affect the
* treatment of the ACL with respect to inheritence of an ACL.
* This flag is ignored if the DaclPresent flag is not set.
*
* SE_SACL_PRESENT - This boolean flag, when set, indicates that the
* security descriptor contains a system ACL pointed to by the
* Sacl field. If this flag is set and the Sacl field of the
* SECURITY_DESCRIPTOR is null, then an empty (but present)
* ACL is being specified.
*
* SE_SACL_DEFAULTED - This boolean flag, when set, indicates that the
* ACL pointed to by the Sacl field was provided by a defaulting
* mechanism rather than explicitly provided by the original
* provider of the security descriptor. This may affect the
* treatment of the ACL with respect to inheritence of an ACL.
* This flag is ignored if the SaclPresent flag is not set.
*
* SE_SELF_RELATIVE - This boolean flag, when set, indicates that the
* security descriptor is in self-relative form. In this form,
* all fields of the security descriptor are contiguous in memory
* and all pointer fields are expressed as offsets from the
* beginning of the security descriptor.
*/
typedef enum {
SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001),
SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002),
SE_DACL_PRESENT = const_cpu_to_le16(0x0004),
SE_DACL_DEFAULTED = const_cpu_to_le16(0x0008),
SE_SACL_PRESENT = const_cpu_to_le16(0x0010),
SE_SACL_DEFAULTED = const_cpu_to_le16(0x0020),
SE_DACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0100),
SE_SACL_AUTO_INHERIT_REQ = const_cpu_to_le16(0x0200),
SE_DACL_AUTO_INHERITED = const_cpu_to_le16(0x0400),
SE_SACL_AUTO_INHERITED = const_cpu_to_le16(0x0800),
SE_DACL_PROTECTED = const_cpu_to_le16(0x1000),
SE_SACL_PROTECTED = const_cpu_to_le16(0x2000),
SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000),
SE_SELF_RELATIVE = const_cpu_to_le16(0x8000),
} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_CONTROL;
/*
* Self-relative security descriptor. Contains the owner and group SIDs as well
* as the sacl and dacl ACLs inside the security descriptor itself.
*/
typedef struct {
__u8 revision; /* Revision level of the security descriptor. */
__u8 alignment;
SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
the descriptor as well as the following fields. */
__u32 owner; /* Byte offset to a SID representing an object's
owner. If this is NULL, no owner SID is present in
the descriptor. */
__u32 group; /* Byte offset to a SID representing an object's
primary group. If this is NULL, no primary group
SID is present in the descriptor. */
__u32 sacl; /* Byte offset to a system ACL. Only valid, if
SE_SACL_PRESENT is set in the control field. If
SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
is specified. */
__u32 dacl; /* Byte offset to a discretionary ACL. Only valid, if
SE_DACL_PRESENT is set in the control field. If
SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
(unconditionally granting access) is specified. */
/* sizeof() = 0x14 bytes */
} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_RELATIVE;
/*
* Absolute security descriptor. Does not contain the owner and group SIDs, nor
* the sacl and dacl ACLs inside the security descriptor. Instead, it contains
* pointers to these structures in memory. Obviously, absolute security
* descriptors are only useful for in memory representations of security
* descriptors. On disk, a self-relative security descriptor is used.
*/
typedef struct {
__u8 revision; /* Revision level of the security descriptor. */
__u8 alignment;
SECURITY_DESCRIPTOR_CONTROL control; /* Flags qualifying the type of
the descriptor as well as the following fields. */
SID *owner; /* Points to a SID representing an object's owner. If
this is NULL, no owner SID is present in the
descriptor. */
SID *group; /* Points to a SID representing an object's primary
group. If this is NULL, no primary group SID is
present in the descriptor. */
ACL *sacl; /* Points to a system ACL. Only valid, if
SE_SACL_PRESENT is set in the control field. If
SE_SACL_PRESENT is set but sacl is NULL, a NULL ACL
is specified. */
ACL *dacl; /* Points to a discretionary ACL. Only valid, if
SE_DACL_PRESENT is set in the control field. If
SE_DACL_PRESENT is set but dacl is NULL, a NULL ACL
(unconditionally granting access) is specified. */
} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR;
/*
* Current constants for security descriptors.
*/
typedef enum {
/* Current revision. */
SECURITY_DESCRIPTOR_REVISION = 1,
SECURITY_DESCRIPTOR_REVISION1 = 1,
/* The sizes of both the absolute and relative security descriptors is
the same as pointers, at least on ia32 architecture are 32-bit. */
SECURITY_DESCRIPTOR_MIN_LENGTH = sizeof(SECURITY_DESCRIPTOR),
} SECURITY_DESCRIPTOR_CONSTANTS;
/*
* Attribute: Security descriptor (0x50). A standard self-relative security
* descriptor.
*
* NOTE: Can be resident or non-resident.
* NOTE: Not used in NTFS 3.0+, as security descriptors are stored centrally
* in FILE_Secure and the correct descriptor is found using the security_id
* from the standard information attribute.
*/
typedef SECURITY_DESCRIPTOR_RELATIVE SECURITY_DESCRIPTOR_ATTR;
/*
* On NTFS 3.0+, all security descriptors are stored in FILE_Secure. Only one
* referenced instance of each unique security descriptor is stored.
*
* FILE_Secure contains no unnamed data attribute, i.e. it has zero length. It
* does, however, contain two indexes ($SDH and $SII) as well as a named data
* stream ($SDS).
*
* Every unique security descriptor is assigned a unique security identifier
* (security_id, not to be confused with a SID). The security_id is unique for
* the NTFS volume and is used as an index into the $SII index, which maps
* security_ids to the security descriptor's storage location within the $SDS
* data attribute. The $SII index is sorted by ascending security_id.
*
* A simple hash is computed from each security descriptor. This hash is used
* as an index into the $SDH index, which maps security descriptor hashes to
* the security descriptor's storage location within the $SDS data attribute.
* The $SDH index is sorted by security descriptor hash and is stored in a B+
* tree. When searching $SDH (with the intent of determining whether or not a
* new security descriptor is already present in the $SDS data stream), if a
* matching hash is found, but the security descriptors do not match, the
* search in the $SDH index is continued, searching for a next matching hash.
*
* When a precise match is found, the security_id coresponding to the security
* descriptor in the $SDS attribute is read from the found $SDH index entry and
* is stored in the $STANDARD_INFORMATION attribute of the file/directory to
* which the security descriptor is being applied. The $STANDARD_INFORMATION
* attribute is present in all base mft records (i.e. in all files and
* directories).
*
* If a match is not found, the security descriptor is assigned a new unique
* security_id and is added to the $SDS data attribute. Then, entries
* referencing the this security descriptor in the $SDS data attribute are
* added to the $SDH and $SII indexes.
*
* Note: Entries are never deleted from FILE_Secure, even if nothing
* references an entry any more.
*/
/*
* This header precedes each security descriptor in the $SDS data stream.
* This is also the index entry data part of both the $SII and $SDH indexes.
*/
typedef struct {
__u32 hash; /* Hash of the security descriptor. */
__u32 security_id; /* The security_id assigned to the descriptor. */
__u64 offset; /* Byte offset of this entry in the $SDS stream. */
__u32 length; /* Size in bytes of this entry in $SDS stream. */
} __attribute__ ((__packed__)) SECURITY_DESCRIPTOR_HEADER;
/*
* The $SDS data stream contains the security descriptors, aligned on 16-byte
* boundaries, sorted by security_id in a B+ tree. Security descriptors cannot
* cross 256kib boundaries (this restriction is imposed by the Windows cache
* manager). Each security descriptor is contained in a SDS_ENTRY structure.
* Also, each security descriptor is stored twice in the $SDS stream with a
* fixed offset of 0x40000 bytes (256kib, the Windows cache manager's max size)
* between them; i.e. if a SDS_ENTRY specifies an offset of 0x51d0, then the
* the first copy of the security descriptor will be at offset 0x51d0 in the
* $SDS data stream and the second copy will be at offset 0x451d0.
*/
typedef struct {
SECURITY_DESCRIPTOR_HEADER; /* The security descriptor header. */
SECURITY_DESCRIPTOR_RELATIVE sid; /* The self-relative security
descriptor. */
} __attribute__ ((__packed__)) SDS_ENTRY;
/*
* The index entry key used in the $SII index. The collation type is
* COLLATION_NTOFS_ULONG.
*/
typedef struct {
__u32 security_id; /* The security_id assigned to the descriptor. */
} __attribute__ ((__packed__)) SII_INDEX_KEY;
/*
* The index entry key used in the $SDH index. The keys are sorted first by
* hash and then by security_id. The collation rule is
* COLLATION_NTOFS_SECURITY_HASH.
*/
typedef struct {
__u32 hash; /* Hash of the security descriptor. */
__u32 security_id; /* The security_id assigned to the descriptor. */
} __attribute__ ((__packed__)) SDH_INDEX_KEY;
/*
* Attribute: Volume name (0x60).
*
* NOTE: Always resident.
* NOTE: Present only in FILE_Volume.
*/
typedef struct {
uchar_t name[0]; /* The name of the volume in Unicode. */
} __attribute__ ((__packed__)) VOLUME_NAME;
/*
* Possible flags for the volume (16-bit).
*/
typedef enum {
VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001),
VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002),
VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004),
VOLUME_MOUNTED_ON_NT4 = const_cpu_to_le16(0x0008),
VOLUME_DELETE_USN_UNDERWAY = const_cpu_to_le16(0x0010),
VOLUME_REPAIR_OBJECT_ID = const_cpu_to_le16(0x0020),
VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000),
VOLUME_FLAGS_MASK = const_cpu_to_le16(0x803f),
} __attribute__ ((__packed__)) VOLUME_FLAGS;
/*
* Attribute: Volume information (0x70).
*
* NOTE: Always resident.
* NOTE: Present only in FILE_Volume.
* NOTE: Windows 2000 uses NTFS 3.0 while Windows NT4 service pack 6a uses
* NTFS 1.2. I haven't personally seen other values yet.
*/
typedef struct {
__u64 reserved; /* Not used (yet?). */
__u8 major_ver; /* Major version of the ntfs format. */
__u8 minor_ver; /* Minor version of the ntfs format. */
VOLUME_FLAGS flags; /* Bit array of VOLUME_* flags. */
} __attribute__ ((__packed__)) VOLUME_INFORMATION;
/*
* Attribute: Data attribute (0x80).
*
* NOTE: Can be resident or non-resident.
*
* Data contents of a file (i.e. the unnamed stream) or of a named stream.
*/
typedef struct {
__u8 data[0]; /* The file's data contents. */
} __attribute__ ((__packed__)) DATA_ATTR;
/*
* Index header flags (8-bit).
*/
typedef enum {
/* When index header is in an index root attribute: */
SMALL_INDEX = 0, /* The index is small enough to fit inside the
index root attribute and there is no index
allocation attribute present. */
LARGE_INDEX = 1, /* The index is too large to fit in the index
root attribute and/or an index allocation
attribute is present. */
/*
* When index header is in an index block, i.e. is part of index
* allocation attribute:
*/
LEAF_NODE = 0, /* This is a leaf node, i.e. there are no more
nodes branching off it. */
INDEX_NODE = 1, /* This node indexes other nodes, i.e. is not a
leaf node. */
NODE_MASK = 1, /* Mask for accessing the *_NODE bits. */
} __attribute__ ((__packed__)) INDEX_HEADER_FLAGS;
/*
* This is the header for indexes, describing the INDEX_ENTRY records, which
* follow the INDEX_HEADER. Together the index header and the index entries
* make up a complete index.
*
* IMPORTANT NOTE: The offset, length and size structure members are counted
* relative to the start of the index header structure and not relative to the
* start of the index root or index allocation structures themselves.
*/
typedef struct {
__u32 entries_offset; /* Byte offset to first INDEX_ENTRY
aligned to 8-byte boundary. */
__u32 index_length; /* Data size of the index in bytes,
i.e. bytes used from allocated
size, aligned to 8-byte boundary. */
__u32 allocated_size; /* Byte size of this index (block),
multiple of 8 bytes. */
/* NOTE: For the index root attribute, the above two numbers are always
equal, as the attribute is resident and it is resized as needed. In
the case of the index allocation attribute the attribute is not
resident and hence the allocated_size is a fixed value and must
equal the index_block_size specified by the INDEX_ROOT attribute
corresponding to the INDEX_ALLOCATION attribute this INDEX_BLOCK
belongs to. */
INDEX_HEADER_FLAGS flags; /* Bit field of INDEX_HEADER_FLAGS. */
__u8 reserved[3]; /* Reserved/align to 8-byte boundary. */
} __attribute__ ((__packed__)) INDEX_HEADER;
/*
* Attribute: Index root (0x90).
*
* NOTE: Always resident.
*
* This is followed by a sequence of index entries (INDEX_ENTRY structures)
* as described by the index header.
*
* When a directory is small enough to fit inside the index root then this
* is the only attribute describing the directory. When the directory is too
* large to fit in the index root, on the other hand, two aditional attributes
* are present: an index allocation attribute, containing sub-nodes of the B+
* directory tree (see below), and a bitmap attribute, describing which virtual
* cluster numbers (vcns) in the index allocation attribute are in use by an
* index block.
*
* NOTE: The root directory (FILE_root) contains an entry for itself. Other
* dircetories do not contain entries for themselves, though.
*/
typedef struct {
ATTR_TYPES type; /* Type of the indexed attribute. Is
$FILE_NAME for directories, zero
for view indexes. No other values
allowed. */
COLLATION_RULES collation_rule; /* Collation rule used to sort the
index entries. If type is $FILE_NAME,
this must be COLLATION_FILE_NAME. */
__u32 index_block_size; /* Size of each index block in bytes (in
the index allocation attribute). */
__u8 clusters_per_index_block; /* Cluster size of each index block (in
the index allocation attribute), when
an index block is >= than a cluster,
otherwise this will be the log of
the size (like how the encoding of
the mft record size and the index
record size found in the boot sector
work). Has to be a power of 2. */
__u8 reserved[3]; /* Reserved/align to 8-byte boundary. */
INDEX_HEADER index; /* Index header describing the
following index entries. */
} __attribute__ ((__packed__)) INDEX_ROOT;
/*
* Attribute: Index allocation (0xa0).
*
* NOTE: Always non-resident (doesn't make sense to be resident anyway!).
*
* This is an array of index blocks. Each index block starts with an
* INDEX_BLOCK structure containing an index header, followed by a sequence of
* index entries (INDEX_ENTRY structures), as described by the INDEX_HEADER.
*/
typedef struct {
/* 0*/ NTFS_RECORD; /* Magic is "INDX". */
/* 8*/ __s64 lsn; /* $LogFile sequence number of the last
modification of this index block. */
/* 16*/ VCN index_block_vcn; /* Virtual cluster number of the index block. */
/* 24*/ INDEX_HEADER index; /* Describes the following index entries. */
/* sizeof()= 40 (0x28) bytes */
/*
* When creating the index block, we place the update sequence array at this
* offset, i.e. before we start with the index entries. This also makes sense,
* otherwise we could run into problems with the update sequence array
* containing in itself the last two bytes of a sector which would mean that
* multi sector transfer protection wouldn't work. As you can't protect data
* by overwriting it since you then can't get it back...
* When reading use the data from the ntfs record header.
*/
} __attribute__ ((__packed__)) INDEX_BLOCK;
typedef INDEX_BLOCK INDEX_ALLOCATION;
/*
* The system file FILE_Extend/$Reparse contains an index named $R listing
* all reparse points on the volume. The index entry keys are as defined
* below. Note, that there is no index data associated with the index entries.
*
* The index entries are sorted by the index key file_id. The collation rule is
* COLLATION_NTOFS_ULONGS. FIXME: Verify whether the reparse_tag is not the
* primary key / is not a key at all. (AIA)
*/
typedef struct {
__u32 reparse_tag; /* Reparse point type (inc. flags). */
MFT_REF file_id; /* Mft record of the file containing the
reparse point attribute. */
} __attribute__ ((__packed__)) REPARSE_INDEX_KEY;
/*
* Quota flags (32-bit).
*/
typedef enum {
/* The user quota flags. Names explain meaning. */
QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001),
QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002),
QUOTA_FLAG_ID_DELETED = const_cpu_to_le32(0x00000004),
QUOTA_FLAG_USER_MASK = const_cpu_to_le32(0x00000007),
/* Bit mask for user quota flags. */
/* These flags are only present in the quota defaults index entry,
i.e. in the entry where owner_id = QUOTA_DEFAULTS_ID. */
QUOTA_FLAG_TRACKING_ENABLED = const_cpu_to_le32(0x00000010),
QUOTA_FLAG_ENFORCEMENT_ENABLED = const_cpu_to_le32(0x00000020),
QUOTA_FLAG_TRACKING_REQUESTED = const_cpu_to_le32(0x00000040),
QUOTA_FLAG_LOG_THRESHOLD = const_cpu_to_le32(0x00000080),
QUOTA_FLAG_LOG_LIMIT = const_cpu_to_le32(0x00000100),
QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200),
QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400),
QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800),
} QUOTA_FLAGS;
/*
* The system file FILE_Extend/$Quota contains two indexes $O and $Q. Quotas
* are on a per volume and per user basis.
*
* The $Q index contains one entry for each existing user_id on the volume. The
* index key is the user_id of the user/group owning this quota control entry,
* i.e. the key is the owner_id. The user_id of the owner of a file, i.e. the
* owner_id, is found in the standard information attribute. The collation rule
* for $Q is COLLATION_NTOFS_ULONG.
*
* The $O index contains one entry for each user/group who has been assigned
* a quota on that volume. The index key holds the SID of the user_id the
* entry belongs to, i.e. the owner_id. The collation rule for $O is
* COLLATION_NTOFS_SID.
*
* The $O index entry data is the user_id of the user corresponding to the SID.
* This user_id is used as an index into $Q to find the quota control entry
* associated with the SID.
*
* The $Q index entry data is the quota control entry and is defined below.
*/
typedef struct {
__u32 version; /* Currently equals 2. */
QUOTA_FLAGS flags; /* Flags describing this quota entry. */
__u64 bytes_used; /* How many bytes of the quota are in use. */
__s64 change_time; /* Last time this quota entry was changed. */
__s64 threshold; /* Soft quota (-1 if not limited). */
__s64 limit; /* Hard quota (-1 if not limited). */
__s64 exceeded_time; /* How long the soft quota has been exceeded. */
SID sid; /* The SID of the user/object associated with
this quota entry. Equals zero for the quota
defaults entry. */
} __attribute__ ((__packed__)) QUOTA_CONTROL_ENTRY;
/*
* Predefined owner_id values (32-bit).
*/
typedef enum {
QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000),
QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001),
QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100),
} PREDEFINED_OWNER_IDS;
/*
* Index entry flags (16-bit).
*/
typedef enum {
INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a sub-node,
i.e. a reference to an index
block in form of a virtual
cluster number (see below). */
INDEX_ENTRY_END = const_cpu_to_le16(2), /* This signifies the last entry in
an index block. The index entry
does not represent a file but it
can point to a sub-node. */
INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */
} __attribute__ ((__packed__)) INDEX_ENTRY_FLAGS;
/*
* This the index entry header (see below).
*/
typedef struct {
/* 0*/ union { /* Only valid when INDEX_ENTRY_END is not set. */
MFT_REF indexed_file; /* The mft reference of the file
described by this index
entry. Used for directory
indexes. */
struct { /* Used for views/indexes to find the entry's data. */
__u16 data_offset; /* Data byte offset from this
INDEX_ENTRY. Follows the
index key. */
__u16 data_length; /* Data length in bytes. */
__u32 reservedV; /* Reserved (zero). */
} __attribute__ ((__packed__));
} __attribute__ ((__packed__));
/* 8*/ __u16 length; /* Byte size of this index entry, multiple of
8-bytes. */
/* 10*/ __u16 key_length; /* Byte size of the key value, which is in the
index entry. It follows field reserved. Not
multiple of 8-bytes. */
/* 12*/ INDEX_ENTRY_FLAGS flags; /* Bit field of INDEX_ENTRY_* flags. */
/* 14*/ __u16 reserved; /* Reserved/align to 8-byte boundary. */
/* sizeof() = 16 bytes */
} __attribute__ ((__packed__)) INDEX_ENTRY_HEADER;
/*
* This is an index entry. A sequence of such entries follows each INDEX_HEADER
* structure. Together they make up a complete index. The index follows either
* an index root attribute or an index allocation attribute.
*
* NOTE: Before NTFS 3.0 only filename attributes were indexed.
*/
typedef struct {
/* 0*/ INDEX_ENTRY_HEADER; /* The index entry header (see above). */
/* 16*/ union { /* The key of the indexed attribute. NOTE: Only present
if INDEX_ENTRY_END bit in flags is not set. NOTE: On
NTFS versions before 3.0 the only valid key is the
FILE_NAME_ATTR. On NTFS 3.0+ the following
additional index keys are defined: */
FILE_NAME_ATTR file_name;/* $I30 index in directories. */
SII_INDEX_KEY sii; /* $SII index in $Secure. */
SDH_INDEX_KEY sdh; /* $SDH index in $Secure. */
GUID object_id; /* $O index in FILE_Extend/$ObjId: The
object_id of the mft record found in
the data part of the index. */
REPARSE_INDEX_KEY; /* $R index in FILE_Extend/$Reparse. */
SID sid; /* $O index in FILE_Extend/$Quota:
SID of the owner of the user_id. */
__u32 owner_id; /* $Q index in FILE_Extend/$Quota:
user_id of the owner of the quota
control entry in the data part of
the index. */
} __attribute__ ((__packed__)) key;
/* The (optional) index data is inserted here when creating. */
// VCN vcn; /* If INDEX_ENTRY_NODE bit in flags is set, the last
// eight bytes of this index entry contain the virtual
// cluster number of the index block that holds the
// entries immediately preceding the current entry (the
// vcn references the corresponding cluster in the data
// of the non-resident index allocation attribute). If
// the key_length is zero, then the vcn immediately
// follows the INDEX_ENTRY_HEADER. Regardless of
// key_length, the address of the 8-byte boundary
// alligned vcn of INDEX_ENTRY{_HEADER} *ie is given by
// (char*)ie + le16_to_cpu(ie*)->length) - sizeof(VCN),
// where sizeof(VCN) can be hardcoded as 8 if wanted. */
} __attribute__ ((__packed__)) INDEX_ENTRY;
/*
* Attribute: Bitmap (0xb0).
*
* Contains an array of bits (aka a bitfield).
*
* When used in conjunction with the index allocation attribute, each bit
* corresponds to one index block within the index allocation attribute. Thus
* the number of bits in the bitmap * index block size / cluster size is the
* number of clusters in the index allocation attribute.
*/
typedef struct {
__u8 bitmap[0]; /* Array of bits. */
} __attribute__ ((__packed__)) BITMAP_ATTR;
/*
* The reparse point tag defines the type of the reparse point. It also
* includes several flags, which further describe the reparse point.
*
* The reparse point tag is an unsigned 32-bit value divided in three parts:
*
* 1. The least significant 16 bits (i.e. bits 0 to 15) specifiy the type of
* the reparse point.
* 2. The 13 bits after this (i.e. bits 16 to 28) are reserved for future use.
* 3. The most significant three bits are flags describing the reparse point.
* They are defined as follows:
* bit 29: Name surrogate bit. If set, the filename is an alias for
* another object in the system.
* bit 30: High-latency bit. If set, accessing the first byte of data will
* be slow. (E.g. the data is stored on a tape drive.)
* bit 31: Microsoft bit. If set, the tag is owned by Microsoft. User
* defined tags have to use zero here.
*/
typedef enum {
IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000),
IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000),
IO_REPARSE_TAG_IS_MICROSOFT = const_cpu_to_le32(0x80000000),
IO_REPARSE_TAG_RESERVED_ZERO = const_cpu_to_le32(0x00000000),
IO_REPARSE_TAG_RESERVED_ONE = const_cpu_to_le32(0x00000001),
IO_REPARSE_TAG_RESERVED_RANGE = const_cpu_to_le32(0x00000001),
IO_REPARSE_TAG_NSS = const_cpu_to_le32(0x68000005),
IO_REPARSE_TAG_NSS_RECOVER = const_cpu_to_le32(0x68000006),
IO_REPARSE_TAG_SIS = const_cpu_to_le32(0x68000007),
IO_REPARSE_TAG_DFS = const_cpu_to_le32(0x68000008),
IO_REPARSE_TAG_MOUNT_POINT = const_cpu_to_le32(0x88000003),
IO_REPARSE_TAG_HSM = const_cpu_to_le32(0xa8000004),
IO_REPARSE_TAG_SYMBOLIC_LINK = const_cpu_to_le32(0xe8000000),
IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xe000ffff),
} PREDEFINED_REPARSE_TAGS;
/*
* Attribute: Reparse point (0xc0).
*
* NOTE: Can be resident or non-resident.
*/
typedef struct {
__u32 reparse_tag; /* Reparse point type (inc. flags). */
__u16 reparse_data_length; /* Byte size of reparse data. */
__u16 reserved; /* Align to 8-byte boundary. */
__u8 reparse_data[0]; /* Meaning depends on reparse_tag. */
} __attribute__ ((__packed__)) REPARSE_POINT;
/*
* Attribute: Extended attribute (EA) information (0xd0).
*
* NOTE: Always resident. (Is this true???)
*/
typedef struct {
__u16 ea_length; /* Byte size of the packed extended
attributes. */
__u16 need_ea_count; /* The number of extended attributes which have
the NEED_EA bit set. */
__u32 ea_query_length; /* Byte size of the buffer required to query
the extended attributes when calling
ZwQueryEaFile() in Windows NT/2k. I.e. the
byte size of the unpacked extended
attributes. */
} __attribute__ ((__packed__)) EA_INFORMATION;
/*
* Extended attribute flags (8-bit).
*/
typedef enum {
NEED_EA = 0x80,
} __attribute__ ((__packed__)) EA_FLAGS;
/*
* Attribute: Extended attribute (EA) (0xe0).
*
* NOTE: Always non-resident. (Is this true?)
*
* Like the attribute list and the index buffer list, the EA attribute value is
* a sequence of EA_ATTR variable length records.
*
* FIXME: It appears weird that the EA name is not unicode. Is it true?
*/
typedef struct {
__u32 next_entry_offset; /* Offset to the next EA_ATTR. */
EA_FLAGS flags; /* Flags describing the EA. */
__u8 ea_name_length; /* Length of the name of the extended
attribute in bytes. */
__u16 ea_value_length; /* Byte size of the EA's value. */
__u8 ea_name[0]; /* Name of the EA. */
__u8 ea_value[0]; /* The value of the EA. Immediately
follows the name. */
} __attribute__ ((__packed__)) EA_ATTR;
/*
* Attribute: Property set (0xf0).
*
* Intended to support Native Structure Storage (NSS) - a feature removed from
* NTFS 3.0 during beta testing.
*/
typedef struct {
/* Irrelevant as feature unused. */
} __attribute__ ((__packed__)) PROPERTY_SET;
/*
* Attribute: Logged utility stream (0x100).
*
* NOTE: Can be resident or non-resident.
*
* Operations on this attribute are logged to the journal ($LogFile) like
* normal metadata changes.
*
* Used by the Encrypting File System (EFS). All encrypted files have this
* attribute with the name $EFS.
*/
typedef struct {
/* Can be anything the creator chooses. */
/* EFS uses it as follows: */
// FIXME: Type this info, verifying it along the way. (AIA)
} __attribute__ ((__packed__)) LOGGED_UTILITY_STREAM, EFS_ATTR;
#endif /* _LINUX_NTFS_LAYOUT_H */
......@@ -164,7 +164,8 @@ EXPORT_SYMBOL(d_alloc);
EXPORT_SYMBOL(d_lookup);
EXPORT_SYMBOL(__d_path);
EXPORT_SYMBOL(mark_buffer_dirty);
EXPORT_SYMBOL(set_buffer_async_io); /* for reiserfs_writepage */
EXPORT_SYMBOL(end_buffer_io_sync);
EXPORT_SYMBOL(set_buffer_async_io);
EXPORT_SYMBOL(__mark_buffer_dirty);
EXPORT_SYMBOL(__mark_inode_dirty);
EXPORT_SYMBOL(get_empty_filp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment