VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / fs / ntfs / ntfs.h
1 /*
2  * ntfs.h - Defines for NTFS Linux kernel driver. Part of the Linux-NTFS
3  *          project.
4  *
5  * Copyright (c) 2001-2004 Anton Altaparmakov
6  * Copyright (C) 2002 Richard Russon
7  *
8  * This program/include file is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program/include file is distributed in the hope that it will be
14  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * 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
20  * distribution in the file COPYING); if not, write to the Free Software
21  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef _LINUX_NTFS_H
25 #define _LINUX_NTFS_H
26
27 #include <linux/stddef.h>
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/compiler.h>
31 #include <linux/fs.h>
32 #include <linux/buffer_head.h>
33 #include <linux/nls.h>
34 #include <linux/pagemap.h>
35 #include <linux/smp.h>
36 #include <asm/atomic.h>
37
38 #include "types.h"
39 #include "debug.h"
40 #include "malloc.h"
41 #include "endian.h"
42 #include "volume.h"
43 #include "inode.h"
44 #include "layout.h"
45 #include "attrib.h"
46 #include "mft.h"
47
48 typedef enum {
49         NTFS_BLOCK_SIZE         = 512,
50         NTFS_BLOCK_SIZE_BITS    = 9,
51         NTFS_SB_MAGIC           = 0x5346544e,   /* 'NTFS' */
52         NTFS_MAX_NAME_LEN       = 255,
53 } NTFS_CONSTANTS;
54
55 /* Global variables. */
56
57 /* Slab caches (from super.c). */
58 extern kmem_cache_t *ntfs_name_cache;
59 extern kmem_cache_t *ntfs_inode_cache;
60 extern kmem_cache_t *ntfs_big_inode_cache;
61 extern kmem_cache_t *ntfs_attr_ctx_cache;
62 extern kmem_cache_t *ntfs_index_ctx_cache;
63
64 /* The various operations structs defined throughout the driver files. */
65 extern struct super_operations ntfs_sops;
66 extern struct address_space_operations ntfs_aops;
67 extern struct address_space_operations ntfs_mst_aops;
68 extern struct address_space_operations ntfs_mft_aops;
69
70 extern struct  file_operations ntfs_file_ops;
71 extern struct inode_operations ntfs_file_inode_ops;
72
73 extern struct  file_operations ntfs_dir_ops;
74 extern struct inode_operations ntfs_dir_inode_ops;
75
76 extern struct  file_operations ntfs_empty_file_ops;
77 extern struct inode_operations ntfs_empty_inode_ops;
78
79 /**
80  * NTFS_SB - return the ntfs volume given a vfs super block
81  * @sb:         VFS super block
82  *
83  * NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
84  */
85 static inline ntfs_volume *NTFS_SB(struct super_block *sb)
86 {
87         return sb->s_fs_info;
88 }
89
90 /**
91  * ntfs_unmap_page - release a page that was mapped using ntfs_map_page()
92  * @page:       the page to release
93  *
94  * Unpin, unmap and release a page that was obtained from ntfs_map_page().
95  */
96 static inline void ntfs_unmap_page(struct page *page)
97 {
98         kunmap(page);
99         page_cache_release(page);
100 }
101
102 /**
103  * ntfs_map_page - map a page into accessible memory, reading it if necessary
104  * @mapping:    address space for which to obtain the page
105  * @index:      index into the page cache for @mapping of the page to map
106  *
107  * Read a page from the page cache of the address space @mapping at position
108  * @index, where @index is in units of PAGE_CACHE_SIZE, and not in bytes.
109  *
110  * If the page is not in memory it is loaded from disk first using the readpage
111  * method defined in the address space operations of @mapping and the page is
112  * added to the page cache of @mapping in the process.
113  *
114  * If the page is in high memory it is mapped into memory directly addressible
115  * by the kernel.
116  *
117  * Finally the page count is incremented, thus pinning the page into place.
118  *
119  * The above means that page_address(page) can be used on all pages obtained
120  * with ntfs_map_page() to get the kernel virtual address of the page.
121  *
122  * When finished with the page, the caller has to call ntfs_unmap_page() to
123  * unpin, unmap and release the page.
124  *
125  * Note this does not grant exclusive access. If such is desired, the caller
126  * must provide it independently of the ntfs_{un}map_page() calls by using
127  * a {rw_}semaphore or other means of serialization. A spin lock cannot be
128  * used as ntfs_map_page() can block.
129  *
130  * The unlocked and uptodate page is returned on success or an encoded error
131  * on failure. Caller has to test for error using the IS_ERR() macro on the
132  * return value. If that evaluates to TRUE, the negative error code can be
133  * obtained using PTR_ERR() on the return value of ntfs_map_page().
134  */
135 static inline struct page *ntfs_map_page(struct address_space *mapping,
136                 unsigned long index)
137 {
138         struct page *page = read_cache_page(mapping, index,
139                         (filler_t*)mapping->a_ops->readpage, NULL);
140
141         if (!IS_ERR(page)) {
142                 wait_on_page_locked(page);
143                 kmap(page);
144                 if (PageUptodate(page) && !PageError(page))
145                         return page;
146                 ntfs_unmap_page(page);
147                 return ERR_PTR(-EIO);
148         }
149         return page;
150 }
151
152 /* Declarations of functions and global variables. */
153
154 /* From fs/ntfs/compress.c */
155 extern int ntfs_read_compressed_block(struct page *page);
156
157 /* From fs/ntfs/super.c */
158 #define default_upcase_len 0x10000
159 extern wchar_t *default_upcase;
160 extern unsigned long ntfs_nr_upcase_users;
161 extern unsigned long ntfs_nr_mounts;
162 extern struct semaphore ntfs_lock;
163
164 typedef struct {
165         int val;
166         char *str;
167 } option_t;
168 extern const option_t on_errors_arr[];
169
170 /* From fs/ntfs/compress.c */
171 extern int allocate_compression_buffers(void);
172 extern void free_compression_buffers(void);
173
174 /* From fs/ntfs/mst.c */
175 extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
176 extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
177 extern void post_write_mst_fixup(NTFS_RECORD *b);
178
179 /* From fs/ntfs/unistr.c */
180 extern BOOL ntfs_are_names_equal(const ntfschar *s1, size_t s1_len,
181                 const ntfschar *s2, size_t s2_len,
182                 const IGNORE_CASE_BOOL ic,
183                 const ntfschar *upcase, const u32 upcase_size);
184 extern int ntfs_collate_names(const ntfschar *name1, const u32 name1_len,
185                 const ntfschar *name2, const u32 name2_len,
186                 const int err_val, const IGNORE_CASE_BOOL ic,
187                 const ntfschar *upcase, const u32 upcase_len);
188 extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
189 extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
190                 const ntfschar *upcase, const u32 upcase_size);
191 extern void ntfs_upcase_name(ntfschar *name, u32 name_len,
192                 const ntfschar *upcase, const u32 upcase_len);
193 extern void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
194                 const ntfschar *upcase, const u32 upcase_len);
195 extern int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
196                 FILE_NAME_ATTR *file_name_attr2,
197                 const int err_val, const IGNORE_CASE_BOOL ic,
198                 const ntfschar *upcase, const u32 upcase_len);
199 extern int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins,
200                 const int ins_len, ntfschar **outs);
201 extern int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins,
202                 const int ins_len, unsigned char **outs, int outs_len);
203
204 /* From fs/ntfs/upcase.c */
205 extern ntfschar *generate_default_upcase(void);
206
207 #endif /* _LINUX_NTFS_H */