http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200309071734.tar.bz2
[ntfsprogs.git] / include / volume.h
1 /*
2  * volume.h - Exports for NTFS volume handling. Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2000-2003 Anton Altaparmakov
5  *
6  * This program/include file is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program/include file is distributed in the hope that it will be
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (in the main directory of the Linux-NTFS
18  * distribution in the file COPYING); if not, write to the Free Software
19  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef _NTFS_VOLUME_H
23 #define _NTFS_VOLUME_H
24
25 #include "config.h"
26
27 #include <stdio.h>
28 #include <sys/mount.h>
29 #ifdef HAVE_MNTENT_H
30 #       include <mntent.h>
31 #endif
32
33 /* Forward declaration */
34 typedef struct _ntfs_volume ntfs_volume;
35
36 #include "types.h"
37 #include "support.h"
38 #include "inode.h"
39 #include "device.h"
40
41 /*
42  * Flags returned by the ntfs_check_if_mounted() function.
43  */
44 typedef enum {
45         NTFS_MF_MOUNTED         = 1,    /* Device is mounted. */
46         NTFS_MF_ISROOT          = 2,    /* Device is mounted as system root. */
47         NTFS_MF_READONLY        = 4,    /* Device is mounted read-only. */
48 } ntfs_mount_flags;
49
50 extern int ntfs_check_if_mounted(const char *file, unsigned long *mnt_flags);
51
52 /*
53  * Defined bits for the state field in the ntfs_volume structure.
54  */
55 typedef enum {
56         NV_ReadOnly,            /* 1: Volume is read-only. */
57         NV_CaseSensitive,       /* 1: Volume is mounted case-sensitive. */
58 } ntfs_volume_state_bits;
59
60 #define  test_nvol_flag(nv, flag)        test_bit(NV_##flag, (nv)->state)
61 #define   set_nvol_flag(nv, flag)         set_bit(NV_##flag, (nv)->state)
62 #define clear_nvol_flag(nv, flag)       clear_bit(NV_##flag, (nv)->state)
63
64 #define NVolReadOnly(nv)                 test_nvol_flag(nv, ReadOnly)
65 #define NVolSetReadOnly(nv)               set_nvol_flag(nv, ReadOnly)
66 #define NVolClearReadOnly(nv)           clear_nvol_flag(nv, ReadOnly)
67
68 #define NVolCaseSensitive(nv)            test_nvol_flag(nv, CaseSensitive)
69 #define NVolSetCaseSensitive(nv)          set_nvol_flag(nv, CaseSensitive)
70 #define NVolClearCaseSensitive(nv)      clear_nvol_flag(nv, CaseSensitive)
71
72 /*
73  * NTFS version 1.1 and 1.2 are used by Windows NT4.
74  * NTFS version 2.x is used by Windows 2000 Beta
75  * NTFS version 3.0 is used by Windows 2000.
76  * NTFS version 3.1 is used by Windows XP and .NET.
77  */
78
79 #define NTFS_V1_1(major, minor) ((major) == 1 && (minor) == 1)
80 #define NTFS_V1_2(major, minor) ((major) == 1 && (minor) == 2)
81 #define NTFS_V2_X(major, minor) ((major) == 2)
82 #define NTFS_V3_0(major, minor) ((major) == 3 && (minor) == 0)
83 #define NTFS_V3_1(major, minor) ((major) == 3 && (minor) == 1)
84
85 #define NTFS_BUF_SIZE 8192
86
87 /*
88  * ntfs_volume - structure describing an open volume in memory
89  */
90 struct _ntfs_volume {
91         struct ntfs_device *dev;/* NTFS device associated with the volume. */
92         char *vol_name;         /* Name of the volume. */
93         unsigned long state;    /* NTFS specific flags describing this volume.
94                                    See ntfs_volume_state_bits above. */
95         u8 major_ver;           /* Ntfs major version of volume. */
96         u8 minor_ver;           /* Ntfs minor version of volume. */
97         u16 flags;              /* Bit array of VOLUME_* flags. */
98
99         u16 sector_size;        /* Byte size of a sector. */
100         u8 sector_size_bits;    /* Log(2) of the byte size of a sector. */
101         u32 cluster_size;       /* Byte size of a cluster. */
102         u32 mft_record_size;    /* Byte size of a mft record. */
103         u8 cluster_size_bits;   /* Log(2) of the byte size of a cluster. */
104         u8 mft_record_size_bits;/* Log(2) of the byte size of a mft record. */
105
106         /* Variables used by the cluster and mft allocators. */
107         u8 mft_zone_multiplier; /* Initial mft zone multiplier. */
108         s64 mft_data_pos;       /* Mft record number at which to allocate the
109                                    next mft record. */
110         LCN mft_zone_start;     /* First cluster of the mft zone. */
111         LCN mft_zone_end;       /* First cluster beyond the mft zone. */
112         LCN mft_zone_pos;       /* Current position in the mft zone. */
113         LCN data1_zone_pos;     /* Current position in the first data zone. */
114         LCN data2_zone_pos;     /* Current position in the second data zone. */
115
116         s64 nr_clusters;        /* Volume size in clusters, hence also the
117                                    number of bits in lcn_bitmap. */
118         ntfs_inode *lcnbmp_ni;  /* ntfs_inode structure for FILE_Bitmap. */
119         ntfs_attr *lcnbmp_na;   /* ntfs_attr structure for the data attribute
120                                    of FILE_Bitmap. Each bit represents a
121                                    cluster on the volume, bit 0 representing
122                                    lcn 0 and so on. A set bit means that the
123                                    cluster and vice versa. */
124
125         s64 nr_mft_records;     /* Number of records in the mft, equals the
126                                    number of bits in mft_bitmap. */
127         LCN mft_lcn;            /* Logical cluster number of the data attribute
128                                    for FILE_MFT. */
129         ntfs_inode *mft_ni;     /* ntfs_inode structure for FILE_MFT. */
130         ntfs_attr *mft_na;      /* ntfs_attr structure for the data attribute
131                                    of FILE_MFT. */
132         ntfs_attr *mftbmp_na;   /* ntfs_attr structure for the bitmap attribute
133                                    of FILE_MFT. Each bit represents an mft
134                                    record in the $DATA attribute, bit 0
135                                    representing mft record 0 and so on. A set
136                                    bit means that the mft record is in use and
137                                    vice versa. */
138
139         int mftmirr_size;       /* Size of the FILE_MFTMirr in mft records. */
140         LCN mftmirr_lcn;        /* Logical cluster number of the data attribute
141                                    for FILE_MFTMirr. */
142         ntfs_inode *mftmirr_ni; /* ntfs_inode structure for FILE_MFTMirr. */
143         ntfs_attr *mftmirr_na;  /* ntfs_attr structure for the data attribute
144                                    of FILE_MFTMirr. */
145
146         uchar_t *upcase;        /* Upper case equivalents of all 65536 2-byte
147                                    Unicode characters. Obtained from
148                                    FILE_UpCase. */
149         u32 upcase_len;         /* Length in Unicode characters of the upcase
150                                    table. */
151
152         ATTR_DEF *attrdef;      /* Attribute definitions. Obtained from
153                                    FILE_AttrDef. */
154         u32 attrdef_len;        /* Size of the attribute definition table in
155                                    bytes. */
156 };
157
158 extern ntfs_volume *ntfs_volume_alloc(void);
159
160 extern ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev,
161                 unsigned long rwflag);
162
163 extern ntfs_volume *ntfs_device_mount(struct ntfs_device *dev,
164                 unsigned long rwflag);
165 extern ntfs_volume *ntfs_mount(const char *name, unsigned long rwflag);
166 extern int ntfs_umount(ntfs_volume *vol, const BOOL force);
167
168 extern int ntfs_version_is_supported(ntfs_volume *vol);
169 extern int ntfs_logfile_reset(ntfs_volume *vol);
170 extern int ntfs_volume_set_flags(ntfs_volume *v, const u16 flags);
171
172 #endif /* defined _NTFS_VOLUME_H */
173