xref: /onnv-gate/usr/src/lib/libntfs/common/include/ntfs/mft.h (revision 9663:ace9a2ac3683)
1*9663SMark.Logan@Sun.COM /*
2*9663SMark.Logan@Sun.COM  * mft.h - Exports for MFT record handling. Part of the Linux-NTFS project.
3*9663SMark.Logan@Sun.COM  *
4*9663SMark.Logan@Sun.COM  * Copyright (c) 2000-2002 Anton Altaparmakov
5*9663SMark.Logan@Sun.COM  * Copyright (c) 2004-2005 Richard Russon
6*9663SMark.Logan@Sun.COM  *
7*9663SMark.Logan@Sun.COM  * This program/include file is free software; you can redistribute it and/or
8*9663SMark.Logan@Sun.COM  * modify it under the terms of the GNU General Public License as published
9*9663SMark.Logan@Sun.COM  * by the Free Software Foundation; either version 2 of the License, or
10*9663SMark.Logan@Sun.COM  * (at your option) any later version.
11*9663SMark.Logan@Sun.COM  *
12*9663SMark.Logan@Sun.COM  * This program/include file is distributed in the hope that it will be
13*9663SMark.Logan@Sun.COM  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14*9663SMark.Logan@Sun.COM  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*9663SMark.Logan@Sun.COM  * GNU General Public License for more details.
16*9663SMark.Logan@Sun.COM  *
17*9663SMark.Logan@Sun.COM  * You should have received a copy of the GNU General Public License
18*9663SMark.Logan@Sun.COM  * along with this program (in the main directory of the Linux-NTFS
19*9663SMark.Logan@Sun.COM  * distribution in the file COPYING); if not, write to the Free Software
20*9663SMark.Logan@Sun.COM  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21*9663SMark.Logan@Sun.COM  */
22*9663SMark.Logan@Sun.COM 
23*9663SMark.Logan@Sun.COM #ifndef _NTFS_MFT_H
24*9663SMark.Logan@Sun.COM #define _NTFS_MFT_H
25*9663SMark.Logan@Sun.COM 
26*9663SMark.Logan@Sun.COM #include "volume.h"
27*9663SMark.Logan@Sun.COM #include "inode.h"
28*9663SMark.Logan@Sun.COM #include "layout.h"
29*9663SMark.Logan@Sun.COM 
30*9663SMark.Logan@Sun.COM extern int ntfs_mft_records_read(const ntfs_volume *vol, const MFT_REF mref,
31*9663SMark.Logan@Sun.COM 		const s64 count, MFT_RECORD *b);
32*9663SMark.Logan@Sun.COM 
33*9663SMark.Logan@Sun.COM /**
34*9663SMark.Logan@Sun.COM  * ntfs_mft_record_read - read a record from the mft
35*9663SMark.Logan@Sun.COM  * @vol:	volume to read from
36*9663SMark.Logan@Sun.COM  * @mref:	mft record number to read
37*9663SMark.Logan@Sun.COM  * @b:		output data buffer
38*9663SMark.Logan@Sun.COM  *
39*9663SMark.Logan@Sun.COM  * Read the mft record specified by @mref from volume @vol into buffer @b.
40*9663SMark.Logan@Sun.COM  * Return 0 on success or -1 on error, with errno set to the error code.
41*9663SMark.Logan@Sun.COM  *
42*9663SMark.Logan@Sun.COM  * The read mft record is mst deprotected and is hence ready to use. The caller
43*9663SMark.Logan@Sun.COM  * should check the record with is_baad_record() in case mst deprotection
44*9663SMark.Logan@Sun.COM  * failed.
45*9663SMark.Logan@Sun.COM  *
46*9663SMark.Logan@Sun.COM  * NOTE: @b has to be at least of size vol->mft_record_size.
47*9663SMark.Logan@Sun.COM  */
ntfs_mft_record_read(const ntfs_volume * vol,const MFT_REF mref,MFT_RECORD * b)48*9663SMark.Logan@Sun.COM static __inline__ int ntfs_mft_record_read(const ntfs_volume *vol,
49*9663SMark.Logan@Sun.COM 		const MFT_REF mref, MFT_RECORD *b)
50*9663SMark.Logan@Sun.COM {
51*9663SMark.Logan@Sun.COM 	return ntfs_mft_records_read(vol, mref, 1, b);
52*9663SMark.Logan@Sun.COM }
53*9663SMark.Logan@Sun.COM 
54*9663SMark.Logan@Sun.COM extern int ntfs_file_record_read(const ntfs_volume *vol, const MFT_REF mref,
55*9663SMark.Logan@Sun.COM 		MFT_RECORD **mrec, ATTR_RECORD **attr);
56*9663SMark.Logan@Sun.COM 
57*9663SMark.Logan@Sun.COM extern int ntfs_mft_records_write(const ntfs_volume *vol, const MFT_REF mref,
58*9663SMark.Logan@Sun.COM 		const s64 count, MFT_RECORD *b);
59*9663SMark.Logan@Sun.COM 
60*9663SMark.Logan@Sun.COM /**
61*9663SMark.Logan@Sun.COM  * ntfs_mft_record_write - write an mft record to disk
62*9663SMark.Logan@Sun.COM  * @vol:	volume to write to
63*9663SMark.Logan@Sun.COM  * @mref:	mft record number to write
64*9663SMark.Logan@Sun.COM  * @b:		data buffer containing the mft record to write
65*9663SMark.Logan@Sun.COM  *
66*9663SMark.Logan@Sun.COM  * Write the mft record specified by @mref from buffer @b to volume @vol.
67*9663SMark.Logan@Sun.COM  * Return 0 on success or -1 on error, with errno set to the error code.
68*9663SMark.Logan@Sun.COM  *
69*9663SMark.Logan@Sun.COM  * Before the mft record is written, it is mst protected. After the write, it
70*9663SMark.Logan@Sun.COM  * is deprotected again, thus resulting in an increase in the update sequence
71*9663SMark.Logan@Sun.COM  * number inside the buffer @b.
72*9663SMark.Logan@Sun.COM  *
73*9663SMark.Logan@Sun.COM  * NOTE: @b has to be at least of size vol->mft_record_size.
74*9663SMark.Logan@Sun.COM  */
ntfs_mft_record_write(const ntfs_volume * vol,const MFT_REF mref,MFT_RECORD * b)75*9663SMark.Logan@Sun.COM static __inline__ int ntfs_mft_record_write(const ntfs_volume *vol,
76*9663SMark.Logan@Sun.COM 		const MFT_REF mref, MFT_RECORD *b)
77*9663SMark.Logan@Sun.COM {
78*9663SMark.Logan@Sun.COM 	return ntfs_mft_records_write(vol, mref, 1, b);
79*9663SMark.Logan@Sun.COM }
80*9663SMark.Logan@Sun.COM 
81*9663SMark.Logan@Sun.COM /**
82*9663SMark.Logan@Sun.COM  * ntfs_mft_record_get_data_size - return number of bytes used in mft record @b
83*9663SMark.Logan@Sun.COM  * @m:		mft record to get the data size of
84*9663SMark.Logan@Sun.COM  *
85*9663SMark.Logan@Sun.COM  * Takes the mft record @m and returns the number of bytes used in the record
86*9663SMark.Logan@Sun.COM  * or 0 on error (i.e. @m is not a valid mft record).  Zero is not a valid size
87*9663SMark.Logan@Sun.COM  * for an mft record as it at least has to have the MFT_RECORD itself and a
88*9663SMark.Logan@Sun.COM  * zero length attribute of type AT_END, thus making the minimum size 56 bytes.
89*9663SMark.Logan@Sun.COM  *
90*9663SMark.Logan@Sun.COM  * Aside:  The size is independent of NTFS versions 1.x/3.x because the 8-byte
91*9663SMark.Logan@Sun.COM  * alignment of the first attribute mask the difference in MFT_RECORD size
92*9663SMark.Logan@Sun.COM  * between NTFS 1.x and 3.x.  Also, you would expect every mft record to
93*9663SMark.Logan@Sun.COM  * contain an update sequence array as well but that could in theory be
94*9663SMark.Logan@Sun.COM  * non-existent (don't know if Windows' NTFS driver/chkdsk wouldn't view this
95*9663SMark.Logan@Sun.COM  * as corruption in itself though).
96*9663SMark.Logan@Sun.COM  */
ntfs_mft_record_get_data_size(const MFT_RECORD * m)97*9663SMark.Logan@Sun.COM static __inline__ u32 ntfs_mft_record_get_data_size(const MFT_RECORD *m)
98*9663SMark.Logan@Sun.COM {
99*9663SMark.Logan@Sun.COM 	if (!m || !ntfs_is_mft_record(m->magic))
100*9663SMark.Logan@Sun.COM 		return 0;
101*9663SMark.Logan@Sun.COM 	/* Get the number of used bytes and return it. */
102*9663SMark.Logan@Sun.COM 	return le32_to_cpu(m->bytes_in_use);
103*9663SMark.Logan@Sun.COM }
104*9663SMark.Logan@Sun.COM 
105*9663SMark.Logan@Sun.COM extern int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref,
106*9663SMark.Logan@Sun.COM 		MFT_RECORD *mrec);
107*9663SMark.Logan@Sun.COM 
108*9663SMark.Logan@Sun.COM extern int ntfs_mft_record_format(const ntfs_volume *vol, const MFT_REF mref);
109*9663SMark.Logan@Sun.COM 
110*9663SMark.Logan@Sun.COM extern ntfs_inode *ntfs_mft_record_alloc(ntfs_volume *vol, ntfs_inode *base_ni);
111*9663SMark.Logan@Sun.COM 
112*9663SMark.Logan@Sun.COM extern int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni);
113*9663SMark.Logan@Sun.COM 
114*9663SMark.Logan@Sun.COM extern int ntfs_mft_usn_dec(MFT_RECORD *mrec);
115*9663SMark.Logan@Sun.COM 
116*9663SMark.Logan@Sun.COM #endif /* defined _NTFS_MFT_H */
117