inode.h 10.1 KB
Newer Older
Anton Altaparmakov's avatar
Anton Altaparmakov committed
1 2 3 4
/*
 * inode.h - Defines for inode structures NTFS Linux kernel driver. Part of
 *	     the Linux-NTFS project.
 *
5
 * Copyright (c) 2001-2004 Anton Altaparmakov
6
 * Copyright (c) 2002 Richard Russon
Anton Altaparmakov's avatar
Anton Altaparmakov committed
7 8 9 10 11 12
 *
 * 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.
 *
13 14
 * This program/include file is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
Anton Altaparmakov's avatar
Anton Altaparmakov committed
15 16 17 18
 * 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
19
 * along with this program (in the main directory of the Linux-NTFS
Anton Altaparmakov's avatar
Anton Altaparmakov committed
20 21 22 23 24 25 26 27 28
 * 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_INODE_H
#define _LINUX_NTFS_INODE_H

#include <linux/seq_file.h>

29
#include "layout.h"
Anton Altaparmakov's avatar
Anton Altaparmakov committed
30 31 32 33 34 35 36 37 38
#include "volume.h"

typedef struct _ntfs_inode ntfs_inode;

/*
 * 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 {
39 40
	s64 initialized_size;	/* Copy from the attribute record. */
	s64 allocated_size;	/* Copy from the attribute record. */
Anton Altaparmakov's avatar
Anton Altaparmakov committed
41
	unsigned long state;	/* NTFS specific flags describing this inode.
42
				   See ntfs_inode_state_bits below. */
43
	unsigned long mft_no;	/* Number of the mft record / inode. */
Anton Altaparmakov's avatar
Anton Altaparmakov committed
44 45 46
	u16 seq_no;		/* Sequence number of the mft record. */
	atomic_t count;		/* Inode reference count for book keeping. */
	ntfs_volume *vol;	/* Pointer to the ntfs volume of this inode. */
47 48 49 50 51 52 53 54 55 56
	/*
	 * If NInoAttr() is true, the below fields describe the attribute which
	 * this fake inode belongs to. The actual inode of this attribute is
	 * pointed to by base_ntfs_ino and nr_extents is always set to -1 (see
	 * below). For real inodes, we also set the type (AT_DATA for files and
	 * AT_INDEX_ALLOCATION for directories), with the name = NULL and
	 * name_len = 0 for files and name = I30 (global constant) and
	 * name_len = 4 for directories.
	 */
	ATTR_TYPES type;	/* Attribute type of this fake inode. */
57
	ntfschar *name;		/* Attribute name of this fake inode. */
58
	u32 name_len;		/* Attribute name length of this fake inode. */
Anton Altaparmakov's avatar
Anton Altaparmakov committed
59 60 61
	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
62 63 64 65 66 67 68 69 70 71 72 73 74
				   attribute (directory) or of the attribute
				   described by the fake inode (if NInoAttr()).
				   If run_list.rl is NULL, the run list has not
				   been read in yet or has been unmapped. If
				   NI_NonResident is clear, the attribute is
				   resident (file and fake inode) or there is
				   no $I30 index allocation attribute
				   (small directory). In the latter case
				   run_list.rl is always NULL.*/
	/*
	 * The following fields are only valid for real inodes and extent
	 * inodes.
	 */
75
	struct semaphore mrec_lock; /* Lock for serializing access to the
Anton Altaparmakov's avatar
Anton Altaparmakov committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
				   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*() functions. */
	int page_ofs;		/* Offset into the page at which the mft record
				   begins. This should only be touched by the
				   (un)map_mft_record*() functions. */
	/*
	 * Attribute list support (only for use by the attribute lookup
	 * functions). Setup during read_inode for all inodes with attribute
	 * lists. Only valid if NI_AttrList is set in state, and attr_list_rl is
	 * further only valid if NI_AttrListNonResident is set.
	 */
	u32 attr_list_size;	/* Length of attribute list value in bytes. */
	u8 *attr_list;		/* Attribute list value itself. */
	run_list attr_list_rl;	/* Run list for the attribute list value. */
	union {
		struct { /* It is a directory or $MFT. */
94 95
			struct inode *bmp_ino;	/* Attribute inode for the
						   directory index $BITMAP. */
96 97
			u32 block_size;		/* Size of an index block. */
			u32 vcn_size;		/* Size of a vcn in this
Anton Altaparmakov's avatar
Anton Altaparmakov committed
98
						   directory index. */
99 100 101
			u8 block_size_bits; 	/* Log2 of the above. */
			u8 vcn_size_bits;	/* Log2 of the above. */
		} index;
102
		struct { /* It is a compressed file or fake inode. */
103 104 105 106 107 108 109 110
			s64 size;		/* Copy of compressed_size from
						   $DATA. */
			u32 block_size;		/* Size of a compression block
						   (cb). */
			u8 block_size_bits;	/* Log2 of the size of a cb. */
			u8 block_clusters;	/* Number of clusters per cb. */
		} compressed;
	} itype;
Anton Altaparmakov's avatar
Anton Altaparmakov committed
111 112 113
	struct semaphore extent_lock;	/* Lock for accessing/modifying the
					   below . */
	s32 nr_extents;	/* For a base mft record, the number of attached extent
114 115
			   inodes (0 if none), for extent records and for fake
			   inodes describing an attribute this is -1. */
Anton Altaparmakov's avatar
Anton Altaparmakov committed
116 117 118 119 120 121 122
	union {		/* This union is only used if nr_extents != 0. */
		ntfs_inode **extent_ntfs_inos;	/* For nr_extents > 0, array of
						   the ntfs inodes of the extent
						   mft records belonging to
						   this base inode which have
						   been loaded. */
		ntfs_inode *base_ntfs_ino;	/* For nr_extents == -1, the
Anton Altaparmakov's avatar
Anton Altaparmakov committed
123
						   ntfs inode of the base mft
124 125 126
						   record. For fake inodes, the
						   real (base) inode to which
						   the attribute belongs. */
127
	} ext;
Anton Altaparmakov's avatar
Anton Altaparmakov committed
128 129
};

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
/*
 * Defined bits for the state field in the ntfs_inode structure.
 * (f) = files only, (d) = directories only, (a) = attributes/fake inodes only
 */
typedef enum {
	NI_Dirty,		/* 1: Mft record needs to be written to disk. */
	NI_AttrList,		/* 1: Mft record contains an attribute list. */
	NI_AttrListNonResident,	/* 1: Attribute list is non-resident. Implies
				      NI_AttrList is set. */

	NI_Attr,		/* 1: Fake inode for attribute i/o.
				   0: Real inode or extent inode. */

	NI_MstProtected,	/* 1: Attribute is protected by MST fixups.
				   0: Attribute is not protected by fixups. */
	NI_NonResident,		/* 1: Unnamed data attr is non-resident (f).
				   1: Attribute is non-resident (a). */
	NI_IndexAllocPresent = NI_NonResident,	/* 1: $I30 index alloc attr is
						   present (d). */
	NI_Compressed,		/* 1: Unnamed data attr is compressed (f).
				   1: Create compressed files by default (d).
				   1: Attribute is compressed (a). */
	NI_Encrypted,		/* 1: Unnamed data attr is encrypted (f).
				   1: Create encrypted files by default (d).
				   1: Attribute is encrypted (a). */
	NI_Sparse,		/* 1: Unnamed data attr is sparse (f).
				   1: Create sparse files by default (d).
				   1: Attribute is sparse (a). */
} 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.
 */

/*
 * Macro tricks to expand the NInoFoo(), NInoSetFoo(), and NInoClearFoo()
 * functions.
 */
#define NINO_FNS(flag)					\
static inline int NIno##flag(ntfs_inode *ni)		\
{							\
	return test_bit(NI_##flag, &(ni)->state);	\
}							\
static inline void NInoSet##flag(ntfs_inode *ni)	\
{							\
	set_bit(NI_##flag, &(ni)->state);		\
}							\
static inline void NInoClear##flag(ntfs_inode *ni)	\
{							\
	clear_bit(NI_##flag, &(ni)->state);		\
}

184 185 186 187 188 189 190 191 192 193 194 195 196
/*
 * As above for NInoTestSetFoo() and NInoTestClearFoo().
 */
#define TAS_NINO_FNS(flag)					\
static inline int NInoTestSet##flag(ntfs_inode *ni)		\
{								\
	return test_and_set_bit(NI_##flag, &(ni)->state);	\
}								\
static inline int NInoTestClear##flag(ntfs_inode *ni)		\
{								\
	return test_and_clear_bit(NI_##flag, &(ni)->state);	\
}

197 198
/* Emit the ntfs inode bitops functions. */
NINO_FNS(Dirty)
199
TAS_NINO_FNS(Dirty)
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
NINO_FNS(AttrList)
NINO_FNS(AttrListNonResident)
NINO_FNS(Attr)
NINO_FNS(MstProtected)
NINO_FNS(NonResident)
NINO_FNS(IndexAllocPresent)
NINO_FNS(Compressed)
NINO_FNS(Encrypted)
NINO_FNS(Sparse)

/*
 * The full structure containing a ntfs_inode and a vfs struct inode. Used for
 * all real and fake inodes but not for extent inodes which lack the vfs struct
 * inode.
 */
Anton Altaparmakov's avatar
Anton Altaparmakov committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
typedef struct {
	ntfs_inode ntfs_inode;
	struct inode vfs_inode;		/* The vfs inode structure. */
} big_ntfs_inode;

/**
 * NTFS_I - return the ntfs inode given a vfs inode
 * @inode:	VFS inode
 *
 * NTFS_I() returns the ntfs inode associated with the VFS @inode.
 */
static inline ntfs_inode *NTFS_I(struct inode *inode)
{
	return (ntfs_inode *)list_entry(inode, big_ntfs_inode, vfs_inode);
}

static inline struct inode *VFS_I(ntfs_inode *ni)
{
233
	return &((big_ntfs_inode *)ni)->vfs_inode;
Anton Altaparmakov's avatar
Anton Altaparmakov committed
234 235
}

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
/**
 * ntfs_attr - ntfs in memory attribute structure
 * @mft_no:	mft record number of the base mft record of this attribute
 * @name:	Unicode name of the attribute (NULL if unnamed)
 * @name_len:	length of @name in Unicode characters (0 if unnamed)
 * @type:	attribute type (see layout.h)
 *
 * This structure exists only to provide a small structure for the
 * ntfs_{attr_}iget()/ntfs_test_inode()/ntfs_init_locked_inode() mechanism.
 *
 * NOTE: Elements are ordered by size to make the structure as compact as
 * possible on all architectures.
 */
typedef struct {
	unsigned long mft_no;
251
	ntfschar *name;
252 253 254 255 256 257 258 259
	u32 name_len;
	ATTR_TYPES type;
} ntfs_attr;

typedef int (*test_t)(struct inode *, void *);

extern int ntfs_test_inode(struct inode *vi, ntfs_attr *na);

260
extern struct inode *ntfs_iget(struct super_block *sb, unsigned long mft_no);
261
extern struct inode *ntfs_attr_iget(struct inode *base_vi, ATTR_TYPES type,
262
		ntfschar *name, u32 name_len);
263

Anton Altaparmakov's avatar
Anton Altaparmakov committed
264 265 266 267
extern struct inode *ntfs_alloc_big_inode(struct super_block *sb);
extern void ntfs_destroy_big_inode(struct inode *inode);
extern void ntfs_clear_big_inode(struct inode *vi);

268 269
extern ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
		unsigned long mft_no);
270
extern void ntfs_clear_extent_inode(ntfs_inode *ni);
Anton Altaparmakov's avatar
Anton Altaparmakov committed
271

Alexander Viro's avatar
Alexander Viro committed
272
extern int ntfs_read_inode_mount(struct inode *vi);
Anton Altaparmakov's avatar
Anton Altaparmakov committed
273

274 275
extern void ntfs_put_inode(struct inode *vi);

Anton Altaparmakov's avatar
Anton Altaparmakov committed
276 277
extern int ntfs_show_options(struct seq_file *sf, struct vfsmount *mnt);

278 279
#ifdef NTFS_RW

280 281 282 283
extern void ntfs_truncate(struct inode *vi);

extern int ntfs_setattr(struct dentry *dentry, struct iattr *attr);

284
#endif /* NTFS_RW */
285

286
#endif /* _LINUX_NTFS_INODE_H */