Commit 08d8e9749e7f0435ba4683b620e8d30d59276b4c

Authored by Fengguang Wu
Committed by Linus Torvalds
1 parent 2c13657910

writeback: fix ntfs with sb_has_dirty_inodes()

NTFS's if-condition on dirty inodes is not complete.  Fix it with
sb_has_dirty_inodes().

Cc: Anton Altaparmakov <aia21@cantab.net>
Cc: Ken Chen <kenchen@google.com>
Signed-off-by: Fengguang Wu <wfg@mail.ustc.edu.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 12 additions and 3 deletions Inline Diff

1 /* 1 /*
2 * fs/fs-writeback.c 2 * fs/fs-writeback.c
3 * 3 *
4 * Copyright (C) 2002, Linus Torvalds. 4 * Copyright (C) 2002, Linus Torvalds.
5 * 5 *
6 * Contains all the functions related to writing back and waiting 6 * Contains all the functions related to writing back and waiting
7 * upon dirty inodes against superblocks, and writing back dirty 7 * upon dirty inodes against superblocks, and writing back dirty
8 * pages against inodes. ie: data writeback. Writeout of the 8 * pages against inodes. ie: data writeback. Writeout of the
9 * inode itself is not handled here. 9 * inode itself is not handled here.
10 * 10 *
11 * 10Apr2002 akpm@zip.com.au 11 * 10Apr2002 akpm@zip.com.au
12 * Split out of fs/inode.c 12 * Split out of fs/inode.c
13 * Additions for address_space-based writeback 13 * Additions for address_space-based writeback
14 */ 14 */
15 15
16 #include <linux/kernel.h> 16 #include <linux/kernel.h>
17 #include <linux/module.h> 17 #include <linux/module.h>
18 #include <linux/spinlock.h> 18 #include <linux/spinlock.h>
19 #include <linux/sched.h> 19 #include <linux/sched.h>
20 #include <linux/fs.h> 20 #include <linux/fs.h>
21 #include <linux/mm.h> 21 #include <linux/mm.h>
22 #include <linux/writeback.h> 22 #include <linux/writeback.h>
23 #include <linux/blkdev.h> 23 #include <linux/blkdev.h>
24 #include <linux/backing-dev.h> 24 #include <linux/backing-dev.h>
25 #include <linux/buffer_head.h> 25 #include <linux/buffer_head.h>
26 #include "internal.h" 26 #include "internal.h"
27 27
28 /** 28 /**
29 * __mark_inode_dirty - internal function 29 * __mark_inode_dirty - internal function
30 * @inode: inode to mark 30 * @inode: inode to mark
31 * @flags: what kind of dirty (i.e. I_DIRTY_SYNC) 31 * @flags: what kind of dirty (i.e. I_DIRTY_SYNC)
32 * Mark an inode as dirty. Callers should use mark_inode_dirty or 32 * Mark an inode as dirty. Callers should use mark_inode_dirty or
33 * mark_inode_dirty_sync. 33 * mark_inode_dirty_sync.
34 * 34 *
35 * Put the inode on the super block's dirty list. 35 * Put the inode on the super block's dirty list.
36 * 36 *
37 * CAREFUL! We mark it dirty unconditionally, but move it onto the 37 * CAREFUL! We mark it dirty unconditionally, but move it onto the
38 * dirty list only if it is hashed or if it refers to a blockdev. 38 * dirty list only if it is hashed or if it refers to a blockdev.
39 * If it was not hashed, it will never be added to the dirty list 39 * If it was not hashed, it will never be added to the dirty list
40 * even if it is later hashed, as it will have been marked dirty already. 40 * even if it is later hashed, as it will have been marked dirty already.
41 * 41 *
42 * In short, make sure you hash any inodes _before_ you start marking 42 * In short, make sure you hash any inodes _before_ you start marking
43 * them dirty. 43 * them dirty.
44 * 44 *
45 * This function *must* be atomic for the I_DIRTY_PAGES case - 45 * This function *must* be atomic for the I_DIRTY_PAGES case -
46 * set_page_dirty() is called under spinlock in several places. 46 * set_page_dirty() is called under spinlock in several places.
47 * 47 *
48 * Note that for blockdevs, inode->dirtied_when represents the dirtying time of 48 * Note that for blockdevs, inode->dirtied_when represents the dirtying time of
49 * the block-special inode (/dev/hda1) itself. And the ->dirtied_when field of 49 * the block-special inode (/dev/hda1) itself. And the ->dirtied_when field of
50 * the kernel-internal blockdev inode represents the dirtying time of the 50 * the kernel-internal blockdev inode represents the dirtying time of the
51 * blockdev's pages. This is why for I_DIRTY_PAGES we always use 51 * blockdev's pages. This is why for I_DIRTY_PAGES we always use
52 * page->mapping->host, so the page-dirtying time is recorded in the internal 52 * page->mapping->host, so the page-dirtying time is recorded in the internal
53 * blockdev inode. 53 * blockdev inode.
54 */ 54 */
55 void __mark_inode_dirty(struct inode *inode, int flags) 55 void __mark_inode_dirty(struct inode *inode, int flags)
56 { 56 {
57 struct super_block *sb = inode->i_sb; 57 struct super_block *sb = inode->i_sb;
58 58
59 /* 59 /*
60 * Don't do this for I_DIRTY_PAGES - that doesn't actually 60 * Don't do this for I_DIRTY_PAGES - that doesn't actually
61 * dirty the inode itself 61 * dirty the inode itself
62 */ 62 */
63 if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) { 63 if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
64 if (sb->s_op->dirty_inode) 64 if (sb->s_op->dirty_inode)
65 sb->s_op->dirty_inode(inode); 65 sb->s_op->dirty_inode(inode);
66 } 66 }
67 67
68 /* 68 /*
69 * make sure that changes are seen by all cpus before we test i_state 69 * make sure that changes are seen by all cpus before we test i_state
70 * -- mikulas 70 * -- mikulas
71 */ 71 */
72 smp_mb(); 72 smp_mb();
73 73
74 /* avoid the locking if we can */ 74 /* avoid the locking if we can */
75 if ((inode->i_state & flags) == flags) 75 if ((inode->i_state & flags) == flags)
76 return; 76 return;
77 77
78 if (unlikely(block_dump)) { 78 if (unlikely(block_dump)) {
79 struct dentry *dentry = NULL; 79 struct dentry *dentry = NULL;
80 const char *name = "?"; 80 const char *name = "?";
81 81
82 if (!list_empty(&inode->i_dentry)) { 82 if (!list_empty(&inode->i_dentry)) {
83 dentry = list_entry(inode->i_dentry.next, 83 dentry = list_entry(inode->i_dentry.next,
84 struct dentry, d_alias); 84 struct dentry, d_alias);
85 if (dentry && dentry->d_name.name) 85 if (dentry && dentry->d_name.name)
86 name = (const char *) dentry->d_name.name; 86 name = (const char *) dentry->d_name.name;
87 } 87 }
88 88
89 if (inode->i_ino || strcmp(inode->i_sb->s_id, "bdev")) 89 if (inode->i_ino || strcmp(inode->i_sb->s_id, "bdev"))
90 printk(KERN_DEBUG 90 printk(KERN_DEBUG
91 "%s(%d): dirtied inode %lu (%s) on %s\n", 91 "%s(%d): dirtied inode %lu (%s) on %s\n",
92 current->comm, current->pid, inode->i_ino, 92 current->comm, current->pid, inode->i_ino,
93 name, inode->i_sb->s_id); 93 name, inode->i_sb->s_id);
94 } 94 }
95 95
96 spin_lock(&inode_lock); 96 spin_lock(&inode_lock);
97 if ((inode->i_state & flags) != flags) { 97 if ((inode->i_state & flags) != flags) {
98 const int was_dirty = inode->i_state & I_DIRTY; 98 const int was_dirty = inode->i_state & I_DIRTY;
99 99
100 inode->i_state |= flags; 100 inode->i_state |= flags;
101 101
102 /* 102 /*
103 * If the inode is locked, just update its dirty state. 103 * If the inode is locked, just update its dirty state.
104 * The unlocker will place the inode on the appropriate 104 * The unlocker will place the inode on the appropriate
105 * superblock list, based upon its state. 105 * superblock list, based upon its state.
106 */ 106 */
107 if (inode->i_state & I_LOCK) 107 if (inode->i_state & I_LOCK)
108 goto out; 108 goto out;
109 109
110 /* 110 /*
111 * Only add valid (hashed) inodes to the superblock's 111 * Only add valid (hashed) inodes to the superblock's
112 * dirty list. Add blockdev inodes as well. 112 * dirty list. Add blockdev inodes as well.
113 */ 113 */
114 if (!S_ISBLK(inode->i_mode)) { 114 if (!S_ISBLK(inode->i_mode)) {
115 if (hlist_unhashed(&inode->i_hash)) 115 if (hlist_unhashed(&inode->i_hash))
116 goto out; 116 goto out;
117 } 117 }
118 if (inode->i_state & (I_FREEING|I_CLEAR)) 118 if (inode->i_state & (I_FREEING|I_CLEAR))
119 goto out; 119 goto out;
120 120
121 /* 121 /*
122 * If the inode was already on s_dirty/s_io/s_more_io, don't 122 * If the inode was already on s_dirty/s_io/s_more_io, don't
123 * reposition it (that would break s_dirty time-ordering). 123 * reposition it (that would break s_dirty time-ordering).
124 */ 124 */
125 if (!was_dirty) { 125 if (!was_dirty) {
126 inode->dirtied_when = jiffies; 126 inode->dirtied_when = jiffies;
127 list_move(&inode->i_list, &sb->s_dirty); 127 list_move(&inode->i_list, &sb->s_dirty);
128 } 128 }
129 } 129 }
130 out: 130 out:
131 spin_unlock(&inode_lock); 131 spin_unlock(&inode_lock);
132 } 132 }
133 133
134 EXPORT_SYMBOL(__mark_inode_dirty); 134 EXPORT_SYMBOL(__mark_inode_dirty);
135 135
136 static int write_inode(struct inode *inode, int sync) 136 static int write_inode(struct inode *inode, int sync)
137 { 137 {
138 if (inode->i_sb->s_op->write_inode && !is_bad_inode(inode)) 138 if (inode->i_sb->s_op->write_inode && !is_bad_inode(inode))
139 return inode->i_sb->s_op->write_inode(inode, sync); 139 return inode->i_sb->s_op->write_inode(inode, sync);
140 return 0; 140 return 0;
141 } 141 }
142 142
143 /* 143 /*
144 * Redirty an inode: set its when-it-was dirtied timestamp and move it to the 144 * Redirty an inode: set its when-it-was dirtied timestamp and move it to the
145 * furthest end of its superblock's dirty-inode list. 145 * furthest end of its superblock's dirty-inode list.
146 * 146 *
147 * Before stamping the inode's ->dirtied_when, we check to see whether it is 147 * Before stamping the inode's ->dirtied_when, we check to see whether it is
148 * already the most-recently-dirtied inode on the s_dirty list. If that is 148 * already the most-recently-dirtied inode on the s_dirty list. If that is
149 * the case then the inode must have been redirtied while it was being written 149 * the case then the inode must have been redirtied while it was being written
150 * out and we don't reset its dirtied_when. 150 * out and we don't reset its dirtied_when.
151 */ 151 */
152 static void redirty_tail(struct inode *inode) 152 static void redirty_tail(struct inode *inode)
153 { 153 {
154 struct super_block *sb = inode->i_sb; 154 struct super_block *sb = inode->i_sb;
155 155
156 if (!list_empty(&sb->s_dirty)) { 156 if (!list_empty(&sb->s_dirty)) {
157 struct inode *tail_inode; 157 struct inode *tail_inode;
158 158
159 tail_inode = list_entry(sb->s_dirty.next, struct inode, i_list); 159 tail_inode = list_entry(sb->s_dirty.next, struct inode, i_list);
160 if (!time_after_eq(inode->dirtied_when, 160 if (!time_after_eq(inode->dirtied_when,
161 tail_inode->dirtied_when)) 161 tail_inode->dirtied_when))
162 inode->dirtied_when = jiffies; 162 inode->dirtied_when = jiffies;
163 } 163 }
164 list_move(&inode->i_list, &sb->s_dirty); 164 list_move(&inode->i_list, &sb->s_dirty);
165 } 165 }
166 166
167 /* 167 /*
168 * requeue inode for re-scanning after sb->s_io list is exhausted. 168 * requeue inode for re-scanning after sb->s_io list is exhausted.
169 */ 169 */
170 static void requeue_io(struct inode *inode) 170 static void requeue_io(struct inode *inode)
171 { 171 {
172 list_move(&inode->i_list, &inode->i_sb->s_more_io); 172 list_move(&inode->i_list, &inode->i_sb->s_more_io);
173 } 173 }
174 174
175 /* 175 /*
176 * Move expired dirty inodes from @delaying_queue to @dispatch_queue. 176 * Move expired dirty inodes from @delaying_queue to @dispatch_queue.
177 */ 177 */
178 static void move_expired_inodes(struct list_head *delaying_queue, 178 static void move_expired_inodes(struct list_head *delaying_queue,
179 struct list_head *dispatch_queue, 179 struct list_head *dispatch_queue,
180 unsigned long *older_than_this) 180 unsigned long *older_than_this)
181 { 181 {
182 while (!list_empty(delaying_queue)) { 182 while (!list_empty(delaying_queue)) {
183 struct inode *inode = list_entry(delaying_queue->prev, 183 struct inode *inode = list_entry(delaying_queue->prev,
184 struct inode, i_list); 184 struct inode, i_list);
185 if (older_than_this && 185 if (older_than_this &&
186 time_after(inode->dirtied_when, *older_than_this)) 186 time_after(inode->dirtied_when, *older_than_this))
187 break; 187 break;
188 list_move(&inode->i_list, dispatch_queue); 188 list_move(&inode->i_list, dispatch_queue);
189 } 189 }
190 } 190 }
191 191
192 /* 192 /*
193 * Queue all expired dirty inodes for io, eldest first. 193 * Queue all expired dirty inodes for io, eldest first.
194 */ 194 */
195 static void queue_io(struct super_block *sb, 195 static void queue_io(struct super_block *sb,
196 unsigned long *older_than_this) 196 unsigned long *older_than_this)
197 { 197 {
198 list_splice_init(&sb->s_more_io, sb->s_io.prev); 198 list_splice_init(&sb->s_more_io, sb->s_io.prev);
199 move_expired_inodes(&sb->s_dirty, &sb->s_io, older_than_this); 199 move_expired_inodes(&sb->s_dirty, &sb->s_io, older_than_this);
200 } 200 }
201 201
202 int sb_has_dirty_inodes(struct super_block *sb)
203 {
204 return !list_empty(&sb->s_dirty) ||
205 !list_empty(&sb->s_io) ||
206 !list_empty(&sb->s_more_io);
207 }
208 EXPORT_SYMBOL(sb_has_dirty_inodes);
209
202 /* 210 /*
203 * Write a single inode's dirty pages and inode data out to disk. 211 * Write a single inode's dirty pages and inode data out to disk.
204 * If `wait' is set, wait on the writeout. 212 * If `wait' is set, wait on the writeout.
205 * 213 *
206 * The whole writeout design is quite complex and fragile. We want to avoid 214 * The whole writeout design is quite complex and fragile. We want to avoid
207 * starvation of particular inodes when others are being redirtied, prevent 215 * starvation of particular inodes when others are being redirtied, prevent
208 * livelocks, etc. 216 * livelocks, etc.
209 * 217 *
210 * Called under inode_lock. 218 * Called under inode_lock.
211 */ 219 */
212 static int 220 static int
213 __sync_single_inode(struct inode *inode, struct writeback_control *wbc) 221 __sync_single_inode(struct inode *inode, struct writeback_control *wbc)
214 { 222 {
215 unsigned dirty; 223 unsigned dirty;
216 struct address_space *mapping = inode->i_mapping; 224 struct address_space *mapping = inode->i_mapping;
217 int wait = wbc->sync_mode == WB_SYNC_ALL; 225 int wait = wbc->sync_mode == WB_SYNC_ALL;
218 int ret; 226 int ret;
219 227
220 BUG_ON(inode->i_state & I_LOCK); 228 BUG_ON(inode->i_state & I_LOCK);
221 229
222 /* Set I_LOCK, reset I_DIRTY */ 230 /* Set I_LOCK, reset I_DIRTY */
223 dirty = inode->i_state & I_DIRTY; 231 dirty = inode->i_state & I_DIRTY;
224 inode->i_state |= I_LOCK; 232 inode->i_state |= I_LOCK;
225 inode->i_state &= ~I_DIRTY; 233 inode->i_state &= ~I_DIRTY;
226 234
227 spin_unlock(&inode_lock); 235 spin_unlock(&inode_lock);
228 236
229 ret = do_writepages(mapping, wbc); 237 ret = do_writepages(mapping, wbc);
230 238
231 /* Don't write the inode if only I_DIRTY_PAGES was set */ 239 /* Don't write the inode if only I_DIRTY_PAGES was set */
232 if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) { 240 if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
233 int err = write_inode(inode, wait); 241 int err = write_inode(inode, wait);
234 if (ret == 0) 242 if (ret == 0)
235 ret = err; 243 ret = err;
236 } 244 }
237 245
238 if (wait) { 246 if (wait) {
239 int err = filemap_fdatawait(mapping); 247 int err = filemap_fdatawait(mapping);
240 if (ret == 0) 248 if (ret == 0)
241 ret = err; 249 ret = err;
242 } 250 }
243 251
244 spin_lock(&inode_lock); 252 spin_lock(&inode_lock);
245 inode->i_state &= ~I_LOCK; 253 inode->i_state &= ~I_LOCK;
246 if (!(inode->i_state & I_FREEING)) { 254 if (!(inode->i_state & I_FREEING)) {
247 if (!(inode->i_state & I_DIRTY) && 255 if (!(inode->i_state & I_DIRTY) &&
248 mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) { 256 mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) {
249 /* 257 /*
250 * We didn't write back all the pages. nfs_writepages() 258 * We didn't write back all the pages. nfs_writepages()
251 * sometimes bales out without doing anything. Redirty 259 * sometimes bales out without doing anything. Redirty
252 * the inode; Move it from s_io onto s_more_io/s_dirty. 260 * the inode; Move it from s_io onto s_more_io/s_dirty.
253 */ 261 */
254 /* 262 /*
255 * akpm: if the caller was the kupdate function we put 263 * akpm: if the caller was the kupdate function we put
256 * this inode at the head of s_dirty so it gets first 264 * this inode at the head of s_dirty so it gets first
257 * consideration. Otherwise, move it to the tail, for 265 * consideration. Otherwise, move it to the tail, for
258 * the reasons described there. I'm not really sure 266 * the reasons described there. I'm not really sure
259 * how much sense this makes. Presumably I had a good 267 * how much sense this makes. Presumably I had a good
260 * reasons for doing it this way, and I'd rather not 268 * reasons for doing it this way, and I'd rather not
261 * muck with it at present. 269 * muck with it at present.
262 */ 270 */
263 if (wbc->for_kupdate) { 271 if (wbc->for_kupdate) {
264 /* 272 /*
265 * For the kupdate function we move the inode 273 * For the kupdate function we move the inode
266 * to s_more_io so it will get more writeout as 274 * to s_more_io so it will get more writeout as
267 * soon as the queue becomes uncongested. 275 * soon as the queue becomes uncongested.
268 */ 276 */
269 inode->i_state |= I_DIRTY_PAGES; 277 inode->i_state |= I_DIRTY_PAGES;
270 requeue_io(inode); 278 requeue_io(inode);
271 } else { 279 } else {
272 /* 280 /*
273 * Otherwise fully redirty the inode so that 281 * Otherwise fully redirty the inode so that
274 * other inodes on this superblock will get some 282 * other inodes on this superblock will get some
275 * writeout. Otherwise heavy writing to one 283 * writeout. Otherwise heavy writing to one
276 * file would indefinitely suspend writeout of 284 * file would indefinitely suspend writeout of
277 * all the other files. 285 * all the other files.
278 */ 286 */
279 inode->i_state |= I_DIRTY_PAGES; 287 inode->i_state |= I_DIRTY_PAGES;
280 redirty_tail(inode); 288 redirty_tail(inode);
281 } 289 }
282 } else if (inode->i_state & I_DIRTY) { 290 } else if (inode->i_state & I_DIRTY) {
283 /* 291 /*
284 * Someone redirtied the inode while were writing back 292 * Someone redirtied the inode while were writing back
285 * the pages. 293 * the pages.
286 */ 294 */
287 redirty_tail(inode); 295 redirty_tail(inode);
288 } else if (atomic_read(&inode->i_count)) { 296 } else if (atomic_read(&inode->i_count)) {
289 /* 297 /*
290 * The inode is clean, inuse 298 * The inode is clean, inuse
291 */ 299 */
292 list_move(&inode->i_list, &inode_in_use); 300 list_move(&inode->i_list, &inode_in_use);
293 } else { 301 } else {
294 /* 302 /*
295 * The inode is clean, unused 303 * The inode is clean, unused
296 */ 304 */
297 list_move(&inode->i_list, &inode_unused); 305 list_move(&inode->i_list, &inode_unused);
298 } 306 }
299 } 307 }
300 wake_up_inode(inode); 308 wake_up_inode(inode);
301 return ret; 309 return ret;
302 } 310 }
303 311
304 /* 312 /*
305 * Write out an inode's dirty pages. Called under inode_lock. Either the 313 * Write out an inode's dirty pages. Called under inode_lock. Either the
306 * caller has ref on the inode (either via __iget or via syscall against an fd) 314 * caller has ref on the inode (either via __iget or via syscall against an fd)
307 * or the inode has I_WILL_FREE set (via generic_forget_inode) 315 * or the inode has I_WILL_FREE set (via generic_forget_inode)
308 */ 316 */
309 static int 317 static int
310 __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) 318 __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
311 { 319 {
312 wait_queue_head_t *wqh; 320 wait_queue_head_t *wqh;
313 321
314 if (!atomic_read(&inode->i_count)) 322 if (!atomic_read(&inode->i_count))
315 WARN_ON(!(inode->i_state & (I_WILL_FREE|I_FREEING))); 323 WARN_ON(!(inode->i_state & (I_WILL_FREE|I_FREEING)));
316 else 324 else
317 WARN_ON(inode->i_state & I_WILL_FREE); 325 WARN_ON(inode->i_state & I_WILL_FREE);
318 326
319 if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_LOCK)) { 327 if ((wbc->sync_mode != WB_SYNC_ALL) && (inode->i_state & I_LOCK)) {
320 struct address_space *mapping = inode->i_mapping; 328 struct address_space *mapping = inode->i_mapping;
321 int ret; 329 int ret;
322 330
323 /* 331 /*
324 * We're skipping this inode because it's locked, and we're not 332 * We're skipping this inode because it's locked, and we're not
325 * doing writeback-for-data-integrity. Move it to s_more_io so 333 * doing writeback-for-data-integrity. Move it to s_more_io so
326 * that writeback can proceed with the other inodes on s_io. 334 * that writeback can proceed with the other inodes on s_io.
327 * We'll have another go at writing back this inode when we 335 * We'll have another go at writing back this inode when we
328 * completed a full scan of s_io. 336 * completed a full scan of s_io.
329 */ 337 */
330 requeue_io(inode); 338 requeue_io(inode);
331 339
332 /* 340 /*
333 * Even if we don't actually write the inode itself here, 341 * Even if we don't actually write the inode itself here,
334 * we can at least start some of the data writeout.. 342 * we can at least start some of the data writeout..
335 */ 343 */
336 spin_unlock(&inode_lock); 344 spin_unlock(&inode_lock);
337 ret = do_writepages(mapping, wbc); 345 ret = do_writepages(mapping, wbc);
338 spin_lock(&inode_lock); 346 spin_lock(&inode_lock);
339 return ret; 347 return ret;
340 } 348 }
341 349
342 /* 350 /*
343 * It's a data-integrity sync. We must wait. 351 * It's a data-integrity sync. We must wait.
344 */ 352 */
345 if (inode->i_state & I_LOCK) { 353 if (inode->i_state & I_LOCK) {
346 DEFINE_WAIT_BIT(wq, &inode->i_state, __I_LOCK); 354 DEFINE_WAIT_BIT(wq, &inode->i_state, __I_LOCK);
347 355
348 wqh = bit_waitqueue(&inode->i_state, __I_LOCK); 356 wqh = bit_waitqueue(&inode->i_state, __I_LOCK);
349 do { 357 do {
350 spin_unlock(&inode_lock); 358 spin_unlock(&inode_lock);
351 __wait_on_bit(wqh, &wq, inode_wait, 359 __wait_on_bit(wqh, &wq, inode_wait,
352 TASK_UNINTERRUPTIBLE); 360 TASK_UNINTERRUPTIBLE);
353 spin_lock(&inode_lock); 361 spin_lock(&inode_lock);
354 } while (inode->i_state & I_LOCK); 362 } while (inode->i_state & I_LOCK);
355 } 363 }
356 return __sync_single_inode(inode, wbc); 364 return __sync_single_inode(inode, wbc);
357 } 365 }
358 366
359 /* 367 /*
360 * Write out a superblock's list of dirty inodes. A wait will be performed 368 * Write out a superblock's list of dirty inodes. A wait will be performed
361 * upon no inodes, all inodes or the final one, depending upon sync_mode. 369 * upon no inodes, all inodes or the final one, depending upon sync_mode.
362 * 370 *
363 * If older_than_this is non-NULL, then only write out inodes which 371 * If older_than_this is non-NULL, then only write out inodes which
364 * had their first dirtying at a time earlier than *older_than_this. 372 * had their first dirtying at a time earlier than *older_than_this.
365 * 373 *
366 * If we're a pdlfush thread, then implement pdflush collision avoidance 374 * If we're a pdlfush thread, then implement pdflush collision avoidance
367 * against the entire list. 375 * against the entire list.
368 * 376 *
369 * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so 377 * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so
370 * that it can be located for waiting on in __writeback_single_inode(). 378 * that it can be located for waiting on in __writeback_single_inode().
371 * 379 *
372 * Called under inode_lock. 380 * Called under inode_lock.
373 * 381 *
374 * If `bdi' is non-zero then we're being asked to writeback a specific queue. 382 * If `bdi' is non-zero then we're being asked to writeback a specific queue.
375 * This function assumes that the blockdev superblock's inodes are backed by 383 * This function assumes that the blockdev superblock's inodes are backed by
376 * a variety of queues, so all inodes are searched. For other superblocks, 384 * a variety of queues, so all inodes are searched. For other superblocks,
377 * assume that all inodes are backed by the same queue. 385 * assume that all inodes are backed by the same queue.
378 * 386 *
379 * FIXME: this linear search could get expensive with many fileystems. But 387 * FIXME: this linear search could get expensive with many fileystems. But
380 * how to fix? We need to go from an address_space to all inodes which share 388 * how to fix? We need to go from an address_space to all inodes which share
381 * a queue with that address_space. (Easy: have a global "dirty superblocks" 389 * a queue with that address_space. (Easy: have a global "dirty superblocks"
382 * list). 390 * list).
383 * 391 *
384 * The inodes to be written are parked on sb->s_io. They are moved back onto 392 * The inodes to be written are parked on sb->s_io. They are moved back onto
385 * sb->s_dirty as they are selected for writing. This way, none can be missed 393 * sb->s_dirty as they are selected for writing. This way, none can be missed
386 * on the writer throttling path, and we get decent balancing between many 394 * on the writer throttling path, and we get decent balancing between many
387 * throttled threads: we don't want them all piling up on __wait_on_inode. 395 * throttled threads: we don't want them all piling up on __wait_on_inode.
388 */ 396 */
389 static void 397 static void
390 sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc) 398 sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc)
391 { 399 {
392 const unsigned long start = jiffies; /* livelock avoidance */ 400 const unsigned long start = jiffies; /* livelock avoidance */
393 401
394 if (!wbc->for_kupdate || list_empty(&sb->s_io)) 402 if (!wbc->for_kupdate || list_empty(&sb->s_io))
395 queue_io(sb, wbc->older_than_this); 403 queue_io(sb, wbc->older_than_this);
396 404
397 while (!list_empty(&sb->s_io)) { 405 while (!list_empty(&sb->s_io)) {
398 struct inode *inode = list_entry(sb->s_io.prev, 406 struct inode *inode = list_entry(sb->s_io.prev,
399 struct inode, i_list); 407 struct inode, i_list);
400 struct address_space *mapping = inode->i_mapping; 408 struct address_space *mapping = inode->i_mapping;
401 struct backing_dev_info *bdi = mapping->backing_dev_info; 409 struct backing_dev_info *bdi = mapping->backing_dev_info;
402 long pages_skipped; 410 long pages_skipped;
403 411
404 if (!bdi_cap_writeback_dirty(bdi)) { 412 if (!bdi_cap_writeback_dirty(bdi)) {
405 redirty_tail(inode); 413 redirty_tail(inode);
406 if (sb_is_blkdev_sb(sb)) { 414 if (sb_is_blkdev_sb(sb)) {
407 /* 415 /*
408 * Dirty memory-backed blockdev: the ramdisk 416 * Dirty memory-backed blockdev: the ramdisk
409 * driver does this. Skip just this inode 417 * driver does this. Skip just this inode
410 */ 418 */
411 continue; 419 continue;
412 } 420 }
413 /* 421 /*
414 * Dirty memory-backed inode against a filesystem other 422 * Dirty memory-backed inode against a filesystem other
415 * than the kernel-internal bdev filesystem. Skip the 423 * than the kernel-internal bdev filesystem. Skip the
416 * entire superblock. 424 * entire superblock.
417 */ 425 */
418 break; 426 break;
419 } 427 }
420 428
421 if (wbc->nonblocking && bdi_write_congested(bdi)) { 429 if (wbc->nonblocking && bdi_write_congested(bdi)) {
422 wbc->encountered_congestion = 1; 430 wbc->encountered_congestion = 1;
423 if (!sb_is_blkdev_sb(sb)) 431 if (!sb_is_blkdev_sb(sb))
424 break; /* Skip a congested fs */ 432 break; /* Skip a congested fs */
425 requeue_io(inode); 433 requeue_io(inode);
426 continue; /* Skip a congested blockdev */ 434 continue; /* Skip a congested blockdev */
427 } 435 }
428 436
429 if (wbc->bdi && bdi != wbc->bdi) { 437 if (wbc->bdi && bdi != wbc->bdi) {
430 if (!sb_is_blkdev_sb(sb)) 438 if (!sb_is_blkdev_sb(sb))
431 break; /* fs has the wrong queue */ 439 break; /* fs has the wrong queue */
432 requeue_io(inode); 440 requeue_io(inode);
433 continue; /* blockdev has wrong queue */ 441 continue; /* blockdev has wrong queue */
434 } 442 }
435 443
436 /* Was this inode dirtied after sync_sb_inodes was called? */ 444 /* Was this inode dirtied after sync_sb_inodes was called? */
437 if (time_after(inode->dirtied_when, start)) 445 if (time_after(inode->dirtied_when, start))
438 break; 446 break;
439 447
440 /* Is another pdflush already flushing this queue? */ 448 /* Is another pdflush already flushing this queue? */
441 if (current_is_pdflush() && !writeback_acquire(bdi)) 449 if (current_is_pdflush() && !writeback_acquire(bdi))
442 break; 450 break;
443 451
444 BUG_ON(inode->i_state & I_FREEING); 452 BUG_ON(inode->i_state & I_FREEING);
445 __iget(inode); 453 __iget(inode);
446 pages_skipped = wbc->pages_skipped; 454 pages_skipped = wbc->pages_skipped;
447 __writeback_single_inode(inode, wbc); 455 __writeback_single_inode(inode, wbc);
448 if (wbc->sync_mode == WB_SYNC_HOLD) { 456 if (wbc->sync_mode == WB_SYNC_HOLD) {
449 inode->dirtied_when = jiffies; 457 inode->dirtied_when = jiffies;
450 list_move(&inode->i_list, &sb->s_dirty); 458 list_move(&inode->i_list, &sb->s_dirty);
451 } 459 }
452 if (current_is_pdflush()) 460 if (current_is_pdflush())
453 writeback_release(bdi); 461 writeback_release(bdi);
454 if (wbc->pages_skipped != pages_skipped) { 462 if (wbc->pages_skipped != pages_skipped) {
455 /* 463 /*
456 * writeback is not making progress due to locked 464 * writeback is not making progress due to locked
457 * buffers. Skip this inode for now. 465 * buffers. Skip this inode for now.
458 */ 466 */
459 redirty_tail(inode); 467 redirty_tail(inode);
460 } 468 }
461 spin_unlock(&inode_lock); 469 spin_unlock(&inode_lock);
462 iput(inode); 470 iput(inode);
463 cond_resched(); 471 cond_resched();
464 spin_lock(&inode_lock); 472 spin_lock(&inode_lock);
465 if (wbc->nr_to_write <= 0) 473 if (wbc->nr_to_write <= 0)
466 break; 474 break;
467 } 475 }
468 return; /* Leave any unwritten inodes on s_io */ 476 return; /* Leave any unwritten inodes on s_io */
469 } 477 }
470 478
471 /* 479 /*
472 * Start writeback of dirty pagecache data against all unlocked inodes. 480 * Start writeback of dirty pagecache data against all unlocked inodes.
473 * 481 *
474 * Note: 482 * Note:
475 * We don't need to grab a reference to superblock here. If it has non-empty 483 * We don't need to grab a reference to superblock here. If it has non-empty
476 * ->s_dirty it's hadn't been killed yet and kill_super() won't proceed 484 * ->s_dirty it's hadn't been killed yet and kill_super() won't proceed
477 * past sync_inodes_sb() until the ->s_dirty/s_io/s_more_io lists are all 485 * past sync_inodes_sb() until the ->s_dirty/s_io/s_more_io lists are all
478 * empty. Since __sync_single_inode() regains inode_lock before it finally moves 486 * empty. Since __sync_single_inode() regains inode_lock before it finally moves
479 * inode from superblock lists we are OK. 487 * inode from superblock lists we are OK.
480 * 488 *
481 * If `older_than_this' is non-zero then only flush inodes which have a 489 * If `older_than_this' is non-zero then only flush inodes which have a
482 * flushtime older than *older_than_this. 490 * flushtime older than *older_than_this.
483 * 491 *
484 * If `bdi' is non-zero then we will scan the first inode against each 492 * If `bdi' is non-zero then we will scan the first inode against each
485 * superblock until we find the matching ones. One group will be the dirty 493 * superblock until we find the matching ones. One group will be the dirty
486 * inodes against a filesystem. Then when we hit the dummy blockdev superblock, 494 * inodes against a filesystem. Then when we hit the dummy blockdev superblock,
487 * sync_sb_inodes will seekout the blockdev which matches `bdi'. Maybe not 495 * sync_sb_inodes will seekout the blockdev which matches `bdi'. Maybe not
488 * super-efficient but we're about to do a ton of I/O... 496 * super-efficient but we're about to do a ton of I/O...
489 */ 497 */
490 void 498 void
491 writeback_inodes(struct writeback_control *wbc) 499 writeback_inodes(struct writeback_control *wbc)
492 { 500 {
493 struct super_block *sb; 501 struct super_block *sb;
494 502
495 might_sleep(); 503 might_sleep();
496 spin_lock(&sb_lock); 504 spin_lock(&sb_lock);
497 restart: 505 restart:
498 sb = sb_entry(super_blocks.prev); 506 sb = sb_entry(super_blocks.prev);
499 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) { 507 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
500 if (!list_empty(&sb->s_dirty) || !list_empty(&sb->s_io)) { 508 if (sb_has_dirty_inodes(sb)) {
501 /* we're making our own get_super here */ 509 /* we're making our own get_super here */
502 sb->s_count++; 510 sb->s_count++;
503 spin_unlock(&sb_lock); 511 spin_unlock(&sb_lock);
504 /* 512 /*
505 * If we can't get the readlock, there's no sense in 513 * If we can't get the readlock, there's no sense in
506 * waiting around, most of the time the FS is going to 514 * waiting around, most of the time the FS is going to
507 * be unmounted by the time it is released. 515 * be unmounted by the time it is released.
508 */ 516 */
509 if (down_read_trylock(&sb->s_umount)) { 517 if (down_read_trylock(&sb->s_umount)) {
510 if (sb->s_root) { 518 if (sb->s_root) {
511 spin_lock(&inode_lock); 519 spin_lock(&inode_lock);
512 sync_sb_inodes(sb, wbc); 520 sync_sb_inodes(sb, wbc);
513 spin_unlock(&inode_lock); 521 spin_unlock(&inode_lock);
514 } 522 }
515 up_read(&sb->s_umount); 523 up_read(&sb->s_umount);
516 } 524 }
517 spin_lock(&sb_lock); 525 spin_lock(&sb_lock);
518 if (__put_super_and_need_restart(sb)) 526 if (__put_super_and_need_restart(sb))
519 goto restart; 527 goto restart;
520 } 528 }
521 if (wbc->nr_to_write <= 0) 529 if (wbc->nr_to_write <= 0)
522 break; 530 break;
523 } 531 }
524 spin_unlock(&sb_lock); 532 spin_unlock(&sb_lock);
525 } 533 }
526 534
527 /* 535 /*
528 * writeback and wait upon the filesystem's dirty inodes. The caller will 536 * writeback and wait upon the filesystem's dirty inodes. The caller will
529 * do this in two passes - one to write, and one to wait. WB_SYNC_HOLD is 537 * do this in two passes - one to write, and one to wait. WB_SYNC_HOLD is
530 * used to park the written inodes on sb->s_dirty for the wait pass. 538 * used to park the written inodes on sb->s_dirty for the wait pass.
531 * 539 *
532 * A finite limit is set on the number of pages which will be written. 540 * A finite limit is set on the number of pages which will be written.
533 * To prevent infinite livelock of sys_sync(). 541 * To prevent infinite livelock of sys_sync().
534 * 542 *
535 * We add in the number of potentially dirty inodes, because each inode write 543 * We add in the number of potentially dirty inodes, because each inode write
536 * can dirty pagecache in the underlying blockdev. 544 * can dirty pagecache in the underlying blockdev.
537 */ 545 */
538 void sync_inodes_sb(struct super_block *sb, int wait) 546 void sync_inodes_sb(struct super_block *sb, int wait)
539 { 547 {
540 struct writeback_control wbc = { 548 struct writeback_control wbc = {
541 .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_HOLD, 549 .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_HOLD,
542 .range_start = 0, 550 .range_start = 0,
543 .range_end = LLONG_MAX, 551 .range_end = LLONG_MAX,
544 }; 552 };
545 unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY); 553 unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
546 unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS); 554 unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
547 555
548 wbc.nr_to_write = nr_dirty + nr_unstable + 556 wbc.nr_to_write = nr_dirty + nr_unstable +
549 (inodes_stat.nr_inodes - inodes_stat.nr_unused) + 557 (inodes_stat.nr_inodes - inodes_stat.nr_unused) +
550 nr_dirty + nr_unstable; 558 nr_dirty + nr_unstable;
551 wbc.nr_to_write += wbc.nr_to_write / 2; /* Bit more for luck */ 559 wbc.nr_to_write += wbc.nr_to_write / 2; /* Bit more for luck */
552 spin_lock(&inode_lock); 560 spin_lock(&inode_lock);
553 sync_sb_inodes(sb, &wbc); 561 sync_sb_inodes(sb, &wbc);
554 spin_unlock(&inode_lock); 562 spin_unlock(&inode_lock);
555 } 563 }
556 564
557 /* 565 /*
558 * Rather lame livelock avoidance. 566 * Rather lame livelock avoidance.
559 */ 567 */
560 static void set_sb_syncing(int val) 568 static void set_sb_syncing(int val)
561 { 569 {
562 struct super_block *sb; 570 struct super_block *sb;
563 spin_lock(&sb_lock); 571 spin_lock(&sb_lock);
564 sb = sb_entry(super_blocks.prev); 572 sb = sb_entry(super_blocks.prev);
565 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) { 573 for (; sb != sb_entry(&super_blocks); sb = sb_entry(sb->s_list.prev)) {
566 sb->s_syncing = val; 574 sb->s_syncing = val;
567 } 575 }
568 spin_unlock(&sb_lock); 576 spin_unlock(&sb_lock);
569 } 577 }
570 578
571 /** 579 /**
572 * sync_inodes - writes all inodes to disk 580 * sync_inodes - writes all inodes to disk
573 * @wait: wait for completion 581 * @wait: wait for completion
574 * 582 *
575 * sync_inodes() goes through each super block's dirty inode list, writes the 583 * sync_inodes() goes through each super block's dirty inode list, writes the
576 * inodes out, waits on the writeout and puts the inodes back on the normal 584 * inodes out, waits on the writeout and puts the inodes back on the normal
577 * list. 585 * list.
578 * 586 *
579 * This is for sys_sync(). fsync_dev() uses the same algorithm. The subtle 587 * This is for sys_sync(). fsync_dev() uses the same algorithm. The subtle
580 * part of the sync functions is that the blockdev "superblock" is processed 588 * part of the sync functions is that the blockdev "superblock" is processed
581 * last. This is because the write_inode() function of a typical fs will 589 * last. This is because the write_inode() function of a typical fs will
582 * perform no I/O, but will mark buffers in the blockdev mapping as dirty. 590 * perform no I/O, but will mark buffers in the blockdev mapping as dirty.
583 * What we want to do is to perform all that dirtying first, and then write 591 * What we want to do is to perform all that dirtying first, and then write
584 * back all those inode blocks via the blockdev mapping in one sweep. So the 592 * back all those inode blocks via the blockdev mapping in one sweep. So the
585 * additional (somewhat redundant) sync_blockdev() calls here are to make 593 * additional (somewhat redundant) sync_blockdev() calls here are to make
586 * sure that really happens. Because if we call sync_inodes_sb(wait=1) with 594 * sure that really happens. Because if we call sync_inodes_sb(wait=1) with
587 * outstanding dirty inodes, the writeback goes block-at-a-time within the 595 * outstanding dirty inodes, the writeback goes block-at-a-time within the
588 * filesystem's write_inode(). This is extremely slow. 596 * filesystem's write_inode(). This is extremely slow.
589 */ 597 */
590 static void __sync_inodes(int wait) 598 static void __sync_inodes(int wait)
591 { 599 {
592 struct super_block *sb; 600 struct super_block *sb;
593 601
594 spin_lock(&sb_lock); 602 spin_lock(&sb_lock);
595 restart: 603 restart:
596 list_for_each_entry(sb, &super_blocks, s_list) { 604 list_for_each_entry(sb, &super_blocks, s_list) {
597 if (sb->s_syncing) 605 if (sb->s_syncing)
598 continue; 606 continue;
599 sb->s_syncing = 1; 607 sb->s_syncing = 1;
600 sb->s_count++; 608 sb->s_count++;
601 spin_unlock(&sb_lock); 609 spin_unlock(&sb_lock);
602 down_read(&sb->s_umount); 610 down_read(&sb->s_umount);
603 if (sb->s_root) { 611 if (sb->s_root) {
604 sync_inodes_sb(sb, wait); 612 sync_inodes_sb(sb, wait);
605 sync_blockdev(sb->s_bdev); 613 sync_blockdev(sb->s_bdev);
606 } 614 }
607 up_read(&sb->s_umount); 615 up_read(&sb->s_umount);
608 spin_lock(&sb_lock); 616 spin_lock(&sb_lock);
609 if (__put_super_and_need_restart(sb)) 617 if (__put_super_and_need_restart(sb))
610 goto restart; 618 goto restart;
611 } 619 }
612 spin_unlock(&sb_lock); 620 spin_unlock(&sb_lock);
613 } 621 }
614 622
615 void sync_inodes(int wait) 623 void sync_inodes(int wait)
616 { 624 {
617 set_sb_syncing(0); 625 set_sb_syncing(0);
618 __sync_inodes(0); 626 __sync_inodes(0);
619 627
620 if (wait) { 628 if (wait) {
621 set_sb_syncing(0); 629 set_sb_syncing(0);
622 __sync_inodes(1); 630 __sync_inodes(1);
623 } 631 }
624 } 632 }
625 633
626 /** 634 /**
627 * write_inode_now - write an inode to disk 635 * write_inode_now - write an inode to disk
628 * @inode: inode to write to disk 636 * @inode: inode to write to disk
629 * @sync: whether the write should be synchronous or not 637 * @sync: whether the write should be synchronous or not
630 * 638 *
631 * This function commits an inode to disk immediately if it is dirty. This is 639 * This function commits an inode to disk immediately if it is dirty. This is
632 * primarily needed by knfsd. 640 * primarily needed by knfsd.
633 * 641 *
634 * The caller must either have a ref on the inode or must have set I_WILL_FREE. 642 * The caller must either have a ref on the inode or must have set I_WILL_FREE.
635 */ 643 */
636 int write_inode_now(struct inode *inode, int sync) 644 int write_inode_now(struct inode *inode, int sync)
637 { 645 {
638 int ret; 646 int ret;
639 struct writeback_control wbc = { 647 struct writeback_control wbc = {
640 .nr_to_write = LONG_MAX, 648 .nr_to_write = LONG_MAX,
641 .sync_mode = WB_SYNC_ALL, 649 .sync_mode = WB_SYNC_ALL,
642 .range_start = 0, 650 .range_start = 0,
643 .range_end = LLONG_MAX, 651 .range_end = LLONG_MAX,
644 }; 652 };
645 653
646 if (!mapping_cap_writeback_dirty(inode->i_mapping)) 654 if (!mapping_cap_writeback_dirty(inode->i_mapping))
647 wbc.nr_to_write = 0; 655 wbc.nr_to_write = 0;
648 656
649 might_sleep(); 657 might_sleep();
650 spin_lock(&inode_lock); 658 spin_lock(&inode_lock);
651 ret = __writeback_single_inode(inode, &wbc); 659 ret = __writeback_single_inode(inode, &wbc);
652 spin_unlock(&inode_lock); 660 spin_unlock(&inode_lock);
653 if (sync) 661 if (sync)
654 wait_on_inode(inode); 662 wait_on_inode(inode);
655 return ret; 663 return ret;
656 } 664 }
657 EXPORT_SYMBOL(write_inode_now); 665 EXPORT_SYMBOL(write_inode_now);
658 666
659 /** 667 /**
660 * sync_inode - write an inode and its pages to disk. 668 * sync_inode - write an inode and its pages to disk.
661 * @inode: the inode to sync 669 * @inode: the inode to sync
662 * @wbc: controls the writeback mode 670 * @wbc: controls the writeback mode
663 * 671 *
664 * sync_inode() will write an inode and its pages to disk. It will also 672 * sync_inode() will write an inode and its pages to disk. It will also
665 * correctly update the inode on its superblock's dirty inode lists and will 673 * correctly update the inode on its superblock's dirty inode lists and will
666 * update inode->i_state. 674 * update inode->i_state.
667 * 675 *
668 * The caller must have a ref on the inode. 676 * The caller must have a ref on the inode.
669 */ 677 */
670 int sync_inode(struct inode *inode, struct writeback_control *wbc) 678 int sync_inode(struct inode *inode, struct writeback_control *wbc)
671 { 679 {
672 int ret; 680 int ret;
673 681
674 spin_lock(&inode_lock); 682 spin_lock(&inode_lock);
675 ret = __writeback_single_inode(inode, wbc); 683 ret = __writeback_single_inode(inode, wbc);
676 spin_unlock(&inode_lock); 684 spin_unlock(&inode_lock);
677 return ret; 685 return ret;
678 } 686 }
679 EXPORT_SYMBOL(sync_inode); 687 EXPORT_SYMBOL(sync_inode);
680 688
681 /** 689 /**
682 * generic_osync_inode - flush all dirty data for a given inode to disk 690 * generic_osync_inode - flush all dirty data for a given inode to disk
683 * @inode: inode to write 691 * @inode: inode to write
684 * @mapping: the address_space that should be flushed 692 * @mapping: the address_space that should be flushed
685 * @what: what to write and wait upon 693 * @what: what to write and wait upon
686 * 694 *
687 * This can be called by file_write functions for files which have the 695 * This can be called by file_write functions for files which have the
688 * O_SYNC flag set, to flush dirty writes to disk. 696 * O_SYNC flag set, to flush dirty writes to disk.
689 * 697 *
690 * @what is a bitmask, specifying which part of the inode's data should be 698 * @what is a bitmask, specifying which part of the inode's data should be
691 * written and waited upon. 699 * written and waited upon.
692 * 700 *
693 * OSYNC_DATA: i_mapping's dirty data 701 * OSYNC_DATA: i_mapping's dirty data
694 * OSYNC_METADATA: the buffers at i_mapping->private_list 702 * OSYNC_METADATA: the buffers at i_mapping->private_list
695 * OSYNC_INODE: the inode itself 703 * OSYNC_INODE: the inode itself
696 */ 704 */
697 705
698 int generic_osync_inode(struct inode *inode, struct address_space *mapping, int what) 706 int generic_osync_inode(struct inode *inode, struct address_space *mapping, int what)
699 { 707 {
700 int err = 0; 708 int err = 0;
701 int need_write_inode_now = 0; 709 int need_write_inode_now = 0;
702 int err2; 710 int err2;
703 711
704 if (what & OSYNC_DATA) 712 if (what & OSYNC_DATA)
705 err = filemap_fdatawrite(mapping); 713 err = filemap_fdatawrite(mapping);
706 if (what & (OSYNC_METADATA|OSYNC_DATA)) { 714 if (what & (OSYNC_METADATA|OSYNC_DATA)) {
707 err2 = sync_mapping_buffers(mapping); 715 err2 = sync_mapping_buffers(mapping);
708 if (!err) 716 if (!err)
709 err = err2; 717 err = err2;
710 } 718 }
711 if (what & OSYNC_DATA) { 719 if (what & OSYNC_DATA) {
712 err2 = filemap_fdatawait(mapping); 720 err2 = filemap_fdatawait(mapping);
713 if (!err) 721 if (!err)
714 err = err2; 722 err = err2;
715 } 723 }
716 724
717 spin_lock(&inode_lock); 725 spin_lock(&inode_lock);
718 if ((inode->i_state & I_DIRTY) && 726 if ((inode->i_state & I_DIRTY) &&
719 ((what & OSYNC_INODE) || (inode->i_state & I_DIRTY_DATASYNC))) 727 ((what & OSYNC_INODE) || (inode->i_state & I_DIRTY_DATASYNC)))
720 need_write_inode_now = 1; 728 need_write_inode_now = 1;
721 spin_unlock(&inode_lock); 729 spin_unlock(&inode_lock);
722 730
723 if (need_write_inode_now) { 731 if (need_write_inode_now) {
724 err2 = write_inode_now(inode, 1); 732 err2 = write_inode_now(inode, 1);
725 if (!err) 733 if (!err)
726 err = err2; 734 err = err2;
727 } 735 }
728 else 736 else
729 wait_on_inode(inode); 737 wait_on_inode(inode);
730 738
731 return err; 739 return err;
732 } 740 }
733 741
734 EXPORT_SYMBOL(generic_osync_inode); 742 EXPORT_SYMBOL(generic_osync_inode);
735 743
736 /** 744 /**
737 * writeback_acquire: attempt to get exclusive writeback access to a device 745 * writeback_acquire: attempt to get exclusive writeback access to a device
738 * @bdi: the device's backing_dev_info structure 746 * @bdi: the device's backing_dev_info structure
739 * 747 *
740 * It is a waste of resources to have more than one pdflush thread blocked on 748 * It is a waste of resources to have more than one pdflush thread blocked on
741 * a single request queue. Exclusion at the request_queue level is obtained 749 * a single request queue. Exclusion at the request_queue level is obtained
742 * via a flag in the request_queue's backing_dev_info.state. 750 * via a flag in the request_queue's backing_dev_info.state.
743 * 751 *
744 * Non-request_queue-backed address_spaces will share default_backing_dev_info, 752 * Non-request_queue-backed address_spaces will share default_backing_dev_info,
745 * unless they implement their own. Which is somewhat inefficient, as this 753 * unless they implement their own. Which is somewhat inefficient, as this
746 * may prevent concurrent writeback against multiple devices. 754 * may prevent concurrent writeback against multiple devices.
747 */ 755 */
748 int writeback_acquire(struct backing_dev_info *bdi) 756 int writeback_acquire(struct backing_dev_info *bdi)
749 { 757 {
750 return !test_and_set_bit(BDI_pdflush, &bdi->state); 758 return !test_and_set_bit(BDI_pdflush, &bdi->state);
751 } 759 }
752 760
753 /** 761 /**
754 * writeback_in_progress: determine whether there is writeback in progress 762 * writeback_in_progress: determine whether there is writeback in progress
755 * @bdi: the device's backing_dev_info structure. 763 * @bdi: the device's backing_dev_info structure.
756 * 764 *
757 * Determine whether there is writeback in progress against a backing device. 765 * Determine whether there is writeback in progress against a backing device.
758 */ 766 */
759 int writeback_in_progress(struct backing_dev_info *bdi) 767 int writeback_in_progress(struct backing_dev_info *bdi)
760 { 768 {
761 return test_bit(BDI_pdflush, &bdi->state); 769 return test_bit(BDI_pdflush, &bdi->state);
762 } 770 }
763 771
764 /** 772 /**
765 * writeback_release: relinquish exclusive writeback access against a device. 773 * writeback_release: relinquish exclusive writeback access against a device.
766 * @bdi: the device's backing_dev_info structure 774 * @bdi: the device's backing_dev_info structure
767 */ 775 */
768 void writeback_release(struct backing_dev_info *bdi) 776 void writeback_release(struct backing_dev_info *bdi)
769 { 777 {
770 BUG_ON(!writeback_in_progress(bdi)); 778 BUG_ON(!writeback_in_progress(bdi));
771 clear_bit(BDI_pdflush, &bdi->state); 779 clear_bit(BDI_pdflush, &bdi->state);
772 } 780 }
773 781
1 /* 1 /*
2 * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project. 2 * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project.
3 * 3 *
4 * Copyright (c) 2001-2007 Anton Altaparmakov 4 * Copyright (c) 2001-2007 Anton Altaparmakov
5 * Copyright (c) 2001,2002 Richard Russon 5 * Copyright (c) 2001,2002 Richard Russon
6 * 6 *
7 * This program/include file is free software; you can redistribute it and/or 7 * This program/include file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as published 8 * modify it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2 of the License, or 9 * by the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version. 10 * (at your option) any later version.
11 * 11 *
12 * This program/include file is distributed in the hope that it will be 12 * This program/include file is distributed in the hope that it will be
13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 13 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 * along with this program (in the main directory of the Linux-NTFS 18 * along with this program (in the main directory of the Linux-NTFS
19 * distribution in the file COPYING); if not, write to the Free Software 19 * distribution in the file COPYING); if not, write to the Free Software
20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23 #include <linux/stddef.h> 23 #include <linux/stddef.h>
24 #include <linux/init.h> 24 #include <linux/init.h>
25 #include <linux/slab.h> 25 #include <linux/slab.h>
26 #include <linux/string.h> 26 #include <linux/string.h>
27 #include <linux/spinlock.h> 27 #include <linux/spinlock.h>
28 #include <linux/blkdev.h> /* For bdev_hardsect_size(). */ 28 #include <linux/blkdev.h> /* For bdev_hardsect_size(). */
29 #include <linux/backing-dev.h> 29 #include <linux/backing-dev.h>
30 #include <linux/buffer_head.h> 30 #include <linux/buffer_head.h>
31 #include <linux/vfs.h> 31 #include <linux/vfs.h>
32 #include <linux/moduleparam.h> 32 #include <linux/moduleparam.h>
33 #include <linux/smp_lock.h> 33 #include <linux/smp_lock.h>
34 34
35 #include "sysctl.h" 35 #include "sysctl.h"
36 #include "logfile.h" 36 #include "logfile.h"
37 #include "quota.h" 37 #include "quota.h"
38 #include "usnjrnl.h" 38 #include "usnjrnl.h"
39 #include "dir.h" 39 #include "dir.h"
40 #include "debug.h" 40 #include "debug.h"
41 #include "index.h" 41 #include "index.h"
42 #include "aops.h" 42 #include "aops.h"
43 #include "layout.h" 43 #include "layout.h"
44 #include "malloc.h" 44 #include "malloc.h"
45 #include "ntfs.h" 45 #include "ntfs.h"
46 46
47 /* Number of mounted filesystems which have compression enabled. */ 47 /* Number of mounted filesystems which have compression enabled. */
48 static unsigned long ntfs_nr_compression_users; 48 static unsigned long ntfs_nr_compression_users;
49 49
50 /* A global default upcase table and a corresponding reference count. */ 50 /* A global default upcase table and a corresponding reference count. */
51 static ntfschar *default_upcase = NULL; 51 static ntfschar *default_upcase = NULL;
52 static unsigned long ntfs_nr_upcase_users = 0; 52 static unsigned long ntfs_nr_upcase_users = 0;
53 53
54 /* Error constants/strings used in inode.c::ntfs_show_options(). */ 54 /* Error constants/strings used in inode.c::ntfs_show_options(). */
55 typedef enum { 55 typedef enum {
56 /* One of these must be present, default is ON_ERRORS_CONTINUE. */ 56 /* One of these must be present, default is ON_ERRORS_CONTINUE. */
57 ON_ERRORS_PANIC = 0x01, 57 ON_ERRORS_PANIC = 0x01,
58 ON_ERRORS_REMOUNT_RO = 0x02, 58 ON_ERRORS_REMOUNT_RO = 0x02,
59 ON_ERRORS_CONTINUE = 0x04, 59 ON_ERRORS_CONTINUE = 0x04,
60 /* Optional, can be combined with any of the above. */ 60 /* Optional, can be combined with any of the above. */
61 ON_ERRORS_RECOVER = 0x10, 61 ON_ERRORS_RECOVER = 0x10,
62 } ON_ERRORS_ACTIONS; 62 } ON_ERRORS_ACTIONS;
63 63
64 const option_t on_errors_arr[] = { 64 const option_t on_errors_arr[] = {
65 { ON_ERRORS_PANIC, "panic" }, 65 { ON_ERRORS_PANIC, "panic" },
66 { ON_ERRORS_REMOUNT_RO, "remount-ro", }, 66 { ON_ERRORS_REMOUNT_RO, "remount-ro", },
67 { ON_ERRORS_CONTINUE, "continue", }, 67 { ON_ERRORS_CONTINUE, "continue", },
68 { ON_ERRORS_RECOVER, "recover" }, 68 { ON_ERRORS_RECOVER, "recover" },
69 { 0, NULL } 69 { 0, NULL }
70 }; 70 };
71 71
72 /** 72 /**
73 * simple_getbool - 73 * simple_getbool -
74 * 74 *
75 * Copied from old ntfs driver (which copied from vfat driver). 75 * Copied from old ntfs driver (which copied from vfat driver).
76 */ 76 */
77 static int simple_getbool(char *s, bool *setval) 77 static int simple_getbool(char *s, bool *setval)
78 { 78 {
79 if (s) { 79 if (s) {
80 if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true")) 80 if (!strcmp(s, "1") || !strcmp(s, "yes") || !strcmp(s, "true"))
81 *setval = true; 81 *setval = true;
82 else if (!strcmp(s, "0") || !strcmp(s, "no") || 82 else if (!strcmp(s, "0") || !strcmp(s, "no") ||
83 !strcmp(s, "false")) 83 !strcmp(s, "false"))
84 *setval = false; 84 *setval = false;
85 else 85 else
86 return 0; 86 return 0;
87 } else 87 } else
88 *setval = true; 88 *setval = true;
89 return 1; 89 return 1;
90 } 90 }
91 91
92 /** 92 /**
93 * parse_options - parse the (re)mount options 93 * parse_options - parse the (re)mount options
94 * @vol: ntfs volume 94 * @vol: ntfs volume
95 * @opt: string containing the (re)mount options 95 * @opt: string containing the (re)mount options
96 * 96 *
97 * Parse the recognized options in @opt for the ntfs volume described by @vol. 97 * Parse the recognized options in @opt for the ntfs volume described by @vol.
98 */ 98 */
99 static bool parse_options(ntfs_volume *vol, char *opt) 99 static bool parse_options(ntfs_volume *vol, char *opt)
100 { 100 {
101 char *p, *v, *ov; 101 char *p, *v, *ov;
102 static char *utf8 = "utf8"; 102 static char *utf8 = "utf8";
103 int errors = 0, sloppy = 0; 103 int errors = 0, sloppy = 0;
104 uid_t uid = (uid_t)-1; 104 uid_t uid = (uid_t)-1;
105 gid_t gid = (gid_t)-1; 105 gid_t gid = (gid_t)-1;
106 mode_t fmask = (mode_t)-1, dmask = (mode_t)-1; 106 mode_t fmask = (mode_t)-1, dmask = (mode_t)-1;
107 int mft_zone_multiplier = -1, on_errors = -1; 107 int mft_zone_multiplier = -1, on_errors = -1;
108 int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; 108 int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1;
109 struct nls_table *nls_map = NULL, *old_nls; 109 struct nls_table *nls_map = NULL, *old_nls;
110 110
111 /* I am lazy... (-8 */ 111 /* I am lazy... (-8 */
112 #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ 112 #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \
113 if (!strcmp(p, option)) { \ 113 if (!strcmp(p, option)) { \
114 if (!v || !*v) \ 114 if (!v || !*v) \
115 variable = default_value; \ 115 variable = default_value; \
116 else { \ 116 else { \
117 variable = simple_strtoul(ov = v, &v, 0); \ 117 variable = simple_strtoul(ov = v, &v, 0); \
118 if (*v) \ 118 if (*v) \
119 goto needs_val; \ 119 goto needs_val; \
120 } \ 120 } \
121 } 121 }
122 #define NTFS_GETOPT(option, variable) \ 122 #define NTFS_GETOPT(option, variable) \
123 if (!strcmp(p, option)) { \ 123 if (!strcmp(p, option)) { \
124 if (!v || !*v) \ 124 if (!v || !*v) \
125 goto needs_arg; \ 125 goto needs_arg; \
126 variable = simple_strtoul(ov = v, &v, 0); \ 126 variable = simple_strtoul(ov = v, &v, 0); \
127 if (*v) \ 127 if (*v) \
128 goto needs_val; \ 128 goto needs_val; \
129 } 129 }
130 #define NTFS_GETOPT_OCTAL(option, variable) \ 130 #define NTFS_GETOPT_OCTAL(option, variable) \
131 if (!strcmp(p, option)) { \ 131 if (!strcmp(p, option)) { \
132 if (!v || !*v) \ 132 if (!v || !*v) \
133 goto needs_arg; \ 133 goto needs_arg; \
134 variable = simple_strtoul(ov = v, &v, 8); \ 134 variable = simple_strtoul(ov = v, &v, 8); \
135 if (*v) \ 135 if (*v) \
136 goto needs_val; \ 136 goto needs_val; \
137 } 137 }
138 #define NTFS_GETOPT_BOOL(option, variable) \ 138 #define NTFS_GETOPT_BOOL(option, variable) \
139 if (!strcmp(p, option)) { \ 139 if (!strcmp(p, option)) { \
140 bool val; \ 140 bool val; \
141 if (!simple_getbool(v, &val)) \ 141 if (!simple_getbool(v, &val)) \
142 goto needs_bool; \ 142 goto needs_bool; \
143 variable = val; \ 143 variable = val; \
144 } 144 }
145 #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \ 145 #define NTFS_GETOPT_OPTIONS_ARRAY(option, variable, opt_array) \
146 if (!strcmp(p, option)) { \ 146 if (!strcmp(p, option)) { \
147 int _i; \ 147 int _i; \
148 if (!v || !*v) \ 148 if (!v || !*v) \
149 goto needs_arg; \ 149 goto needs_arg; \
150 ov = v; \ 150 ov = v; \
151 if (variable == -1) \ 151 if (variable == -1) \
152 variable = 0; \ 152 variable = 0; \
153 for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \ 153 for (_i = 0; opt_array[_i].str && *opt_array[_i].str; _i++) \
154 if (!strcmp(opt_array[_i].str, v)) { \ 154 if (!strcmp(opt_array[_i].str, v)) { \
155 variable |= opt_array[_i].val; \ 155 variable |= opt_array[_i].val; \
156 break; \ 156 break; \
157 } \ 157 } \
158 if (!opt_array[_i].str || !*opt_array[_i].str) \ 158 if (!opt_array[_i].str || !*opt_array[_i].str) \
159 goto needs_val; \ 159 goto needs_val; \
160 } 160 }
161 if (!opt || !*opt) 161 if (!opt || !*opt)
162 goto no_mount_options; 162 goto no_mount_options;
163 ntfs_debug("Entering with mount options string: %s", opt); 163 ntfs_debug("Entering with mount options string: %s", opt);
164 while ((p = strsep(&opt, ","))) { 164 while ((p = strsep(&opt, ","))) {
165 if ((v = strchr(p, '='))) 165 if ((v = strchr(p, '=')))
166 *v++ = 0; 166 *v++ = 0;
167 NTFS_GETOPT("uid", uid) 167 NTFS_GETOPT("uid", uid)
168 else NTFS_GETOPT("gid", gid) 168 else NTFS_GETOPT("gid", gid)
169 else NTFS_GETOPT_OCTAL("umask", fmask = dmask) 169 else NTFS_GETOPT_OCTAL("umask", fmask = dmask)
170 else NTFS_GETOPT_OCTAL("fmask", fmask) 170 else NTFS_GETOPT_OCTAL("fmask", fmask)
171 else NTFS_GETOPT_OCTAL("dmask", dmask) 171 else NTFS_GETOPT_OCTAL("dmask", dmask)
172 else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier) 172 else NTFS_GETOPT("mft_zone_multiplier", mft_zone_multiplier)
173 else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, true) 173 else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, true)
174 else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files) 174 else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
175 else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive) 175 else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
176 else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse) 176 else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse)
177 else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors, 177 else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
178 on_errors_arr) 178 on_errors_arr)
179 else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes")) 179 else if (!strcmp(p, "posix") || !strcmp(p, "show_inodes"))
180 ntfs_warning(vol->sb, "Ignoring obsolete option %s.", 180 ntfs_warning(vol->sb, "Ignoring obsolete option %s.",
181 p); 181 p);
182 else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) { 182 else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) {
183 if (!strcmp(p, "iocharset")) 183 if (!strcmp(p, "iocharset"))
184 ntfs_warning(vol->sb, "Option iocharset is " 184 ntfs_warning(vol->sb, "Option iocharset is "
185 "deprecated. Please use " 185 "deprecated. Please use "
186 "option nls=<charsetname> in " 186 "option nls=<charsetname> in "
187 "the future."); 187 "the future.");
188 if (!v || !*v) 188 if (!v || !*v)
189 goto needs_arg; 189 goto needs_arg;
190 use_utf8: 190 use_utf8:
191 old_nls = nls_map; 191 old_nls = nls_map;
192 nls_map = load_nls(v); 192 nls_map = load_nls(v);
193 if (!nls_map) { 193 if (!nls_map) {
194 if (!old_nls) { 194 if (!old_nls) {
195 ntfs_error(vol->sb, "NLS character set " 195 ntfs_error(vol->sb, "NLS character set "
196 "%s not found.", v); 196 "%s not found.", v);
197 return false; 197 return false;
198 } 198 }
199 ntfs_error(vol->sb, "NLS character set %s not " 199 ntfs_error(vol->sb, "NLS character set %s not "
200 "found. Using previous one %s.", 200 "found. Using previous one %s.",
201 v, old_nls->charset); 201 v, old_nls->charset);
202 nls_map = old_nls; 202 nls_map = old_nls;
203 } else /* nls_map */ { 203 } else /* nls_map */ {
204 if (old_nls) 204 if (old_nls)
205 unload_nls(old_nls); 205 unload_nls(old_nls);
206 } 206 }
207 } else if (!strcmp(p, "utf8")) { 207 } else if (!strcmp(p, "utf8")) {
208 bool val = false; 208 bool val = false;
209 ntfs_warning(vol->sb, "Option utf8 is no longer " 209 ntfs_warning(vol->sb, "Option utf8 is no longer "
210 "supported, using option nls=utf8. Please " 210 "supported, using option nls=utf8. Please "
211 "use option nls=utf8 in the future and " 211 "use option nls=utf8 in the future and "
212 "make sure utf8 is compiled either as a " 212 "make sure utf8 is compiled either as a "
213 "module or into the kernel."); 213 "module or into the kernel.");
214 if (!v || !*v) 214 if (!v || !*v)
215 val = true; 215 val = true;
216 else if (!simple_getbool(v, &val)) 216 else if (!simple_getbool(v, &val))
217 goto needs_bool; 217 goto needs_bool;
218 if (val) { 218 if (val) {
219 v = utf8; 219 v = utf8;
220 goto use_utf8; 220 goto use_utf8;
221 } 221 }
222 } else { 222 } else {
223 ntfs_error(vol->sb, "Unrecognized mount option %s.", p); 223 ntfs_error(vol->sb, "Unrecognized mount option %s.", p);
224 if (errors < INT_MAX) 224 if (errors < INT_MAX)
225 errors++; 225 errors++;
226 } 226 }
227 #undef NTFS_GETOPT_OPTIONS_ARRAY 227 #undef NTFS_GETOPT_OPTIONS_ARRAY
228 #undef NTFS_GETOPT_BOOL 228 #undef NTFS_GETOPT_BOOL
229 #undef NTFS_GETOPT 229 #undef NTFS_GETOPT
230 #undef NTFS_GETOPT_WITH_DEFAULT 230 #undef NTFS_GETOPT_WITH_DEFAULT
231 } 231 }
232 no_mount_options: 232 no_mount_options:
233 if (errors && !sloppy) 233 if (errors && !sloppy)
234 return false; 234 return false;
235 if (sloppy) 235 if (sloppy)
236 ntfs_warning(vol->sb, "Sloppy option given. Ignoring " 236 ntfs_warning(vol->sb, "Sloppy option given. Ignoring "
237 "unrecognized mount option(s) and continuing."); 237 "unrecognized mount option(s) and continuing.");
238 /* Keep this first! */ 238 /* Keep this first! */
239 if (on_errors != -1) { 239 if (on_errors != -1) {
240 if (!on_errors) { 240 if (!on_errors) {
241 ntfs_error(vol->sb, "Invalid errors option argument " 241 ntfs_error(vol->sb, "Invalid errors option argument "
242 "or bug in options parser."); 242 "or bug in options parser.");
243 return false; 243 return false;
244 } 244 }
245 } 245 }
246 if (nls_map) { 246 if (nls_map) {
247 if (vol->nls_map && vol->nls_map != nls_map) { 247 if (vol->nls_map && vol->nls_map != nls_map) {
248 ntfs_error(vol->sb, "Cannot change NLS character set " 248 ntfs_error(vol->sb, "Cannot change NLS character set "
249 "on remount."); 249 "on remount.");
250 return false; 250 return false;
251 } /* else (!vol->nls_map) */ 251 } /* else (!vol->nls_map) */
252 ntfs_debug("Using NLS character set %s.", nls_map->charset); 252 ntfs_debug("Using NLS character set %s.", nls_map->charset);
253 vol->nls_map = nls_map; 253 vol->nls_map = nls_map;
254 } else /* (!nls_map) */ { 254 } else /* (!nls_map) */ {
255 if (!vol->nls_map) { 255 if (!vol->nls_map) {
256 vol->nls_map = load_nls_default(); 256 vol->nls_map = load_nls_default();
257 if (!vol->nls_map) { 257 if (!vol->nls_map) {
258 ntfs_error(vol->sb, "Failed to load default " 258 ntfs_error(vol->sb, "Failed to load default "
259 "NLS character set."); 259 "NLS character set.");
260 return false; 260 return false;
261 } 261 }
262 ntfs_debug("Using default NLS character set (%s).", 262 ntfs_debug("Using default NLS character set (%s).",
263 vol->nls_map->charset); 263 vol->nls_map->charset);
264 } 264 }
265 } 265 }
266 if (mft_zone_multiplier != -1) { 266 if (mft_zone_multiplier != -1) {
267 if (vol->mft_zone_multiplier && vol->mft_zone_multiplier != 267 if (vol->mft_zone_multiplier && vol->mft_zone_multiplier !=
268 mft_zone_multiplier) { 268 mft_zone_multiplier) {
269 ntfs_error(vol->sb, "Cannot change mft_zone_multiplier " 269 ntfs_error(vol->sb, "Cannot change mft_zone_multiplier "
270 "on remount."); 270 "on remount.");
271 return false; 271 return false;
272 } 272 }
273 if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) { 273 if (mft_zone_multiplier < 1 || mft_zone_multiplier > 4) {
274 ntfs_error(vol->sb, "Invalid mft_zone_multiplier. " 274 ntfs_error(vol->sb, "Invalid mft_zone_multiplier. "
275 "Using default value, i.e. 1."); 275 "Using default value, i.e. 1.");
276 mft_zone_multiplier = 1; 276 mft_zone_multiplier = 1;
277 } 277 }
278 vol->mft_zone_multiplier = mft_zone_multiplier; 278 vol->mft_zone_multiplier = mft_zone_multiplier;
279 } 279 }
280 if (!vol->mft_zone_multiplier) 280 if (!vol->mft_zone_multiplier)
281 vol->mft_zone_multiplier = 1; 281 vol->mft_zone_multiplier = 1;
282 if (on_errors != -1) 282 if (on_errors != -1)
283 vol->on_errors = on_errors; 283 vol->on_errors = on_errors;
284 if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER) 284 if (!vol->on_errors || vol->on_errors == ON_ERRORS_RECOVER)
285 vol->on_errors |= ON_ERRORS_CONTINUE; 285 vol->on_errors |= ON_ERRORS_CONTINUE;
286 if (uid != (uid_t)-1) 286 if (uid != (uid_t)-1)
287 vol->uid = uid; 287 vol->uid = uid;
288 if (gid != (gid_t)-1) 288 if (gid != (gid_t)-1)
289 vol->gid = gid; 289 vol->gid = gid;
290 if (fmask != (mode_t)-1) 290 if (fmask != (mode_t)-1)
291 vol->fmask = fmask; 291 vol->fmask = fmask;
292 if (dmask != (mode_t)-1) 292 if (dmask != (mode_t)-1)
293 vol->dmask = dmask; 293 vol->dmask = dmask;
294 if (show_sys_files != -1) { 294 if (show_sys_files != -1) {
295 if (show_sys_files) 295 if (show_sys_files)
296 NVolSetShowSystemFiles(vol); 296 NVolSetShowSystemFiles(vol);
297 else 297 else
298 NVolClearShowSystemFiles(vol); 298 NVolClearShowSystemFiles(vol);
299 } 299 }
300 if (case_sensitive != -1) { 300 if (case_sensitive != -1) {
301 if (case_sensitive) 301 if (case_sensitive)
302 NVolSetCaseSensitive(vol); 302 NVolSetCaseSensitive(vol);
303 else 303 else
304 NVolClearCaseSensitive(vol); 304 NVolClearCaseSensitive(vol);
305 } 305 }
306 if (disable_sparse != -1) { 306 if (disable_sparse != -1) {
307 if (disable_sparse) 307 if (disable_sparse)
308 NVolClearSparseEnabled(vol); 308 NVolClearSparseEnabled(vol);
309 else { 309 else {
310 if (!NVolSparseEnabled(vol) && 310 if (!NVolSparseEnabled(vol) &&
311 vol->major_ver && vol->major_ver < 3) 311 vol->major_ver && vol->major_ver < 3)
312 ntfs_warning(vol->sb, "Not enabling sparse " 312 ntfs_warning(vol->sb, "Not enabling sparse "
313 "support due to NTFS volume " 313 "support due to NTFS volume "
314 "version %i.%i (need at least " 314 "version %i.%i (need at least "
315 "version 3.0).", vol->major_ver, 315 "version 3.0).", vol->major_ver,
316 vol->minor_ver); 316 vol->minor_ver);
317 else 317 else
318 NVolSetSparseEnabled(vol); 318 NVolSetSparseEnabled(vol);
319 } 319 }
320 } 320 }
321 return true; 321 return true;
322 needs_arg: 322 needs_arg:
323 ntfs_error(vol->sb, "The %s option requires an argument.", p); 323 ntfs_error(vol->sb, "The %s option requires an argument.", p);
324 return false; 324 return false;
325 needs_bool: 325 needs_bool:
326 ntfs_error(vol->sb, "The %s option requires a boolean argument.", p); 326 ntfs_error(vol->sb, "The %s option requires a boolean argument.", p);
327 return false; 327 return false;
328 needs_val: 328 needs_val:
329 ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov); 329 ntfs_error(vol->sb, "Invalid %s option argument: %s", p, ov);
330 return false; 330 return false;
331 } 331 }
332 332
333 #ifdef NTFS_RW 333 #ifdef NTFS_RW
334 334
335 /** 335 /**
336 * ntfs_write_volume_flags - write new flags to the volume information flags 336 * ntfs_write_volume_flags - write new flags to the volume information flags
337 * @vol: ntfs volume on which to modify the flags 337 * @vol: ntfs volume on which to modify the flags
338 * @flags: new flags value for the volume information flags 338 * @flags: new flags value for the volume information flags
339 * 339 *
340 * Internal function. You probably want to use ntfs_{set,clear}_volume_flags() 340 * Internal function. You probably want to use ntfs_{set,clear}_volume_flags()
341 * instead (see below). 341 * instead (see below).
342 * 342 *
343 * Replace the volume information flags on the volume @vol with the value 343 * Replace the volume information flags on the volume @vol with the value
344 * supplied in @flags. Note, this overwrites the volume information flags, so 344 * supplied in @flags. Note, this overwrites the volume information flags, so
345 * make sure to combine the flags you want to modify with the old flags and use 345 * make sure to combine the flags you want to modify with the old flags and use
346 * the result when calling ntfs_write_volume_flags(). 346 * the result when calling ntfs_write_volume_flags().
347 * 347 *
348 * Return 0 on success and -errno on error. 348 * Return 0 on success and -errno on error.
349 */ 349 */
350 static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags) 350 static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags)
351 { 351 {
352 ntfs_inode *ni = NTFS_I(vol->vol_ino); 352 ntfs_inode *ni = NTFS_I(vol->vol_ino);
353 MFT_RECORD *m; 353 MFT_RECORD *m;
354 VOLUME_INFORMATION *vi; 354 VOLUME_INFORMATION *vi;
355 ntfs_attr_search_ctx *ctx; 355 ntfs_attr_search_ctx *ctx;
356 int err; 356 int err;
357 357
358 ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.", 358 ntfs_debug("Entering, old flags = 0x%x, new flags = 0x%x.",
359 le16_to_cpu(vol->vol_flags), le16_to_cpu(flags)); 359 le16_to_cpu(vol->vol_flags), le16_to_cpu(flags));
360 if (vol->vol_flags == flags) 360 if (vol->vol_flags == flags)
361 goto done; 361 goto done;
362 BUG_ON(!ni); 362 BUG_ON(!ni);
363 m = map_mft_record(ni); 363 m = map_mft_record(ni);
364 if (IS_ERR(m)) { 364 if (IS_ERR(m)) {
365 err = PTR_ERR(m); 365 err = PTR_ERR(m);
366 goto err_out; 366 goto err_out;
367 } 367 }
368 ctx = ntfs_attr_get_search_ctx(ni, m); 368 ctx = ntfs_attr_get_search_ctx(ni, m);
369 if (!ctx) { 369 if (!ctx) {
370 err = -ENOMEM; 370 err = -ENOMEM;
371 goto put_unm_err_out; 371 goto put_unm_err_out;
372 } 372 }
373 err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, 373 err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
374 ctx); 374 ctx);
375 if (err) 375 if (err)
376 goto put_unm_err_out; 376 goto put_unm_err_out;
377 vi = (VOLUME_INFORMATION*)((u8*)ctx->attr + 377 vi = (VOLUME_INFORMATION*)((u8*)ctx->attr +
378 le16_to_cpu(ctx->attr->data.resident.value_offset)); 378 le16_to_cpu(ctx->attr->data.resident.value_offset));
379 vol->vol_flags = vi->flags = flags; 379 vol->vol_flags = vi->flags = flags;
380 flush_dcache_mft_record_page(ctx->ntfs_ino); 380 flush_dcache_mft_record_page(ctx->ntfs_ino);
381 mark_mft_record_dirty(ctx->ntfs_ino); 381 mark_mft_record_dirty(ctx->ntfs_ino);
382 ntfs_attr_put_search_ctx(ctx); 382 ntfs_attr_put_search_ctx(ctx);
383 unmap_mft_record(ni); 383 unmap_mft_record(ni);
384 done: 384 done:
385 ntfs_debug("Done."); 385 ntfs_debug("Done.");
386 return 0; 386 return 0;
387 put_unm_err_out: 387 put_unm_err_out:
388 if (ctx) 388 if (ctx)
389 ntfs_attr_put_search_ctx(ctx); 389 ntfs_attr_put_search_ctx(ctx);
390 unmap_mft_record(ni); 390 unmap_mft_record(ni);
391 err_out: 391 err_out:
392 ntfs_error(vol->sb, "Failed with error code %i.", -err); 392 ntfs_error(vol->sb, "Failed with error code %i.", -err);
393 return err; 393 return err;
394 } 394 }
395 395
396 /** 396 /**
397 * ntfs_set_volume_flags - set bits in the volume information flags 397 * ntfs_set_volume_flags - set bits in the volume information flags
398 * @vol: ntfs volume on which to modify the flags 398 * @vol: ntfs volume on which to modify the flags
399 * @flags: flags to set on the volume 399 * @flags: flags to set on the volume
400 * 400 *
401 * Set the bits in @flags in the volume information flags on the volume @vol. 401 * Set the bits in @flags in the volume information flags on the volume @vol.
402 * 402 *
403 * Return 0 on success and -errno on error. 403 * Return 0 on success and -errno on error.
404 */ 404 */
405 static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) 405 static inline int ntfs_set_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)
406 { 406 {
407 flags &= VOLUME_FLAGS_MASK; 407 flags &= VOLUME_FLAGS_MASK;
408 return ntfs_write_volume_flags(vol, vol->vol_flags | flags); 408 return ntfs_write_volume_flags(vol, vol->vol_flags | flags);
409 } 409 }
410 410
411 /** 411 /**
412 * ntfs_clear_volume_flags - clear bits in the volume information flags 412 * ntfs_clear_volume_flags - clear bits in the volume information flags
413 * @vol: ntfs volume on which to modify the flags 413 * @vol: ntfs volume on which to modify the flags
414 * @flags: flags to clear on the volume 414 * @flags: flags to clear on the volume
415 * 415 *
416 * Clear the bits in @flags in the volume information flags on the volume @vol. 416 * Clear the bits in @flags in the volume information flags on the volume @vol.
417 * 417 *
418 * Return 0 on success and -errno on error. 418 * Return 0 on success and -errno on error.
419 */ 419 */
420 static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags) 420 static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)
421 { 421 {
422 flags &= VOLUME_FLAGS_MASK; 422 flags &= VOLUME_FLAGS_MASK;
423 flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags)); 423 flags = vol->vol_flags & cpu_to_le16(~le16_to_cpu(flags));
424 return ntfs_write_volume_flags(vol, flags); 424 return ntfs_write_volume_flags(vol, flags);
425 } 425 }
426 426
427 #endif /* NTFS_RW */ 427 #endif /* NTFS_RW */
428 428
429 /** 429 /**
430 * ntfs_remount - change the mount options of a mounted ntfs filesystem 430 * ntfs_remount - change the mount options of a mounted ntfs filesystem
431 * @sb: superblock of mounted ntfs filesystem 431 * @sb: superblock of mounted ntfs filesystem
432 * @flags: remount flags 432 * @flags: remount flags
433 * @opt: remount options string 433 * @opt: remount options string
434 * 434 *
435 * Change the mount options of an already mounted ntfs filesystem. 435 * Change the mount options of an already mounted ntfs filesystem.
436 * 436 *
437 * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after 437 * NOTE: The VFS sets the @sb->s_flags remount flags to @flags after
438 * ntfs_remount() returns successfully (i.e. returns 0). Otherwise, 438 * ntfs_remount() returns successfully (i.e. returns 0). Otherwise,
439 * @sb->s_flags are not changed. 439 * @sb->s_flags are not changed.
440 */ 440 */
441 static int ntfs_remount(struct super_block *sb, int *flags, char *opt) 441 static int ntfs_remount(struct super_block *sb, int *flags, char *opt)
442 { 442 {
443 ntfs_volume *vol = NTFS_SB(sb); 443 ntfs_volume *vol = NTFS_SB(sb);
444 444
445 ntfs_debug("Entering with remount options string: %s", opt); 445 ntfs_debug("Entering with remount options string: %s", opt);
446 #ifndef NTFS_RW 446 #ifndef NTFS_RW
447 /* For read-only compiled driver, enforce read-only flag. */ 447 /* For read-only compiled driver, enforce read-only flag. */
448 *flags |= MS_RDONLY; 448 *flags |= MS_RDONLY;
449 #else /* NTFS_RW */ 449 #else /* NTFS_RW */
450 /* 450 /*
451 * For the read-write compiled driver, if we are remounting read-write, 451 * For the read-write compiled driver, if we are remounting read-write,
452 * make sure there are no volume errors and that no unsupported volume 452 * make sure there are no volume errors and that no unsupported volume
453 * flags are set. Also, empty the logfile journal as it would become 453 * flags are set. Also, empty the logfile journal as it would become
454 * stale as soon as something is written to the volume and mark the 454 * stale as soon as something is written to the volume and mark the
455 * volume dirty so that chkdsk is run if the volume is not umounted 455 * volume dirty so that chkdsk is run if the volume is not umounted
456 * cleanly. Finally, mark the quotas out of date so Windows rescans 456 * cleanly. Finally, mark the quotas out of date so Windows rescans
457 * the volume on boot and updates them. 457 * the volume on boot and updates them.
458 * 458 *
459 * When remounting read-only, mark the volume clean if no volume errors 459 * When remounting read-only, mark the volume clean if no volume errors
460 * have occured. 460 * have occured.
461 */ 461 */
462 if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { 462 if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
463 static const char *es = ". Cannot remount read-write."; 463 static const char *es = ". Cannot remount read-write.";
464 464
465 /* Remounting read-write. */ 465 /* Remounting read-write. */
466 if (NVolErrors(vol)) { 466 if (NVolErrors(vol)) {
467 ntfs_error(sb, "Volume has errors and is read-only%s", 467 ntfs_error(sb, "Volume has errors and is read-only%s",
468 es); 468 es);
469 return -EROFS; 469 return -EROFS;
470 } 470 }
471 if (vol->vol_flags & VOLUME_IS_DIRTY) { 471 if (vol->vol_flags & VOLUME_IS_DIRTY) {
472 ntfs_error(sb, "Volume is dirty and read-only%s", es); 472 ntfs_error(sb, "Volume is dirty and read-only%s", es);
473 return -EROFS; 473 return -EROFS;
474 } 474 }
475 if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { 475 if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
476 ntfs_error(sb, "Volume has been modified by chkdsk " 476 ntfs_error(sb, "Volume has been modified by chkdsk "
477 "and is read-only%s", es); 477 "and is read-only%s", es);
478 return -EROFS; 478 return -EROFS;
479 } 479 }
480 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { 480 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
481 ntfs_error(sb, "Volume has unsupported flags set " 481 ntfs_error(sb, "Volume has unsupported flags set "
482 "(0x%x) and is read-only%s", 482 "(0x%x) and is read-only%s",
483 (unsigned)le16_to_cpu(vol->vol_flags), 483 (unsigned)le16_to_cpu(vol->vol_flags),
484 es); 484 es);
485 return -EROFS; 485 return -EROFS;
486 } 486 }
487 if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { 487 if (ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) {
488 ntfs_error(sb, "Failed to set dirty bit in volume " 488 ntfs_error(sb, "Failed to set dirty bit in volume "
489 "information flags%s", es); 489 "information flags%s", es);
490 return -EROFS; 490 return -EROFS;
491 } 491 }
492 #if 0 492 #if 0
493 // TODO: Enable this code once we start modifying anything that 493 // TODO: Enable this code once we start modifying anything that
494 // is different between NTFS 1.2 and 3.x... 494 // is different between NTFS 1.2 and 3.x...
495 /* Set NT4 compatibility flag on newer NTFS version volumes. */ 495 /* Set NT4 compatibility flag on newer NTFS version volumes. */
496 if ((vol->major_ver > 1)) { 496 if ((vol->major_ver > 1)) {
497 if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { 497 if (ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) {
498 ntfs_error(sb, "Failed to set NT4 " 498 ntfs_error(sb, "Failed to set NT4 "
499 "compatibility flag%s", es); 499 "compatibility flag%s", es);
500 NVolSetErrors(vol); 500 NVolSetErrors(vol);
501 return -EROFS; 501 return -EROFS;
502 } 502 }
503 } 503 }
504 #endif 504 #endif
505 if (!ntfs_empty_logfile(vol->logfile_ino)) { 505 if (!ntfs_empty_logfile(vol->logfile_ino)) {
506 ntfs_error(sb, "Failed to empty journal $LogFile%s", 506 ntfs_error(sb, "Failed to empty journal $LogFile%s",
507 es); 507 es);
508 NVolSetErrors(vol); 508 NVolSetErrors(vol);
509 return -EROFS; 509 return -EROFS;
510 } 510 }
511 if (!ntfs_mark_quotas_out_of_date(vol)) { 511 if (!ntfs_mark_quotas_out_of_date(vol)) {
512 ntfs_error(sb, "Failed to mark quotas out of date%s", 512 ntfs_error(sb, "Failed to mark quotas out of date%s",
513 es); 513 es);
514 NVolSetErrors(vol); 514 NVolSetErrors(vol);
515 return -EROFS; 515 return -EROFS;
516 } 516 }
517 if (!ntfs_stamp_usnjrnl(vol)) { 517 if (!ntfs_stamp_usnjrnl(vol)) {
518 ntfs_error(sb, "Failed to stamp transation log " 518 ntfs_error(sb, "Failed to stamp transation log "
519 "($UsnJrnl)%s", es); 519 "($UsnJrnl)%s", es);
520 NVolSetErrors(vol); 520 NVolSetErrors(vol);
521 return -EROFS; 521 return -EROFS;
522 } 522 }
523 } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) { 523 } else if (!(sb->s_flags & MS_RDONLY) && (*flags & MS_RDONLY)) {
524 /* Remounting read-only. */ 524 /* Remounting read-only. */
525 if (!NVolErrors(vol)) { 525 if (!NVolErrors(vol)) {
526 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) 526 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY))
527 ntfs_warning(sb, "Failed to clear dirty bit " 527 ntfs_warning(sb, "Failed to clear dirty bit "
528 "in volume information " 528 "in volume information "
529 "flags. Run chkdsk."); 529 "flags. Run chkdsk.");
530 } 530 }
531 } 531 }
532 #endif /* NTFS_RW */ 532 #endif /* NTFS_RW */
533 533
534 // TODO: Deal with *flags. 534 // TODO: Deal with *flags.
535 535
536 if (!parse_options(vol, opt)) 536 if (!parse_options(vol, opt))
537 return -EINVAL; 537 return -EINVAL;
538 ntfs_debug("Done."); 538 ntfs_debug("Done.");
539 return 0; 539 return 0;
540 } 540 }
541 541
542 /** 542 /**
543 * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector 543 * is_boot_sector_ntfs - check whether a boot sector is a valid NTFS boot sector
544 * @sb: Super block of the device to which @b belongs. 544 * @sb: Super block of the device to which @b belongs.
545 * @b: Boot sector of device @sb to check. 545 * @b: Boot sector of device @sb to check.
546 * @silent: If 'true', all output will be silenced. 546 * @silent: If 'true', all output will be silenced.
547 * 547 *
548 * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot 548 * is_boot_sector_ntfs() checks whether the boot sector @b is a valid NTFS boot
549 * sector. Returns 'true' if it is valid and 'false' if not. 549 * sector. Returns 'true' if it is valid and 'false' if not.
550 * 550 *
551 * @sb is only needed for warning/error output, i.e. it can be NULL when silent 551 * @sb is only needed for warning/error output, i.e. it can be NULL when silent
552 * is 'true'. 552 * is 'true'.
553 */ 553 */
554 static bool is_boot_sector_ntfs(const struct super_block *sb, 554 static bool is_boot_sector_ntfs(const struct super_block *sb,
555 const NTFS_BOOT_SECTOR *b, const bool silent) 555 const NTFS_BOOT_SECTOR *b, const bool silent)
556 { 556 {
557 /* 557 /*
558 * Check that checksum == sum of u32 values from b to the checksum 558 * Check that checksum == sum of u32 values from b to the checksum
559 * field. If checksum is zero, no checking is done. We will work when 559 * field. If checksum is zero, no checking is done. We will work when
560 * the checksum test fails, since some utilities update the boot sector 560 * the checksum test fails, since some utilities update the boot sector
561 * ignoring the checksum which leaves the checksum out-of-date. We 561 * ignoring the checksum which leaves the checksum out-of-date. We
562 * report a warning if this is the case. 562 * report a warning if this is the case.
563 */ 563 */
564 if ((void*)b < (void*)&b->checksum && b->checksum && !silent) { 564 if ((void*)b < (void*)&b->checksum && b->checksum && !silent) {
565 le32 *u; 565 le32 *u;
566 u32 i; 566 u32 i;
567 567
568 for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u) 568 for (i = 0, u = (le32*)b; u < (le32*)(&b->checksum); ++u)
569 i += le32_to_cpup(u); 569 i += le32_to_cpup(u);
570 if (le32_to_cpu(b->checksum) != i) 570 if (le32_to_cpu(b->checksum) != i)
571 ntfs_warning(sb, "Invalid boot sector checksum."); 571 ntfs_warning(sb, "Invalid boot sector checksum.");
572 } 572 }
573 /* Check OEMidentifier is "NTFS " */ 573 /* Check OEMidentifier is "NTFS " */
574 if (b->oem_id != magicNTFS) 574 if (b->oem_id != magicNTFS)
575 goto not_ntfs; 575 goto not_ntfs;
576 /* Check bytes per sector value is between 256 and 4096. */ 576 /* Check bytes per sector value is between 256 and 4096. */
577 if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 || 577 if (le16_to_cpu(b->bpb.bytes_per_sector) < 0x100 ||
578 le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000) 578 le16_to_cpu(b->bpb.bytes_per_sector) > 0x1000)
579 goto not_ntfs; 579 goto not_ntfs;
580 /* Check sectors per cluster value is valid. */ 580 /* Check sectors per cluster value is valid. */
581 switch (b->bpb.sectors_per_cluster) { 581 switch (b->bpb.sectors_per_cluster) {
582 case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128: 582 case 1: case 2: case 4: case 8: case 16: case 32: case 64: case 128:
583 break; 583 break;
584 default: 584 default:
585 goto not_ntfs; 585 goto not_ntfs;
586 } 586 }
587 /* Check the cluster size is not above the maximum (64kiB). */ 587 /* Check the cluster size is not above the maximum (64kiB). */
588 if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) * 588 if ((u32)le16_to_cpu(b->bpb.bytes_per_sector) *
589 b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE) 589 b->bpb.sectors_per_cluster > NTFS_MAX_CLUSTER_SIZE)
590 goto not_ntfs; 590 goto not_ntfs;
591 /* Check reserved/unused fields are really zero. */ 591 /* Check reserved/unused fields are really zero. */
592 if (le16_to_cpu(b->bpb.reserved_sectors) || 592 if (le16_to_cpu(b->bpb.reserved_sectors) ||
593 le16_to_cpu(b->bpb.root_entries) || 593 le16_to_cpu(b->bpb.root_entries) ||
594 le16_to_cpu(b->bpb.sectors) || 594 le16_to_cpu(b->bpb.sectors) ||
595 le16_to_cpu(b->bpb.sectors_per_fat) || 595 le16_to_cpu(b->bpb.sectors_per_fat) ||
596 le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats) 596 le32_to_cpu(b->bpb.large_sectors) || b->bpb.fats)
597 goto not_ntfs; 597 goto not_ntfs;
598 /* Check clusters per file mft record value is valid. */ 598 /* Check clusters per file mft record value is valid. */
599 if ((u8)b->clusters_per_mft_record < 0xe1 || 599 if ((u8)b->clusters_per_mft_record < 0xe1 ||
600 (u8)b->clusters_per_mft_record > 0xf7) 600 (u8)b->clusters_per_mft_record > 0xf7)
601 switch (b->clusters_per_mft_record) { 601 switch (b->clusters_per_mft_record) {
602 case 1: case 2: case 4: case 8: case 16: case 32: case 64: 602 case 1: case 2: case 4: case 8: case 16: case 32: case 64:
603 break; 603 break;
604 default: 604 default:
605 goto not_ntfs; 605 goto not_ntfs;
606 } 606 }
607 /* Check clusters per index block value is valid. */ 607 /* Check clusters per index block value is valid. */
608 if ((u8)b->clusters_per_index_record < 0xe1 || 608 if ((u8)b->clusters_per_index_record < 0xe1 ||
609 (u8)b->clusters_per_index_record > 0xf7) 609 (u8)b->clusters_per_index_record > 0xf7)
610 switch (b->clusters_per_index_record) { 610 switch (b->clusters_per_index_record) {
611 case 1: case 2: case 4: case 8: case 16: case 32: case 64: 611 case 1: case 2: case 4: case 8: case 16: case 32: case 64:
612 break; 612 break;
613 default: 613 default:
614 goto not_ntfs; 614 goto not_ntfs;
615 } 615 }
616 /* 616 /*
617 * Check for valid end of sector marker. We will work without it, but 617 * Check for valid end of sector marker. We will work without it, but
618 * many BIOSes will refuse to boot from a bootsector if the magic is 618 * many BIOSes will refuse to boot from a bootsector if the magic is
619 * incorrect, so we emit a warning. 619 * incorrect, so we emit a warning.
620 */ 620 */
621 if (!silent && b->end_of_sector_marker != const_cpu_to_le16(0xaa55)) 621 if (!silent && b->end_of_sector_marker != const_cpu_to_le16(0xaa55))
622 ntfs_warning(sb, "Invalid end of sector marker."); 622 ntfs_warning(sb, "Invalid end of sector marker.");
623 return true; 623 return true;
624 not_ntfs: 624 not_ntfs:
625 return false; 625 return false;
626 } 626 }
627 627
628 /** 628 /**
629 * read_ntfs_boot_sector - read the NTFS boot sector of a device 629 * read_ntfs_boot_sector - read the NTFS boot sector of a device
630 * @sb: super block of device to read the boot sector from 630 * @sb: super block of device to read the boot sector from
631 * @silent: if true, suppress all output 631 * @silent: if true, suppress all output
632 * 632 *
633 * Reads the boot sector from the device and validates it. If that fails, tries 633 * Reads the boot sector from the device and validates it. If that fails, tries
634 * to read the backup boot sector, first from the end of the device a-la NT4 and 634 * to read the backup boot sector, first from the end of the device a-la NT4 and
635 * later and then from the middle of the device a-la NT3.51 and before. 635 * later and then from the middle of the device a-la NT3.51 and before.
636 * 636 *
637 * If a valid boot sector is found but it is not the primary boot sector, we 637 * If a valid boot sector is found but it is not the primary boot sector, we
638 * repair the primary boot sector silently (unless the device is read-only or 638 * repair the primary boot sector silently (unless the device is read-only or
639 * the primary boot sector is not accessible). 639 * the primary boot sector is not accessible).
640 * 640 *
641 * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super 641 * NOTE: To call this function, @sb must have the fields s_dev, the ntfs super
642 * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized 642 * block (u.ntfs_sb), nr_blocks and the device flags (s_flags) initialized
643 * to their respective values. 643 * to their respective values.
644 * 644 *
645 * Return the unlocked buffer head containing the boot sector or NULL on error. 645 * Return the unlocked buffer head containing the boot sector or NULL on error.
646 */ 646 */
647 static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb, 647 static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
648 const int silent) 648 const int silent)
649 { 649 {
650 const char *read_err_str = "Unable to read %s boot sector."; 650 const char *read_err_str = "Unable to read %s boot sector.";
651 struct buffer_head *bh_primary, *bh_backup; 651 struct buffer_head *bh_primary, *bh_backup;
652 sector_t nr_blocks = NTFS_SB(sb)->nr_blocks; 652 sector_t nr_blocks = NTFS_SB(sb)->nr_blocks;
653 653
654 /* Try to read primary boot sector. */ 654 /* Try to read primary boot sector. */
655 if ((bh_primary = sb_bread(sb, 0))) { 655 if ((bh_primary = sb_bread(sb, 0))) {
656 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) 656 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
657 bh_primary->b_data, silent)) 657 bh_primary->b_data, silent))
658 return bh_primary; 658 return bh_primary;
659 if (!silent) 659 if (!silent)
660 ntfs_error(sb, "Primary boot sector is invalid."); 660 ntfs_error(sb, "Primary boot sector is invalid.");
661 } else if (!silent) 661 } else if (!silent)
662 ntfs_error(sb, read_err_str, "primary"); 662 ntfs_error(sb, read_err_str, "primary");
663 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) { 663 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
664 if (bh_primary) 664 if (bh_primary)
665 brelse(bh_primary); 665 brelse(bh_primary);
666 if (!silent) 666 if (!silent)
667 ntfs_error(sb, "Mount option errors=recover not used. " 667 ntfs_error(sb, "Mount option errors=recover not used. "
668 "Aborting without trying to recover."); 668 "Aborting without trying to recover.");
669 return NULL; 669 return NULL;
670 } 670 }
671 /* Try to read NT4+ backup boot sector. */ 671 /* Try to read NT4+ backup boot sector. */
672 if ((bh_backup = sb_bread(sb, nr_blocks - 1))) { 672 if ((bh_backup = sb_bread(sb, nr_blocks - 1))) {
673 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) 673 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
674 bh_backup->b_data, silent)) 674 bh_backup->b_data, silent))
675 goto hotfix_primary_boot_sector; 675 goto hotfix_primary_boot_sector;
676 brelse(bh_backup); 676 brelse(bh_backup);
677 } else if (!silent) 677 } else if (!silent)
678 ntfs_error(sb, read_err_str, "backup"); 678 ntfs_error(sb, read_err_str, "backup");
679 /* Try to read NT3.51- backup boot sector. */ 679 /* Try to read NT3.51- backup boot sector. */
680 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) { 680 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
681 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*) 681 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
682 bh_backup->b_data, silent)) 682 bh_backup->b_data, silent))
683 goto hotfix_primary_boot_sector; 683 goto hotfix_primary_boot_sector;
684 if (!silent) 684 if (!silent)
685 ntfs_error(sb, "Could not find a valid backup boot " 685 ntfs_error(sb, "Could not find a valid backup boot "
686 "sector."); 686 "sector.");
687 brelse(bh_backup); 687 brelse(bh_backup);
688 } else if (!silent) 688 } else if (!silent)
689 ntfs_error(sb, read_err_str, "backup"); 689 ntfs_error(sb, read_err_str, "backup");
690 /* We failed. Cleanup and return. */ 690 /* We failed. Cleanup and return. */
691 if (bh_primary) 691 if (bh_primary)
692 brelse(bh_primary); 692 brelse(bh_primary);
693 return NULL; 693 return NULL;
694 hotfix_primary_boot_sector: 694 hotfix_primary_boot_sector:
695 if (bh_primary) { 695 if (bh_primary) {
696 /* 696 /*
697 * If we managed to read sector zero and the volume is not 697 * If we managed to read sector zero and the volume is not
698 * read-only, copy the found, valid backup boot sector to the 698 * read-only, copy the found, valid backup boot sector to the
699 * primary boot sector. Note we only copy the actual boot 699 * primary boot sector. Note we only copy the actual boot
700 * sector structure, not the actual whole device sector as that 700 * sector structure, not the actual whole device sector as that
701 * may be bigger and would potentially damage the $Boot system 701 * may be bigger and would potentially damage the $Boot system
702 * file (FIXME: Would be nice to know if the backup boot sector 702 * file (FIXME: Would be nice to know if the backup boot sector
703 * on a large sector device contains the whole boot loader or 703 * on a large sector device contains the whole boot loader or
704 * just the first 512 bytes). 704 * just the first 512 bytes).
705 */ 705 */
706 if (!(sb->s_flags & MS_RDONLY)) { 706 if (!(sb->s_flags & MS_RDONLY)) {
707 ntfs_warning(sb, "Hot-fix: Recovering invalid primary " 707 ntfs_warning(sb, "Hot-fix: Recovering invalid primary "
708 "boot sector from backup copy."); 708 "boot sector from backup copy.");
709 memcpy(bh_primary->b_data, bh_backup->b_data, 709 memcpy(bh_primary->b_data, bh_backup->b_data,
710 NTFS_BLOCK_SIZE); 710 NTFS_BLOCK_SIZE);
711 mark_buffer_dirty(bh_primary); 711 mark_buffer_dirty(bh_primary);
712 sync_dirty_buffer(bh_primary); 712 sync_dirty_buffer(bh_primary);
713 if (buffer_uptodate(bh_primary)) { 713 if (buffer_uptodate(bh_primary)) {
714 brelse(bh_backup); 714 brelse(bh_backup);
715 return bh_primary; 715 return bh_primary;
716 } 716 }
717 ntfs_error(sb, "Hot-fix: Device write error while " 717 ntfs_error(sb, "Hot-fix: Device write error while "
718 "recovering primary boot sector."); 718 "recovering primary boot sector.");
719 } else { 719 } else {
720 ntfs_warning(sb, "Hot-fix: Recovery of primary boot " 720 ntfs_warning(sb, "Hot-fix: Recovery of primary boot "
721 "sector failed: Read-only mount."); 721 "sector failed: Read-only mount.");
722 } 722 }
723 brelse(bh_primary); 723 brelse(bh_primary);
724 } 724 }
725 ntfs_warning(sb, "Using backup boot sector."); 725 ntfs_warning(sb, "Using backup boot sector.");
726 return bh_backup; 726 return bh_backup;
727 } 727 }
728 728
729 /** 729 /**
730 * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol 730 * parse_ntfs_boot_sector - parse the boot sector and store the data in @vol
731 * @vol: volume structure to initialise with data from boot sector 731 * @vol: volume structure to initialise with data from boot sector
732 * @b: boot sector to parse 732 * @b: boot sector to parse
733 * 733 *
734 * Parse the ntfs boot sector @b and store all imporant information therein in 734 * Parse the ntfs boot sector @b and store all imporant information therein in
735 * the ntfs super block @vol. Return 'true' on success and 'false' on error. 735 * the ntfs super block @vol. Return 'true' on success and 'false' on error.
736 */ 736 */
737 static bool parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b) 737 static bool parse_ntfs_boot_sector(ntfs_volume *vol, const NTFS_BOOT_SECTOR *b)
738 { 738 {
739 unsigned int sectors_per_cluster_bits, nr_hidden_sects; 739 unsigned int sectors_per_cluster_bits, nr_hidden_sects;
740 int clusters_per_mft_record, clusters_per_index_record; 740 int clusters_per_mft_record, clusters_per_index_record;
741 s64 ll; 741 s64 ll;
742 742
743 vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector); 743 vol->sector_size = le16_to_cpu(b->bpb.bytes_per_sector);
744 vol->sector_size_bits = ffs(vol->sector_size) - 1; 744 vol->sector_size_bits = ffs(vol->sector_size) - 1;
745 ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size, 745 ntfs_debug("vol->sector_size = %i (0x%x)", vol->sector_size,
746 vol->sector_size); 746 vol->sector_size);
747 ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits, 747 ntfs_debug("vol->sector_size_bits = %i (0x%x)", vol->sector_size_bits,
748 vol->sector_size_bits); 748 vol->sector_size_bits);
749 if (vol->sector_size < vol->sb->s_blocksize) { 749 if (vol->sector_size < vol->sb->s_blocksize) {
750 ntfs_error(vol->sb, "Sector size (%i) is smaller than the " 750 ntfs_error(vol->sb, "Sector size (%i) is smaller than the "
751 "device block size (%lu). This is not " 751 "device block size (%lu). This is not "
752 "supported. Sorry.", vol->sector_size, 752 "supported. Sorry.", vol->sector_size,
753 vol->sb->s_blocksize); 753 vol->sb->s_blocksize);
754 return false; 754 return false;
755 } 755 }
756 ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster); 756 ntfs_debug("sectors_per_cluster = 0x%x", b->bpb.sectors_per_cluster);
757 sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1; 757 sectors_per_cluster_bits = ffs(b->bpb.sectors_per_cluster) - 1;
758 ntfs_debug("sectors_per_cluster_bits = 0x%x", 758 ntfs_debug("sectors_per_cluster_bits = 0x%x",
759 sectors_per_cluster_bits); 759 sectors_per_cluster_bits);
760 nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors); 760 nr_hidden_sects = le32_to_cpu(b->bpb.hidden_sectors);
761 ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects); 761 ntfs_debug("number of hidden sectors = 0x%x", nr_hidden_sects);
762 vol->cluster_size = vol->sector_size << sectors_per_cluster_bits; 762 vol->cluster_size = vol->sector_size << sectors_per_cluster_bits;
763 vol->cluster_size_mask = vol->cluster_size - 1; 763 vol->cluster_size_mask = vol->cluster_size - 1;
764 vol->cluster_size_bits = ffs(vol->cluster_size) - 1; 764 vol->cluster_size_bits = ffs(vol->cluster_size) - 1;
765 ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size, 765 ntfs_debug("vol->cluster_size = %i (0x%x)", vol->cluster_size,
766 vol->cluster_size); 766 vol->cluster_size);
767 ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask); 767 ntfs_debug("vol->cluster_size_mask = 0x%x", vol->cluster_size_mask);
768 ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits); 768 ntfs_debug("vol->cluster_size_bits = %i", vol->cluster_size_bits);
769 if (vol->cluster_size < vol->sector_size) { 769 if (vol->cluster_size < vol->sector_size) {
770 ntfs_error(vol->sb, "Cluster size (%i) is smaller than the " 770 ntfs_error(vol->sb, "Cluster size (%i) is smaller than the "
771 "sector size (%i). This is not supported. " 771 "sector size (%i). This is not supported. "
772 "Sorry.", vol->cluster_size, vol->sector_size); 772 "Sorry.", vol->cluster_size, vol->sector_size);
773 return false; 773 return false;
774 } 774 }
775 clusters_per_mft_record = b->clusters_per_mft_record; 775 clusters_per_mft_record = b->clusters_per_mft_record;
776 ntfs_debug("clusters_per_mft_record = %i (0x%x)", 776 ntfs_debug("clusters_per_mft_record = %i (0x%x)",
777 clusters_per_mft_record, clusters_per_mft_record); 777 clusters_per_mft_record, clusters_per_mft_record);
778 if (clusters_per_mft_record > 0) 778 if (clusters_per_mft_record > 0)
779 vol->mft_record_size = vol->cluster_size << 779 vol->mft_record_size = vol->cluster_size <<
780 (ffs(clusters_per_mft_record) - 1); 780 (ffs(clusters_per_mft_record) - 1);
781 else 781 else
782 /* 782 /*
783 * When mft_record_size < cluster_size, clusters_per_mft_record 783 * When mft_record_size < cluster_size, clusters_per_mft_record
784 * = -log2(mft_record_size) bytes. mft_record_size normaly is 784 * = -log2(mft_record_size) bytes. mft_record_size normaly is
785 * 1024 bytes, which is encoded as 0xF6 (-10 in decimal). 785 * 1024 bytes, which is encoded as 0xF6 (-10 in decimal).
786 */ 786 */
787 vol->mft_record_size = 1 << -clusters_per_mft_record; 787 vol->mft_record_size = 1 << -clusters_per_mft_record;
788 vol->mft_record_size_mask = vol->mft_record_size - 1; 788 vol->mft_record_size_mask = vol->mft_record_size - 1;
789 vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1; 789 vol->mft_record_size_bits = ffs(vol->mft_record_size) - 1;
790 ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size, 790 ntfs_debug("vol->mft_record_size = %i (0x%x)", vol->mft_record_size,
791 vol->mft_record_size); 791 vol->mft_record_size);
792 ntfs_debug("vol->mft_record_size_mask = 0x%x", 792 ntfs_debug("vol->mft_record_size_mask = 0x%x",
793 vol->mft_record_size_mask); 793 vol->mft_record_size_mask);
794 ntfs_debug("vol->mft_record_size_bits = %i (0x%x)", 794 ntfs_debug("vol->mft_record_size_bits = %i (0x%x)",
795 vol->mft_record_size_bits, vol->mft_record_size_bits); 795 vol->mft_record_size_bits, vol->mft_record_size_bits);
796 /* 796 /*
797 * We cannot support mft record sizes above the PAGE_CACHE_SIZE since 797 * We cannot support mft record sizes above the PAGE_CACHE_SIZE since
798 * we store $MFT/$DATA, the table of mft records in the page cache. 798 * we store $MFT/$DATA, the table of mft records in the page cache.
799 */ 799 */
800 if (vol->mft_record_size > PAGE_CACHE_SIZE) { 800 if (vol->mft_record_size > PAGE_CACHE_SIZE) {
801 ntfs_error(vol->sb, "Mft record size (%i) exceeds the " 801 ntfs_error(vol->sb, "Mft record size (%i) exceeds the "
802 "PAGE_CACHE_SIZE on your system (%lu). " 802 "PAGE_CACHE_SIZE on your system (%lu). "
803 "This is not supported. Sorry.", 803 "This is not supported. Sorry.",
804 vol->mft_record_size, PAGE_CACHE_SIZE); 804 vol->mft_record_size, PAGE_CACHE_SIZE);
805 return false; 805 return false;
806 } 806 }
807 /* We cannot support mft record sizes below the sector size. */ 807 /* We cannot support mft record sizes below the sector size. */
808 if (vol->mft_record_size < vol->sector_size) { 808 if (vol->mft_record_size < vol->sector_size) {
809 ntfs_error(vol->sb, "Mft record size (%i) is smaller than the " 809 ntfs_error(vol->sb, "Mft record size (%i) is smaller than the "
810 "sector size (%i). This is not supported. " 810 "sector size (%i). This is not supported. "
811 "Sorry.", vol->mft_record_size, 811 "Sorry.", vol->mft_record_size,
812 vol->sector_size); 812 vol->sector_size);
813 return false; 813 return false;
814 } 814 }
815 clusters_per_index_record = b->clusters_per_index_record; 815 clusters_per_index_record = b->clusters_per_index_record;
816 ntfs_debug("clusters_per_index_record = %i (0x%x)", 816 ntfs_debug("clusters_per_index_record = %i (0x%x)",
817 clusters_per_index_record, clusters_per_index_record); 817 clusters_per_index_record, clusters_per_index_record);
818 if (clusters_per_index_record > 0) 818 if (clusters_per_index_record > 0)
819 vol->index_record_size = vol->cluster_size << 819 vol->index_record_size = vol->cluster_size <<
820 (ffs(clusters_per_index_record) - 1); 820 (ffs(clusters_per_index_record) - 1);
821 else 821 else
822 /* 822 /*
823 * When index_record_size < cluster_size, 823 * When index_record_size < cluster_size,
824 * clusters_per_index_record = -log2(index_record_size) bytes. 824 * clusters_per_index_record = -log2(index_record_size) bytes.
825 * index_record_size normaly equals 4096 bytes, which is 825 * index_record_size normaly equals 4096 bytes, which is
826 * encoded as 0xF4 (-12 in decimal). 826 * encoded as 0xF4 (-12 in decimal).
827 */ 827 */
828 vol->index_record_size = 1 << -clusters_per_index_record; 828 vol->index_record_size = 1 << -clusters_per_index_record;
829 vol->index_record_size_mask = vol->index_record_size - 1; 829 vol->index_record_size_mask = vol->index_record_size - 1;
830 vol->index_record_size_bits = ffs(vol->index_record_size) - 1; 830 vol->index_record_size_bits = ffs(vol->index_record_size) - 1;
831 ntfs_debug("vol->index_record_size = %i (0x%x)", 831 ntfs_debug("vol->index_record_size = %i (0x%x)",
832 vol->index_record_size, vol->index_record_size); 832 vol->index_record_size, vol->index_record_size);
833 ntfs_debug("vol->index_record_size_mask = 0x%x", 833 ntfs_debug("vol->index_record_size_mask = 0x%x",
834 vol->index_record_size_mask); 834 vol->index_record_size_mask);
835 ntfs_debug("vol->index_record_size_bits = %i (0x%x)", 835 ntfs_debug("vol->index_record_size_bits = %i (0x%x)",
836 vol->index_record_size_bits, 836 vol->index_record_size_bits,
837 vol->index_record_size_bits); 837 vol->index_record_size_bits);
838 /* We cannot support index record sizes below the sector size. */ 838 /* We cannot support index record sizes below the sector size. */
839 if (vol->index_record_size < vol->sector_size) { 839 if (vol->index_record_size < vol->sector_size) {
840 ntfs_error(vol->sb, "Index record size (%i) is smaller than " 840 ntfs_error(vol->sb, "Index record size (%i) is smaller than "
841 "the sector size (%i). This is not " 841 "the sector size (%i). This is not "
842 "supported. Sorry.", vol->index_record_size, 842 "supported. Sorry.", vol->index_record_size,
843 vol->sector_size); 843 vol->sector_size);
844 return false; 844 return false;
845 } 845 }
846 /* 846 /*
847 * Get the size of the volume in clusters and check for 64-bit-ness. 847 * Get the size of the volume in clusters and check for 64-bit-ness.
848 * Windows currently only uses 32 bits to save the clusters so we do 848 * Windows currently only uses 32 bits to save the clusters so we do
849 * the same as it is much faster on 32-bit CPUs. 849 * the same as it is much faster on 32-bit CPUs.
850 */ 850 */
851 ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits; 851 ll = sle64_to_cpu(b->number_of_sectors) >> sectors_per_cluster_bits;
852 if ((u64)ll >= 1ULL << 32) { 852 if ((u64)ll >= 1ULL << 32) {
853 ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry."); 853 ntfs_error(vol->sb, "Cannot handle 64-bit clusters. Sorry.");
854 return false; 854 return false;
855 } 855 }
856 vol->nr_clusters = ll; 856 vol->nr_clusters = ll;
857 ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters); 857 ntfs_debug("vol->nr_clusters = 0x%llx", (long long)vol->nr_clusters);
858 /* 858 /*
859 * On an architecture where unsigned long is 32-bits, we restrict the 859 * On an architecture where unsigned long is 32-bits, we restrict the
860 * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler 860 * volume size to 2TiB (2^41). On a 64-bit architecture, the compiler
861 * will hopefully optimize the whole check away. 861 * will hopefully optimize the whole check away.
862 */ 862 */
863 if (sizeof(unsigned long) < 8) { 863 if (sizeof(unsigned long) < 8) {
864 if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) { 864 if ((ll << vol->cluster_size_bits) >= (1ULL << 41)) {
865 ntfs_error(vol->sb, "Volume size (%lluTiB) is too " 865 ntfs_error(vol->sb, "Volume size (%lluTiB) is too "
866 "large for this architecture. " 866 "large for this architecture. "
867 "Maximum supported is 2TiB. Sorry.", 867 "Maximum supported is 2TiB. Sorry.",
868 (unsigned long long)ll >> (40 - 868 (unsigned long long)ll >> (40 -
869 vol->cluster_size_bits)); 869 vol->cluster_size_bits));
870 return false; 870 return false;
871 } 871 }
872 } 872 }
873 ll = sle64_to_cpu(b->mft_lcn); 873 ll = sle64_to_cpu(b->mft_lcn);
874 if (ll >= vol->nr_clusters) { 874 if (ll >= vol->nr_clusters) {
875 ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of " 875 ntfs_error(vol->sb, "MFT LCN (%lli, 0x%llx) is beyond end of "
876 "volume. Weird.", (unsigned long long)ll, 876 "volume. Weird.", (unsigned long long)ll,
877 (unsigned long long)ll); 877 (unsigned long long)ll);
878 return false; 878 return false;
879 } 879 }
880 vol->mft_lcn = ll; 880 vol->mft_lcn = ll;
881 ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn); 881 ntfs_debug("vol->mft_lcn = 0x%llx", (long long)vol->mft_lcn);
882 ll = sle64_to_cpu(b->mftmirr_lcn); 882 ll = sle64_to_cpu(b->mftmirr_lcn);
883 if (ll >= vol->nr_clusters) { 883 if (ll >= vol->nr_clusters) {
884 ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end " 884 ntfs_error(vol->sb, "MFTMirr LCN (%lli, 0x%llx) is beyond end "
885 "of volume. Weird.", (unsigned long long)ll, 885 "of volume. Weird.", (unsigned long long)ll,
886 (unsigned long long)ll); 886 (unsigned long long)ll);
887 return false; 887 return false;
888 } 888 }
889 vol->mftmirr_lcn = ll; 889 vol->mftmirr_lcn = ll;
890 ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn); 890 ntfs_debug("vol->mftmirr_lcn = 0x%llx", (long long)vol->mftmirr_lcn);
891 #ifdef NTFS_RW 891 #ifdef NTFS_RW
892 /* 892 /*
893 * Work out the size of the mft mirror in number of mft records. If the 893 * Work out the size of the mft mirror in number of mft records. If the
894 * cluster size is less than or equal to the size taken by four mft 894 * cluster size is less than or equal to the size taken by four mft
895 * records, the mft mirror stores the first four mft records. If the 895 * records, the mft mirror stores the first four mft records. If the
896 * cluster size is bigger than the size taken by four mft records, the 896 * cluster size is bigger than the size taken by four mft records, the
897 * mft mirror contains as many mft records as will fit into one 897 * mft mirror contains as many mft records as will fit into one
898 * cluster. 898 * cluster.
899 */ 899 */
900 if (vol->cluster_size <= (4 << vol->mft_record_size_bits)) 900 if (vol->cluster_size <= (4 << vol->mft_record_size_bits))
901 vol->mftmirr_size = 4; 901 vol->mftmirr_size = 4;
902 else 902 else
903 vol->mftmirr_size = vol->cluster_size >> 903 vol->mftmirr_size = vol->cluster_size >>
904 vol->mft_record_size_bits; 904 vol->mft_record_size_bits;
905 ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size); 905 ntfs_debug("vol->mftmirr_size = %i", vol->mftmirr_size);
906 #endif /* NTFS_RW */ 906 #endif /* NTFS_RW */
907 vol->serial_no = le64_to_cpu(b->volume_serial_number); 907 vol->serial_no = le64_to_cpu(b->volume_serial_number);
908 ntfs_debug("vol->serial_no = 0x%llx", 908 ntfs_debug("vol->serial_no = 0x%llx",
909 (unsigned long long)vol->serial_no); 909 (unsigned long long)vol->serial_no);
910 return true; 910 return true;
911 } 911 }
912 912
913 /** 913 /**
914 * ntfs_setup_allocators - initialize the cluster and mft allocators 914 * ntfs_setup_allocators - initialize the cluster and mft allocators
915 * @vol: volume structure for which to setup the allocators 915 * @vol: volume structure for which to setup the allocators
916 * 916 *
917 * Setup the cluster (lcn) and mft allocators to the starting values. 917 * Setup the cluster (lcn) and mft allocators to the starting values.
918 */ 918 */
919 static void ntfs_setup_allocators(ntfs_volume *vol) 919 static void ntfs_setup_allocators(ntfs_volume *vol)
920 { 920 {
921 #ifdef NTFS_RW 921 #ifdef NTFS_RW
922 LCN mft_zone_size, mft_lcn; 922 LCN mft_zone_size, mft_lcn;
923 #endif /* NTFS_RW */ 923 #endif /* NTFS_RW */
924 924
925 ntfs_debug("vol->mft_zone_multiplier = 0x%x", 925 ntfs_debug("vol->mft_zone_multiplier = 0x%x",
926 vol->mft_zone_multiplier); 926 vol->mft_zone_multiplier);
927 #ifdef NTFS_RW 927 #ifdef NTFS_RW
928 /* Determine the size of the MFT zone. */ 928 /* Determine the size of the MFT zone. */
929 mft_zone_size = vol->nr_clusters; 929 mft_zone_size = vol->nr_clusters;
930 switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */ 930 switch (vol->mft_zone_multiplier) { /* % of volume size in clusters */
931 case 4: 931 case 4:
932 mft_zone_size >>= 1; /* 50% */ 932 mft_zone_size >>= 1; /* 50% */
933 break; 933 break;
934 case 3: 934 case 3:
935 mft_zone_size = (mft_zone_size + 935 mft_zone_size = (mft_zone_size +
936 (mft_zone_size >> 1)) >> 2; /* 37.5% */ 936 (mft_zone_size >> 1)) >> 2; /* 37.5% */
937 break; 937 break;
938 case 2: 938 case 2:
939 mft_zone_size >>= 2; /* 25% */ 939 mft_zone_size >>= 2; /* 25% */
940 break; 940 break;
941 /* case 1: */ 941 /* case 1: */
942 default: 942 default:
943 mft_zone_size >>= 3; /* 12.5% */ 943 mft_zone_size >>= 3; /* 12.5% */
944 break; 944 break;
945 } 945 }
946 /* Setup the mft zone. */ 946 /* Setup the mft zone. */
947 vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn; 947 vol->mft_zone_start = vol->mft_zone_pos = vol->mft_lcn;
948 ntfs_debug("vol->mft_zone_pos = 0x%llx", 948 ntfs_debug("vol->mft_zone_pos = 0x%llx",
949 (unsigned long long)vol->mft_zone_pos); 949 (unsigned long long)vol->mft_zone_pos);
950 /* 950 /*
951 * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs 951 * Calculate the mft_lcn for an unmodified NTFS volume (see mkntfs
952 * source) and if the actual mft_lcn is in the expected place or even 952 * source) and if the actual mft_lcn is in the expected place or even
953 * further to the front of the volume, extend the mft_zone to cover the 953 * further to the front of the volume, extend the mft_zone to cover the
954 * beginning of the volume as well. This is in order to protect the 954 * beginning of the volume as well. This is in order to protect the
955 * area reserved for the mft bitmap as well within the mft_zone itself. 955 * area reserved for the mft bitmap as well within the mft_zone itself.
956 * On non-standard volumes we do not protect it as the overhead would 956 * On non-standard volumes we do not protect it as the overhead would
957 * be higher than the speed increase we would get by doing it. 957 * be higher than the speed increase we would get by doing it.
958 */ 958 */
959 mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size; 959 mft_lcn = (8192 + 2 * vol->cluster_size - 1) / vol->cluster_size;
960 if (mft_lcn * vol->cluster_size < 16 * 1024) 960 if (mft_lcn * vol->cluster_size < 16 * 1024)
961 mft_lcn = (16 * 1024 + vol->cluster_size - 1) / 961 mft_lcn = (16 * 1024 + vol->cluster_size - 1) /
962 vol->cluster_size; 962 vol->cluster_size;
963 if (vol->mft_zone_start <= mft_lcn) 963 if (vol->mft_zone_start <= mft_lcn)
964 vol->mft_zone_start = 0; 964 vol->mft_zone_start = 0;
965 ntfs_debug("vol->mft_zone_start = 0x%llx", 965 ntfs_debug("vol->mft_zone_start = 0x%llx",
966 (unsigned long long)vol->mft_zone_start); 966 (unsigned long long)vol->mft_zone_start);
967 /* 967 /*
968 * Need to cap the mft zone on non-standard volumes so that it does 968 * Need to cap the mft zone on non-standard volumes so that it does
969 * not point outside the boundaries of the volume. We do this by 969 * not point outside the boundaries of the volume. We do this by
970 * halving the zone size until we are inside the volume. 970 * halving the zone size until we are inside the volume.
971 */ 971 */
972 vol->mft_zone_end = vol->mft_lcn + mft_zone_size; 972 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
973 while (vol->mft_zone_end >= vol->nr_clusters) { 973 while (vol->mft_zone_end >= vol->nr_clusters) {
974 mft_zone_size >>= 1; 974 mft_zone_size >>= 1;
975 vol->mft_zone_end = vol->mft_lcn + mft_zone_size; 975 vol->mft_zone_end = vol->mft_lcn + mft_zone_size;
976 } 976 }
977 ntfs_debug("vol->mft_zone_end = 0x%llx", 977 ntfs_debug("vol->mft_zone_end = 0x%llx",
978 (unsigned long long)vol->mft_zone_end); 978 (unsigned long long)vol->mft_zone_end);
979 /* 979 /*
980 * Set the current position within each data zone to the start of the 980 * Set the current position within each data zone to the start of the
981 * respective zone. 981 * respective zone.
982 */ 982 */
983 vol->data1_zone_pos = vol->mft_zone_end; 983 vol->data1_zone_pos = vol->mft_zone_end;
984 ntfs_debug("vol->data1_zone_pos = 0x%llx", 984 ntfs_debug("vol->data1_zone_pos = 0x%llx",
985 (unsigned long long)vol->data1_zone_pos); 985 (unsigned long long)vol->data1_zone_pos);
986 vol->data2_zone_pos = 0; 986 vol->data2_zone_pos = 0;
987 ntfs_debug("vol->data2_zone_pos = 0x%llx", 987 ntfs_debug("vol->data2_zone_pos = 0x%llx",
988 (unsigned long long)vol->data2_zone_pos); 988 (unsigned long long)vol->data2_zone_pos);
989 989
990 /* Set the mft data allocation position to mft record 24. */ 990 /* Set the mft data allocation position to mft record 24. */
991 vol->mft_data_pos = 24; 991 vol->mft_data_pos = 24;
992 ntfs_debug("vol->mft_data_pos = 0x%llx", 992 ntfs_debug("vol->mft_data_pos = 0x%llx",
993 (unsigned long long)vol->mft_data_pos); 993 (unsigned long long)vol->mft_data_pos);
994 #endif /* NTFS_RW */ 994 #endif /* NTFS_RW */
995 } 995 }
996 996
997 #ifdef NTFS_RW 997 #ifdef NTFS_RW
998 998
999 /** 999 /**
1000 * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume 1000 * load_and_init_mft_mirror - load and setup the mft mirror inode for a volume
1001 * @vol: ntfs super block describing device whose mft mirror to load 1001 * @vol: ntfs super block describing device whose mft mirror to load
1002 * 1002 *
1003 * Return 'true' on success or 'false' on error. 1003 * Return 'true' on success or 'false' on error.
1004 */ 1004 */
1005 static bool load_and_init_mft_mirror(ntfs_volume *vol) 1005 static bool load_and_init_mft_mirror(ntfs_volume *vol)
1006 { 1006 {
1007 struct inode *tmp_ino; 1007 struct inode *tmp_ino;
1008 ntfs_inode *tmp_ni; 1008 ntfs_inode *tmp_ni;
1009 1009
1010 ntfs_debug("Entering."); 1010 ntfs_debug("Entering.");
1011 /* Get mft mirror inode. */ 1011 /* Get mft mirror inode. */
1012 tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr); 1012 tmp_ino = ntfs_iget(vol->sb, FILE_MFTMirr);
1013 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { 1013 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
1014 if (!IS_ERR(tmp_ino)) 1014 if (!IS_ERR(tmp_ino))
1015 iput(tmp_ino); 1015 iput(tmp_ino);
1016 /* Caller will display error message. */ 1016 /* Caller will display error message. */
1017 return false; 1017 return false;
1018 } 1018 }
1019 /* 1019 /*
1020 * Re-initialize some specifics about $MFTMirr's inode as 1020 * Re-initialize some specifics about $MFTMirr's inode as
1021 * ntfs_read_inode() will have set up the default ones. 1021 * ntfs_read_inode() will have set up the default ones.
1022 */ 1022 */
1023 /* Set uid and gid to root. */ 1023 /* Set uid and gid to root. */
1024 tmp_ino->i_uid = tmp_ino->i_gid = 0; 1024 tmp_ino->i_uid = tmp_ino->i_gid = 0;
1025 /* Regular file. No access for anyone. */ 1025 /* Regular file. No access for anyone. */
1026 tmp_ino->i_mode = S_IFREG; 1026 tmp_ino->i_mode = S_IFREG;
1027 /* No VFS initiated operations allowed for $MFTMirr. */ 1027 /* No VFS initiated operations allowed for $MFTMirr. */
1028 tmp_ino->i_op = &ntfs_empty_inode_ops; 1028 tmp_ino->i_op = &ntfs_empty_inode_ops;
1029 tmp_ino->i_fop = &ntfs_empty_file_ops; 1029 tmp_ino->i_fop = &ntfs_empty_file_ops;
1030 /* Put in our special address space operations. */ 1030 /* Put in our special address space operations. */
1031 tmp_ino->i_mapping->a_ops = &ntfs_mst_aops; 1031 tmp_ino->i_mapping->a_ops = &ntfs_mst_aops;
1032 tmp_ni = NTFS_I(tmp_ino); 1032 tmp_ni = NTFS_I(tmp_ino);
1033 /* The $MFTMirr, like the $MFT is multi sector transfer protected. */ 1033 /* The $MFTMirr, like the $MFT is multi sector transfer protected. */
1034 NInoSetMstProtected(tmp_ni); 1034 NInoSetMstProtected(tmp_ni);
1035 NInoSetSparseDisabled(tmp_ni); 1035 NInoSetSparseDisabled(tmp_ni);
1036 /* 1036 /*
1037 * Set up our little cheat allowing us to reuse the async read io 1037 * Set up our little cheat allowing us to reuse the async read io
1038 * completion handler for directories. 1038 * completion handler for directories.
1039 */ 1039 */
1040 tmp_ni->itype.index.block_size = vol->mft_record_size; 1040 tmp_ni->itype.index.block_size = vol->mft_record_size;
1041 tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits; 1041 tmp_ni->itype.index.block_size_bits = vol->mft_record_size_bits;
1042 vol->mftmirr_ino = tmp_ino; 1042 vol->mftmirr_ino = tmp_ino;
1043 ntfs_debug("Done."); 1043 ntfs_debug("Done.");
1044 return true; 1044 return true;
1045 } 1045 }
1046 1046
1047 /** 1047 /**
1048 * check_mft_mirror - compare contents of the mft mirror with the mft 1048 * check_mft_mirror - compare contents of the mft mirror with the mft
1049 * @vol: ntfs super block describing device whose mft mirror to check 1049 * @vol: ntfs super block describing device whose mft mirror to check
1050 * 1050 *
1051 * Return 'true' on success or 'false' on error. 1051 * Return 'true' on success or 'false' on error.
1052 * 1052 *
1053 * Note, this function also results in the mft mirror runlist being completely 1053 * Note, this function also results in the mft mirror runlist being completely
1054 * mapped into memory. The mft mirror write code requires this and will BUG() 1054 * mapped into memory. The mft mirror write code requires this and will BUG()
1055 * should it find an unmapped runlist element. 1055 * should it find an unmapped runlist element.
1056 */ 1056 */
1057 static bool check_mft_mirror(ntfs_volume *vol) 1057 static bool check_mft_mirror(ntfs_volume *vol)
1058 { 1058 {
1059 struct super_block *sb = vol->sb; 1059 struct super_block *sb = vol->sb;
1060 ntfs_inode *mirr_ni; 1060 ntfs_inode *mirr_ni;
1061 struct page *mft_page, *mirr_page; 1061 struct page *mft_page, *mirr_page;
1062 u8 *kmft, *kmirr; 1062 u8 *kmft, *kmirr;
1063 runlist_element *rl, rl2[2]; 1063 runlist_element *rl, rl2[2];
1064 pgoff_t index; 1064 pgoff_t index;
1065 int mrecs_per_page, i; 1065 int mrecs_per_page, i;
1066 1066
1067 ntfs_debug("Entering."); 1067 ntfs_debug("Entering.");
1068 /* Compare contents of $MFT and $MFTMirr. */ 1068 /* Compare contents of $MFT and $MFTMirr. */
1069 mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size; 1069 mrecs_per_page = PAGE_CACHE_SIZE / vol->mft_record_size;
1070 BUG_ON(!mrecs_per_page); 1070 BUG_ON(!mrecs_per_page);
1071 BUG_ON(!vol->mftmirr_size); 1071 BUG_ON(!vol->mftmirr_size);
1072 mft_page = mirr_page = NULL; 1072 mft_page = mirr_page = NULL;
1073 kmft = kmirr = NULL; 1073 kmft = kmirr = NULL;
1074 index = i = 0; 1074 index = i = 0;
1075 do { 1075 do {
1076 u32 bytes; 1076 u32 bytes;
1077 1077
1078 /* Switch pages if necessary. */ 1078 /* Switch pages if necessary. */
1079 if (!(i % mrecs_per_page)) { 1079 if (!(i % mrecs_per_page)) {
1080 if (index) { 1080 if (index) {
1081 ntfs_unmap_page(mft_page); 1081 ntfs_unmap_page(mft_page);
1082 ntfs_unmap_page(mirr_page); 1082 ntfs_unmap_page(mirr_page);
1083 } 1083 }
1084 /* Get the $MFT page. */ 1084 /* Get the $MFT page. */
1085 mft_page = ntfs_map_page(vol->mft_ino->i_mapping, 1085 mft_page = ntfs_map_page(vol->mft_ino->i_mapping,
1086 index); 1086 index);
1087 if (IS_ERR(mft_page)) { 1087 if (IS_ERR(mft_page)) {
1088 ntfs_error(sb, "Failed to read $MFT."); 1088 ntfs_error(sb, "Failed to read $MFT.");
1089 return false; 1089 return false;
1090 } 1090 }
1091 kmft = page_address(mft_page); 1091 kmft = page_address(mft_page);
1092 /* Get the $MFTMirr page. */ 1092 /* Get the $MFTMirr page. */
1093 mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping, 1093 mirr_page = ntfs_map_page(vol->mftmirr_ino->i_mapping,
1094 index); 1094 index);
1095 if (IS_ERR(mirr_page)) { 1095 if (IS_ERR(mirr_page)) {
1096 ntfs_error(sb, "Failed to read $MFTMirr."); 1096 ntfs_error(sb, "Failed to read $MFTMirr.");
1097 goto mft_unmap_out; 1097 goto mft_unmap_out;
1098 } 1098 }
1099 kmirr = page_address(mirr_page); 1099 kmirr = page_address(mirr_page);
1100 ++index; 1100 ++index;
1101 } 1101 }
1102 /* Do not check the record if it is not in use. */ 1102 /* Do not check the record if it is not in use. */
1103 if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) { 1103 if (((MFT_RECORD*)kmft)->flags & MFT_RECORD_IN_USE) {
1104 /* Make sure the record is ok. */ 1104 /* Make sure the record is ok. */
1105 if (ntfs_is_baad_recordp((le32*)kmft)) { 1105 if (ntfs_is_baad_recordp((le32*)kmft)) {
1106 ntfs_error(sb, "Incomplete multi sector " 1106 ntfs_error(sb, "Incomplete multi sector "
1107 "transfer detected in mft " 1107 "transfer detected in mft "
1108 "record %i.", i); 1108 "record %i.", i);
1109 mm_unmap_out: 1109 mm_unmap_out:
1110 ntfs_unmap_page(mirr_page); 1110 ntfs_unmap_page(mirr_page);
1111 mft_unmap_out: 1111 mft_unmap_out:
1112 ntfs_unmap_page(mft_page); 1112 ntfs_unmap_page(mft_page);
1113 return false; 1113 return false;
1114 } 1114 }
1115 } 1115 }
1116 /* Do not check the mirror record if it is not in use. */ 1116 /* Do not check the mirror record if it is not in use. */
1117 if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) { 1117 if (((MFT_RECORD*)kmirr)->flags & MFT_RECORD_IN_USE) {
1118 if (ntfs_is_baad_recordp((le32*)kmirr)) { 1118 if (ntfs_is_baad_recordp((le32*)kmirr)) {
1119 ntfs_error(sb, "Incomplete multi sector " 1119 ntfs_error(sb, "Incomplete multi sector "
1120 "transfer detected in mft " 1120 "transfer detected in mft "
1121 "mirror record %i.", i); 1121 "mirror record %i.", i);
1122 goto mm_unmap_out; 1122 goto mm_unmap_out;
1123 } 1123 }
1124 } 1124 }
1125 /* Get the amount of data in the current record. */ 1125 /* Get the amount of data in the current record. */
1126 bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use); 1126 bytes = le32_to_cpu(((MFT_RECORD*)kmft)->bytes_in_use);
1127 if (bytes < sizeof(MFT_RECORD_OLD) || 1127 if (bytes < sizeof(MFT_RECORD_OLD) ||
1128 bytes > vol->mft_record_size || 1128 bytes > vol->mft_record_size ||
1129 ntfs_is_baad_recordp((le32*)kmft)) { 1129 ntfs_is_baad_recordp((le32*)kmft)) {
1130 bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use); 1130 bytes = le32_to_cpu(((MFT_RECORD*)kmirr)->bytes_in_use);
1131 if (bytes < sizeof(MFT_RECORD_OLD) || 1131 if (bytes < sizeof(MFT_RECORD_OLD) ||
1132 bytes > vol->mft_record_size || 1132 bytes > vol->mft_record_size ||
1133 ntfs_is_baad_recordp((le32*)kmirr)) 1133 ntfs_is_baad_recordp((le32*)kmirr))
1134 bytes = vol->mft_record_size; 1134 bytes = vol->mft_record_size;
1135 } 1135 }
1136 /* Compare the two records. */ 1136 /* Compare the two records. */
1137 if (memcmp(kmft, kmirr, bytes)) { 1137 if (memcmp(kmft, kmirr, bytes)) {
1138 ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not " 1138 ntfs_error(sb, "$MFT and $MFTMirr (record %i) do not "
1139 "match. Run ntfsfix or chkdsk.", i); 1139 "match. Run ntfsfix or chkdsk.", i);
1140 goto mm_unmap_out; 1140 goto mm_unmap_out;
1141 } 1141 }
1142 kmft += vol->mft_record_size; 1142 kmft += vol->mft_record_size;
1143 kmirr += vol->mft_record_size; 1143 kmirr += vol->mft_record_size;
1144 } while (++i < vol->mftmirr_size); 1144 } while (++i < vol->mftmirr_size);
1145 /* Release the last pages. */ 1145 /* Release the last pages. */
1146 ntfs_unmap_page(mft_page); 1146 ntfs_unmap_page(mft_page);
1147 ntfs_unmap_page(mirr_page); 1147 ntfs_unmap_page(mirr_page);
1148 1148
1149 /* Construct the mft mirror runlist by hand. */ 1149 /* Construct the mft mirror runlist by hand. */
1150 rl2[0].vcn = 0; 1150 rl2[0].vcn = 0;
1151 rl2[0].lcn = vol->mftmirr_lcn; 1151 rl2[0].lcn = vol->mftmirr_lcn;
1152 rl2[0].length = (vol->mftmirr_size * vol->mft_record_size + 1152 rl2[0].length = (vol->mftmirr_size * vol->mft_record_size +
1153 vol->cluster_size - 1) / vol->cluster_size; 1153 vol->cluster_size - 1) / vol->cluster_size;
1154 rl2[1].vcn = rl2[0].length; 1154 rl2[1].vcn = rl2[0].length;
1155 rl2[1].lcn = LCN_ENOENT; 1155 rl2[1].lcn = LCN_ENOENT;
1156 rl2[1].length = 0; 1156 rl2[1].length = 0;
1157 /* 1157 /*
1158 * Because we have just read all of the mft mirror, we know we have 1158 * Because we have just read all of the mft mirror, we know we have
1159 * mapped the full runlist for it. 1159 * mapped the full runlist for it.
1160 */ 1160 */
1161 mirr_ni = NTFS_I(vol->mftmirr_ino); 1161 mirr_ni = NTFS_I(vol->mftmirr_ino);
1162 down_read(&mirr_ni->runlist.lock); 1162 down_read(&mirr_ni->runlist.lock);
1163 rl = mirr_ni->runlist.rl; 1163 rl = mirr_ni->runlist.rl;
1164 /* Compare the two runlists. They must be identical. */ 1164 /* Compare the two runlists. They must be identical. */
1165 i = 0; 1165 i = 0;
1166 do { 1166 do {
1167 if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn || 1167 if (rl2[i].vcn != rl[i].vcn || rl2[i].lcn != rl[i].lcn ||
1168 rl2[i].length != rl[i].length) { 1168 rl2[i].length != rl[i].length) {
1169 ntfs_error(sb, "$MFTMirr location mismatch. " 1169 ntfs_error(sb, "$MFTMirr location mismatch. "
1170 "Run chkdsk."); 1170 "Run chkdsk.");
1171 up_read(&mirr_ni->runlist.lock); 1171 up_read(&mirr_ni->runlist.lock);
1172 return false; 1172 return false;
1173 } 1173 }
1174 } while (rl2[i++].length); 1174 } while (rl2[i++].length);
1175 up_read(&mirr_ni->runlist.lock); 1175 up_read(&mirr_ni->runlist.lock);
1176 ntfs_debug("Done."); 1176 ntfs_debug("Done.");
1177 return true; 1177 return true;
1178 } 1178 }
1179 1179
1180 /** 1180 /**
1181 * load_and_check_logfile - load and check the logfile inode for a volume 1181 * load_and_check_logfile - load and check the logfile inode for a volume
1182 * @vol: ntfs super block describing device whose logfile to load 1182 * @vol: ntfs super block describing device whose logfile to load
1183 * 1183 *
1184 * Return 'true' on success or 'false' on error. 1184 * Return 'true' on success or 'false' on error.
1185 */ 1185 */
1186 static bool load_and_check_logfile(ntfs_volume *vol, 1186 static bool load_and_check_logfile(ntfs_volume *vol,
1187 RESTART_PAGE_HEADER **rp) 1187 RESTART_PAGE_HEADER **rp)
1188 { 1188 {
1189 struct inode *tmp_ino; 1189 struct inode *tmp_ino;
1190 1190
1191 ntfs_debug("Entering."); 1191 ntfs_debug("Entering.");
1192 tmp_ino = ntfs_iget(vol->sb, FILE_LogFile); 1192 tmp_ino = ntfs_iget(vol->sb, FILE_LogFile);
1193 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { 1193 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
1194 if (!IS_ERR(tmp_ino)) 1194 if (!IS_ERR(tmp_ino))
1195 iput(tmp_ino); 1195 iput(tmp_ino);
1196 /* Caller will display error message. */ 1196 /* Caller will display error message. */
1197 return false; 1197 return false;
1198 } 1198 }
1199 if (!ntfs_check_logfile(tmp_ino, rp)) { 1199 if (!ntfs_check_logfile(tmp_ino, rp)) {
1200 iput(tmp_ino); 1200 iput(tmp_ino);
1201 /* ntfs_check_logfile() will have displayed error output. */ 1201 /* ntfs_check_logfile() will have displayed error output. */
1202 return false; 1202 return false;
1203 } 1203 }
1204 NInoSetSparseDisabled(NTFS_I(tmp_ino)); 1204 NInoSetSparseDisabled(NTFS_I(tmp_ino));
1205 vol->logfile_ino = tmp_ino; 1205 vol->logfile_ino = tmp_ino;
1206 ntfs_debug("Done."); 1206 ntfs_debug("Done.");
1207 return true; 1207 return true;
1208 } 1208 }
1209 1209
1210 #define NTFS_HIBERFIL_HEADER_SIZE 4096 1210 #define NTFS_HIBERFIL_HEADER_SIZE 4096
1211 1211
1212 /** 1212 /**
1213 * check_windows_hibernation_status - check if Windows is suspended on a volume 1213 * check_windows_hibernation_status - check if Windows is suspended on a volume
1214 * @vol: ntfs super block of device to check 1214 * @vol: ntfs super block of device to check
1215 * 1215 *
1216 * Check if Windows is hibernated on the ntfs volume @vol. This is done by 1216 * Check if Windows is hibernated on the ntfs volume @vol. This is done by
1217 * looking for the file hiberfil.sys in the root directory of the volume. If 1217 * looking for the file hiberfil.sys in the root directory of the volume. If
1218 * the file is not present Windows is definitely not suspended. 1218 * the file is not present Windows is definitely not suspended.
1219 * 1219 *
1220 * If hiberfil.sys exists and is less than 4kiB in size it means Windows is 1220 * If hiberfil.sys exists and is less than 4kiB in size it means Windows is
1221 * definitely suspended (this volume is not the system volume). Caveat: on a 1221 * definitely suspended (this volume is not the system volume). Caveat: on a
1222 * system with many volumes it is possible that the < 4kiB check is bogus but 1222 * system with many volumes it is possible that the < 4kiB check is bogus but
1223 * for now this should do fine. 1223 * for now this should do fine.
1224 * 1224 *
1225 * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the 1225 * If hiberfil.sys exists and is larger than 4kiB in size, we need to read the
1226 * hiberfil header (which is the first 4kiB). If this begins with "hibr", 1226 * hiberfil header (which is the first 4kiB). If this begins with "hibr",
1227 * Windows is definitely suspended. If it is completely full of zeroes, 1227 * Windows is definitely suspended. If it is completely full of zeroes,
1228 * Windows is definitely not hibernated. Any other case is treated as if 1228 * Windows is definitely not hibernated. Any other case is treated as if
1229 * Windows is suspended. This caters for the above mentioned caveat of a 1229 * Windows is suspended. This caters for the above mentioned caveat of a
1230 * system with many volumes where no "hibr" magic would be present and there is 1230 * system with many volumes where no "hibr" magic would be present and there is
1231 * no zero header. 1231 * no zero header.
1232 * 1232 *
1233 * Return 0 if Windows is not hibernated on the volume, >0 if Windows is 1233 * Return 0 if Windows is not hibernated on the volume, >0 if Windows is
1234 * hibernated on the volume, and -errno on error. 1234 * hibernated on the volume, and -errno on error.
1235 */ 1235 */
1236 static int check_windows_hibernation_status(ntfs_volume *vol) 1236 static int check_windows_hibernation_status(ntfs_volume *vol)
1237 { 1237 {
1238 MFT_REF mref; 1238 MFT_REF mref;
1239 struct inode *vi; 1239 struct inode *vi;
1240 ntfs_inode *ni; 1240 ntfs_inode *ni;
1241 struct page *page; 1241 struct page *page;
1242 u32 *kaddr, *kend; 1242 u32 *kaddr, *kend;
1243 ntfs_name *name = NULL; 1243 ntfs_name *name = NULL;
1244 int ret = 1; 1244 int ret = 1;
1245 static const ntfschar hiberfil[13] = { const_cpu_to_le16('h'), 1245 static const ntfschar hiberfil[13] = { const_cpu_to_le16('h'),
1246 const_cpu_to_le16('i'), const_cpu_to_le16('b'), 1246 const_cpu_to_le16('i'), const_cpu_to_le16('b'),
1247 const_cpu_to_le16('e'), const_cpu_to_le16('r'), 1247 const_cpu_to_le16('e'), const_cpu_to_le16('r'),
1248 const_cpu_to_le16('f'), const_cpu_to_le16('i'), 1248 const_cpu_to_le16('f'), const_cpu_to_le16('i'),
1249 const_cpu_to_le16('l'), const_cpu_to_le16('.'), 1249 const_cpu_to_le16('l'), const_cpu_to_le16('.'),
1250 const_cpu_to_le16('s'), const_cpu_to_le16('y'), 1250 const_cpu_to_le16('s'), const_cpu_to_le16('y'),
1251 const_cpu_to_le16('s'), 0 }; 1251 const_cpu_to_le16('s'), 0 };
1252 1252
1253 ntfs_debug("Entering."); 1253 ntfs_debug("Entering.");
1254 /* 1254 /*
1255 * Find the inode number for the hibernation file by looking up the 1255 * Find the inode number for the hibernation file by looking up the
1256 * filename hiberfil.sys in the root directory. 1256 * filename hiberfil.sys in the root directory.
1257 */ 1257 */
1258 mutex_lock(&vol->root_ino->i_mutex); 1258 mutex_lock(&vol->root_ino->i_mutex);
1259 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12, 1259 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->root_ino), hiberfil, 12,
1260 &name); 1260 &name);
1261 mutex_unlock(&vol->root_ino->i_mutex); 1261 mutex_unlock(&vol->root_ino->i_mutex);
1262 if (IS_ERR_MREF(mref)) { 1262 if (IS_ERR_MREF(mref)) {
1263 ret = MREF_ERR(mref); 1263 ret = MREF_ERR(mref);
1264 /* If the file does not exist, Windows is not hibernated. */ 1264 /* If the file does not exist, Windows is not hibernated. */
1265 if (ret == -ENOENT) { 1265 if (ret == -ENOENT) {
1266 ntfs_debug("hiberfil.sys not present. Windows is not " 1266 ntfs_debug("hiberfil.sys not present. Windows is not "
1267 "hibernated on the volume."); 1267 "hibernated on the volume.");
1268 return 0; 1268 return 0;
1269 } 1269 }
1270 /* A real error occured. */ 1270 /* A real error occured. */
1271 ntfs_error(vol->sb, "Failed to find inode number for " 1271 ntfs_error(vol->sb, "Failed to find inode number for "
1272 "hiberfil.sys."); 1272 "hiberfil.sys.");
1273 return ret; 1273 return ret;
1274 } 1274 }
1275 /* We do not care for the type of match that was found. */ 1275 /* We do not care for the type of match that was found. */
1276 kfree(name); 1276 kfree(name);
1277 /* Get the inode. */ 1277 /* Get the inode. */
1278 vi = ntfs_iget(vol->sb, MREF(mref)); 1278 vi = ntfs_iget(vol->sb, MREF(mref));
1279 if (IS_ERR(vi) || is_bad_inode(vi)) { 1279 if (IS_ERR(vi) || is_bad_inode(vi)) {
1280 if (!IS_ERR(vi)) 1280 if (!IS_ERR(vi))
1281 iput(vi); 1281 iput(vi);
1282 ntfs_error(vol->sb, "Failed to load hiberfil.sys."); 1282 ntfs_error(vol->sb, "Failed to load hiberfil.sys.");
1283 return IS_ERR(vi) ? PTR_ERR(vi) : -EIO; 1283 return IS_ERR(vi) ? PTR_ERR(vi) : -EIO;
1284 } 1284 }
1285 if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) { 1285 if (unlikely(i_size_read(vi) < NTFS_HIBERFIL_HEADER_SIZE)) {
1286 ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). " 1286 ntfs_debug("hiberfil.sys is smaller than 4kiB (0x%llx). "
1287 "Windows is hibernated on the volume. This " 1287 "Windows is hibernated on the volume. This "
1288 "is not the system volume.", i_size_read(vi)); 1288 "is not the system volume.", i_size_read(vi));
1289 goto iput_out; 1289 goto iput_out;
1290 } 1290 }
1291 ni = NTFS_I(vi); 1291 ni = NTFS_I(vi);
1292 page = ntfs_map_page(vi->i_mapping, 0); 1292 page = ntfs_map_page(vi->i_mapping, 0);
1293 if (IS_ERR(page)) { 1293 if (IS_ERR(page)) {
1294 ntfs_error(vol->sb, "Failed to read from hiberfil.sys."); 1294 ntfs_error(vol->sb, "Failed to read from hiberfil.sys.");
1295 ret = PTR_ERR(page); 1295 ret = PTR_ERR(page);
1296 goto iput_out; 1296 goto iput_out;
1297 } 1297 }
1298 kaddr = (u32*)page_address(page); 1298 kaddr = (u32*)page_address(page);
1299 if (*(le32*)kaddr == const_cpu_to_le32(0x72626968)/*'hibr'*/) { 1299 if (*(le32*)kaddr == const_cpu_to_le32(0x72626968)/*'hibr'*/) {
1300 ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is " 1300 ntfs_debug("Magic \"hibr\" found in hiberfil.sys. Windows is "
1301 "hibernated on the volume. This is the " 1301 "hibernated on the volume. This is the "
1302 "system volume."); 1302 "system volume.");
1303 goto unm_iput_out; 1303 goto unm_iput_out;
1304 } 1304 }
1305 kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr); 1305 kend = kaddr + NTFS_HIBERFIL_HEADER_SIZE/sizeof(*kaddr);
1306 do { 1306 do {
1307 if (unlikely(*kaddr)) { 1307 if (unlikely(*kaddr)) {
1308 ntfs_debug("hiberfil.sys is larger than 4kiB " 1308 ntfs_debug("hiberfil.sys is larger than 4kiB "
1309 "(0x%llx), does not contain the " 1309 "(0x%llx), does not contain the "
1310 "\"hibr\" magic, and does not have a " 1310 "\"hibr\" magic, and does not have a "
1311 "zero header. Windows is hibernated " 1311 "zero header. Windows is hibernated "
1312 "on the volume. This is not the " 1312 "on the volume. This is not the "
1313 "system volume.", i_size_read(vi)); 1313 "system volume.", i_size_read(vi));
1314 goto unm_iput_out; 1314 goto unm_iput_out;
1315 } 1315 }
1316 } while (++kaddr < kend); 1316 } while (++kaddr < kend);
1317 ntfs_debug("hiberfil.sys contains a zero header. Windows is not " 1317 ntfs_debug("hiberfil.sys contains a zero header. Windows is not "
1318 "hibernated on the volume. This is the system " 1318 "hibernated on the volume. This is the system "
1319 "volume."); 1319 "volume.");
1320 ret = 0; 1320 ret = 0;
1321 unm_iput_out: 1321 unm_iput_out:
1322 ntfs_unmap_page(page); 1322 ntfs_unmap_page(page);
1323 iput_out: 1323 iput_out:
1324 iput(vi); 1324 iput(vi);
1325 return ret; 1325 return ret;
1326 } 1326 }
1327 1327
1328 /** 1328 /**
1329 * load_and_init_quota - load and setup the quota file for a volume if present 1329 * load_and_init_quota - load and setup the quota file for a volume if present
1330 * @vol: ntfs super block describing device whose quota file to load 1330 * @vol: ntfs super block describing device whose quota file to load
1331 * 1331 *
1332 * Return 'true' on success or 'false' on error. If $Quota is not present, we 1332 * Return 'true' on success or 'false' on error. If $Quota is not present, we
1333 * leave vol->quota_ino as NULL and return success. 1333 * leave vol->quota_ino as NULL and return success.
1334 */ 1334 */
1335 static bool load_and_init_quota(ntfs_volume *vol) 1335 static bool load_and_init_quota(ntfs_volume *vol)
1336 { 1336 {
1337 MFT_REF mref; 1337 MFT_REF mref;
1338 struct inode *tmp_ino; 1338 struct inode *tmp_ino;
1339 ntfs_name *name = NULL; 1339 ntfs_name *name = NULL;
1340 static const ntfschar Quota[7] = { const_cpu_to_le16('$'), 1340 static const ntfschar Quota[7] = { const_cpu_to_le16('$'),
1341 const_cpu_to_le16('Q'), const_cpu_to_le16('u'), 1341 const_cpu_to_le16('Q'), const_cpu_to_le16('u'),
1342 const_cpu_to_le16('o'), const_cpu_to_le16('t'), 1342 const_cpu_to_le16('o'), const_cpu_to_le16('t'),
1343 const_cpu_to_le16('a'), 0 }; 1343 const_cpu_to_le16('a'), 0 };
1344 static ntfschar Q[3] = { const_cpu_to_le16('$'), 1344 static ntfschar Q[3] = { const_cpu_to_le16('$'),
1345 const_cpu_to_le16('Q'), 0 }; 1345 const_cpu_to_le16('Q'), 0 };
1346 1346
1347 ntfs_debug("Entering."); 1347 ntfs_debug("Entering.");
1348 /* 1348 /*
1349 * Find the inode number for the quota file by looking up the filename 1349 * Find the inode number for the quota file by looking up the filename
1350 * $Quota in the extended system files directory $Extend. 1350 * $Quota in the extended system files directory $Extend.
1351 */ 1351 */
1352 mutex_lock(&vol->extend_ino->i_mutex); 1352 mutex_lock(&vol->extend_ino->i_mutex);
1353 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6, 1353 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), Quota, 6,
1354 &name); 1354 &name);
1355 mutex_unlock(&vol->extend_ino->i_mutex); 1355 mutex_unlock(&vol->extend_ino->i_mutex);
1356 if (IS_ERR_MREF(mref)) { 1356 if (IS_ERR_MREF(mref)) {
1357 /* 1357 /*
1358 * If the file does not exist, quotas are disabled and have 1358 * If the file does not exist, quotas are disabled and have
1359 * never been enabled on this volume, just return success. 1359 * never been enabled on this volume, just return success.
1360 */ 1360 */
1361 if (MREF_ERR(mref) == -ENOENT) { 1361 if (MREF_ERR(mref) == -ENOENT) {
1362 ntfs_debug("$Quota not present. Volume does not have " 1362 ntfs_debug("$Quota not present. Volume does not have "
1363 "quotas enabled."); 1363 "quotas enabled.");
1364 /* 1364 /*
1365 * No need to try to set quotas out of date if they are 1365 * No need to try to set quotas out of date if they are
1366 * not enabled. 1366 * not enabled.
1367 */ 1367 */
1368 NVolSetQuotaOutOfDate(vol); 1368 NVolSetQuotaOutOfDate(vol);
1369 return true; 1369 return true;
1370 } 1370 }
1371 /* A real error occured. */ 1371 /* A real error occured. */
1372 ntfs_error(vol->sb, "Failed to find inode number for $Quota."); 1372 ntfs_error(vol->sb, "Failed to find inode number for $Quota.");
1373 return false; 1373 return false;
1374 } 1374 }
1375 /* We do not care for the type of match that was found. */ 1375 /* We do not care for the type of match that was found. */
1376 kfree(name); 1376 kfree(name);
1377 /* Get the inode. */ 1377 /* Get the inode. */
1378 tmp_ino = ntfs_iget(vol->sb, MREF(mref)); 1378 tmp_ino = ntfs_iget(vol->sb, MREF(mref));
1379 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) { 1379 if (IS_ERR(tmp_ino) || is_bad_inode(tmp_ino)) {
1380 if (!IS_ERR(tmp_ino)) 1380 if (!IS_ERR(tmp_ino))
1381 iput(tmp_ino); 1381 iput(tmp_ino);
1382 ntfs_error(vol->sb, "Failed to load $Quota."); 1382 ntfs_error(vol->sb, "Failed to load $Quota.");
1383 return false; 1383 return false;
1384 } 1384 }
1385 vol->quota_ino = tmp_ino; 1385 vol->quota_ino = tmp_ino;
1386 /* Get the $Q index allocation attribute. */ 1386 /* Get the $Q index allocation attribute. */
1387 tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2); 1387 tmp_ino = ntfs_index_iget(vol->quota_ino, Q, 2);
1388 if (IS_ERR(tmp_ino)) { 1388 if (IS_ERR(tmp_ino)) {
1389 ntfs_error(vol->sb, "Failed to load $Quota/$Q index."); 1389 ntfs_error(vol->sb, "Failed to load $Quota/$Q index.");
1390 return false; 1390 return false;
1391 } 1391 }
1392 vol->quota_q_ino = tmp_ino; 1392 vol->quota_q_ino = tmp_ino;
1393 ntfs_debug("Done."); 1393 ntfs_debug("Done.");
1394 return true; 1394 return true;
1395 } 1395 }
1396 1396
1397 /** 1397 /**
1398 * load_and_init_usnjrnl - load and setup the transaction log if present 1398 * load_and_init_usnjrnl - load and setup the transaction log if present
1399 * @vol: ntfs super block describing device whose usnjrnl file to load 1399 * @vol: ntfs super block describing device whose usnjrnl file to load
1400 * 1400 *
1401 * Return 'true' on success or 'false' on error. 1401 * Return 'true' on success or 'false' on error.
1402 * 1402 *
1403 * If $UsnJrnl is not present or in the process of being disabled, we set 1403 * If $UsnJrnl is not present or in the process of being disabled, we set
1404 * NVolUsnJrnlStamped() and return success. 1404 * NVolUsnJrnlStamped() and return success.
1405 * 1405 *
1406 * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn, 1406 * If the $UsnJrnl $DATA/$J attribute has a size equal to the lowest valid usn,
1407 * i.e. transaction logging has only just been enabled or the journal has been 1407 * i.e. transaction logging has only just been enabled or the journal has been
1408 * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped() 1408 * stamped and nothing has been logged since, we also set NVolUsnJrnlStamped()
1409 * and return success. 1409 * and return success.
1410 */ 1410 */
1411 static bool load_and_init_usnjrnl(ntfs_volume *vol) 1411 static bool load_and_init_usnjrnl(ntfs_volume *vol)
1412 { 1412 {
1413 MFT_REF mref; 1413 MFT_REF mref;
1414 struct inode *tmp_ino; 1414 struct inode *tmp_ino;
1415 ntfs_inode *tmp_ni; 1415 ntfs_inode *tmp_ni;
1416 struct page *page; 1416 struct page *page;
1417 ntfs_name *name = NULL; 1417 ntfs_name *name = NULL;
1418 USN_HEADER *uh; 1418 USN_HEADER *uh;
1419 static const ntfschar UsnJrnl[9] = { const_cpu_to_le16('$'), 1419 static const ntfschar UsnJrnl[9] = { const_cpu_to_le16('$'),
1420 const_cpu_to_le16('U'), const_cpu_to_le16('s'), 1420 const_cpu_to_le16('U'), const_cpu_to_le16('s'),
1421 const_cpu_to_le16('n'), const_cpu_to_le16('J'), 1421 const_cpu_to_le16('n'), const_cpu_to_le16('J'),
1422 const_cpu_to_le16('r'), const_cpu_to_le16('n'), 1422 const_cpu_to_le16('r'), const_cpu_to_le16('n'),
1423 const_cpu_to_le16('l'), 0 }; 1423 const_cpu_to_le16('l'), 0 };
1424 static ntfschar Max[5] = { const_cpu_to_le16('$'), 1424 static ntfschar Max[5] = { const_cpu_to_le16('$'),
1425 const_cpu_to_le16('M'), const_cpu_to_le16('a'), 1425 const_cpu_to_le16('M'), const_cpu_to_le16('a'),
1426 const_cpu_to_le16('x'), 0 }; 1426 const_cpu_to_le16('x'), 0 };
1427 static ntfschar J[3] = { const_cpu_to_le16('$'), 1427 static ntfschar J[3] = { const_cpu_to_le16('$'),
1428 const_cpu_to_le16('J'), 0 }; 1428 const_cpu_to_le16('J'), 0 };
1429 1429
1430 ntfs_debug("Entering."); 1430 ntfs_debug("Entering.");
1431 /* 1431 /*
1432 * Find the inode number for the transaction log file by looking up the 1432 * Find the inode number for the transaction log file by looking up the
1433 * filename $UsnJrnl in the extended system files directory $Extend. 1433 * filename $UsnJrnl in the extended system files directory $Extend.
1434 */ 1434 */
1435 mutex_lock(&vol->extend_ino->i_mutex); 1435 mutex_lock(&vol->extend_ino->i_mutex);
1436 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8, 1436 mref = ntfs_lookup_inode_by_name(NTFS_I(vol->extend_ino), UsnJrnl, 8,
1437 &name); 1437 &name);
1438 mutex_unlock(&vol->extend_ino->i_mutex); 1438 mutex_unlock(&vol->extend_ino->i_mutex);
1439 if (IS_ERR_MREF(mref)) { 1439 if (IS_ERR_MREF(mref)) {
1440 /* 1440 /*
1441 * If the file does not exist, transaction logging is disabled, 1441 * If the file does not exist, transaction logging is disabled,
1442 * just return success. 1442 * just return success.
1443 */ 1443 */
1444 if (MREF_ERR(mref) == -ENOENT) { 1444 if (MREF_ERR(mref) == -ENOENT) {
1445 ntfs_debug("$UsnJrnl not present. Volume does not " 1445 ntfs_debug("$UsnJrnl not present. Volume does not "
1446 "have transaction logging enabled."); 1446 "have transaction logging enabled.");
1447 not_enabled: 1447 not_enabled:
1448 /* 1448 /*
1449 * No need to try to stamp the transaction log if 1449 * No need to try to stamp the transaction log if
1450 * transaction logging is not enabled. 1450 * transaction logging is not enabled.
1451 */ 1451 */
1452 NVolSetUsnJrnlStamped(vol); 1452 NVolSetUsnJrnlStamped(vol);
1453 return true; 1453 return true;
1454 } 1454 }
1455 /* A real error occured. */ 1455 /* A real error occured. */
1456 ntfs_error(vol->sb, "Failed to find inode number for " 1456 ntfs_error(vol->sb, "Failed to find inode number for "
1457 "$UsnJrnl."); 1457 "$UsnJrnl.");
1458 return false; 1458 return false;
1459 } 1459 }
1460 /* We do not care for the type of match that was found. */ 1460 /* We do not care for the type of match that was found. */
1461 kfree(name); 1461 kfree(name);
1462 /* Get the inode. */ 1462 /* Get the inode. */
1463 tmp_ino = ntfs_iget(vol->sb, MREF(mref)); 1463 tmp_ino = ntfs_iget(vol->sb, MREF(mref));
1464 if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) { 1464 if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) {
1465 if (!IS_ERR(tmp_ino)) 1465 if (!IS_ERR(tmp_ino))
1466 iput(tmp_ino); 1466 iput(tmp_ino);
1467 ntfs_error(vol->sb, "Failed to load $UsnJrnl."); 1467 ntfs_error(vol->sb, "Failed to load $UsnJrnl.");
1468 return false; 1468 return false;
1469 } 1469 }
1470 vol->usnjrnl_ino = tmp_ino; 1470 vol->usnjrnl_ino = tmp_ino;
1471 /* 1471 /*
1472 * If the transaction log is in the process of being deleted, we can 1472 * If the transaction log is in the process of being deleted, we can
1473 * ignore it. 1473 * ignore it.
1474 */ 1474 */
1475 if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) { 1475 if (unlikely(vol->vol_flags & VOLUME_DELETE_USN_UNDERWAY)) {
1476 ntfs_debug("$UsnJrnl in the process of being disabled. " 1476 ntfs_debug("$UsnJrnl in the process of being disabled. "
1477 "Volume does not have transaction logging " 1477 "Volume does not have transaction logging "
1478 "enabled."); 1478 "enabled.");
1479 goto not_enabled; 1479 goto not_enabled;
1480 } 1480 }
1481 /* Get the $DATA/$Max attribute. */ 1481 /* Get the $DATA/$Max attribute. */
1482 tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4); 1482 tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, Max, 4);
1483 if (IS_ERR(tmp_ino)) { 1483 if (IS_ERR(tmp_ino)) {
1484 ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max " 1484 ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$Max "
1485 "attribute."); 1485 "attribute.");
1486 return false; 1486 return false;
1487 } 1487 }
1488 vol->usnjrnl_max_ino = tmp_ino; 1488 vol->usnjrnl_max_ino = tmp_ino;
1489 if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) { 1489 if (unlikely(i_size_read(tmp_ino) < sizeof(USN_HEADER))) {
1490 ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max " 1490 ntfs_error(vol->sb, "Found corrupt $UsnJrnl/$DATA/$Max "
1491 "attribute (size is 0x%llx but should be at " 1491 "attribute (size is 0x%llx but should be at "
1492 "least 0x%zx bytes).", i_size_read(tmp_ino), 1492 "least 0x%zx bytes).", i_size_read(tmp_ino),
1493 sizeof(USN_HEADER)); 1493 sizeof(USN_HEADER));
1494 return false; 1494 return false;
1495 } 1495 }
1496 /* Get the $DATA/$J attribute. */ 1496 /* Get the $DATA/$J attribute. */
1497 tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2); 1497 tmp_ino = ntfs_attr_iget(vol->usnjrnl_ino, AT_DATA, J, 2);
1498 if (IS_ERR(tmp_ino)) { 1498 if (IS_ERR(tmp_ino)) {
1499 ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J " 1499 ntfs_error(vol->sb, "Failed to load $UsnJrnl/$DATA/$J "
1500 "attribute."); 1500 "attribute.");
1501 return false; 1501 return false;
1502 } 1502 }
1503 vol->usnjrnl_j_ino = tmp_ino; 1503 vol->usnjrnl_j_ino = tmp_ino;
1504 /* Verify $J is non-resident and sparse. */ 1504 /* Verify $J is non-resident and sparse. */
1505 tmp_ni = NTFS_I(vol->usnjrnl_j_ino); 1505 tmp_ni = NTFS_I(vol->usnjrnl_j_ino);
1506 if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) { 1506 if (unlikely(!NInoNonResident(tmp_ni) || !NInoSparse(tmp_ni))) {
1507 ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident " 1507 ntfs_error(vol->sb, "$UsnJrnl/$DATA/$J attribute is resident "
1508 "and/or not sparse."); 1508 "and/or not sparse.");
1509 return false; 1509 return false;
1510 } 1510 }
1511 /* Read the USN_HEADER from $DATA/$Max. */ 1511 /* Read the USN_HEADER from $DATA/$Max. */
1512 page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0); 1512 page = ntfs_map_page(vol->usnjrnl_max_ino->i_mapping, 0);
1513 if (IS_ERR(page)) { 1513 if (IS_ERR(page)) {
1514 ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max " 1514 ntfs_error(vol->sb, "Failed to read from $UsnJrnl/$DATA/$Max "
1515 "attribute."); 1515 "attribute.");
1516 return false; 1516 return false;
1517 } 1517 }
1518 uh = (USN_HEADER*)page_address(page); 1518 uh = (USN_HEADER*)page_address(page);
1519 /* Sanity check the $Max. */ 1519 /* Sanity check the $Max. */
1520 if (unlikely(sle64_to_cpu(uh->allocation_delta) > 1520 if (unlikely(sle64_to_cpu(uh->allocation_delta) >
1521 sle64_to_cpu(uh->maximum_size))) { 1521 sle64_to_cpu(uh->maximum_size))) {
1522 ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds " 1522 ntfs_error(vol->sb, "Allocation delta (0x%llx) exceeds "
1523 "maximum size (0x%llx). $UsnJrnl is corrupt.", 1523 "maximum size (0x%llx). $UsnJrnl is corrupt.",
1524 (long long)sle64_to_cpu(uh->allocation_delta), 1524 (long long)sle64_to_cpu(uh->allocation_delta),
1525 (long long)sle64_to_cpu(uh->maximum_size)); 1525 (long long)sle64_to_cpu(uh->maximum_size));
1526 ntfs_unmap_page(page); 1526 ntfs_unmap_page(page);
1527 return false; 1527 return false;
1528 } 1528 }
1529 /* 1529 /*
1530 * If the transaction log has been stamped and nothing has been written 1530 * If the transaction log has been stamped and nothing has been written
1531 * to it since, we do not need to stamp it. 1531 * to it since, we do not need to stamp it.
1532 */ 1532 */
1533 if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >= 1533 if (unlikely(sle64_to_cpu(uh->lowest_valid_usn) >=
1534 i_size_read(vol->usnjrnl_j_ino))) { 1534 i_size_read(vol->usnjrnl_j_ino))) {
1535 if (likely(sle64_to_cpu(uh->lowest_valid_usn) == 1535 if (likely(sle64_to_cpu(uh->lowest_valid_usn) ==
1536 i_size_read(vol->usnjrnl_j_ino))) { 1536 i_size_read(vol->usnjrnl_j_ino))) {
1537 ntfs_unmap_page(page); 1537 ntfs_unmap_page(page);
1538 ntfs_debug("$UsnJrnl is enabled but nothing has been " 1538 ntfs_debug("$UsnJrnl is enabled but nothing has been "
1539 "logged since it was last stamped. " 1539 "logged since it was last stamped. "
1540 "Treating this as if the volume does " 1540 "Treating this as if the volume does "
1541 "not have transaction logging " 1541 "not have transaction logging "
1542 "enabled."); 1542 "enabled.");
1543 goto not_enabled; 1543 goto not_enabled;
1544 } 1544 }
1545 ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) " 1545 ntfs_error(vol->sb, "$UsnJrnl has lowest valid usn (0x%llx) "
1546 "which is out of bounds (0x%llx). $UsnJrnl " 1546 "which is out of bounds (0x%llx). $UsnJrnl "
1547 "is corrupt.", 1547 "is corrupt.",
1548 (long long)sle64_to_cpu(uh->lowest_valid_usn), 1548 (long long)sle64_to_cpu(uh->lowest_valid_usn),
1549 i_size_read(vol->usnjrnl_j_ino)); 1549 i_size_read(vol->usnjrnl_j_ino));
1550 ntfs_unmap_page(page); 1550 ntfs_unmap_page(page);
1551 return false; 1551 return false;
1552 } 1552 }
1553 ntfs_unmap_page(page); 1553 ntfs_unmap_page(page);
1554 ntfs_debug("Done."); 1554 ntfs_debug("Done.");
1555 return true; 1555 return true;
1556 } 1556 }
1557 1557
1558 /** 1558 /**
1559 * load_and_init_attrdef - load the attribute definitions table for a volume 1559 * load_and_init_attrdef - load the attribute definitions table for a volume
1560 * @vol: ntfs super block describing device whose attrdef to load 1560 * @vol: ntfs super block describing device whose attrdef to load
1561 * 1561 *
1562 * Return 'true' on success or 'false' on error. 1562 * Return 'true' on success or 'false' on error.
1563 */ 1563 */
1564 static bool load_and_init_attrdef(ntfs_volume *vol) 1564 static bool load_and_init_attrdef(ntfs_volume *vol)
1565 { 1565 {
1566 loff_t i_size; 1566 loff_t i_size;
1567 struct super_block *sb = vol->sb; 1567 struct super_block *sb = vol->sb;
1568 struct inode *ino; 1568 struct inode *ino;
1569 struct page *page; 1569 struct page *page;
1570 pgoff_t index, max_index; 1570 pgoff_t index, max_index;
1571 unsigned int size; 1571 unsigned int size;
1572 1572
1573 ntfs_debug("Entering."); 1573 ntfs_debug("Entering.");
1574 /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */ 1574 /* Read attrdef table and setup vol->attrdef and vol->attrdef_size. */
1575 ino = ntfs_iget(sb, FILE_AttrDef); 1575 ino = ntfs_iget(sb, FILE_AttrDef);
1576 if (IS_ERR(ino) || is_bad_inode(ino)) { 1576 if (IS_ERR(ino) || is_bad_inode(ino)) {
1577 if (!IS_ERR(ino)) 1577 if (!IS_ERR(ino))
1578 iput(ino); 1578 iput(ino);
1579 goto failed; 1579 goto failed;
1580 } 1580 }
1581 NInoSetSparseDisabled(NTFS_I(ino)); 1581 NInoSetSparseDisabled(NTFS_I(ino));
1582 /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */ 1582 /* The size of FILE_AttrDef must be above 0 and fit inside 31 bits. */
1583 i_size = i_size_read(ino); 1583 i_size = i_size_read(ino);
1584 if (i_size <= 0 || i_size > 0x7fffffff) 1584 if (i_size <= 0 || i_size > 0x7fffffff)
1585 goto iput_failed; 1585 goto iput_failed;
1586 vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size); 1586 vol->attrdef = (ATTR_DEF*)ntfs_malloc_nofs(i_size);
1587 if (!vol->attrdef) 1587 if (!vol->attrdef)
1588 goto iput_failed; 1588 goto iput_failed;
1589 index = 0; 1589 index = 0;
1590 max_index = i_size >> PAGE_CACHE_SHIFT; 1590 max_index = i_size >> PAGE_CACHE_SHIFT;
1591 size = PAGE_CACHE_SIZE; 1591 size = PAGE_CACHE_SIZE;
1592 while (index < max_index) { 1592 while (index < max_index) {
1593 /* Read the attrdef table and copy it into the linear buffer. */ 1593 /* Read the attrdef table and copy it into the linear buffer. */
1594 read_partial_attrdef_page: 1594 read_partial_attrdef_page:
1595 page = ntfs_map_page(ino->i_mapping, index); 1595 page = ntfs_map_page(ino->i_mapping, index);
1596 if (IS_ERR(page)) 1596 if (IS_ERR(page))
1597 goto free_iput_failed; 1597 goto free_iput_failed;
1598 memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT), 1598 memcpy((u8*)vol->attrdef + (index++ << PAGE_CACHE_SHIFT),
1599 page_address(page), size); 1599 page_address(page), size);
1600 ntfs_unmap_page(page); 1600 ntfs_unmap_page(page);
1601 }; 1601 };
1602 if (size == PAGE_CACHE_SIZE) { 1602 if (size == PAGE_CACHE_SIZE) {
1603 size = i_size & ~PAGE_CACHE_MASK; 1603 size = i_size & ~PAGE_CACHE_MASK;
1604 if (size) 1604 if (size)
1605 goto read_partial_attrdef_page; 1605 goto read_partial_attrdef_page;
1606 } 1606 }
1607 vol->attrdef_size = i_size; 1607 vol->attrdef_size = i_size;
1608 ntfs_debug("Read %llu bytes from $AttrDef.", i_size); 1608 ntfs_debug("Read %llu bytes from $AttrDef.", i_size);
1609 iput(ino); 1609 iput(ino);
1610 return true; 1610 return true;
1611 free_iput_failed: 1611 free_iput_failed:
1612 ntfs_free(vol->attrdef); 1612 ntfs_free(vol->attrdef);
1613 vol->attrdef = NULL; 1613 vol->attrdef = NULL;
1614 iput_failed: 1614 iput_failed:
1615 iput(ino); 1615 iput(ino);
1616 failed: 1616 failed:
1617 ntfs_error(sb, "Failed to initialize attribute definition table."); 1617 ntfs_error(sb, "Failed to initialize attribute definition table.");
1618 return false; 1618 return false;
1619 } 1619 }
1620 1620
1621 #endif /* NTFS_RW */ 1621 #endif /* NTFS_RW */
1622 1622
1623 /** 1623 /**
1624 * load_and_init_upcase - load the upcase table for an ntfs volume 1624 * load_and_init_upcase - load the upcase table for an ntfs volume
1625 * @vol: ntfs super block describing device whose upcase to load 1625 * @vol: ntfs super block describing device whose upcase to load
1626 * 1626 *
1627 * Return 'true' on success or 'false' on error. 1627 * Return 'true' on success or 'false' on error.
1628 */ 1628 */
1629 static bool load_and_init_upcase(ntfs_volume *vol) 1629 static bool load_and_init_upcase(ntfs_volume *vol)
1630 { 1630 {
1631 loff_t i_size; 1631 loff_t i_size;
1632 struct super_block *sb = vol->sb; 1632 struct super_block *sb = vol->sb;
1633 struct inode *ino; 1633 struct inode *ino;
1634 struct page *page; 1634 struct page *page;
1635 pgoff_t index, max_index; 1635 pgoff_t index, max_index;
1636 unsigned int size; 1636 unsigned int size;
1637 int i, max; 1637 int i, max;
1638 1638
1639 ntfs_debug("Entering."); 1639 ntfs_debug("Entering.");
1640 /* Read upcase table and setup vol->upcase and vol->upcase_len. */ 1640 /* Read upcase table and setup vol->upcase and vol->upcase_len. */
1641 ino = ntfs_iget(sb, FILE_UpCase); 1641 ino = ntfs_iget(sb, FILE_UpCase);
1642 if (IS_ERR(ino) || is_bad_inode(ino)) { 1642 if (IS_ERR(ino) || is_bad_inode(ino)) {
1643 if (!IS_ERR(ino)) 1643 if (!IS_ERR(ino))
1644 iput(ino); 1644 iput(ino);
1645 goto upcase_failed; 1645 goto upcase_failed;
1646 } 1646 }
1647 /* 1647 /*
1648 * The upcase size must not be above 64k Unicode characters, must not 1648 * The upcase size must not be above 64k Unicode characters, must not
1649 * be zero and must be a multiple of sizeof(ntfschar). 1649 * be zero and must be a multiple of sizeof(ntfschar).
1650 */ 1650 */
1651 i_size = i_size_read(ino); 1651 i_size = i_size_read(ino);
1652 if (!i_size || i_size & (sizeof(ntfschar) - 1) || 1652 if (!i_size || i_size & (sizeof(ntfschar) - 1) ||
1653 i_size > 64ULL * 1024 * sizeof(ntfschar)) 1653 i_size > 64ULL * 1024 * sizeof(ntfschar))
1654 goto iput_upcase_failed; 1654 goto iput_upcase_failed;
1655 vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size); 1655 vol->upcase = (ntfschar*)ntfs_malloc_nofs(i_size);
1656 if (!vol->upcase) 1656 if (!vol->upcase)
1657 goto iput_upcase_failed; 1657 goto iput_upcase_failed;
1658 index = 0; 1658 index = 0;
1659 max_index = i_size >> PAGE_CACHE_SHIFT; 1659 max_index = i_size >> PAGE_CACHE_SHIFT;
1660 size = PAGE_CACHE_SIZE; 1660 size = PAGE_CACHE_SIZE;
1661 while (index < max_index) { 1661 while (index < max_index) {
1662 /* Read the upcase table and copy it into the linear buffer. */ 1662 /* Read the upcase table and copy it into the linear buffer. */
1663 read_partial_upcase_page: 1663 read_partial_upcase_page:
1664 page = ntfs_map_page(ino->i_mapping, index); 1664 page = ntfs_map_page(ino->i_mapping, index);
1665 if (IS_ERR(page)) 1665 if (IS_ERR(page))
1666 goto iput_upcase_failed; 1666 goto iput_upcase_failed;
1667 memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT), 1667 memcpy((char*)vol->upcase + (index++ << PAGE_CACHE_SHIFT),
1668 page_address(page), size); 1668 page_address(page), size);
1669 ntfs_unmap_page(page); 1669 ntfs_unmap_page(page);
1670 }; 1670 };
1671 if (size == PAGE_CACHE_SIZE) { 1671 if (size == PAGE_CACHE_SIZE) {
1672 size = i_size & ~PAGE_CACHE_MASK; 1672 size = i_size & ~PAGE_CACHE_MASK;
1673 if (size) 1673 if (size)
1674 goto read_partial_upcase_page; 1674 goto read_partial_upcase_page;
1675 } 1675 }
1676 vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS; 1676 vol->upcase_len = i_size >> UCHAR_T_SIZE_BITS;
1677 ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).", 1677 ntfs_debug("Read %llu bytes from $UpCase (expected %zu bytes).",
1678 i_size, 64 * 1024 * sizeof(ntfschar)); 1678 i_size, 64 * 1024 * sizeof(ntfschar));
1679 iput(ino); 1679 iput(ino);
1680 mutex_lock(&ntfs_lock); 1680 mutex_lock(&ntfs_lock);
1681 if (!default_upcase) { 1681 if (!default_upcase) {
1682 ntfs_debug("Using volume specified $UpCase since default is " 1682 ntfs_debug("Using volume specified $UpCase since default is "
1683 "not present."); 1683 "not present.");
1684 mutex_unlock(&ntfs_lock); 1684 mutex_unlock(&ntfs_lock);
1685 return true; 1685 return true;
1686 } 1686 }
1687 max = default_upcase_len; 1687 max = default_upcase_len;
1688 if (max > vol->upcase_len) 1688 if (max > vol->upcase_len)
1689 max = vol->upcase_len; 1689 max = vol->upcase_len;
1690 for (i = 0; i < max; i++) 1690 for (i = 0; i < max; i++)
1691 if (vol->upcase[i] != default_upcase[i]) 1691 if (vol->upcase[i] != default_upcase[i])
1692 break; 1692 break;
1693 if (i == max) { 1693 if (i == max) {
1694 ntfs_free(vol->upcase); 1694 ntfs_free(vol->upcase);
1695 vol->upcase = default_upcase; 1695 vol->upcase = default_upcase;
1696 vol->upcase_len = max; 1696 vol->upcase_len = max;
1697 ntfs_nr_upcase_users++; 1697 ntfs_nr_upcase_users++;
1698 mutex_unlock(&ntfs_lock); 1698 mutex_unlock(&ntfs_lock);
1699 ntfs_debug("Volume specified $UpCase matches default. Using " 1699 ntfs_debug("Volume specified $UpCase matches default. Using "
1700 "default."); 1700 "default.");
1701 return true; 1701 return true;
1702 } 1702 }
1703 mutex_unlock(&ntfs_lock); 1703 mutex_unlock(&ntfs_lock);
1704 ntfs_debug("Using volume specified $UpCase since it does not match " 1704 ntfs_debug("Using volume specified $UpCase since it does not match "
1705 "the default."); 1705 "the default.");
1706 return true; 1706 return true;
1707 iput_upcase_failed: 1707 iput_upcase_failed:
1708 iput(ino); 1708 iput(ino);
1709 ntfs_free(vol->upcase); 1709 ntfs_free(vol->upcase);
1710 vol->upcase = NULL; 1710 vol->upcase = NULL;
1711 upcase_failed: 1711 upcase_failed:
1712 mutex_lock(&ntfs_lock); 1712 mutex_lock(&ntfs_lock);
1713 if (default_upcase) { 1713 if (default_upcase) {
1714 vol->upcase = default_upcase; 1714 vol->upcase = default_upcase;
1715 vol->upcase_len = default_upcase_len; 1715 vol->upcase_len = default_upcase_len;
1716 ntfs_nr_upcase_users++; 1716 ntfs_nr_upcase_users++;
1717 mutex_unlock(&ntfs_lock); 1717 mutex_unlock(&ntfs_lock);
1718 ntfs_error(sb, "Failed to load $UpCase from the volume. Using " 1718 ntfs_error(sb, "Failed to load $UpCase from the volume. Using "
1719 "default."); 1719 "default.");
1720 return true; 1720 return true;
1721 } 1721 }
1722 mutex_unlock(&ntfs_lock); 1722 mutex_unlock(&ntfs_lock);
1723 ntfs_error(sb, "Failed to initialize upcase table."); 1723 ntfs_error(sb, "Failed to initialize upcase table.");
1724 return false; 1724 return false;
1725 } 1725 }
1726 1726
1727 /* 1727 /*
1728 * The lcn and mft bitmap inodes are NTFS-internal inodes with 1728 * The lcn and mft bitmap inodes are NTFS-internal inodes with
1729 * their own special locking rules: 1729 * their own special locking rules:
1730 */ 1730 */
1731 static struct lock_class_key 1731 static struct lock_class_key
1732 lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key, 1732 lcnbmp_runlist_lock_key, lcnbmp_mrec_lock_key,
1733 mftbmp_runlist_lock_key, mftbmp_mrec_lock_key; 1733 mftbmp_runlist_lock_key, mftbmp_mrec_lock_key;
1734 1734
1735 /** 1735 /**
1736 * load_system_files - open the system files using normal functions 1736 * load_system_files - open the system files using normal functions
1737 * @vol: ntfs super block describing device whose system files to load 1737 * @vol: ntfs super block describing device whose system files to load
1738 * 1738 *
1739 * Open the system files with normal access functions and complete setting up 1739 * Open the system files with normal access functions and complete setting up
1740 * the ntfs super block @vol. 1740 * the ntfs super block @vol.
1741 * 1741 *
1742 * Return 'true' on success or 'false' on error. 1742 * Return 'true' on success or 'false' on error.
1743 */ 1743 */
1744 static bool load_system_files(ntfs_volume *vol) 1744 static bool load_system_files(ntfs_volume *vol)
1745 { 1745 {
1746 struct super_block *sb = vol->sb; 1746 struct super_block *sb = vol->sb;
1747 MFT_RECORD *m; 1747 MFT_RECORD *m;
1748 VOLUME_INFORMATION *vi; 1748 VOLUME_INFORMATION *vi;
1749 ntfs_attr_search_ctx *ctx; 1749 ntfs_attr_search_ctx *ctx;
1750 #ifdef NTFS_RW 1750 #ifdef NTFS_RW
1751 RESTART_PAGE_HEADER *rp; 1751 RESTART_PAGE_HEADER *rp;
1752 int err; 1752 int err;
1753 #endif /* NTFS_RW */ 1753 #endif /* NTFS_RW */
1754 1754
1755 ntfs_debug("Entering."); 1755 ntfs_debug("Entering.");
1756 #ifdef NTFS_RW 1756 #ifdef NTFS_RW
1757 /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */ 1757 /* Get mft mirror inode compare the contents of $MFT and $MFTMirr. */
1758 if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) { 1758 if (!load_and_init_mft_mirror(vol) || !check_mft_mirror(vol)) {
1759 static const char *es1 = "Failed to load $MFTMirr"; 1759 static const char *es1 = "Failed to load $MFTMirr";
1760 static const char *es2 = "$MFTMirr does not match $MFT"; 1760 static const char *es2 = "$MFTMirr does not match $MFT";
1761 static const char *es3 = ". Run ntfsfix and/or chkdsk."; 1761 static const char *es3 = ". Run ntfsfix and/or chkdsk.";
1762 1762
1763 /* If a read-write mount, convert it to a read-only mount. */ 1763 /* If a read-write mount, convert it to a read-only mount. */
1764 if (!(sb->s_flags & MS_RDONLY)) { 1764 if (!(sb->s_flags & MS_RDONLY)) {
1765 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 1765 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1766 ON_ERRORS_CONTINUE))) { 1766 ON_ERRORS_CONTINUE))) {
1767 ntfs_error(sb, "%s and neither on_errors=" 1767 ntfs_error(sb, "%s and neither on_errors="
1768 "continue nor on_errors=" 1768 "continue nor on_errors="
1769 "remount-ro was specified%s", 1769 "remount-ro was specified%s",
1770 !vol->mftmirr_ino ? es1 : es2, 1770 !vol->mftmirr_ino ? es1 : es2,
1771 es3); 1771 es3);
1772 goto iput_mirr_err_out; 1772 goto iput_mirr_err_out;
1773 } 1773 }
1774 sb->s_flags |= MS_RDONLY; 1774 sb->s_flags |= MS_RDONLY;
1775 ntfs_error(sb, "%s. Mounting read-only%s", 1775 ntfs_error(sb, "%s. Mounting read-only%s",
1776 !vol->mftmirr_ino ? es1 : es2, es3); 1776 !vol->mftmirr_ino ? es1 : es2, es3);
1777 } else 1777 } else
1778 ntfs_warning(sb, "%s. Will not be able to remount " 1778 ntfs_warning(sb, "%s. Will not be able to remount "
1779 "read-write%s", 1779 "read-write%s",
1780 !vol->mftmirr_ino ? es1 : es2, es3); 1780 !vol->mftmirr_ino ? es1 : es2, es3);
1781 /* This will prevent a read-write remount. */ 1781 /* This will prevent a read-write remount. */
1782 NVolSetErrors(vol); 1782 NVolSetErrors(vol);
1783 } 1783 }
1784 #endif /* NTFS_RW */ 1784 #endif /* NTFS_RW */
1785 /* Get mft bitmap attribute inode. */ 1785 /* Get mft bitmap attribute inode. */
1786 vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0); 1786 vol->mftbmp_ino = ntfs_attr_iget(vol->mft_ino, AT_BITMAP, NULL, 0);
1787 if (IS_ERR(vol->mftbmp_ino)) { 1787 if (IS_ERR(vol->mftbmp_ino)) {
1788 ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute."); 1788 ntfs_error(sb, "Failed to load $MFT/$BITMAP attribute.");
1789 goto iput_mirr_err_out; 1789 goto iput_mirr_err_out;
1790 } 1790 }
1791 lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->runlist.lock, 1791 lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->runlist.lock,
1792 &mftbmp_runlist_lock_key); 1792 &mftbmp_runlist_lock_key);
1793 lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->mrec_lock, 1793 lockdep_set_class(&NTFS_I(vol->mftbmp_ino)->mrec_lock,
1794 &mftbmp_mrec_lock_key); 1794 &mftbmp_mrec_lock_key);
1795 /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */ 1795 /* Read upcase table and setup @vol->upcase and @vol->upcase_len. */
1796 if (!load_and_init_upcase(vol)) 1796 if (!load_and_init_upcase(vol))
1797 goto iput_mftbmp_err_out; 1797 goto iput_mftbmp_err_out;
1798 #ifdef NTFS_RW 1798 #ifdef NTFS_RW
1799 /* 1799 /*
1800 * Read attribute definitions table and setup @vol->attrdef and 1800 * Read attribute definitions table and setup @vol->attrdef and
1801 * @vol->attrdef_size. 1801 * @vol->attrdef_size.
1802 */ 1802 */
1803 if (!load_and_init_attrdef(vol)) 1803 if (!load_and_init_attrdef(vol))
1804 goto iput_upcase_err_out; 1804 goto iput_upcase_err_out;
1805 #endif /* NTFS_RW */ 1805 #endif /* NTFS_RW */
1806 /* 1806 /*
1807 * Get the cluster allocation bitmap inode and verify the size, no 1807 * Get the cluster allocation bitmap inode and verify the size, no
1808 * need for any locking at this stage as we are already running 1808 * need for any locking at this stage as we are already running
1809 * exclusively as we are mount in progress task. 1809 * exclusively as we are mount in progress task.
1810 */ 1810 */
1811 vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap); 1811 vol->lcnbmp_ino = ntfs_iget(sb, FILE_Bitmap);
1812 if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) { 1812 if (IS_ERR(vol->lcnbmp_ino) || is_bad_inode(vol->lcnbmp_ino)) {
1813 if (!IS_ERR(vol->lcnbmp_ino)) 1813 if (!IS_ERR(vol->lcnbmp_ino))
1814 iput(vol->lcnbmp_ino); 1814 iput(vol->lcnbmp_ino);
1815 goto bitmap_failed; 1815 goto bitmap_failed;
1816 } 1816 }
1817 lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->runlist.lock, 1817 lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->runlist.lock,
1818 &lcnbmp_runlist_lock_key); 1818 &lcnbmp_runlist_lock_key);
1819 lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->mrec_lock, 1819 lockdep_set_class(&NTFS_I(vol->lcnbmp_ino)->mrec_lock,
1820 &lcnbmp_mrec_lock_key); 1820 &lcnbmp_mrec_lock_key);
1821 1821
1822 NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino)); 1822 NInoSetSparseDisabled(NTFS_I(vol->lcnbmp_ino));
1823 if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) { 1823 if ((vol->nr_clusters + 7) >> 3 > i_size_read(vol->lcnbmp_ino)) {
1824 iput(vol->lcnbmp_ino); 1824 iput(vol->lcnbmp_ino);
1825 bitmap_failed: 1825 bitmap_failed:
1826 ntfs_error(sb, "Failed to load $Bitmap."); 1826 ntfs_error(sb, "Failed to load $Bitmap.");
1827 goto iput_attrdef_err_out; 1827 goto iput_attrdef_err_out;
1828 } 1828 }
1829 /* 1829 /*
1830 * Get the volume inode and setup our cache of the volume flags and 1830 * Get the volume inode and setup our cache of the volume flags and
1831 * version. 1831 * version.
1832 */ 1832 */
1833 vol->vol_ino = ntfs_iget(sb, FILE_Volume); 1833 vol->vol_ino = ntfs_iget(sb, FILE_Volume);
1834 if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) { 1834 if (IS_ERR(vol->vol_ino) || is_bad_inode(vol->vol_ino)) {
1835 if (!IS_ERR(vol->vol_ino)) 1835 if (!IS_ERR(vol->vol_ino))
1836 iput(vol->vol_ino); 1836 iput(vol->vol_ino);
1837 volume_failed: 1837 volume_failed:
1838 ntfs_error(sb, "Failed to load $Volume."); 1838 ntfs_error(sb, "Failed to load $Volume.");
1839 goto iput_lcnbmp_err_out; 1839 goto iput_lcnbmp_err_out;
1840 } 1840 }
1841 m = map_mft_record(NTFS_I(vol->vol_ino)); 1841 m = map_mft_record(NTFS_I(vol->vol_ino));
1842 if (IS_ERR(m)) { 1842 if (IS_ERR(m)) {
1843 iput_volume_failed: 1843 iput_volume_failed:
1844 iput(vol->vol_ino); 1844 iput(vol->vol_ino);
1845 goto volume_failed; 1845 goto volume_failed;
1846 } 1846 }
1847 if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) { 1847 if (!(ctx = ntfs_attr_get_search_ctx(NTFS_I(vol->vol_ino), m))) {
1848 ntfs_error(sb, "Failed to get attribute search context."); 1848 ntfs_error(sb, "Failed to get attribute search context.");
1849 goto get_ctx_vol_failed; 1849 goto get_ctx_vol_failed;
1850 } 1850 }
1851 if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0, 1851 if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
1852 ctx) || ctx->attr->non_resident || ctx->attr->flags) { 1852 ctx) || ctx->attr->non_resident || ctx->attr->flags) {
1853 err_put_vol: 1853 err_put_vol:
1854 ntfs_attr_put_search_ctx(ctx); 1854 ntfs_attr_put_search_ctx(ctx);
1855 get_ctx_vol_failed: 1855 get_ctx_vol_failed:
1856 unmap_mft_record(NTFS_I(vol->vol_ino)); 1856 unmap_mft_record(NTFS_I(vol->vol_ino));
1857 goto iput_volume_failed; 1857 goto iput_volume_failed;
1858 } 1858 }
1859 vi = (VOLUME_INFORMATION*)((char*)ctx->attr + 1859 vi = (VOLUME_INFORMATION*)((char*)ctx->attr +
1860 le16_to_cpu(ctx->attr->data.resident.value_offset)); 1860 le16_to_cpu(ctx->attr->data.resident.value_offset));
1861 /* Some bounds checks. */ 1861 /* Some bounds checks. */
1862 if ((u8*)vi < (u8*)ctx->attr || (u8*)vi + 1862 if ((u8*)vi < (u8*)ctx->attr || (u8*)vi +
1863 le32_to_cpu(ctx->attr->data.resident.value_length) > 1863 le32_to_cpu(ctx->attr->data.resident.value_length) >
1864 (u8*)ctx->attr + le32_to_cpu(ctx->attr->length)) 1864 (u8*)ctx->attr + le32_to_cpu(ctx->attr->length))
1865 goto err_put_vol; 1865 goto err_put_vol;
1866 /* Copy the volume flags and version to the ntfs_volume structure. */ 1866 /* Copy the volume flags and version to the ntfs_volume structure. */
1867 vol->vol_flags = vi->flags; 1867 vol->vol_flags = vi->flags;
1868 vol->major_ver = vi->major_ver; 1868 vol->major_ver = vi->major_ver;
1869 vol->minor_ver = vi->minor_ver; 1869 vol->minor_ver = vi->minor_ver;
1870 ntfs_attr_put_search_ctx(ctx); 1870 ntfs_attr_put_search_ctx(ctx);
1871 unmap_mft_record(NTFS_I(vol->vol_ino)); 1871 unmap_mft_record(NTFS_I(vol->vol_ino));
1872 printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver, 1872 printk(KERN_INFO "NTFS volume version %i.%i.\n", vol->major_ver,
1873 vol->minor_ver); 1873 vol->minor_ver);
1874 if (vol->major_ver < 3 && NVolSparseEnabled(vol)) { 1874 if (vol->major_ver < 3 && NVolSparseEnabled(vol)) {
1875 ntfs_warning(vol->sb, "Disabling sparse support due to NTFS " 1875 ntfs_warning(vol->sb, "Disabling sparse support due to NTFS "
1876 "volume version %i.%i (need at least version " 1876 "volume version %i.%i (need at least version "
1877 "3.0).", vol->major_ver, vol->minor_ver); 1877 "3.0).", vol->major_ver, vol->minor_ver);
1878 NVolClearSparseEnabled(vol); 1878 NVolClearSparseEnabled(vol);
1879 } 1879 }
1880 #ifdef NTFS_RW 1880 #ifdef NTFS_RW
1881 /* Make sure that no unsupported volume flags are set. */ 1881 /* Make sure that no unsupported volume flags are set. */
1882 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) { 1882 if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
1883 static const char *es1a = "Volume is dirty"; 1883 static const char *es1a = "Volume is dirty";
1884 static const char *es1b = "Volume has been modified by chkdsk"; 1884 static const char *es1b = "Volume has been modified by chkdsk";
1885 static const char *es1c = "Volume has unsupported flags set"; 1885 static const char *es1c = "Volume has unsupported flags set";
1886 static const char *es2a = ". Run chkdsk and mount in Windows."; 1886 static const char *es2a = ". Run chkdsk and mount in Windows.";
1887 static const char *es2b = ". Mount in Windows."; 1887 static const char *es2b = ". Mount in Windows.";
1888 const char *es1, *es2; 1888 const char *es1, *es2;
1889 1889
1890 es2 = es2a; 1890 es2 = es2a;
1891 if (vol->vol_flags & VOLUME_IS_DIRTY) 1891 if (vol->vol_flags & VOLUME_IS_DIRTY)
1892 es1 = es1a; 1892 es1 = es1a;
1893 else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) { 1893 else if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
1894 es1 = es1b; 1894 es1 = es1b;
1895 es2 = es2b; 1895 es2 = es2b;
1896 } else { 1896 } else {
1897 es1 = es1c; 1897 es1 = es1c;
1898 ntfs_warning(sb, "Unsupported volume flags 0x%x " 1898 ntfs_warning(sb, "Unsupported volume flags 0x%x "
1899 "encountered.", 1899 "encountered.",
1900 (unsigned)le16_to_cpu(vol->vol_flags)); 1900 (unsigned)le16_to_cpu(vol->vol_flags));
1901 } 1901 }
1902 /* If a read-write mount, convert it to a read-only mount. */ 1902 /* If a read-write mount, convert it to a read-only mount. */
1903 if (!(sb->s_flags & MS_RDONLY)) { 1903 if (!(sb->s_flags & MS_RDONLY)) {
1904 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 1904 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1905 ON_ERRORS_CONTINUE))) { 1905 ON_ERRORS_CONTINUE))) {
1906 ntfs_error(sb, "%s and neither on_errors=" 1906 ntfs_error(sb, "%s and neither on_errors="
1907 "continue nor on_errors=" 1907 "continue nor on_errors="
1908 "remount-ro was specified%s", 1908 "remount-ro was specified%s",
1909 es1, es2); 1909 es1, es2);
1910 goto iput_vol_err_out; 1910 goto iput_vol_err_out;
1911 } 1911 }
1912 sb->s_flags |= MS_RDONLY; 1912 sb->s_flags |= MS_RDONLY;
1913 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 1913 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1914 } else 1914 } else
1915 ntfs_warning(sb, "%s. Will not be able to remount " 1915 ntfs_warning(sb, "%s. Will not be able to remount "
1916 "read-write%s", es1, es2); 1916 "read-write%s", es1, es2);
1917 /* 1917 /*
1918 * Do not set NVolErrors() because ntfs_remount() re-checks the 1918 * Do not set NVolErrors() because ntfs_remount() re-checks the
1919 * flags which we need to do in case any flags have changed. 1919 * flags which we need to do in case any flags have changed.
1920 */ 1920 */
1921 } 1921 }
1922 /* 1922 /*
1923 * Get the inode for the logfile, check it and determine if the volume 1923 * Get the inode for the logfile, check it and determine if the volume
1924 * was shutdown cleanly. 1924 * was shutdown cleanly.
1925 */ 1925 */
1926 rp = NULL; 1926 rp = NULL;
1927 if (!load_and_check_logfile(vol, &rp) || 1927 if (!load_and_check_logfile(vol, &rp) ||
1928 !ntfs_is_logfile_clean(vol->logfile_ino, rp)) { 1928 !ntfs_is_logfile_clean(vol->logfile_ino, rp)) {
1929 static const char *es1a = "Failed to load $LogFile"; 1929 static const char *es1a = "Failed to load $LogFile";
1930 static const char *es1b = "$LogFile is not clean"; 1930 static const char *es1b = "$LogFile is not clean";
1931 static const char *es2 = ". Mount in Windows."; 1931 static const char *es2 = ". Mount in Windows.";
1932 const char *es1; 1932 const char *es1;
1933 1933
1934 es1 = !vol->logfile_ino ? es1a : es1b; 1934 es1 = !vol->logfile_ino ? es1a : es1b;
1935 /* If a read-write mount, convert it to a read-only mount. */ 1935 /* If a read-write mount, convert it to a read-only mount. */
1936 if (!(sb->s_flags & MS_RDONLY)) { 1936 if (!(sb->s_flags & MS_RDONLY)) {
1937 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 1937 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1938 ON_ERRORS_CONTINUE))) { 1938 ON_ERRORS_CONTINUE))) {
1939 ntfs_error(sb, "%s and neither on_errors=" 1939 ntfs_error(sb, "%s and neither on_errors="
1940 "continue nor on_errors=" 1940 "continue nor on_errors="
1941 "remount-ro was specified%s", 1941 "remount-ro was specified%s",
1942 es1, es2); 1942 es1, es2);
1943 if (vol->logfile_ino) { 1943 if (vol->logfile_ino) {
1944 BUG_ON(!rp); 1944 BUG_ON(!rp);
1945 ntfs_free(rp); 1945 ntfs_free(rp);
1946 } 1946 }
1947 goto iput_logfile_err_out; 1947 goto iput_logfile_err_out;
1948 } 1948 }
1949 sb->s_flags |= MS_RDONLY; 1949 sb->s_flags |= MS_RDONLY;
1950 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 1950 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1951 } else 1951 } else
1952 ntfs_warning(sb, "%s. Will not be able to remount " 1952 ntfs_warning(sb, "%s. Will not be able to remount "
1953 "read-write%s", es1, es2); 1953 "read-write%s", es1, es2);
1954 /* This will prevent a read-write remount. */ 1954 /* This will prevent a read-write remount. */
1955 NVolSetErrors(vol); 1955 NVolSetErrors(vol);
1956 } 1956 }
1957 ntfs_free(rp); 1957 ntfs_free(rp);
1958 #endif /* NTFS_RW */ 1958 #endif /* NTFS_RW */
1959 /* Get the root directory inode so we can do path lookups. */ 1959 /* Get the root directory inode so we can do path lookups. */
1960 vol->root_ino = ntfs_iget(sb, FILE_root); 1960 vol->root_ino = ntfs_iget(sb, FILE_root);
1961 if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) { 1961 if (IS_ERR(vol->root_ino) || is_bad_inode(vol->root_ino)) {
1962 if (!IS_ERR(vol->root_ino)) 1962 if (!IS_ERR(vol->root_ino))
1963 iput(vol->root_ino); 1963 iput(vol->root_ino);
1964 ntfs_error(sb, "Failed to load root directory."); 1964 ntfs_error(sb, "Failed to load root directory.");
1965 goto iput_logfile_err_out; 1965 goto iput_logfile_err_out;
1966 } 1966 }
1967 #ifdef NTFS_RW 1967 #ifdef NTFS_RW
1968 /* 1968 /*
1969 * Check if Windows is suspended to disk on the target volume. If it 1969 * Check if Windows is suspended to disk on the target volume. If it
1970 * is hibernated, we must not write *anything* to the disk so set 1970 * is hibernated, we must not write *anything* to the disk so set
1971 * NVolErrors() without setting the dirty volume flag and mount 1971 * NVolErrors() without setting the dirty volume flag and mount
1972 * read-only. This will prevent read-write remounting and it will also 1972 * read-only. This will prevent read-write remounting and it will also
1973 * prevent all writes. 1973 * prevent all writes.
1974 */ 1974 */
1975 err = check_windows_hibernation_status(vol); 1975 err = check_windows_hibernation_status(vol);
1976 if (unlikely(err)) { 1976 if (unlikely(err)) {
1977 static const char *es1a = "Failed to determine if Windows is " 1977 static const char *es1a = "Failed to determine if Windows is "
1978 "hibernated"; 1978 "hibernated";
1979 static const char *es1b = "Windows is hibernated"; 1979 static const char *es1b = "Windows is hibernated";
1980 static const char *es2 = ". Run chkdsk."; 1980 static const char *es2 = ". Run chkdsk.";
1981 const char *es1; 1981 const char *es1;
1982 1982
1983 es1 = err < 0 ? es1a : es1b; 1983 es1 = err < 0 ? es1a : es1b;
1984 /* If a read-write mount, convert it to a read-only mount. */ 1984 /* If a read-write mount, convert it to a read-only mount. */
1985 if (!(sb->s_flags & MS_RDONLY)) { 1985 if (!(sb->s_flags & MS_RDONLY)) {
1986 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 1986 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
1987 ON_ERRORS_CONTINUE))) { 1987 ON_ERRORS_CONTINUE))) {
1988 ntfs_error(sb, "%s and neither on_errors=" 1988 ntfs_error(sb, "%s and neither on_errors="
1989 "continue nor on_errors=" 1989 "continue nor on_errors="
1990 "remount-ro was specified%s", 1990 "remount-ro was specified%s",
1991 es1, es2); 1991 es1, es2);
1992 goto iput_root_err_out; 1992 goto iput_root_err_out;
1993 } 1993 }
1994 sb->s_flags |= MS_RDONLY; 1994 sb->s_flags |= MS_RDONLY;
1995 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 1995 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
1996 } else 1996 } else
1997 ntfs_warning(sb, "%s. Will not be able to remount " 1997 ntfs_warning(sb, "%s. Will not be able to remount "
1998 "read-write%s", es1, es2); 1998 "read-write%s", es1, es2);
1999 /* This will prevent a read-write remount. */ 1999 /* This will prevent a read-write remount. */
2000 NVolSetErrors(vol); 2000 NVolSetErrors(vol);
2001 } 2001 }
2002 /* If (still) a read-write mount, mark the volume dirty. */ 2002 /* If (still) a read-write mount, mark the volume dirty. */
2003 if (!(sb->s_flags & MS_RDONLY) && 2003 if (!(sb->s_flags & MS_RDONLY) &&
2004 ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) { 2004 ntfs_set_volume_flags(vol, VOLUME_IS_DIRTY)) {
2005 static const char *es1 = "Failed to set dirty bit in volume " 2005 static const char *es1 = "Failed to set dirty bit in volume "
2006 "information flags"; 2006 "information flags";
2007 static const char *es2 = ". Run chkdsk."; 2007 static const char *es2 = ". Run chkdsk.";
2008 2008
2009 /* Convert to a read-only mount. */ 2009 /* Convert to a read-only mount. */
2010 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2010 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2011 ON_ERRORS_CONTINUE))) { 2011 ON_ERRORS_CONTINUE))) {
2012 ntfs_error(sb, "%s and neither on_errors=continue nor " 2012 ntfs_error(sb, "%s and neither on_errors=continue nor "
2013 "on_errors=remount-ro was specified%s", 2013 "on_errors=remount-ro was specified%s",
2014 es1, es2); 2014 es1, es2);
2015 goto iput_root_err_out; 2015 goto iput_root_err_out;
2016 } 2016 }
2017 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2017 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2018 sb->s_flags |= MS_RDONLY; 2018 sb->s_flags |= MS_RDONLY;
2019 /* 2019 /*
2020 * Do not set NVolErrors() because ntfs_remount() might manage 2020 * Do not set NVolErrors() because ntfs_remount() might manage
2021 * to set the dirty flag in which case all would be well. 2021 * to set the dirty flag in which case all would be well.
2022 */ 2022 */
2023 } 2023 }
2024 #if 0 2024 #if 0
2025 // TODO: Enable this code once we start modifying anything that is 2025 // TODO: Enable this code once we start modifying anything that is
2026 // different between NTFS 1.2 and 3.x... 2026 // different between NTFS 1.2 and 3.x...
2027 /* 2027 /*
2028 * If (still) a read-write mount, set the NT4 compatibility flag on 2028 * If (still) a read-write mount, set the NT4 compatibility flag on
2029 * newer NTFS version volumes. 2029 * newer NTFS version volumes.
2030 */ 2030 */
2031 if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) && 2031 if (!(sb->s_flags & MS_RDONLY) && (vol->major_ver > 1) &&
2032 ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) { 2032 ntfs_set_volume_flags(vol, VOLUME_MOUNTED_ON_NT4)) {
2033 static const char *es1 = "Failed to set NT4 compatibility flag"; 2033 static const char *es1 = "Failed to set NT4 compatibility flag";
2034 static const char *es2 = ". Run chkdsk."; 2034 static const char *es2 = ". Run chkdsk.";
2035 2035
2036 /* Convert to a read-only mount. */ 2036 /* Convert to a read-only mount. */
2037 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2037 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2038 ON_ERRORS_CONTINUE))) { 2038 ON_ERRORS_CONTINUE))) {
2039 ntfs_error(sb, "%s and neither on_errors=continue nor " 2039 ntfs_error(sb, "%s and neither on_errors=continue nor "
2040 "on_errors=remount-ro was specified%s", 2040 "on_errors=remount-ro was specified%s",
2041 es1, es2); 2041 es1, es2);
2042 goto iput_root_err_out; 2042 goto iput_root_err_out;
2043 } 2043 }
2044 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2044 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2045 sb->s_flags |= MS_RDONLY; 2045 sb->s_flags |= MS_RDONLY;
2046 NVolSetErrors(vol); 2046 NVolSetErrors(vol);
2047 } 2047 }
2048 #endif 2048 #endif
2049 /* If (still) a read-write mount, empty the logfile. */ 2049 /* If (still) a read-write mount, empty the logfile. */
2050 if (!(sb->s_flags & MS_RDONLY) && 2050 if (!(sb->s_flags & MS_RDONLY) &&
2051 !ntfs_empty_logfile(vol->logfile_ino)) { 2051 !ntfs_empty_logfile(vol->logfile_ino)) {
2052 static const char *es1 = "Failed to empty $LogFile"; 2052 static const char *es1 = "Failed to empty $LogFile";
2053 static const char *es2 = ". Mount in Windows."; 2053 static const char *es2 = ". Mount in Windows.";
2054 2054
2055 /* Convert to a read-only mount. */ 2055 /* Convert to a read-only mount. */
2056 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2056 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2057 ON_ERRORS_CONTINUE))) { 2057 ON_ERRORS_CONTINUE))) {
2058 ntfs_error(sb, "%s and neither on_errors=continue nor " 2058 ntfs_error(sb, "%s and neither on_errors=continue nor "
2059 "on_errors=remount-ro was specified%s", 2059 "on_errors=remount-ro was specified%s",
2060 es1, es2); 2060 es1, es2);
2061 goto iput_root_err_out; 2061 goto iput_root_err_out;
2062 } 2062 }
2063 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2063 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2064 sb->s_flags |= MS_RDONLY; 2064 sb->s_flags |= MS_RDONLY;
2065 NVolSetErrors(vol); 2065 NVolSetErrors(vol);
2066 } 2066 }
2067 #endif /* NTFS_RW */ 2067 #endif /* NTFS_RW */
2068 /* If on NTFS versions before 3.0, we are done. */ 2068 /* If on NTFS versions before 3.0, we are done. */
2069 if (unlikely(vol->major_ver < 3)) 2069 if (unlikely(vol->major_ver < 3))
2070 return true; 2070 return true;
2071 /* NTFS 3.0+ specific initialization. */ 2071 /* NTFS 3.0+ specific initialization. */
2072 /* Get the security descriptors inode. */ 2072 /* Get the security descriptors inode. */
2073 vol->secure_ino = ntfs_iget(sb, FILE_Secure); 2073 vol->secure_ino = ntfs_iget(sb, FILE_Secure);
2074 if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) { 2074 if (IS_ERR(vol->secure_ino) || is_bad_inode(vol->secure_ino)) {
2075 if (!IS_ERR(vol->secure_ino)) 2075 if (!IS_ERR(vol->secure_ino))
2076 iput(vol->secure_ino); 2076 iput(vol->secure_ino);
2077 ntfs_error(sb, "Failed to load $Secure."); 2077 ntfs_error(sb, "Failed to load $Secure.");
2078 goto iput_root_err_out; 2078 goto iput_root_err_out;
2079 } 2079 }
2080 // TODO: Initialize security. 2080 // TODO: Initialize security.
2081 /* Get the extended system files' directory inode. */ 2081 /* Get the extended system files' directory inode. */
2082 vol->extend_ino = ntfs_iget(sb, FILE_Extend); 2082 vol->extend_ino = ntfs_iget(sb, FILE_Extend);
2083 if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) { 2083 if (IS_ERR(vol->extend_ino) || is_bad_inode(vol->extend_ino)) {
2084 if (!IS_ERR(vol->extend_ino)) 2084 if (!IS_ERR(vol->extend_ino))
2085 iput(vol->extend_ino); 2085 iput(vol->extend_ino);
2086 ntfs_error(sb, "Failed to load $Extend."); 2086 ntfs_error(sb, "Failed to load $Extend.");
2087 goto iput_sec_err_out; 2087 goto iput_sec_err_out;
2088 } 2088 }
2089 #ifdef NTFS_RW 2089 #ifdef NTFS_RW
2090 /* Find the quota file, load it if present, and set it up. */ 2090 /* Find the quota file, load it if present, and set it up. */
2091 if (!load_and_init_quota(vol)) { 2091 if (!load_and_init_quota(vol)) {
2092 static const char *es1 = "Failed to load $Quota"; 2092 static const char *es1 = "Failed to load $Quota";
2093 static const char *es2 = ". Run chkdsk."; 2093 static const char *es2 = ". Run chkdsk.";
2094 2094
2095 /* If a read-write mount, convert it to a read-only mount. */ 2095 /* If a read-write mount, convert it to a read-only mount. */
2096 if (!(sb->s_flags & MS_RDONLY)) { 2096 if (!(sb->s_flags & MS_RDONLY)) {
2097 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2097 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2098 ON_ERRORS_CONTINUE))) { 2098 ON_ERRORS_CONTINUE))) {
2099 ntfs_error(sb, "%s and neither on_errors=" 2099 ntfs_error(sb, "%s and neither on_errors="
2100 "continue nor on_errors=" 2100 "continue nor on_errors="
2101 "remount-ro was specified%s", 2101 "remount-ro was specified%s",
2102 es1, es2); 2102 es1, es2);
2103 goto iput_quota_err_out; 2103 goto iput_quota_err_out;
2104 } 2104 }
2105 sb->s_flags |= MS_RDONLY; 2105 sb->s_flags |= MS_RDONLY;
2106 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2106 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2107 } else 2107 } else
2108 ntfs_warning(sb, "%s. Will not be able to remount " 2108 ntfs_warning(sb, "%s. Will not be able to remount "
2109 "read-write%s", es1, es2); 2109 "read-write%s", es1, es2);
2110 /* This will prevent a read-write remount. */ 2110 /* This will prevent a read-write remount. */
2111 NVolSetErrors(vol); 2111 NVolSetErrors(vol);
2112 } 2112 }
2113 /* If (still) a read-write mount, mark the quotas out of date. */ 2113 /* If (still) a read-write mount, mark the quotas out of date. */
2114 if (!(sb->s_flags & MS_RDONLY) && 2114 if (!(sb->s_flags & MS_RDONLY) &&
2115 !ntfs_mark_quotas_out_of_date(vol)) { 2115 !ntfs_mark_quotas_out_of_date(vol)) {
2116 static const char *es1 = "Failed to mark quotas out of date"; 2116 static const char *es1 = "Failed to mark quotas out of date";
2117 static const char *es2 = ". Run chkdsk."; 2117 static const char *es2 = ". Run chkdsk.";
2118 2118
2119 /* Convert to a read-only mount. */ 2119 /* Convert to a read-only mount. */
2120 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2120 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2121 ON_ERRORS_CONTINUE))) { 2121 ON_ERRORS_CONTINUE))) {
2122 ntfs_error(sb, "%s and neither on_errors=continue nor " 2122 ntfs_error(sb, "%s and neither on_errors=continue nor "
2123 "on_errors=remount-ro was specified%s", 2123 "on_errors=remount-ro was specified%s",
2124 es1, es2); 2124 es1, es2);
2125 goto iput_quota_err_out; 2125 goto iput_quota_err_out;
2126 } 2126 }
2127 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2127 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2128 sb->s_flags |= MS_RDONLY; 2128 sb->s_flags |= MS_RDONLY;
2129 NVolSetErrors(vol); 2129 NVolSetErrors(vol);
2130 } 2130 }
2131 /* 2131 /*
2132 * Find the transaction log file ($UsnJrnl), load it if present, check 2132 * Find the transaction log file ($UsnJrnl), load it if present, check
2133 * it, and set it up. 2133 * it, and set it up.
2134 */ 2134 */
2135 if (!load_and_init_usnjrnl(vol)) { 2135 if (!load_and_init_usnjrnl(vol)) {
2136 static const char *es1 = "Failed to load $UsnJrnl"; 2136 static const char *es1 = "Failed to load $UsnJrnl";
2137 static const char *es2 = ". Run chkdsk."; 2137 static const char *es2 = ". Run chkdsk.";
2138 2138
2139 /* If a read-write mount, convert it to a read-only mount. */ 2139 /* If a read-write mount, convert it to a read-only mount. */
2140 if (!(sb->s_flags & MS_RDONLY)) { 2140 if (!(sb->s_flags & MS_RDONLY)) {
2141 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2141 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2142 ON_ERRORS_CONTINUE))) { 2142 ON_ERRORS_CONTINUE))) {
2143 ntfs_error(sb, "%s and neither on_errors=" 2143 ntfs_error(sb, "%s and neither on_errors="
2144 "continue nor on_errors=" 2144 "continue nor on_errors="
2145 "remount-ro was specified%s", 2145 "remount-ro was specified%s",
2146 es1, es2); 2146 es1, es2);
2147 goto iput_usnjrnl_err_out; 2147 goto iput_usnjrnl_err_out;
2148 } 2148 }
2149 sb->s_flags |= MS_RDONLY; 2149 sb->s_flags |= MS_RDONLY;
2150 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2150 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2151 } else 2151 } else
2152 ntfs_warning(sb, "%s. Will not be able to remount " 2152 ntfs_warning(sb, "%s. Will not be able to remount "
2153 "read-write%s", es1, es2); 2153 "read-write%s", es1, es2);
2154 /* This will prevent a read-write remount. */ 2154 /* This will prevent a read-write remount. */
2155 NVolSetErrors(vol); 2155 NVolSetErrors(vol);
2156 } 2156 }
2157 /* If (still) a read-write mount, stamp the transaction log. */ 2157 /* If (still) a read-write mount, stamp the transaction log. */
2158 if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) { 2158 if (!(sb->s_flags & MS_RDONLY) && !ntfs_stamp_usnjrnl(vol)) {
2159 static const char *es1 = "Failed to stamp transaction log " 2159 static const char *es1 = "Failed to stamp transaction log "
2160 "($UsnJrnl)"; 2160 "($UsnJrnl)";
2161 static const char *es2 = ". Run chkdsk."; 2161 static const char *es2 = ". Run chkdsk.";
2162 2162
2163 /* Convert to a read-only mount. */ 2163 /* Convert to a read-only mount. */
2164 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO | 2164 if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
2165 ON_ERRORS_CONTINUE))) { 2165 ON_ERRORS_CONTINUE))) {
2166 ntfs_error(sb, "%s and neither on_errors=continue nor " 2166 ntfs_error(sb, "%s and neither on_errors=continue nor "
2167 "on_errors=remount-ro was specified%s", 2167 "on_errors=remount-ro was specified%s",
2168 es1, es2); 2168 es1, es2);
2169 goto iput_usnjrnl_err_out; 2169 goto iput_usnjrnl_err_out;
2170 } 2170 }
2171 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2); 2171 ntfs_error(sb, "%s. Mounting read-only%s", es1, es2);
2172 sb->s_flags |= MS_RDONLY; 2172 sb->s_flags |= MS_RDONLY;
2173 NVolSetErrors(vol); 2173 NVolSetErrors(vol);
2174 } 2174 }
2175 #endif /* NTFS_RW */ 2175 #endif /* NTFS_RW */
2176 return true; 2176 return true;
2177 #ifdef NTFS_RW 2177 #ifdef NTFS_RW
2178 iput_usnjrnl_err_out: 2178 iput_usnjrnl_err_out:
2179 if (vol->usnjrnl_j_ino) 2179 if (vol->usnjrnl_j_ino)
2180 iput(vol->usnjrnl_j_ino); 2180 iput(vol->usnjrnl_j_ino);
2181 if (vol->usnjrnl_max_ino) 2181 if (vol->usnjrnl_max_ino)
2182 iput(vol->usnjrnl_max_ino); 2182 iput(vol->usnjrnl_max_ino);
2183 if (vol->usnjrnl_ino) 2183 if (vol->usnjrnl_ino)
2184 iput(vol->usnjrnl_ino); 2184 iput(vol->usnjrnl_ino);
2185 iput_quota_err_out: 2185 iput_quota_err_out:
2186 if (vol->quota_q_ino) 2186 if (vol->quota_q_ino)
2187 iput(vol->quota_q_ino); 2187 iput(vol->quota_q_ino);
2188 if (vol->quota_ino) 2188 if (vol->quota_ino)
2189 iput(vol->quota_ino); 2189 iput(vol->quota_ino);
2190 iput(vol->extend_ino); 2190 iput(vol->extend_ino);
2191 #endif /* NTFS_RW */ 2191 #endif /* NTFS_RW */
2192 iput_sec_err_out: 2192 iput_sec_err_out:
2193 iput(vol->secure_ino); 2193 iput(vol->secure_ino);
2194 iput_root_err_out: 2194 iput_root_err_out:
2195 iput(vol->root_ino); 2195 iput(vol->root_ino);
2196 iput_logfile_err_out: 2196 iput_logfile_err_out:
2197 #ifdef NTFS_RW 2197 #ifdef NTFS_RW
2198 if (vol->logfile_ino) 2198 if (vol->logfile_ino)
2199 iput(vol->logfile_ino); 2199 iput(vol->logfile_ino);
2200 iput_vol_err_out: 2200 iput_vol_err_out:
2201 #endif /* NTFS_RW */ 2201 #endif /* NTFS_RW */
2202 iput(vol->vol_ino); 2202 iput(vol->vol_ino);
2203 iput_lcnbmp_err_out: 2203 iput_lcnbmp_err_out:
2204 iput(vol->lcnbmp_ino); 2204 iput(vol->lcnbmp_ino);
2205 iput_attrdef_err_out: 2205 iput_attrdef_err_out:
2206 vol->attrdef_size = 0; 2206 vol->attrdef_size = 0;
2207 if (vol->attrdef) { 2207 if (vol->attrdef) {
2208 ntfs_free(vol->attrdef); 2208 ntfs_free(vol->attrdef);
2209 vol->attrdef = NULL; 2209 vol->attrdef = NULL;
2210 } 2210 }
2211 #ifdef NTFS_RW 2211 #ifdef NTFS_RW
2212 iput_upcase_err_out: 2212 iput_upcase_err_out:
2213 #endif /* NTFS_RW */ 2213 #endif /* NTFS_RW */
2214 vol->upcase_len = 0; 2214 vol->upcase_len = 0;
2215 mutex_lock(&ntfs_lock); 2215 mutex_lock(&ntfs_lock);
2216 if (vol->upcase == default_upcase) { 2216 if (vol->upcase == default_upcase) {
2217 ntfs_nr_upcase_users--; 2217 ntfs_nr_upcase_users--;
2218 vol->upcase = NULL; 2218 vol->upcase = NULL;
2219 } 2219 }
2220 mutex_unlock(&ntfs_lock); 2220 mutex_unlock(&ntfs_lock);
2221 if (vol->upcase) { 2221 if (vol->upcase) {
2222 ntfs_free(vol->upcase); 2222 ntfs_free(vol->upcase);
2223 vol->upcase = NULL; 2223 vol->upcase = NULL;
2224 } 2224 }
2225 iput_mftbmp_err_out: 2225 iput_mftbmp_err_out:
2226 iput(vol->mftbmp_ino); 2226 iput(vol->mftbmp_ino);
2227 iput_mirr_err_out: 2227 iput_mirr_err_out:
2228 #ifdef NTFS_RW 2228 #ifdef NTFS_RW
2229 if (vol->mftmirr_ino) 2229 if (vol->mftmirr_ino)
2230 iput(vol->mftmirr_ino); 2230 iput(vol->mftmirr_ino);
2231 #endif /* NTFS_RW */ 2231 #endif /* NTFS_RW */
2232 return false; 2232 return false;
2233 } 2233 }
2234 2234
2235 /** 2235 /**
2236 * ntfs_put_super - called by the vfs to unmount a volume 2236 * ntfs_put_super - called by the vfs to unmount a volume
2237 * @sb: vfs superblock of volume to unmount 2237 * @sb: vfs superblock of volume to unmount
2238 * 2238 *
2239 * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when 2239 * ntfs_put_super() is called by the VFS (from fs/super.c::do_umount()) when
2240 * the volume is being unmounted (umount system call has been invoked) and it 2240 * the volume is being unmounted (umount system call has been invoked) and it
2241 * releases all inodes and memory belonging to the NTFS specific part of the 2241 * releases all inodes and memory belonging to the NTFS specific part of the
2242 * super block. 2242 * super block.
2243 */ 2243 */
2244 static void ntfs_put_super(struct super_block *sb) 2244 static void ntfs_put_super(struct super_block *sb)
2245 { 2245 {
2246 ntfs_volume *vol = NTFS_SB(sb); 2246 ntfs_volume *vol = NTFS_SB(sb);
2247 2247
2248 ntfs_debug("Entering."); 2248 ntfs_debug("Entering.");
2249 #ifdef NTFS_RW 2249 #ifdef NTFS_RW
2250 /* 2250 /*
2251 * Commit all inodes while they are still open in case some of them 2251 * Commit all inodes while they are still open in case some of them
2252 * cause others to be dirtied. 2252 * cause others to be dirtied.
2253 */ 2253 */
2254 ntfs_commit_inode(vol->vol_ino); 2254 ntfs_commit_inode(vol->vol_ino);
2255 2255
2256 /* NTFS 3.0+ specific. */ 2256 /* NTFS 3.0+ specific. */
2257 if (vol->major_ver >= 3) { 2257 if (vol->major_ver >= 3) {
2258 if (vol->usnjrnl_j_ino) 2258 if (vol->usnjrnl_j_ino)
2259 ntfs_commit_inode(vol->usnjrnl_j_ino); 2259 ntfs_commit_inode(vol->usnjrnl_j_ino);
2260 if (vol->usnjrnl_max_ino) 2260 if (vol->usnjrnl_max_ino)
2261 ntfs_commit_inode(vol->usnjrnl_max_ino); 2261 ntfs_commit_inode(vol->usnjrnl_max_ino);
2262 if (vol->usnjrnl_ino) 2262 if (vol->usnjrnl_ino)
2263 ntfs_commit_inode(vol->usnjrnl_ino); 2263 ntfs_commit_inode(vol->usnjrnl_ino);
2264 if (vol->quota_q_ino) 2264 if (vol->quota_q_ino)
2265 ntfs_commit_inode(vol->quota_q_ino); 2265 ntfs_commit_inode(vol->quota_q_ino);
2266 if (vol->quota_ino) 2266 if (vol->quota_ino)
2267 ntfs_commit_inode(vol->quota_ino); 2267 ntfs_commit_inode(vol->quota_ino);
2268 if (vol->extend_ino) 2268 if (vol->extend_ino)
2269 ntfs_commit_inode(vol->extend_ino); 2269 ntfs_commit_inode(vol->extend_ino);
2270 if (vol->secure_ino) 2270 if (vol->secure_ino)
2271 ntfs_commit_inode(vol->secure_ino); 2271 ntfs_commit_inode(vol->secure_ino);
2272 } 2272 }
2273 2273
2274 ntfs_commit_inode(vol->root_ino); 2274 ntfs_commit_inode(vol->root_ino);
2275 2275
2276 down_write(&vol->lcnbmp_lock); 2276 down_write(&vol->lcnbmp_lock);
2277 ntfs_commit_inode(vol->lcnbmp_ino); 2277 ntfs_commit_inode(vol->lcnbmp_ino);
2278 up_write(&vol->lcnbmp_lock); 2278 up_write(&vol->lcnbmp_lock);
2279 2279
2280 down_write(&vol->mftbmp_lock); 2280 down_write(&vol->mftbmp_lock);
2281 ntfs_commit_inode(vol->mftbmp_ino); 2281 ntfs_commit_inode(vol->mftbmp_ino);
2282 up_write(&vol->mftbmp_lock); 2282 up_write(&vol->mftbmp_lock);
2283 2283
2284 if (vol->logfile_ino) 2284 if (vol->logfile_ino)
2285 ntfs_commit_inode(vol->logfile_ino); 2285 ntfs_commit_inode(vol->logfile_ino);
2286 2286
2287 if (vol->mftmirr_ino) 2287 if (vol->mftmirr_ino)
2288 ntfs_commit_inode(vol->mftmirr_ino); 2288 ntfs_commit_inode(vol->mftmirr_ino);
2289 ntfs_commit_inode(vol->mft_ino); 2289 ntfs_commit_inode(vol->mft_ino);
2290 2290
2291 /* 2291 /*
2292 * If a read-write mount and no volume errors have occured, mark the 2292 * If a read-write mount and no volume errors have occured, mark the
2293 * volume clean. Also, re-commit all affected inodes. 2293 * volume clean. Also, re-commit all affected inodes.
2294 */ 2294 */
2295 if (!(sb->s_flags & MS_RDONLY)) { 2295 if (!(sb->s_flags & MS_RDONLY)) {
2296 if (!NVolErrors(vol)) { 2296 if (!NVolErrors(vol)) {
2297 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY)) 2297 if (ntfs_clear_volume_flags(vol, VOLUME_IS_DIRTY))
2298 ntfs_warning(sb, "Failed to clear dirty bit " 2298 ntfs_warning(sb, "Failed to clear dirty bit "
2299 "in volume information " 2299 "in volume information "
2300 "flags. Run chkdsk."); 2300 "flags. Run chkdsk.");
2301 ntfs_commit_inode(vol->vol_ino); 2301 ntfs_commit_inode(vol->vol_ino);
2302 ntfs_commit_inode(vol->root_ino); 2302 ntfs_commit_inode(vol->root_ino);
2303 if (vol->mftmirr_ino) 2303 if (vol->mftmirr_ino)
2304 ntfs_commit_inode(vol->mftmirr_ino); 2304 ntfs_commit_inode(vol->mftmirr_ino);
2305 ntfs_commit_inode(vol->mft_ino); 2305 ntfs_commit_inode(vol->mft_ino);
2306 } else { 2306 } else {
2307 ntfs_warning(sb, "Volume has errors. Leaving volume " 2307 ntfs_warning(sb, "Volume has errors. Leaving volume "
2308 "marked dirty. Run chkdsk."); 2308 "marked dirty. Run chkdsk.");
2309 } 2309 }
2310 } 2310 }
2311 #endif /* NTFS_RW */ 2311 #endif /* NTFS_RW */
2312 2312
2313 iput(vol->vol_ino); 2313 iput(vol->vol_ino);
2314 vol->vol_ino = NULL; 2314 vol->vol_ino = NULL;
2315 2315
2316 /* NTFS 3.0+ specific clean up. */ 2316 /* NTFS 3.0+ specific clean up. */
2317 if (vol->major_ver >= 3) { 2317 if (vol->major_ver >= 3) {
2318 #ifdef NTFS_RW 2318 #ifdef NTFS_RW
2319 if (vol->usnjrnl_j_ino) { 2319 if (vol->usnjrnl_j_ino) {
2320 iput(vol->usnjrnl_j_ino); 2320 iput(vol->usnjrnl_j_ino);
2321 vol->usnjrnl_j_ino = NULL; 2321 vol->usnjrnl_j_ino = NULL;
2322 } 2322 }
2323 if (vol->usnjrnl_max_ino) { 2323 if (vol->usnjrnl_max_ino) {
2324 iput(vol->usnjrnl_max_ino); 2324 iput(vol->usnjrnl_max_ino);
2325 vol->usnjrnl_max_ino = NULL; 2325 vol->usnjrnl_max_ino = NULL;
2326 } 2326 }
2327 if (vol->usnjrnl_ino) { 2327 if (vol->usnjrnl_ino) {
2328 iput(vol->usnjrnl_ino); 2328 iput(vol->usnjrnl_ino);
2329 vol->usnjrnl_ino = NULL; 2329 vol->usnjrnl_ino = NULL;
2330 } 2330 }
2331 if (vol->quota_q_ino) { 2331 if (vol->quota_q_ino) {
2332 iput(vol->quota_q_ino); 2332 iput(vol->quota_q_ino);
2333 vol->quota_q_ino = NULL; 2333 vol->quota_q_ino = NULL;
2334 } 2334 }
2335 if (vol->quota_ino) { 2335 if (vol->quota_ino) {
2336 iput(vol->quota_ino); 2336 iput(vol->quota_ino);
2337 vol->quota_ino = NULL; 2337 vol->quota_ino = NULL;
2338 } 2338 }
2339 #endif /* NTFS_RW */ 2339 #endif /* NTFS_RW */
2340 if (vol->extend_ino) { 2340 if (vol->extend_ino) {
2341 iput(vol->extend_ino); 2341 iput(vol->extend_ino);
2342 vol->extend_ino = NULL; 2342 vol->extend_ino = NULL;
2343 } 2343 }
2344 if (vol->secure_ino) { 2344 if (vol->secure_ino) {
2345 iput(vol->secure_ino); 2345 iput(vol->secure_ino);
2346 vol->secure_ino = NULL; 2346 vol->secure_ino = NULL;
2347 } 2347 }
2348 } 2348 }
2349 2349
2350 iput(vol->root_ino); 2350 iput(vol->root_ino);
2351 vol->root_ino = NULL; 2351 vol->root_ino = NULL;
2352 2352
2353 down_write(&vol->lcnbmp_lock); 2353 down_write(&vol->lcnbmp_lock);
2354 iput(vol->lcnbmp_ino); 2354 iput(vol->lcnbmp_ino);
2355 vol->lcnbmp_ino = NULL; 2355 vol->lcnbmp_ino = NULL;
2356 up_write(&vol->lcnbmp_lock); 2356 up_write(&vol->lcnbmp_lock);
2357 2357
2358 down_write(&vol->mftbmp_lock); 2358 down_write(&vol->mftbmp_lock);
2359 iput(vol->mftbmp_ino); 2359 iput(vol->mftbmp_ino);
2360 vol->mftbmp_ino = NULL; 2360 vol->mftbmp_ino = NULL;
2361 up_write(&vol->mftbmp_lock); 2361 up_write(&vol->mftbmp_lock);
2362 2362
2363 #ifdef NTFS_RW 2363 #ifdef NTFS_RW
2364 if (vol->logfile_ino) { 2364 if (vol->logfile_ino) {
2365 iput(vol->logfile_ino); 2365 iput(vol->logfile_ino);
2366 vol->logfile_ino = NULL; 2366 vol->logfile_ino = NULL;
2367 } 2367 }
2368 if (vol->mftmirr_ino) { 2368 if (vol->mftmirr_ino) {
2369 /* Re-commit the mft mirror and mft just in case. */ 2369 /* Re-commit the mft mirror and mft just in case. */
2370 ntfs_commit_inode(vol->mftmirr_ino); 2370 ntfs_commit_inode(vol->mftmirr_ino);
2371 ntfs_commit_inode(vol->mft_ino); 2371 ntfs_commit_inode(vol->mft_ino);
2372 iput(vol->mftmirr_ino); 2372 iput(vol->mftmirr_ino);
2373 vol->mftmirr_ino = NULL; 2373 vol->mftmirr_ino = NULL;
2374 } 2374 }
2375 /* 2375 /*
2376 * If any dirty inodes are left, throw away all mft data page cache 2376 * If any dirty inodes are left, throw away all mft data page cache
2377 * pages to allow a clean umount. This should never happen any more 2377 * pages to allow a clean umount. This should never happen any more
2378 * due to mft.c::ntfs_mft_writepage() cleaning all the dirty pages as 2378 * due to mft.c::ntfs_mft_writepage() cleaning all the dirty pages as
2379 * the underlying mft records are written out and cleaned. If it does, 2379 * the underlying mft records are written out and cleaned. If it does,
2380 * happen anyway, we want to know... 2380 * happen anyway, we want to know...
2381 */ 2381 */
2382 ntfs_commit_inode(vol->mft_ino); 2382 ntfs_commit_inode(vol->mft_ino);
2383 write_inode_now(vol->mft_ino, 1); 2383 write_inode_now(vol->mft_ino, 1);
2384 if (!list_empty(&sb->s_dirty)) { 2384 if (sb_has_dirty_inodes(sb)) {
2385 const char *s1, *s2; 2385 const char *s1, *s2;
2386 2386
2387 mutex_lock(&vol->mft_ino->i_mutex); 2387 mutex_lock(&vol->mft_ino->i_mutex);
2388 truncate_inode_pages(vol->mft_ino->i_mapping, 0); 2388 truncate_inode_pages(vol->mft_ino->i_mapping, 0);
2389 mutex_unlock(&vol->mft_ino->i_mutex); 2389 mutex_unlock(&vol->mft_ino->i_mutex);
2390 write_inode_now(vol->mft_ino, 1); 2390 write_inode_now(vol->mft_ino, 1);
2391 if (!list_empty(&sb->s_dirty)) { 2391 if (sb_has_dirty_inodes(sb)) {
2392 static const char *_s1 = "inodes"; 2392 static const char *_s1 = "inodes";
2393 static const char *_s2 = ""; 2393 static const char *_s2 = "";
2394 s1 = _s1; 2394 s1 = _s1;
2395 s2 = _s2; 2395 s2 = _s2;
2396 } else { 2396 } else {
2397 static const char *_s1 = "mft pages"; 2397 static const char *_s1 = "mft pages";
2398 static const char *_s2 = "They have been thrown " 2398 static const char *_s2 = "They have been thrown "
2399 "away. "; 2399 "away. ";
2400 s1 = _s1; 2400 s1 = _s1;
2401 s2 = _s2; 2401 s2 = _s2;
2402 } 2402 }
2403 ntfs_error(sb, "Dirty %s found at umount time. %sYou should " 2403 ntfs_error(sb, "Dirty %s found at umount time. %sYou should "
2404 "run chkdsk. Please email " 2404 "run chkdsk. Please email "
2405 "linux-ntfs-dev@lists.sourceforge.net and say " 2405 "linux-ntfs-dev@lists.sourceforge.net and say "
2406 "that you saw this message. Thank you.", s1, 2406 "that you saw this message. Thank you.", s1,
2407 s2); 2407 s2);
2408 } 2408 }
2409 #endif /* NTFS_RW */ 2409 #endif /* NTFS_RW */
2410 2410
2411 iput(vol->mft_ino); 2411 iput(vol->mft_ino);
2412 vol->mft_ino = NULL; 2412 vol->mft_ino = NULL;
2413 2413
2414 /* Throw away the table of attribute definitions. */ 2414 /* Throw away the table of attribute definitions. */
2415 vol->attrdef_size = 0; 2415 vol->attrdef_size = 0;
2416 if (vol->attrdef) { 2416 if (vol->attrdef) {
2417 ntfs_free(vol->attrdef); 2417 ntfs_free(vol->attrdef);
2418 vol->attrdef = NULL; 2418 vol->attrdef = NULL;
2419 } 2419 }
2420 vol->upcase_len = 0; 2420 vol->upcase_len = 0;
2421 /* 2421 /*
2422 * Destroy the global default upcase table if necessary. Also decrease 2422 * Destroy the global default upcase table if necessary. Also decrease
2423 * the number of upcase users if we are a user. 2423 * the number of upcase users if we are a user.
2424 */ 2424 */
2425 mutex_lock(&ntfs_lock); 2425 mutex_lock(&ntfs_lock);
2426 if (vol->upcase == default_upcase) { 2426 if (vol->upcase == default_upcase) {
2427 ntfs_nr_upcase_users--; 2427 ntfs_nr_upcase_users--;
2428 vol->upcase = NULL; 2428 vol->upcase = NULL;
2429 } 2429 }
2430 if (!ntfs_nr_upcase_users && default_upcase) { 2430 if (!ntfs_nr_upcase_users && default_upcase) {
2431 ntfs_free(default_upcase); 2431 ntfs_free(default_upcase);
2432 default_upcase = NULL; 2432 default_upcase = NULL;
2433 } 2433 }
2434 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) 2434 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
2435 free_compression_buffers(); 2435 free_compression_buffers();
2436 mutex_unlock(&ntfs_lock); 2436 mutex_unlock(&ntfs_lock);
2437 if (vol->upcase) { 2437 if (vol->upcase) {
2438 ntfs_free(vol->upcase); 2438 ntfs_free(vol->upcase);
2439 vol->upcase = NULL; 2439 vol->upcase = NULL;
2440 } 2440 }
2441 if (vol->nls_map) { 2441 if (vol->nls_map) {
2442 unload_nls(vol->nls_map); 2442 unload_nls(vol->nls_map);
2443 vol->nls_map = NULL; 2443 vol->nls_map = NULL;
2444 } 2444 }
2445 sb->s_fs_info = NULL; 2445 sb->s_fs_info = NULL;
2446 kfree(vol); 2446 kfree(vol);
2447 return; 2447 return;
2448 } 2448 }
2449 2449
2450 /** 2450 /**
2451 * get_nr_free_clusters - return the number of free clusters on a volume 2451 * get_nr_free_clusters - return the number of free clusters on a volume
2452 * @vol: ntfs volume for which to obtain free cluster count 2452 * @vol: ntfs volume for which to obtain free cluster count
2453 * 2453 *
2454 * Calculate the number of free clusters on the mounted NTFS volume @vol. We 2454 * Calculate the number of free clusters on the mounted NTFS volume @vol. We
2455 * actually calculate the number of clusters in use instead because this 2455 * actually calculate the number of clusters in use instead because this
2456 * allows us to not care about partial pages as these will be just zero filled 2456 * allows us to not care about partial pages as these will be just zero filled
2457 * and hence not be counted as allocated clusters. 2457 * and hence not be counted as allocated clusters.
2458 * 2458 *
2459 * The only particularity is that clusters beyond the end of the logical ntfs 2459 * The only particularity is that clusters beyond the end of the logical ntfs
2460 * volume will be marked as allocated to prevent errors which means we have to 2460 * volume will be marked as allocated to prevent errors which means we have to
2461 * discount those at the end. This is important as the cluster bitmap always 2461 * discount those at the end. This is important as the cluster bitmap always
2462 * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside 2462 * has a size in multiples of 8 bytes, i.e. up to 63 clusters could be outside
2463 * the logical volume and marked in use when they are not as they do not exist. 2463 * the logical volume and marked in use when they are not as they do not exist.
2464 * 2464 *
2465 * If any pages cannot be read we assume all clusters in the erroring pages are 2465 * If any pages cannot be read we assume all clusters in the erroring pages are
2466 * in use. This means we return an underestimate on errors which is better than 2466 * in use. This means we return an underestimate on errors which is better than
2467 * an overestimate. 2467 * an overestimate.
2468 */ 2468 */
2469 static s64 get_nr_free_clusters(ntfs_volume *vol) 2469 static s64 get_nr_free_clusters(ntfs_volume *vol)
2470 { 2470 {
2471 s64 nr_free = vol->nr_clusters; 2471 s64 nr_free = vol->nr_clusters;
2472 u32 *kaddr; 2472 u32 *kaddr;
2473 struct address_space *mapping = vol->lcnbmp_ino->i_mapping; 2473 struct address_space *mapping = vol->lcnbmp_ino->i_mapping;
2474 struct page *page; 2474 struct page *page;
2475 pgoff_t index, max_index; 2475 pgoff_t index, max_index;
2476 2476
2477 ntfs_debug("Entering."); 2477 ntfs_debug("Entering.");
2478 /* Serialize accesses to the cluster bitmap. */ 2478 /* Serialize accesses to the cluster bitmap. */
2479 down_read(&vol->lcnbmp_lock); 2479 down_read(&vol->lcnbmp_lock);
2480 /* 2480 /*
2481 * Convert the number of bits into bytes rounded up, then convert into 2481 * Convert the number of bits into bytes rounded up, then convert into
2482 * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one 2482 * multiples of PAGE_CACHE_SIZE, rounding up so that if we have one
2483 * full and one partial page max_index = 2. 2483 * full and one partial page max_index = 2.
2484 */ 2484 */
2485 max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> 2485 max_index = (((vol->nr_clusters + 7) >> 3) + PAGE_CACHE_SIZE - 1) >>
2486 PAGE_CACHE_SHIFT; 2486 PAGE_CACHE_SHIFT;
2487 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ 2487 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */
2488 ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.", 2488 ntfs_debug("Reading $Bitmap, max_index = 0x%lx, max_size = 0x%lx.",
2489 max_index, PAGE_CACHE_SIZE / 4); 2489 max_index, PAGE_CACHE_SIZE / 4);
2490 for (index = 0; index < max_index; index++) { 2490 for (index = 0; index < max_index; index++) {
2491 unsigned int i; 2491 unsigned int i;
2492 /* 2492 /*
2493 * Read the page from page cache, getting it from backing store 2493 * Read the page from page cache, getting it from backing store
2494 * if necessary, and increment the use count. 2494 * if necessary, and increment the use count.
2495 */ 2495 */
2496 page = read_mapping_page(mapping, index, NULL); 2496 page = read_mapping_page(mapping, index, NULL);
2497 /* Ignore pages which errored synchronously. */ 2497 /* Ignore pages which errored synchronously. */
2498 if (IS_ERR(page)) { 2498 if (IS_ERR(page)) {
2499 ntfs_debug("read_mapping_page() error. Skipping " 2499 ntfs_debug("read_mapping_page() error. Skipping "
2500 "page (index 0x%lx).", index); 2500 "page (index 0x%lx).", index);
2501 nr_free -= PAGE_CACHE_SIZE * 8; 2501 nr_free -= PAGE_CACHE_SIZE * 8;
2502 continue; 2502 continue;
2503 } 2503 }
2504 kaddr = (u32*)kmap_atomic(page, KM_USER0); 2504 kaddr = (u32*)kmap_atomic(page, KM_USER0);
2505 /* 2505 /*
2506 * For each 4 bytes, subtract the number of set bits. If this 2506 * For each 4 bytes, subtract the number of set bits. If this
2507 * is the last page and it is partial we don't really care as 2507 * is the last page and it is partial we don't really care as
2508 * it just means we do a little extra work but it won't affect 2508 * it just means we do a little extra work but it won't affect
2509 * the result as all out of range bytes are set to zero by 2509 * the result as all out of range bytes are set to zero by
2510 * ntfs_readpage(). 2510 * ntfs_readpage().
2511 */ 2511 */
2512 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++) 2512 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++)
2513 nr_free -= (s64)hweight32(kaddr[i]); 2513 nr_free -= (s64)hweight32(kaddr[i]);
2514 kunmap_atomic(kaddr, KM_USER0); 2514 kunmap_atomic(kaddr, KM_USER0);
2515 page_cache_release(page); 2515 page_cache_release(page);
2516 } 2516 }
2517 ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1); 2517 ntfs_debug("Finished reading $Bitmap, last index = 0x%lx.", index - 1);
2518 /* 2518 /*
2519 * Fixup for eventual bits outside logical ntfs volume (see function 2519 * Fixup for eventual bits outside logical ntfs volume (see function
2520 * description above). 2520 * description above).
2521 */ 2521 */
2522 if (vol->nr_clusters & 63) 2522 if (vol->nr_clusters & 63)
2523 nr_free += 64 - (vol->nr_clusters & 63); 2523 nr_free += 64 - (vol->nr_clusters & 63);
2524 up_read(&vol->lcnbmp_lock); 2524 up_read(&vol->lcnbmp_lock);
2525 /* If errors occured we may well have gone below zero, fix this. */ 2525 /* If errors occured we may well have gone below zero, fix this. */
2526 if (nr_free < 0) 2526 if (nr_free < 0)
2527 nr_free = 0; 2527 nr_free = 0;
2528 ntfs_debug("Exiting."); 2528 ntfs_debug("Exiting.");
2529 return nr_free; 2529 return nr_free;
2530 } 2530 }
2531 2531
2532 /** 2532 /**
2533 * __get_nr_free_mft_records - return the number of free inodes on a volume 2533 * __get_nr_free_mft_records - return the number of free inodes on a volume
2534 * @vol: ntfs volume for which to obtain free inode count 2534 * @vol: ntfs volume for which to obtain free inode count
2535 * @nr_free: number of mft records in filesystem 2535 * @nr_free: number of mft records in filesystem
2536 * @max_index: maximum number of pages containing set bits 2536 * @max_index: maximum number of pages containing set bits
2537 * 2537 *
2538 * Calculate the number of free mft records (inodes) on the mounted NTFS 2538 * Calculate the number of free mft records (inodes) on the mounted NTFS
2539 * volume @vol. We actually calculate the number of mft records in use instead 2539 * volume @vol. We actually calculate the number of mft records in use instead
2540 * because this allows us to not care about partial pages as these will be just 2540 * because this allows us to not care about partial pages as these will be just
2541 * zero filled and hence not be counted as allocated mft record. 2541 * zero filled and hence not be counted as allocated mft record.
2542 * 2542 *
2543 * If any pages cannot be read we assume all mft records in the erroring pages 2543 * If any pages cannot be read we assume all mft records in the erroring pages
2544 * are in use. This means we return an underestimate on errors which is better 2544 * are in use. This means we return an underestimate on errors which is better
2545 * than an overestimate. 2545 * than an overestimate.
2546 * 2546 *
2547 * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing. 2547 * NOTE: Caller must hold mftbmp_lock rw_semaphore for reading or writing.
2548 */ 2548 */
2549 static unsigned long __get_nr_free_mft_records(ntfs_volume *vol, 2549 static unsigned long __get_nr_free_mft_records(ntfs_volume *vol,
2550 s64 nr_free, const pgoff_t max_index) 2550 s64 nr_free, const pgoff_t max_index)
2551 { 2551 {
2552 u32 *kaddr; 2552 u32 *kaddr;
2553 struct address_space *mapping = vol->mftbmp_ino->i_mapping; 2553 struct address_space *mapping = vol->mftbmp_ino->i_mapping;
2554 struct page *page; 2554 struct page *page;
2555 pgoff_t index; 2555 pgoff_t index;
2556 2556
2557 ntfs_debug("Entering."); 2557 ntfs_debug("Entering.");
2558 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */ 2558 /* Use multiples of 4 bytes, thus max_size is PAGE_CACHE_SIZE / 4. */
2559 ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = " 2559 ntfs_debug("Reading $MFT/$BITMAP, max_index = 0x%lx, max_size = "
2560 "0x%lx.", max_index, PAGE_CACHE_SIZE / 4); 2560 "0x%lx.", max_index, PAGE_CACHE_SIZE / 4);
2561 for (index = 0; index < max_index; index++) { 2561 for (index = 0; index < max_index; index++) {
2562 unsigned int i; 2562 unsigned int i;
2563 /* 2563 /*
2564 * Read the page from page cache, getting it from backing store 2564 * Read the page from page cache, getting it from backing store
2565 * if necessary, and increment the use count. 2565 * if necessary, and increment the use count.
2566 */ 2566 */
2567 page = read_mapping_page(mapping, index, NULL); 2567 page = read_mapping_page(mapping, index, NULL);
2568 /* Ignore pages which errored synchronously. */ 2568 /* Ignore pages which errored synchronously. */
2569 if (IS_ERR(page)) { 2569 if (IS_ERR(page)) {
2570 ntfs_debug("read_mapping_page() error. Skipping " 2570 ntfs_debug("read_mapping_page() error. Skipping "
2571 "page (index 0x%lx).", index); 2571 "page (index 0x%lx).", index);
2572 nr_free -= PAGE_CACHE_SIZE * 8; 2572 nr_free -= PAGE_CACHE_SIZE * 8;
2573 continue; 2573 continue;
2574 } 2574 }
2575 kaddr = (u32*)kmap_atomic(page, KM_USER0); 2575 kaddr = (u32*)kmap_atomic(page, KM_USER0);
2576 /* 2576 /*
2577 * For each 4 bytes, subtract the number of set bits. If this 2577 * For each 4 bytes, subtract the number of set bits. If this
2578 * is the last page and it is partial we don't really care as 2578 * is the last page and it is partial we don't really care as
2579 * it just means we do a little extra work but it won't affect 2579 * it just means we do a little extra work but it won't affect
2580 * the result as all out of range bytes are set to zero by 2580 * the result as all out of range bytes are set to zero by
2581 * ntfs_readpage(). 2581 * ntfs_readpage().
2582 */ 2582 */
2583 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++) 2583 for (i = 0; i < PAGE_CACHE_SIZE / 4; i++)
2584 nr_free -= (s64)hweight32(kaddr[i]); 2584 nr_free -= (s64)hweight32(kaddr[i]);
2585 kunmap_atomic(kaddr, KM_USER0); 2585 kunmap_atomic(kaddr, KM_USER0);
2586 page_cache_release(page); 2586 page_cache_release(page);
2587 } 2587 }
2588 ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.", 2588 ntfs_debug("Finished reading $MFT/$BITMAP, last index = 0x%lx.",
2589 index - 1); 2589 index - 1);
2590 /* If errors occured we may well have gone below zero, fix this. */ 2590 /* If errors occured we may well have gone below zero, fix this. */
2591 if (nr_free < 0) 2591 if (nr_free < 0)
2592 nr_free = 0; 2592 nr_free = 0;
2593 ntfs_debug("Exiting."); 2593 ntfs_debug("Exiting.");
2594 return nr_free; 2594 return nr_free;
2595 } 2595 }
2596 2596
2597 /** 2597 /**
2598 * ntfs_statfs - return information about mounted NTFS volume 2598 * ntfs_statfs - return information about mounted NTFS volume
2599 * @dentry: dentry from mounted volume 2599 * @dentry: dentry from mounted volume
2600 * @sfs: statfs structure in which to return the information 2600 * @sfs: statfs structure in which to return the information
2601 * 2601 *
2602 * Return information about the mounted NTFS volume @dentry in the statfs structure 2602 * Return information about the mounted NTFS volume @dentry in the statfs structure
2603 * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is 2603 * pointed to by @sfs (this is initialized with zeros before ntfs_statfs is
2604 * called). We interpret the values to be correct of the moment in time at 2604 * called). We interpret the values to be correct of the moment in time at
2605 * which we are called. Most values are variable otherwise and this isn't just 2605 * which we are called. Most values are variable otherwise and this isn't just
2606 * the free values but the totals as well. For example we can increase the 2606 * the free values but the totals as well. For example we can increase the
2607 * total number of file nodes if we run out and we can keep doing this until 2607 * total number of file nodes if we run out and we can keep doing this until
2608 * there is no more space on the volume left at all. 2608 * there is no more space on the volume left at all.
2609 * 2609 *
2610 * Called from vfs_statfs which is used to handle the statfs, fstatfs, and 2610 * Called from vfs_statfs which is used to handle the statfs, fstatfs, and
2611 * ustat system calls. 2611 * ustat system calls.
2612 * 2612 *
2613 * Return 0 on success or -errno on error. 2613 * Return 0 on success or -errno on error.
2614 */ 2614 */
2615 static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs) 2615 static int ntfs_statfs(struct dentry *dentry, struct kstatfs *sfs)
2616 { 2616 {
2617 struct super_block *sb = dentry->d_sb; 2617 struct super_block *sb = dentry->d_sb;
2618 s64 size; 2618 s64 size;
2619 ntfs_volume *vol = NTFS_SB(sb); 2619 ntfs_volume *vol = NTFS_SB(sb);
2620 ntfs_inode *mft_ni = NTFS_I(vol->mft_ino); 2620 ntfs_inode *mft_ni = NTFS_I(vol->mft_ino);
2621 pgoff_t max_index; 2621 pgoff_t max_index;
2622 unsigned long flags; 2622 unsigned long flags;
2623 2623
2624 ntfs_debug("Entering."); 2624 ntfs_debug("Entering.");
2625 /* Type of filesystem. */ 2625 /* Type of filesystem. */
2626 sfs->f_type = NTFS_SB_MAGIC; 2626 sfs->f_type = NTFS_SB_MAGIC;
2627 /* Optimal transfer block size. */ 2627 /* Optimal transfer block size. */
2628 sfs->f_bsize = PAGE_CACHE_SIZE; 2628 sfs->f_bsize = PAGE_CACHE_SIZE;
2629 /* 2629 /*
2630 * Total data blocks in filesystem in units of f_bsize and since 2630 * Total data blocks in filesystem in units of f_bsize and since
2631 * inodes are also stored in data blocs ($MFT is a file) this is just 2631 * inodes are also stored in data blocs ($MFT is a file) this is just
2632 * the total clusters. 2632 * the total clusters.
2633 */ 2633 */
2634 sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >> 2634 sfs->f_blocks = vol->nr_clusters << vol->cluster_size_bits >>
2635 PAGE_CACHE_SHIFT; 2635 PAGE_CACHE_SHIFT;
2636 /* Free data blocks in filesystem in units of f_bsize. */ 2636 /* Free data blocks in filesystem in units of f_bsize. */
2637 size = get_nr_free_clusters(vol) << vol->cluster_size_bits >> 2637 size = get_nr_free_clusters(vol) << vol->cluster_size_bits >>
2638 PAGE_CACHE_SHIFT; 2638 PAGE_CACHE_SHIFT;
2639 if (size < 0LL) 2639 if (size < 0LL)
2640 size = 0LL; 2640 size = 0LL;
2641 /* Free blocks avail to non-superuser, same as above on NTFS. */ 2641 /* Free blocks avail to non-superuser, same as above on NTFS. */
2642 sfs->f_bavail = sfs->f_bfree = size; 2642 sfs->f_bavail = sfs->f_bfree = size;
2643 /* Serialize accesses to the inode bitmap. */ 2643 /* Serialize accesses to the inode bitmap. */
2644 down_read(&vol->mftbmp_lock); 2644 down_read(&vol->mftbmp_lock);
2645 read_lock_irqsave(&mft_ni->size_lock, flags); 2645 read_lock_irqsave(&mft_ni->size_lock, flags);
2646 size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits; 2646 size = i_size_read(vol->mft_ino) >> vol->mft_record_size_bits;
2647 /* 2647 /*
2648 * Convert the maximum number of set bits into bytes rounded up, then 2648 * Convert the maximum number of set bits into bytes rounded up, then
2649 * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we 2649 * convert into multiples of PAGE_CACHE_SIZE, rounding up so that if we
2650 * have one full and one partial page max_index = 2. 2650 * have one full and one partial page max_index = 2.
2651 */ 2651 */
2652 max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits) 2652 max_index = ((((mft_ni->initialized_size >> vol->mft_record_size_bits)
2653 + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 2653 + 7) >> 3) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
2654 read_unlock_irqrestore(&mft_ni->size_lock, flags); 2654 read_unlock_irqrestore(&mft_ni->size_lock, flags);
2655 /* Number of inodes in filesystem (at this point in time). */ 2655 /* Number of inodes in filesystem (at this point in time). */
2656 sfs->f_files = size; 2656 sfs->f_files = size;
2657 /* Free inodes in fs (based on current total count). */ 2657 /* Free inodes in fs (based on current total count). */
2658 sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index); 2658 sfs->f_ffree = __get_nr_free_mft_records(vol, size, max_index);
2659 up_read(&vol->mftbmp_lock); 2659 up_read(&vol->mftbmp_lock);
2660 /* 2660 /*
2661 * File system id. This is extremely *nix flavour dependent and even 2661 * File system id. This is extremely *nix flavour dependent and even
2662 * within Linux itself all fs do their own thing. I interpret this to 2662 * within Linux itself all fs do their own thing. I interpret this to
2663 * mean a unique id associated with the mounted fs and not the id 2663 * mean a unique id associated with the mounted fs and not the id
2664 * associated with the filesystem driver, the latter is already given 2664 * associated with the filesystem driver, the latter is already given
2665 * by the filesystem type in sfs->f_type. Thus we use the 64-bit 2665 * by the filesystem type in sfs->f_type. Thus we use the 64-bit
2666 * volume serial number splitting it into two 32-bit parts. We enter 2666 * volume serial number splitting it into two 32-bit parts. We enter
2667 * the least significant 32-bits in f_fsid[0] and the most significant 2667 * the least significant 32-bits in f_fsid[0] and the most significant
2668 * 32-bits in f_fsid[1]. 2668 * 32-bits in f_fsid[1].
2669 */ 2669 */
2670 sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff; 2670 sfs->f_fsid.val[0] = vol->serial_no & 0xffffffff;
2671 sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff; 2671 sfs->f_fsid.val[1] = (vol->serial_no >> 32) & 0xffffffff;
2672 /* Maximum length of filenames. */ 2672 /* Maximum length of filenames. */
2673 sfs->f_namelen = NTFS_MAX_NAME_LEN; 2673 sfs->f_namelen = NTFS_MAX_NAME_LEN;
2674 return 0; 2674 return 0;
2675 } 2675 }
2676 2676
2677 /** 2677 /**
2678 * The complete super operations. 2678 * The complete super operations.
2679 */ 2679 */
2680 static const struct super_operations ntfs_sops = { 2680 static const struct super_operations ntfs_sops = {
2681 .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */ 2681 .alloc_inode = ntfs_alloc_big_inode, /* VFS: Allocate new inode. */
2682 .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */ 2682 .destroy_inode = ntfs_destroy_big_inode, /* VFS: Deallocate inode. */
2683 #ifdef NTFS_RW 2683 #ifdef NTFS_RW
2684 //.dirty_inode = NULL, /* VFS: Called from 2684 //.dirty_inode = NULL, /* VFS: Called from
2685 // __mark_inode_dirty(). */ 2685 // __mark_inode_dirty(). */
2686 .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to 2686 .write_inode = ntfs_write_inode, /* VFS: Write dirty inode to
2687 disk. */ 2687 disk. */
2688 //.drop_inode = NULL, /* VFS: Called just after the 2688 //.drop_inode = NULL, /* VFS: Called just after the
2689 // inode reference count has 2689 // inode reference count has
2690 // been decreased to zero. 2690 // been decreased to zero.
2691 // NOTE: The inode lock is 2691 // NOTE: The inode lock is
2692 // held. See fs/inode.c:: 2692 // held. See fs/inode.c::
2693 // generic_drop_inode(). */ 2693 // generic_drop_inode(). */
2694 //.delete_inode = NULL, /* VFS: Delete inode from disk. 2694 //.delete_inode = NULL, /* VFS: Delete inode from disk.
2695 // Called when i_count becomes 2695 // Called when i_count becomes
2696 // 0 and i_nlink is also 0. */ 2696 // 0 and i_nlink is also 0. */
2697 //.write_super = NULL, /* Flush dirty super block to 2697 //.write_super = NULL, /* Flush dirty super block to
2698 // disk. */ 2698 // disk. */
2699 //.sync_fs = NULL, /* ? */ 2699 //.sync_fs = NULL, /* ? */
2700 //.write_super_lockfs = NULL, /* ? */ 2700 //.write_super_lockfs = NULL, /* ? */
2701 //.unlockfs = NULL, /* ? */ 2701 //.unlockfs = NULL, /* ? */
2702 #endif /* NTFS_RW */ 2702 #endif /* NTFS_RW */
2703 .put_super = ntfs_put_super, /* Syscall: umount. */ 2703 .put_super = ntfs_put_super, /* Syscall: umount. */
2704 .statfs = ntfs_statfs, /* Syscall: statfs */ 2704 .statfs = ntfs_statfs, /* Syscall: statfs */
2705 .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */ 2705 .remount_fs = ntfs_remount, /* Syscall: mount -o remount. */
2706 .clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is 2706 .clear_inode = ntfs_clear_big_inode, /* VFS: Called when an inode is
2707 removed from memory. */ 2707 removed from memory. */
2708 //.umount_begin = NULL, /* Forced umount. */ 2708 //.umount_begin = NULL, /* Forced umount. */
2709 .show_options = ntfs_show_options, /* Show mount options in 2709 .show_options = ntfs_show_options, /* Show mount options in
2710 proc. */ 2710 proc. */
2711 }; 2711 };
2712 2712
2713 /** 2713 /**
2714 * ntfs_fill_super - mount an ntfs filesystem 2714 * ntfs_fill_super - mount an ntfs filesystem
2715 * @sb: super block of ntfs filesystem to mount 2715 * @sb: super block of ntfs filesystem to mount
2716 * @opt: string containing the mount options 2716 * @opt: string containing the mount options
2717 * @silent: silence error output 2717 * @silent: silence error output
2718 * 2718 *
2719 * ntfs_fill_super() is called by the VFS to mount the device described by @sb 2719 * ntfs_fill_super() is called by the VFS to mount the device described by @sb
2720 * with the mount otions in @data with the NTFS filesystem. 2720 * with the mount otions in @data with the NTFS filesystem.
2721 * 2721 *
2722 * If @silent is true, remain silent even if errors are detected. This is used 2722 * If @silent is true, remain silent even if errors are detected. This is used
2723 * during bootup, when the kernel tries to mount the root filesystem with all 2723 * during bootup, when the kernel tries to mount the root filesystem with all
2724 * registered filesystems one after the other until one succeeds. This implies 2724 * registered filesystems one after the other until one succeeds. This implies
2725 * that all filesystems except the correct one will quite correctly and 2725 * that all filesystems except the correct one will quite correctly and
2726 * expectedly return an error, but nobody wants to see error messages when in 2726 * expectedly return an error, but nobody wants to see error messages when in
2727 * fact this is what is supposed to happen. 2727 * fact this is what is supposed to happen.
2728 * 2728 *
2729 * NOTE: @sb->s_flags contains the mount options flags. 2729 * NOTE: @sb->s_flags contains the mount options flags.
2730 */ 2730 */
2731 static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) 2731 static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
2732 { 2732 {
2733 ntfs_volume *vol; 2733 ntfs_volume *vol;
2734 struct buffer_head *bh; 2734 struct buffer_head *bh;
2735 struct inode *tmp_ino; 2735 struct inode *tmp_ino;
2736 int blocksize, result; 2736 int blocksize, result;
2737 2737
2738 /* 2738 /*
2739 * We do a pretty difficult piece of bootstrap by reading the 2739 * We do a pretty difficult piece of bootstrap by reading the
2740 * MFT (and other metadata) from disk into memory. We'll only 2740 * MFT (and other metadata) from disk into memory. We'll only
2741 * release this metadata during umount, so the locking patterns 2741 * release this metadata during umount, so the locking patterns
2742 * observed during bootstrap do not count. So turn off the 2742 * observed during bootstrap do not count. So turn off the
2743 * observation of locking patterns (strictly for this context 2743 * observation of locking patterns (strictly for this context
2744 * only) while mounting NTFS. [The validator is still active 2744 * only) while mounting NTFS. [The validator is still active
2745 * otherwise, even for this context: it will for example record 2745 * otherwise, even for this context: it will for example record
2746 * lock class registrations.] 2746 * lock class registrations.]
2747 */ 2747 */
2748 lockdep_off(); 2748 lockdep_off();
2749 ntfs_debug("Entering."); 2749 ntfs_debug("Entering.");
2750 #ifndef NTFS_RW 2750 #ifndef NTFS_RW
2751 sb->s_flags |= MS_RDONLY; 2751 sb->s_flags |= MS_RDONLY;
2752 #endif /* ! NTFS_RW */ 2752 #endif /* ! NTFS_RW */
2753 /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */ 2753 /* Allocate a new ntfs_volume and place it in sb->s_fs_info. */
2754 sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS); 2754 sb->s_fs_info = kmalloc(sizeof(ntfs_volume), GFP_NOFS);
2755 vol = NTFS_SB(sb); 2755 vol = NTFS_SB(sb);
2756 if (!vol) { 2756 if (!vol) {
2757 if (!silent) 2757 if (!silent)
2758 ntfs_error(sb, "Allocation of NTFS volume structure " 2758 ntfs_error(sb, "Allocation of NTFS volume structure "
2759 "failed. Aborting mount..."); 2759 "failed. Aborting mount...");
2760 lockdep_on(); 2760 lockdep_on();
2761 return -ENOMEM; 2761 return -ENOMEM;
2762 } 2762 }
2763 /* Initialize ntfs_volume structure. */ 2763 /* Initialize ntfs_volume structure. */
2764 *vol = (ntfs_volume) { 2764 *vol = (ntfs_volume) {
2765 .sb = sb, 2765 .sb = sb,
2766 /* 2766 /*
2767 * Default is group and other don't have any access to files or 2767 * Default is group and other don't have any access to files or
2768 * directories while owner has full access. Further, files by 2768 * directories while owner has full access. Further, files by
2769 * default are not executable but directories are of course 2769 * default are not executable but directories are of course
2770 * browseable. 2770 * browseable.
2771 */ 2771 */
2772 .fmask = 0177, 2772 .fmask = 0177,
2773 .dmask = 0077, 2773 .dmask = 0077,
2774 }; 2774 };
2775 init_rwsem(&vol->mftbmp_lock); 2775 init_rwsem(&vol->mftbmp_lock);
2776 init_rwsem(&vol->lcnbmp_lock); 2776 init_rwsem(&vol->lcnbmp_lock);
2777 2777
2778 unlock_kernel(); 2778 unlock_kernel();
2779 2779
2780 /* By default, enable sparse support. */ 2780 /* By default, enable sparse support. */
2781 NVolSetSparseEnabled(vol); 2781 NVolSetSparseEnabled(vol);
2782 2782
2783 /* Important to get the mount options dealt with now. */ 2783 /* Important to get the mount options dealt with now. */
2784 if (!parse_options(vol, (char*)opt)) 2784 if (!parse_options(vol, (char*)opt))
2785 goto err_out_now; 2785 goto err_out_now;
2786 2786
2787 /* We support sector sizes up to the PAGE_CACHE_SIZE. */ 2787 /* We support sector sizes up to the PAGE_CACHE_SIZE. */
2788 if (bdev_hardsect_size(sb->s_bdev) > PAGE_CACHE_SIZE) { 2788 if (bdev_hardsect_size(sb->s_bdev) > PAGE_CACHE_SIZE) {
2789 if (!silent) 2789 if (!silent)
2790 ntfs_error(sb, "Device has unsupported sector size " 2790 ntfs_error(sb, "Device has unsupported sector size "
2791 "(%i). The maximum supported sector " 2791 "(%i). The maximum supported sector "
2792 "size on this architecture is %lu " 2792 "size on this architecture is %lu "
2793 "bytes.", 2793 "bytes.",
2794 bdev_hardsect_size(sb->s_bdev), 2794 bdev_hardsect_size(sb->s_bdev),
2795 PAGE_CACHE_SIZE); 2795 PAGE_CACHE_SIZE);
2796 goto err_out_now; 2796 goto err_out_now;
2797 } 2797 }
2798 /* 2798 /*
2799 * Setup the device access block size to NTFS_BLOCK_SIZE or the hard 2799 * Setup the device access block size to NTFS_BLOCK_SIZE or the hard
2800 * sector size, whichever is bigger. 2800 * sector size, whichever is bigger.
2801 */ 2801 */
2802 blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE); 2802 blocksize = sb_min_blocksize(sb, NTFS_BLOCK_SIZE);
2803 if (blocksize < NTFS_BLOCK_SIZE) { 2803 if (blocksize < NTFS_BLOCK_SIZE) {
2804 if (!silent) 2804 if (!silent)
2805 ntfs_error(sb, "Unable to set device block size."); 2805 ntfs_error(sb, "Unable to set device block size.");
2806 goto err_out_now; 2806 goto err_out_now;
2807 } 2807 }
2808 BUG_ON(blocksize != sb->s_blocksize); 2808 BUG_ON(blocksize != sb->s_blocksize);
2809 ntfs_debug("Set device block size to %i bytes (block size bits %i).", 2809 ntfs_debug("Set device block size to %i bytes (block size bits %i).",
2810 blocksize, sb->s_blocksize_bits); 2810 blocksize, sb->s_blocksize_bits);
2811 /* Determine the size of the device in units of block_size bytes. */ 2811 /* Determine the size of the device in units of block_size bytes. */
2812 if (!i_size_read(sb->s_bdev->bd_inode)) { 2812 if (!i_size_read(sb->s_bdev->bd_inode)) {
2813 if (!silent) 2813 if (!silent)
2814 ntfs_error(sb, "Unable to determine device size."); 2814 ntfs_error(sb, "Unable to determine device size.");
2815 goto err_out_now; 2815 goto err_out_now;
2816 } 2816 }
2817 vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> 2817 vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
2818 sb->s_blocksize_bits; 2818 sb->s_blocksize_bits;
2819 /* Read the boot sector and return unlocked buffer head to it. */ 2819 /* Read the boot sector and return unlocked buffer head to it. */
2820 if (!(bh = read_ntfs_boot_sector(sb, silent))) { 2820 if (!(bh = read_ntfs_boot_sector(sb, silent))) {
2821 if (!silent) 2821 if (!silent)
2822 ntfs_error(sb, "Not an NTFS volume."); 2822 ntfs_error(sb, "Not an NTFS volume.");
2823 goto err_out_now; 2823 goto err_out_now;
2824 } 2824 }
2825 /* 2825 /*
2826 * Extract the data from the boot sector and setup the ntfs volume 2826 * Extract the data from the boot sector and setup the ntfs volume
2827 * using it. 2827 * using it.
2828 */ 2828 */
2829 result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data); 2829 result = parse_ntfs_boot_sector(vol, (NTFS_BOOT_SECTOR*)bh->b_data);
2830 brelse(bh); 2830 brelse(bh);
2831 if (!result) { 2831 if (!result) {
2832 if (!silent) 2832 if (!silent)
2833 ntfs_error(sb, "Unsupported NTFS filesystem."); 2833 ntfs_error(sb, "Unsupported NTFS filesystem.");
2834 goto err_out_now; 2834 goto err_out_now;
2835 } 2835 }
2836 /* 2836 /*
2837 * If the boot sector indicates a sector size bigger than the current 2837 * If the boot sector indicates a sector size bigger than the current
2838 * device block size, switch the device block size to the sector size. 2838 * device block size, switch the device block size to the sector size.
2839 * TODO: It may be possible to support this case even when the set 2839 * TODO: It may be possible to support this case even when the set
2840 * below fails, we would just be breaking up the i/o for each sector 2840 * below fails, we would just be breaking up the i/o for each sector
2841 * into multiple blocks for i/o purposes but otherwise it should just 2841 * into multiple blocks for i/o purposes but otherwise it should just
2842 * work. However it is safer to leave disabled until someone hits this 2842 * work. However it is safer to leave disabled until someone hits this
2843 * error message and then we can get them to try it without the setting 2843 * error message and then we can get them to try it without the setting
2844 * so we know for sure that it works. 2844 * so we know for sure that it works.
2845 */ 2845 */
2846 if (vol->sector_size > blocksize) { 2846 if (vol->sector_size > blocksize) {
2847 blocksize = sb_set_blocksize(sb, vol->sector_size); 2847 blocksize = sb_set_blocksize(sb, vol->sector_size);
2848 if (blocksize != vol->sector_size) { 2848 if (blocksize != vol->sector_size) {
2849 if (!silent) 2849 if (!silent)
2850 ntfs_error(sb, "Unable to set device block " 2850 ntfs_error(sb, "Unable to set device block "
2851 "size to sector size (%i).", 2851 "size to sector size (%i).",
2852 vol->sector_size); 2852 vol->sector_size);
2853 goto err_out_now; 2853 goto err_out_now;
2854 } 2854 }
2855 BUG_ON(blocksize != sb->s_blocksize); 2855 BUG_ON(blocksize != sb->s_blocksize);
2856 vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >> 2856 vol->nr_blocks = i_size_read(sb->s_bdev->bd_inode) >>
2857 sb->s_blocksize_bits; 2857 sb->s_blocksize_bits;
2858 ntfs_debug("Changed device block size to %i bytes (block size " 2858 ntfs_debug("Changed device block size to %i bytes (block size "
2859 "bits %i) to match volume sector size.", 2859 "bits %i) to match volume sector size.",
2860 blocksize, sb->s_blocksize_bits); 2860 blocksize, sb->s_blocksize_bits);
2861 } 2861 }
2862 /* Initialize the cluster and mft allocators. */ 2862 /* Initialize the cluster and mft allocators. */
2863 ntfs_setup_allocators(vol); 2863 ntfs_setup_allocators(vol);
2864 /* Setup remaining fields in the super block. */ 2864 /* Setup remaining fields in the super block. */
2865 sb->s_magic = NTFS_SB_MAGIC; 2865 sb->s_magic = NTFS_SB_MAGIC;
2866 /* 2866 /*
2867 * Ntfs allows 63 bits for the file size, i.e. correct would be: 2867 * Ntfs allows 63 bits for the file size, i.e. correct would be:
2868 * sb->s_maxbytes = ~0ULL >> 1; 2868 * sb->s_maxbytes = ~0ULL >> 1;
2869 * But the kernel uses a long as the page cache page index which on 2869 * But the kernel uses a long as the page cache page index which on
2870 * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel 2870 * 32-bit architectures is only 32-bits. MAX_LFS_FILESIZE is kernel
2871 * defined to the maximum the page cache page index can cope with 2871 * defined to the maximum the page cache page index can cope with
2872 * without overflowing the index or to 2^63 - 1, whichever is smaller. 2872 * without overflowing the index or to 2^63 - 1, whichever is smaller.
2873 */ 2873 */
2874 sb->s_maxbytes = MAX_LFS_FILESIZE; 2874 sb->s_maxbytes = MAX_LFS_FILESIZE;
2875 /* Ntfs measures time in 100ns intervals. */ 2875 /* Ntfs measures time in 100ns intervals. */
2876 sb->s_time_gran = 100; 2876 sb->s_time_gran = 100;
2877 /* 2877 /*
2878 * Now load the metadata required for the page cache and our address 2878 * Now load the metadata required for the page cache and our address
2879 * space operations to function. We do this by setting up a specialised 2879 * space operations to function. We do this by setting up a specialised
2880 * read_inode method and then just calling the normal iget() to obtain 2880 * read_inode method and then just calling the normal iget() to obtain
2881 * the inode for $MFT which is sufficient to allow our normal inode 2881 * the inode for $MFT which is sufficient to allow our normal inode
2882 * operations and associated address space operations to function. 2882 * operations and associated address space operations to function.
2883 */ 2883 */
2884 sb->s_op = &ntfs_sops; 2884 sb->s_op = &ntfs_sops;
2885 tmp_ino = new_inode(sb); 2885 tmp_ino = new_inode(sb);
2886 if (!tmp_ino) { 2886 if (!tmp_ino) {
2887 if (!silent) 2887 if (!silent)
2888 ntfs_error(sb, "Failed to load essential metadata."); 2888 ntfs_error(sb, "Failed to load essential metadata.");
2889 goto err_out_now; 2889 goto err_out_now;
2890 } 2890 }
2891 tmp_ino->i_ino = FILE_MFT; 2891 tmp_ino->i_ino = FILE_MFT;
2892 insert_inode_hash(tmp_ino); 2892 insert_inode_hash(tmp_ino);
2893 if (ntfs_read_inode_mount(tmp_ino) < 0) { 2893 if (ntfs_read_inode_mount(tmp_ino) < 0) {
2894 if (!silent) 2894 if (!silent)
2895 ntfs_error(sb, "Failed to load essential metadata."); 2895 ntfs_error(sb, "Failed to load essential metadata.");
2896 goto iput_tmp_ino_err_out_now; 2896 goto iput_tmp_ino_err_out_now;
2897 } 2897 }
2898 mutex_lock(&ntfs_lock); 2898 mutex_lock(&ntfs_lock);
2899 /* 2899 /*
2900 * The current mount is a compression user if the cluster size is 2900 * The current mount is a compression user if the cluster size is
2901 * less than or equal 4kiB. 2901 * less than or equal 4kiB.
2902 */ 2902 */
2903 if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) { 2903 if (vol->cluster_size <= 4096 && !ntfs_nr_compression_users++) {
2904 result = allocate_compression_buffers(); 2904 result = allocate_compression_buffers();
2905 if (result) { 2905 if (result) {
2906 ntfs_error(NULL, "Failed to allocate buffers " 2906 ntfs_error(NULL, "Failed to allocate buffers "
2907 "for compression engine."); 2907 "for compression engine.");
2908 ntfs_nr_compression_users--; 2908 ntfs_nr_compression_users--;
2909 mutex_unlock(&ntfs_lock); 2909 mutex_unlock(&ntfs_lock);
2910 goto iput_tmp_ino_err_out_now; 2910 goto iput_tmp_ino_err_out_now;
2911 } 2911 }
2912 } 2912 }
2913 /* 2913 /*
2914 * Generate the global default upcase table if necessary. Also 2914 * Generate the global default upcase table if necessary. Also
2915 * temporarily increment the number of upcase users to avoid race 2915 * temporarily increment the number of upcase users to avoid race
2916 * conditions with concurrent (u)mounts. 2916 * conditions with concurrent (u)mounts.
2917 */ 2917 */
2918 if (!default_upcase) 2918 if (!default_upcase)
2919 default_upcase = generate_default_upcase(); 2919 default_upcase = generate_default_upcase();
2920 ntfs_nr_upcase_users++; 2920 ntfs_nr_upcase_users++;
2921 mutex_unlock(&ntfs_lock); 2921 mutex_unlock(&ntfs_lock);
2922 /* 2922 /*
2923 * From now on, ignore @silent parameter. If we fail below this line, 2923 * From now on, ignore @silent parameter. If we fail below this line,
2924 * it will be due to a corrupt fs or a system error, so we report it. 2924 * it will be due to a corrupt fs or a system error, so we report it.
2925 */ 2925 */
2926 /* 2926 /*
2927 * Open the system files with normal access functions and complete 2927 * Open the system files with normal access functions and complete
2928 * setting up the ntfs super block. 2928 * setting up the ntfs super block.
2929 */ 2929 */
2930 if (!load_system_files(vol)) { 2930 if (!load_system_files(vol)) {
2931 ntfs_error(sb, "Failed to load system files."); 2931 ntfs_error(sb, "Failed to load system files.");
2932 goto unl_upcase_iput_tmp_ino_err_out_now; 2932 goto unl_upcase_iput_tmp_ino_err_out_now;
2933 } 2933 }
2934 if ((sb->s_root = d_alloc_root(vol->root_ino))) { 2934 if ((sb->s_root = d_alloc_root(vol->root_ino))) {
2935 /* We increment i_count simulating an ntfs_iget(). */ 2935 /* We increment i_count simulating an ntfs_iget(). */
2936 atomic_inc(&vol->root_ino->i_count); 2936 atomic_inc(&vol->root_ino->i_count);
2937 ntfs_debug("Exiting, status successful."); 2937 ntfs_debug("Exiting, status successful.");
2938 /* Release the default upcase if it has no users. */ 2938 /* Release the default upcase if it has no users. */
2939 mutex_lock(&ntfs_lock); 2939 mutex_lock(&ntfs_lock);
2940 if (!--ntfs_nr_upcase_users && default_upcase) { 2940 if (!--ntfs_nr_upcase_users && default_upcase) {
2941 ntfs_free(default_upcase); 2941 ntfs_free(default_upcase);
2942 default_upcase = NULL; 2942 default_upcase = NULL;
2943 } 2943 }
2944 mutex_unlock(&ntfs_lock); 2944 mutex_unlock(&ntfs_lock);
2945 sb->s_export_op = &ntfs_export_ops; 2945 sb->s_export_op = &ntfs_export_ops;
2946 lock_kernel(); 2946 lock_kernel();
2947 lockdep_on(); 2947 lockdep_on();
2948 return 0; 2948 return 0;
2949 } 2949 }
2950 ntfs_error(sb, "Failed to allocate root directory."); 2950 ntfs_error(sb, "Failed to allocate root directory.");
2951 /* Clean up after the successful load_system_files() call from above. */ 2951 /* Clean up after the successful load_system_files() call from above. */
2952 // TODO: Use ntfs_put_super() instead of repeating all this code... 2952 // TODO: Use ntfs_put_super() instead of repeating all this code...
2953 // FIXME: Should mark the volume clean as the error is most likely 2953 // FIXME: Should mark the volume clean as the error is most likely
2954 // -ENOMEM. 2954 // -ENOMEM.
2955 iput(vol->vol_ino); 2955 iput(vol->vol_ino);
2956 vol->vol_ino = NULL; 2956 vol->vol_ino = NULL;
2957 /* NTFS 3.0+ specific clean up. */ 2957 /* NTFS 3.0+ specific clean up. */
2958 if (vol->major_ver >= 3) { 2958 if (vol->major_ver >= 3) {
2959 #ifdef NTFS_RW 2959 #ifdef NTFS_RW
2960 if (vol->usnjrnl_j_ino) { 2960 if (vol->usnjrnl_j_ino) {
2961 iput(vol->usnjrnl_j_ino); 2961 iput(vol->usnjrnl_j_ino);
2962 vol->usnjrnl_j_ino = NULL; 2962 vol->usnjrnl_j_ino = NULL;
2963 } 2963 }
2964 if (vol->usnjrnl_max_ino) { 2964 if (vol->usnjrnl_max_ino) {
2965 iput(vol->usnjrnl_max_ino); 2965 iput(vol->usnjrnl_max_ino);
2966 vol->usnjrnl_max_ino = NULL; 2966 vol->usnjrnl_max_ino = NULL;
2967 } 2967 }
2968 if (vol->usnjrnl_ino) { 2968 if (vol->usnjrnl_ino) {
2969 iput(vol->usnjrnl_ino); 2969 iput(vol->usnjrnl_ino);
2970 vol->usnjrnl_ino = NULL; 2970 vol->usnjrnl_ino = NULL;
2971 } 2971 }
2972 if (vol->quota_q_ino) { 2972 if (vol->quota_q_ino) {
2973 iput(vol->quota_q_ino); 2973 iput(vol->quota_q_ino);
2974 vol->quota_q_ino = NULL; 2974 vol->quota_q_ino = NULL;
2975 } 2975 }
2976 if (vol->quota_ino) { 2976 if (vol->quota_ino) {
2977 iput(vol->quota_ino); 2977 iput(vol->quota_ino);
2978 vol->quota_ino = NULL; 2978 vol->quota_ino = NULL;
2979 } 2979 }
2980 #endif /* NTFS_RW */ 2980 #endif /* NTFS_RW */
2981 if (vol->extend_ino) { 2981 if (vol->extend_ino) {
2982 iput(vol->extend_ino); 2982 iput(vol->extend_ino);
2983 vol->extend_ino = NULL; 2983 vol->extend_ino = NULL;
2984 } 2984 }
2985 if (vol->secure_ino) { 2985 if (vol->secure_ino) {
2986 iput(vol->secure_ino); 2986 iput(vol->secure_ino);
2987 vol->secure_ino = NULL; 2987 vol->secure_ino = NULL;
2988 } 2988 }
2989 } 2989 }
2990 iput(vol->root_ino); 2990 iput(vol->root_ino);
2991 vol->root_ino = NULL; 2991 vol->root_ino = NULL;
2992 iput(vol->lcnbmp_ino); 2992 iput(vol->lcnbmp_ino);
2993 vol->lcnbmp_ino = NULL; 2993 vol->lcnbmp_ino = NULL;
2994 iput(vol->mftbmp_ino); 2994 iput(vol->mftbmp_ino);
2995 vol->mftbmp_ino = NULL; 2995 vol->mftbmp_ino = NULL;
2996 #ifdef NTFS_RW 2996 #ifdef NTFS_RW
2997 if (vol->logfile_ino) { 2997 if (vol->logfile_ino) {
2998 iput(vol->logfile_ino); 2998 iput(vol->logfile_ino);
2999 vol->logfile_ino = NULL; 2999 vol->logfile_ino = NULL;
3000 } 3000 }
3001 if (vol->mftmirr_ino) { 3001 if (vol->mftmirr_ino) {
3002 iput(vol->mftmirr_ino); 3002 iput(vol->mftmirr_ino);
3003 vol->mftmirr_ino = NULL; 3003 vol->mftmirr_ino = NULL;
3004 } 3004 }
3005 #endif /* NTFS_RW */ 3005 #endif /* NTFS_RW */
3006 /* Throw away the table of attribute definitions. */ 3006 /* Throw away the table of attribute definitions. */
3007 vol->attrdef_size = 0; 3007 vol->attrdef_size = 0;
3008 if (vol->attrdef) { 3008 if (vol->attrdef) {
3009 ntfs_free(vol->attrdef); 3009 ntfs_free(vol->attrdef);
3010 vol->attrdef = NULL; 3010 vol->attrdef = NULL;
3011 } 3011 }
3012 vol->upcase_len = 0; 3012 vol->upcase_len = 0;
3013 mutex_lock(&ntfs_lock); 3013 mutex_lock(&ntfs_lock);
3014 if (vol->upcase == default_upcase) { 3014 if (vol->upcase == default_upcase) {
3015 ntfs_nr_upcase_users--; 3015 ntfs_nr_upcase_users--;
3016 vol->upcase = NULL; 3016 vol->upcase = NULL;
3017 } 3017 }
3018 mutex_unlock(&ntfs_lock); 3018 mutex_unlock(&ntfs_lock);
3019 if (vol->upcase) { 3019 if (vol->upcase) {
3020 ntfs_free(vol->upcase); 3020 ntfs_free(vol->upcase);
3021 vol->upcase = NULL; 3021 vol->upcase = NULL;
3022 } 3022 }
3023 if (vol->nls_map) { 3023 if (vol->nls_map) {
3024 unload_nls(vol->nls_map); 3024 unload_nls(vol->nls_map);
3025 vol->nls_map = NULL; 3025 vol->nls_map = NULL;
3026 } 3026 }
3027 /* Error exit code path. */ 3027 /* Error exit code path. */
3028 unl_upcase_iput_tmp_ino_err_out_now: 3028 unl_upcase_iput_tmp_ino_err_out_now:
3029 /* 3029 /*
3030 * Decrease the number of upcase users and destroy the global default 3030 * Decrease the number of upcase users and destroy the global default
3031 * upcase table if necessary. 3031 * upcase table if necessary.
3032 */ 3032 */
3033 mutex_lock(&ntfs_lock); 3033 mutex_lock(&ntfs_lock);
3034 if (!--ntfs_nr_upcase_users && default_upcase) { 3034 if (!--ntfs_nr_upcase_users && default_upcase) {
3035 ntfs_free(default_upcase); 3035 ntfs_free(default_upcase);
3036 default_upcase = NULL; 3036 default_upcase = NULL;
3037 } 3037 }
3038 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users) 3038 if (vol->cluster_size <= 4096 && !--ntfs_nr_compression_users)
3039 free_compression_buffers(); 3039 free_compression_buffers();
3040 mutex_unlock(&ntfs_lock); 3040 mutex_unlock(&ntfs_lock);
3041 iput_tmp_ino_err_out_now: 3041 iput_tmp_ino_err_out_now:
3042 iput(tmp_ino); 3042 iput(tmp_ino);
3043 if (vol->mft_ino && vol->mft_ino != tmp_ino) 3043 if (vol->mft_ino && vol->mft_ino != tmp_ino)
3044 iput(vol->mft_ino); 3044 iput(vol->mft_ino);
3045 vol->mft_ino = NULL; 3045 vol->mft_ino = NULL;
3046 /* 3046 /*
3047 * This is needed to get ntfs_clear_extent_inode() called for each 3047 * This is needed to get ntfs_clear_extent_inode() called for each
3048 * inode we have ever called ntfs_iget()/iput() on, otherwise we A) 3048 * inode we have ever called ntfs_iget()/iput() on, otherwise we A)
3049 * leak resources and B) a subsequent mount fails automatically due to 3049 * leak resources and B) a subsequent mount fails automatically due to
3050 * ntfs_iget() never calling down into our ntfs_read_locked_inode() 3050 * ntfs_iget() never calling down into our ntfs_read_locked_inode()
3051 * method again... FIXME: Do we need to do this twice now because of 3051 * method again... FIXME: Do we need to do this twice now because of
3052 * attribute inodes? I think not, so leave as is for now... (AIA) 3052 * attribute inodes? I think not, so leave as is for now... (AIA)
3053 */ 3053 */
3054 if (invalidate_inodes(sb)) { 3054 if (invalidate_inodes(sb)) {
3055 ntfs_error(sb, "Busy inodes left. This is most likely a NTFS " 3055 ntfs_error(sb, "Busy inodes left. This is most likely a NTFS "
3056 "driver bug."); 3056 "driver bug.");
3057 /* Copied from fs/super.c. I just love this message. (-; */ 3057 /* Copied from fs/super.c. I just love this message. (-; */
3058 printk("NTFS: Busy inodes after umount. Self-destruct in 5 " 3058 printk("NTFS: Busy inodes after umount. Self-destruct in 5 "
3059 "seconds. Have a nice day...\n"); 3059 "seconds. Have a nice day...\n");
3060 } 3060 }
3061 /* Errors at this stage are irrelevant. */ 3061 /* Errors at this stage are irrelevant. */
3062 err_out_now: 3062 err_out_now:
3063 lock_kernel(); 3063 lock_kernel();
3064 sb->s_fs_info = NULL; 3064 sb->s_fs_info = NULL;
3065 kfree(vol); 3065 kfree(vol);
3066 ntfs_debug("Failed, returning -EINVAL."); 3066 ntfs_debug("Failed, returning -EINVAL.");
3067 lockdep_on(); 3067 lockdep_on();
3068 return -EINVAL; 3068 return -EINVAL;
3069 } 3069 }
3070 3070
3071 /* 3071 /*
3072 * This is a slab cache to optimize allocations and deallocations of Unicode 3072 * This is a slab cache to optimize allocations and deallocations of Unicode
3073 * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN 3073 * strings of the maximum length allowed by NTFS, which is NTFS_MAX_NAME_LEN
3074 * (255) Unicode characters + a terminating NULL Unicode character. 3074 * (255) Unicode characters + a terminating NULL Unicode character.
3075 */ 3075 */
3076 struct kmem_cache *ntfs_name_cache; 3076 struct kmem_cache *ntfs_name_cache;
3077 3077
3078 /* Slab caches for efficient allocation/deallocation of inodes. */ 3078 /* Slab caches for efficient allocation/deallocation of inodes. */
3079 struct kmem_cache *ntfs_inode_cache; 3079 struct kmem_cache *ntfs_inode_cache;
3080 struct kmem_cache *ntfs_big_inode_cache; 3080 struct kmem_cache *ntfs_big_inode_cache;
3081 3081
3082 /* Init once constructor for the inode slab cache. */ 3082 /* Init once constructor for the inode slab cache. */
3083 static void ntfs_big_inode_init_once(struct kmem_cache *cachep, void *foo) 3083 static void ntfs_big_inode_init_once(struct kmem_cache *cachep, void *foo)
3084 { 3084 {
3085 ntfs_inode *ni = (ntfs_inode *)foo; 3085 ntfs_inode *ni = (ntfs_inode *)foo;
3086 3086
3087 inode_init_once(VFS_I(ni)); 3087 inode_init_once(VFS_I(ni));
3088 } 3088 }
3089 3089
3090 /* 3090 /*
3091 * Slab caches to optimize allocations and deallocations of attribute search 3091 * Slab caches to optimize allocations and deallocations of attribute search
3092 * contexts and index contexts, respectively. 3092 * contexts and index contexts, respectively.
3093 */ 3093 */
3094 struct kmem_cache *ntfs_attr_ctx_cache; 3094 struct kmem_cache *ntfs_attr_ctx_cache;
3095 struct kmem_cache *ntfs_index_ctx_cache; 3095 struct kmem_cache *ntfs_index_ctx_cache;
3096 3096
3097 /* Driver wide mutex. */ 3097 /* Driver wide mutex. */
3098 DEFINE_MUTEX(ntfs_lock); 3098 DEFINE_MUTEX(ntfs_lock);
3099 3099
3100 static int ntfs_get_sb(struct file_system_type *fs_type, 3100 static int ntfs_get_sb(struct file_system_type *fs_type,
3101 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3101 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
3102 { 3102 {
3103 return get_sb_bdev(fs_type, flags, dev_name, data, ntfs_fill_super, 3103 return get_sb_bdev(fs_type, flags, dev_name, data, ntfs_fill_super,
3104 mnt); 3104 mnt);
3105 } 3105 }
3106 3106
3107 static struct file_system_type ntfs_fs_type = { 3107 static struct file_system_type ntfs_fs_type = {
3108 .owner = THIS_MODULE, 3108 .owner = THIS_MODULE,
3109 .name = "ntfs", 3109 .name = "ntfs",
3110 .get_sb = ntfs_get_sb, 3110 .get_sb = ntfs_get_sb,
3111 .kill_sb = kill_block_super, 3111 .kill_sb = kill_block_super,
3112 .fs_flags = FS_REQUIRES_DEV, 3112 .fs_flags = FS_REQUIRES_DEV,
3113 }; 3113 };
3114 3114
3115 /* Stable names for the slab caches. */ 3115 /* Stable names for the slab caches. */
3116 static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache"; 3116 static const char ntfs_index_ctx_cache_name[] = "ntfs_index_ctx_cache";
3117 static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache"; 3117 static const char ntfs_attr_ctx_cache_name[] = "ntfs_attr_ctx_cache";
3118 static const char ntfs_name_cache_name[] = "ntfs_name_cache"; 3118 static const char ntfs_name_cache_name[] = "ntfs_name_cache";
3119 static const char ntfs_inode_cache_name[] = "ntfs_inode_cache"; 3119 static const char ntfs_inode_cache_name[] = "ntfs_inode_cache";
3120 static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache"; 3120 static const char ntfs_big_inode_cache_name[] = "ntfs_big_inode_cache";
3121 3121
3122 static int __init init_ntfs_fs(void) 3122 static int __init init_ntfs_fs(void)
3123 { 3123 {
3124 int err = 0; 3124 int err = 0;
3125 3125
3126 /* This may be ugly but it results in pretty output so who cares. (-8 */ 3126 /* This may be ugly but it results in pretty output so who cares. (-8 */
3127 printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/" 3127 printk(KERN_INFO "NTFS driver " NTFS_VERSION " [Flags: R/"
3128 #ifdef NTFS_RW 3128 #ifdef NTFS_RW
3129 "W" 3129 "W"
3130 #else 3130 #else
3131 "O" 3131 "O"
3132 #endif 3132 #endif
3133 #ifdef DEBUG 3133 #ifdef DEBUG
3134 " DEBUG" 3134 " DEBUG"
3135 #endif 3135 #endif
3136 #ifdef MODULE 3136 #ifdef MODULE
3137 " MODULE" 3137 " MODULE"
3138 #endif 3138 #endif
3139 "].\n"); 3139 "].\n");
3140 3140
3141 ntfs_debug("Debug messages are enabled."); 3141 ntfs_debug("Debug messages are enabled.");
3142 3142
3143 ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name, 3143 ntfs_index_ctx_cache = kmem_cache_create(ntfs_index_ctx_cache_name,
3144 sizeof(ntfs_index_context), 0 /* offset */, 3144 sizeof(ntfs_index_context), 0 /* offset */,
3145 SLAB_HWCACHE_ALIGN, NULL /* ctor */); 3145 SLAB_HWCACHE_ALIGN, NULL /* ctor */);
3146 if (!ntfs_index_ctx_cache) { 3146 if (!ntfs_index_ctx_cache) {
3147 printk(KERN_CRIT "NTFS: Failed to create %s!\n", 3147 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
3148 ntfs_index_ctx_cache_name); 3148 ntfs_index_ctx_cache_name);
3149 goto ictx_err_out; 3149 goto ictx_err_out;
3150 } 3150 }
3151 ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name, 3151 ntfs_attr_ctx_cache = kmem_cache_create(ntfs_attr_ctx_cache_name,
3152 sizeof(ntfs_attr_search_ctx), 0 /* offset */, 3152 sizeof(ntfs_attr_search_ctx), 0 /* offset */,
3153 SLAB_HWCACHE_ALIGN, NULL /* ctor */); 3153 SLAB_HWCACHE_ALIGN, NULL /* ctor */);
3154 if (!ntfs_attr_ctx_cache) { 3154 if (!ntfs_attr_ctx_cache) {
3155 printk(KERN_CRIT "NTFS: Failed to create %s!\n", 3155 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
3156 ntfs_attr_ctx_cache_name); 3156 ntfs_attr_ctx_cache_name);
3157 goto actx_err_out; 3157 goto actx_err_out;
3158 } 3158 }
3159 3159
3160 ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name, 3160 ntfs_name_cache = kmem_cache_create(ntfs_name_cache_name,
3161 (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0, 3161 (NTFS_MAX_NAME_LEN+1) * sizeof(ntfschar), 0,
3162 SLAB_HWCACHE_ALIGN, NULL); 3162 SLAB_HWCACHE_ALIGN, NULL);
3163 if (!ntfs_name_cache) { 3163 if (!ntfs_name_cache) {
3164 printk(KERN_CRIT "NTFS: Failed to create %s!\n", 3164 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
3165 ntfs_name_cache_name); 3165 ntfs_name_cache_name);
3166 goto name_err_out; 3166 goto name_err_out;
3167 } 3167 }
3168 3168
3169 ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name, 3169 ntfs_inode_cache = kmem_cache_create(ntfs_inode_cache_name,
3170 sizeof(ntfs_inode), 0, 3170 sizeof(ntfs_inode), 0,
3171 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); 3171 SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL);
3172 if (!ntfs_inode_cache) { 3172 if (!ntfs_inode_cache) {
3173 printk(KERN_CRIT "NTFS: Failed to create %s!\n", 3173 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
3174 ntfs_inode_cache_name); 3174 ntfs_inode_cache_name);
3175 goto inode_err_out; 3175 goto inode_err_out;
3176 } 3176 }
3177 3177
3178 ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name, 3178 ntfs_big_inode_cache = kmem_cache_create(ntfs_big_inode_cache_name,
3179 sizeof(big_ntfs_inode), 0, 3179 sizeof(big_ntfs_inode), 0,
3180 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, 3180 SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
3181 ntfs_big_inode_init_once); 3181 ntfs_big_inode_init_once);
3182 if (!ntfs_big_inode_cache) { 3182 if (!ntfs_big_inode_cache) {
3183 printk(KERN_CRIT "NTFS: Failed to create %s!\n", 3183 printk(KERN_CRIT "NTFS: Failed to create %s!\n",
3184 ntfs_big_inode_cache_name); 3184 ntfs_big_inode_cache_name);
3185 goto big_inode_err_out; 3185 goto big_inode_err_out;
3186 } 3186 }
3187 3187
3188 /* Register the ntfs sysctls. */ 3188 /* Register the ntfs sysctls. */
3189 err = ntfs_sysctl(1); 3189 err = ntfs_sysctl(1);
3190 if (err) { 3190 if (err) {
3191 printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n"); 3191 printk(KERN_CRIT "NTFS: Failed to register NTFS sysctls!\n");
3192 goto sysctl_err_out; 3192 goto sysctl_err_out;
3193 } 3193 }
3194 3194
3195 err = register_filesystem(&ntfs_fs_type); 3195 err = register_filesystem(&ntfs_fs_type);
3196 if (!err) { 3196 if (!err) {
3197 ntfs_debug("NTFS driver registered successfully."); 3197 ntfs_debug("NTFS driver registered successfully.");
3198 return 0; /* Success! */ 3198 return 0; /* Success! */
3199 } 3199 }
3200 printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n"); 3200 printk(KERN_CRIT "NTFS: Failed to register NTFS filesystem driver!\n");
3201 3201
3202 sysctl_err_out: 3202 sysctl_err_out:
3203 kmem_cache_destroy(ntfs_big_inode_cache); 3203 kmem_cache_destroy(ntfs_big_inode_cache);
3204 big_inode_err_out: 3204 big_inode_err_out:
3205 kmem_cache_destroy(ntfs_inode_cache); 3205 kmem_cache_destroy(ntfs_inode_cache);
3206 inode_err_out: 3206 inode_err_out:
3207 kmem_cache_destroy(ntfs_name_cache); 3207 kmem_cache_destroy(ntfs_name_cache);
3208 name_err_out: 3208 name_err_out:
3209 kmem_cache_destroy(ntfs_attr_ctx_cache); 3209 kmem_cache_destroy(ntfs_attr_ctx_cache);
3210 actx_err_out: 3210 actx_err_out:
3211 kmem_cache_destroy(ntfs_index_ctx_cache); 3211 kmem_cache_destroy(ntfs_index_ctx_cache);
3212 ictx_err_out: 3212 ictx_err_out:
3213 if (!err) { 3213 if (!err) {
3214 printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver " 3214 printk(KERN_CRIT "NTFS: Aborting NTFS filesystem driver "
3215 "registration...\n"); 3215 "registration...\n");
3216 err = -ENOMEM; 3216 err = -ENOMEM;
3217 } 3217 }
3218 return err; 3218 return err;
3219 } 3219 }
3220 3220
3221 static void __exit exit_ntfs_fs(void) 3221 static void __exit exit_ntfs_fs(void)
3222 { 3222 {
3223 ntfs_debug("Unregistering NTFS driver."); 3223 ntfs_debug("Unregistering NTFS driver.");
3224 3224
3225 unregister_filesystem(&ntfs_fs_type); 3225 unregister_filesystem(&ntfs_fs_type);
3226 kmem_cache_destroy(ntfs_big_inode_cache); 3226 kmem_cache_destroy(ntfs_big_inode_cache);
3227 kmem_cache_destroy(ntfs_inode_cache); 3227 kmem_cache_destroy(ntfs_inode_cache);
3228 kmem_cache_destroy(ntfs_name_cache); 3228 kmem_cache_destroy(ntfs_name_cache);
3229 kmem_cache_destroy(ntfs_attr_ctx_cache); 3229 kmem_cache_destroy(ntfs_attr_ctx_cache);
3230 kmem_cache_destroy(ntfs_index_ctx_cache); 3230 kmem_cache_destroy(ntfs_index_ctx_cache);
3231 /* Unregister the ntfs sysctls. */ 3231 /* Unregister the ntfs sysctls. */
3232 ntfs_sysctl(0); 3232 ntfs_sysctl(0);
3233 } 3233 }
3234 3234
3235 MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>"); 3235 MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>");
3236 MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2007 Anton Altaparmakov"); 3236 MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2007 Anton Altaparmakov");
3237 MODULE_VERSION(NTFS_VERSION); 3237 MODULE_VERSION(NTFS_VERSION);
3238 MODULE_LICENSE("GPL"); 3238 MODULE_LICENSE("GPL");
3239 #ifdef DEBUG 3239 #ifdef DEBUG
3240 module_param(debug_msgs, bool, 0); 3240 module_param(debug_msgs, bool, 0);
3241 MODULE_PARM_DESC(debug_msgs, "Enable debug messages."); 3241 MODULE_PARM_DESC(debug_msgs, "Enable debug messages.");
3242 #endif 3242 #endif
3243 3243
3244 module_init(init_ntfs_fs) 3244 module_init(init_ntfs_fs)
3245 module_exit(exit_ntfs_fs) 3245 module_exit(exit_ntfs_fs)
3246 3246
1 #ifndef _LINUX_FS_H 1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H 2 #define _LINUX_FS_H
3 3
4 /* 4 /*
5 * This file has definitions for some important file table 5 * This file has definitions for some important file table
6 * structures etc. 6 * structures etc.
7 */ 7 */
8 8
9 #include <linux/limits.h> 9 #include <linux/limits.h>
10 #include <linux/ioctl.h> 10 #include <linux/ioctl.h>
11 11
12 /* 12 /*
13 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change 13 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
14 * the file limit at runtime and only root can increase the per-process 14 * the file limit at runtime and only root can increase the per-process
15 * nr_file rlimit, so it's safe to set up a ridiculously high absolute 15 * nr_file rlimit, so it's safe to set up a ridiculously high absolute
16 * upper limit on files-per-process. 16 * upper limit on files-per-process.
17 * 17 *
18 * Some programs (notably those using select()) may have to be 18 * Some programs (notably those using select()) may have to be
19 * recompiled to take full advantage of the new limits.. 19 * recompiled to take full advantage of the new limits..
20 */ 20 */
21 21
22 /* Fixed constants first: */ 22 /* Fixed constants first: */
23 #undef NR_OPEN 23 #undef NR_OPEN
24 #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */ 24 #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
25 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */ 25 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
26 26
27 #define BLOCK_SIZE_BITS 10 27 #define BLOCK_SIZE_BITS 10
28 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) 28 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
29 29
30 #define SEEK_SET 0 /* seek relative to beginning of file */ 30 #define SEEK_SET 0 /* seek relative to beginning of file */
31 #define SEEK_CUR 1 /* seek relative to current file position */ 31 #define SEEK_CUR 1 /* seek relative to current file position */
32 #define SEEK_END 2 /* seek relative to end of file */ 32 #define SEEK_END 2 /* seek relative to end of file */
33 #define SEEK_MAX SEEK_END 33 #define SEEK_MAX SEEK_END
34 34
35 /* And dynamically-tunable limits and defaults: */ 35 /* And dynamically-tunable limits and defaults: */
36 struct files_stat_struct { 36 struct files_stat_struct {
37 int nr_files; /* read only */ 37 int nr_files; /* read only */
38 int nr_free_files; /* read only */ 38 int nr_free_files; /* read only */
39 int max_files; /* tunable */ 39 int max_files; /* tunable */
40 }; 40 };
41 extern struct files_stat_struct files_stat; 41 extern struct files_stat_struct files_stat;
42 extern int get_max_files(void); 42 extern int get_max_files(void);
43 43
44 struct inodes_stat_t { 44 struct inodes_stat_t {
45 int nr_inodes; 45 int nr_inodes;
46 int nr_unused; 46 int nr_unused;
47 int dummy[5]; /* padding for sysctl ABI compatibility */ 47 int dummy[5]; /* padding for sysctl ABI compatibility */
48 }; 48 };
49 extern struct inodes_stat_t inodes_stat; 49 extern struct inodes_stat_t inodes_stat;
50 50
51 extern int leases_enable, lease_break_time; 51 extern int leases_enable, lease_break_time;
52 52
53 #ifdef CONFIG_DNOTIFY 53 #ifdef CONFIG_DNOTIFY
54 extern int dir_notify_enable; 54 extern int dir_notify_enable;
55 #endif 55 #endif
56 56
57 #define NR_FILE 8192 /* this can well be larger on a larger system */ 57 #define NR_FILE 8192 /* this can well be larger on a larger system */
58 58
59 #define MAY_EXEC 1 59 #define MAY_EXEC 1
60 #define MAY_WRITE 2 60 #define MAY_WRITE 2
61 #define MAY_READ 4 61 #define MAY_READ 4
62 #define MAY_APPEND 8 62 #define MAY_APPEND 8
63 63
64 #define FMODE_READ 1 64 #define FMODE_READ 1
65 #define FMODE_WRITE 2 65 #define FMODE_WRITE 2
66 66
67 /* Internal kernel extensions */ 67 /* Internal kernel extensions */
68 #define FMODE_LSEEK 4 68 #define FMODE_LSEEK 4
69 #define FMODE_PREAD 8 69 #define FMODE_PREAD 8
70 #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */ 70 #define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
71 71
72 /* File is being opened for execution. Primary users of this flag are 72 /* File is being opened for execution. Primary users of this flag are
73 distributed filesystems that can use it to achieve correct ETXTBUSY 73 distributed filesystems that can use it to achieve correct ETXTBUSY
74 behavior for cross-node execution/opening_for_writing of files */ 74 behavior for cross-node execution/opening_for_writing of files */
75 #define FMODE_EXEC 16 75 #define FMODE_EXEC 16
76 76
77 #define RW_MASK 1 77 #define RW_MASK 1
78 #define RWA_MASK 2 78 #define RWA_MASK 2
79 #define READ 0 79 #define READ 0
80 #define WRITE 1 80 #define WRITE 1
81 #define READA 2 /* read-ahead - don't block if no resources */ 81 #define READA 2 /* read-ahead - don't block if no resources */
82 #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ 82 #define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */
83 #define READ_SYNC (READ | (1 << BIO_RW_SYNC)) 83 #define READ_SYNC (READ | (1 << BIO_RW_SYNC))
84 #define READ_META (READ | (1 << BIO_RW_META)) 84 #define READ_META (READ | (1 << BIO_RW_META))
85 #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC)) 85 #define WRITE_SYNC (WRITE | (1 << BIO_RW_SYNC))
86 #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER)) 86 #define WRITE_BARRIER ((1 << BIO_RW) | (1 << BIO_RW_BARRIER))
87 87
88 #define SEL_IN 1 88 #define SEL_IN 1
89 #define SEL_OUT 2 89 #define SEL_OUT 2
90 #define SEL_EX 4 90 #define SEL_EX 4
91 91
92 /* public flags for file_system_type */ 92 /* public flags for file_system_type */
93 #define FS_REQUIRES_DEV 1 93 #define FS_REQUIRES_DEV 1
94 #define FS_BINARY_MOUNTDATA 2 94 #define FS_BINARY_MOUNTDATA 2
95 #define FS_HAS_SUBTYPE 4 95 #define FS_HAS_SUBTYPE 4
96 #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ 96 #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */
97 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() 97 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move()
98 * during rename() internally. 98 * during rename() internally.
99 */ 99 */
100 100
101 /* 101 /*
102 * These are the fs-independent mount-flags: up to 32 flags are supported 102 * These are the fs-independent mount-flags: up to 32 flags are supported
103 */ 103 */
104 #define MS_RDONLY 1 /* Mount read-only */ 104 #define MS_RDONLY 1 /* Mount read-only */
105 #define MS_NOSUID 2 /* Ignore suid and sgid bits */ 105 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
106 #define MS_NODEV 4 /* Disallow access to device special files */ 106 #define MS_NODEV 4 /* Disallow access to device special files */
107 #define MS_NOEXEC 8 /* Disallow program execution */ 107 #define MS_NOEXEC 8 /* Disallow program execution */
108 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ 108 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
109 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ 109 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
110 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ 110 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
111 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ 111 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
112 #define MS_NOATIME 1024 /* Do not update access times. */ 112 #define MS_NOATIME 1024 /* Do not update access times. */
113 #define MS_NODIRATIME 2048 /* Do not update directory access times */ 113 #define MS_NODIRATIME 2048 /* Do not update directory access times */
114 #define MS_BIND 4096 114 #define MS_BIND 4096
115 #define MS_MOVE 8192 115 #define MS_MOVE 8192
116 #define MS_REC 16384 116 #define MS_REC 16384
117 #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. 117 #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence.
118 MS_VERBOSE is deprecated. */ 118 MS_VERBOSE is deprecated. */
119 #define MS_SILENT 32768 119 #define MS_SILENT 32768
120 #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ 120 #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */
121 #define MS_UNBINDABLE (1<<17) /* change to unbindable */ 121 #define MS_UNBINDABLE (1<<17) /* change to unbindable */
122 #define MS_PRIVATE (1<<18) /* change to private */ 122 #define MS_PRIVATE (1<<18) /* change to private */
123 #define MS_SLAVE (1<<19) /* change to slave */ 123 #define MS_SLAVE (1<<19) /* change to slave */
124 #define MS_SHARED (1<<20) /* change to shared */ 124 #define MS_SHARED (1<<20) /* change to shared */
125 #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ 125 #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
126 #define MS_ACTIVE (1<<30) 126 #define MS_ACTIVE (1<<30)
127 #define MS_NOUSER (1<<31) 127 #define MS_NOUSER (1<<31)
128 128
129 /* 129 /*
130 * Superblock flags that can be altered by MS_REMOUNT 130 * Superblock flags that can be altered by MS_REMOUNT
131 */ 131 */
132 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK) 132 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK)
133 133
134 /* 134 /*
135 * Old magic mount flag and mask 135 * Old magic mount flag and mask
136 */ 136 */
137 #define MS_MGC_VAL 0xC0ED0000 137 #define MS_MGC_VAL 0xC0ED0000
138 #define MS_MGC_MSK 0xffff0000 138 #define MS_MGC_MSK 0xffff0000
139 139
140 /* Inode flags - they have nothing to superblock flags now */ 140 /* Inode flags - they have nothing to superblock flags now */
141 141
142 #define S_SYNC 1 /* Writes are synced at once */ 142 #define S_SYNC 1 /* Writes are synced at once */
143 #define S_NOATIME 2 /* Do not update access times */ 143 #define S_NOATIME 2 /* Do not update access times */
144 #define S_APPEND 4 /* Append-only file */ 144 #define S_APPEND 4 /* Append-only file */
145 #define S_IMMUTABLE 8 /* Immutable file */ 145 #define S_IMMUTABLE 8 /* Immutable file */
146 #define S_DEAD 16 /* removed, but still open directory */ 146 #define S_DEAD 16 /* removed, but still open directory */
147 #define S_NOQUOTA 32 /* Inode is not counted to quota */ 147 #define S_NOQUOTA 32 /* Inode is not counted to quota */
148 #define S_DIRSYNC 64 /* Directory modifications are synchronous */ 148 #define S_DIRSYNC 64 /* Directory modifications are synchronous */
149 #define S_NOCMTIME 128 /* Do not update file c/mtime */ 149 #define S_NOCMTIME 128 /* Do not update file c/mtime */
150 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ 150 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */
151 #define S_PRIVATE 512 /* Inode is fs-internal */ 151 #define S_PRIVATE 512 /* Inode is fs-internal */
152 152
153 /* 153 /*
154 * Note that nosuid etc flags are inode-specific: setting some file-system 154 * Note that nosuid etc flags are inode-specific: setting some file-system
155 * flags just means all the inodes inherit those flags by default. It might be 155 * flags just means all the inodes inherit those flags by default. It might be
156 * possible to override it selectively if you really wanted to with some 156 * possible to override it selectively if you really wanted to with some
157 * ioctl() that is not currently implemented. 157 * ioctl() that is not currently implemented.
158 * 158 *
159 * Exception: MS_RDONLY is always applied to the entire file system. 159 * Exception: MS_RDONLY is always applied to the entire file system.
160 * 160 *
161 * Unfortunately, it is possible to change a filesystems flags with it mounted 161 * Unfortunately, it is possible to change a filesystems flags with it mounted
162 * with files in use. This means that all of the inodes will not have their 162 * with files in use. This means that all of the inodes will not have their
163 * i_flags updated. Hence, i_flags no longer inherit the superblock mount 163 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
164 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org 164 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
165 */ 165 */
166 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) 166 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
167 167
168 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) 168 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
169 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ 169 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \
170 ((inode)->i_flags & S_SYNC)) 170 ((inode)->i_flags & S_SYNC))
171 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ 171 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
172 ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) 172 ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
173 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) 173 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
174 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) 174 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
175 175
176 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) 176 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
177 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) 177 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
178 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) 178 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
179 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) 179 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
180 180
181 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) 181 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
182 #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) 182 #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME)
183 #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) 183 #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE)
184 #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) 184 #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE)
185 185
186 /* the read-only stuff doesn't really belong here, but any other place is 186 /* the read-only stuff doesn't really belong here, but any other place is
187 probably as bad and I don't want to create yet another include file. */ 187 probably as bad and I don't want to create yet another include file. */
188 188
189 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ 189 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
190 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ 190 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
191 #define BLKRRPART _IO(0x12,95) /* re-read partition table */ 191 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
192 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ 192 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
193 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ 193 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
194 #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ 194 #define BLKRASET _IO(0x12,98) /* set read ahead for block device */
195 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ 195 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
196 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ 196 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
197 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ 197 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
198 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ 198 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
199 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ 199 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
200 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ 200 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
201 #if 0 201 #if 0
202 #define BLKPG _IO(0x12,105)/* See blkpg.h */ 202 #define BLKPG _IO(0x12,105)/* See blkpg.h */
203 203
204 /* Some people are morons. Do not use sizeof! */ 204 /* Some people are morons. Do not use sizeof! */
205 205
206 #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ 206 #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */
207 #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ 207 #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */
208 /* This was here just to show that the number is taken - 208 /* This was here just to show that the number is taken -
209 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ 209 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
210 #endif 210 #endif
211 /* A jump here: 108-111 have been used for various private purposes. */ 211 /* A jump here: 108-111 have been used for various private purposes. */
212 #define BLKBSZGET _IOR(0x12,112,size_t) 212 #define BLKBSZGET _IOR(0x12,112,size_t)
213 #define BLKBSZSET _IOW(0x12,113,size_t) 213 #define BLKBSZSET _IOW(0x12,113,size_t)
214 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ 214 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
215 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) 215 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
216 #define BLKTRACESTART _IO(0x12,116) 216 #define BLKTRACESTART _IO(0x12,116)
217 #define BLKTRACESTOP _IO(0x12,117) 217 #define BLKTRACESTOP _IO(0x12,117)
218 #define BLKTRACETEARDOWN _IO(0x12,118) 218 #define BLKTRACETEARDOWN _IO(0x12,118)
219 219
220 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ 220 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
221 #define FIBMAP _IO(0x00,1) /* bmap access */ 221 #define FIBMAP _IO(0x00,1) /* bmap access */
222 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ 222 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
223 223
224 #define FS_IOC_GETFLAGS _IOR('f', 1, long) 224 #define FS_IOC_GETFLAGS _IOR('f', 1, long)
225 #define FS_IOC_SETFLAGS _IOW('f', 2, long) 225 #define FS_IOC_SETFLAGS _IOW('f', 2, long)
226 #define FS_IOC_GETVERSION _IOR('v', 1, long) 226 #define FS_IOC_GETVERSION _IOR('v', 1, long)
227 #define FS_IOC_SETVERSION _IOW('v', 2, long) 227 #define FS_IOC_SETVERSION _IOW('v', 2, long)
228 #define FS_IOC32_GETFLAGS _IOR('f', 1, int) 228 #define FS_IOC32_GETFLAGS _IOR('f', 1, int)
229 #define FS_IOC32_SETFLAGS _IOW('f', 2, int) 229 #define FS_IOC32_SETFLAGS _IOW('f', 2, int)
230 #define FS_IOC32_GETVERSION _IOR('v', 1, int) 230 #define FS_IOC32_GETVERSION _IOR('v', 1, int)
231 #define FS_IOC32_SETVERSION _IOW('v', 2, int) 231 #define FS_IOC32_SETVERSION _IOW('v', 2, int)
232 232
233 /* 233 /*
234 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) 234 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
235 */ 235 */
236 #define FS_SECRM_FL 0x00000001 /* Secure deletion */ 236 #define FS_SECRM_FL 0x00000001 /* Secure deletion */
237 #define FS_UNRM_FL 0x00000002 /* Undelete */ 237 #define FS_UNRM_FL 0x00000002 /* Undelete */
238 #define FS_COMPR_FL 0x00000004 /* Compress file */ 238 #define FS_COMPR_FL 0x00000004 /* Compress file */
239 #define FS_SYNC_FL 0x00000008 /* Synchronous updates */ 239 #define FS_SYNC_FL 0x00000008 /* Synchronous updates */
240 #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 240 #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
241 #define FS_APPEND_FL 0x00000020 /* writes to file may only append */ 241 #define FS_APPEND_FL 0x00000020 /* writes to file may only append */
242 #define FS_NODUMP_FL 0x00000040 /* do not dump file */ 242 #define FS_NODUMP_FL 0x00000040 /* do not dump file */
243 #define FS_NOATIME_FL 0x00000080 /* do not update atime */ 243 #define FS_NOATIME_FL 0x00000080 /* do not update atime */
244 /* Reserved for compression usage... */ 244 /* Reserved for compression usage... */
245 #define FS_DIRTY_FL 0x00000100 245 #define FS_DIRTY_FL 0x00000100
246 #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 246 #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
247 #define FS_NOCOMP_FL 0x00000400 /* Don't compress */ 247 #define FS_NOCOMP_FL 0x00000400 /* Don't compress */
248 #define FS_ECOMPR_FL 0x00000800 /* Compression error */ 248 #define FS_ECOMPR_FL 0x00000800 /* Compression error */
249 /* End compression flags --- maybe not all used */ 249 /* End compression flags --- maybe not all used */
250 #define FS_BTREE_FL 0x00001000 /* btree format dir */ 250 #define FS_BTREE_FL 0x00001000 /* btree format dir */
251 #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 251 #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */
252 #define FS_IMAGIC_FL 0x00002000 /* AFS directory */ 252 #define FS_IMAGIC_FL 0x00002000 /* AFS directory */
253 #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ 253 #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */
254 #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 254 #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */
255 #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 255 #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
256 #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 256 #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
257 #define FS_EXTENT_FL 0x00080000 /* Extents */ 257 #define FS_EXTENT_FL 0x00080000 /* Extents */
258 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ 258 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
259 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ 259 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
260 260
261 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ 261 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
262 #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ 262 #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
263 263
264 264
265 #define SYNC_FILE_RANGE_WAIT_BEFORE 1 265 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
266 #define SYNC_FILE_RANGE_WRITE 2 266 #define SYNC_FILE_RANGE_WRITE 2
267 #define SYNC_FILE_RANGE_WAIT_AFTER 4 267 #define SYNC_FILE_RANGE_WAIT_AFTER 4
268 268
269 #ifdef __KERNEL__ 269 #ifdef __KERNEL__
270 270
271 #include <linux/linkage.h> 271 #include <linux/linkage.h>
272 #include <linux/wait.h> 272 #include <linux/wait.h>
273 #include <linux/types.h> 273 #include <linux/types.h>
274 #include <linux/kdev_t.h> 274 #include <linux/kdev_t.h>
275 #include <linux/dcache.h> 275 #include <linux/dcache.h>
276 #include <linux/namei.h> 276 #include <linux/namei.h>
277 #include <linux/stat.h> 277 #include <linux/stat.h>
278 #include <linux/cache.h> 278 #include <linux/cache.h>
279 #include <linux/kobject.h> 279 #include <linux/kobject.h>
280 #include <linux/list.h> 280 #include <linux/list.h>
281 #include <linux/radix-tree.h> 281 #include <linux/radix-tree.h>
282 #include <linux/prio_tree.h> 282 #include <linux/prio_tree.h>
283 #include <linux/init.h> 283 #include <linux/init.h>
284 #include <linux/pid.h> 284 #include <linux/pid.h>
285 #include <linux/mutex.h> 285 #include <linux/mutex.h>
286 #include <linux/capability.h> 286 #include <linux/capability.h>
287 287
288 #include <asm/atomic.h> 288 #include <asm/atomic.h>
289 #include <asm/semaphore.h> 289 #include <asm/semaphore.h>
290 #include <asm/byteorder.h> 290 #include <asm/byteorder.h>
291 291
292 struct export_operations; 292 struct export_operations;
293 struct hd_geometry; 293 struct hd_geometry;
294 struct iovec; 294 struct iovec;
295 struct nameidata; 295 struct nameidata;
296 struct kiocb; 296 struct kiocb;
297 struct pipe_inode_info; 297 struct pipe_inode_info;
298 struct poll_table_struct; 298 struct poll_table_struct;
299 struct kstatfs; 299 struct kstatfs;
300 struct vm_area_struct; 300 struct vm_area_struct;
301 struct vfsmount; 301 struct vfsmount;
302 302
303 extern void __init inode_init(void); 303 extern void __init inode_init(void);
304 extern void __init inode_init_early(void); 304 extern void __init inode_init_early(void);
305 extern void __init mnt_init(void); 305 extern void __init mnt_init(void);
306 extern void __init files_init(unsigned long); 306 extern void __init files_init(unsigned long);
307 307
308 struct buffer_head; 308 struct buffer_head;
309 typedef int (get_block_t)(struct inode *inode, sector_t iblock, 309 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
310 struct buffer_head *bh_result, int create); 310 struct buffer_head *bh_result, int create);
311 typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, 311 typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
312 ssize_t bytes, void *private); 312 ssize_t bytes, void *private);
313 313
314 /* 314 /*
315 * Attribute flags. These should be or-ed together to figure out what 315 * Attribute flags. These should be or-ed together to figure out what
316 * has been changed! 316 * has been changed!
317 */ 317 */
318 #define ATTR_MODE 1 318 #define ATTR_MODE 1
319 #define ATTR_UID 2 319 #define ATTR_UID 2
320 #define ATTR_GID 4 320 #define ATTR_GID 4
321 #define ATTR_SIZE 8 321 #define ATTR_SIZE 8
322 #define ATTR_ATIME 16 322 #define ATTR_ATIME 16
323 #define ATTR_MTIME 32 323 #define ATTR_MTIME 32
324 #define ATTR_CTIME 64 324 #define ATTR_CTIME 64
325 #define ATTR_ATIME_SET 128 325 #define ATTR_ATIME_SET 128
326 #define ATTR_MTIME_SET 256 326 #define ATTR_MTIME_SET 256
327 #define ATTR_FORCE 512 /* Not a change, but a change it */ 327 #define ATTR_FORCE 512 /* Not a change, but a change it */
328 #define ATTR_ATTR_FLAG 1024 328 #define ATTR_ATTR_FLAG 1024
329 #define ATTR_KILL_SUID 2048 329 #define ATTR_KILL_SUID 2048
330 #define ATTR_KILL_SGID 4096 330 #define ATTR_KILL_SGID 4096
331 #define ATTR_FILE 8192 331 #define ATTR_FILE 8192
332 332
333 /* 333 /*
334 * This is the Inode Attributes structure, used for notify_change(). It 334 * This is the Inode Attributes structure, used for notify_change(). It
335 * uses the above definitions as flags, to know which values have changed. 335 * uses the above definitions as flags, to know which values have changed.
336 * Also, in this manner, a Filesystem can look at only the values it cares 336 * Also, in this manner, a Filesystem can look at only the values it cares
337 * about. Basically, these are the attributes that the VFS layer can 337 * about. Basically, these are the attributes that the VFS layer can
338 * request to change from the FS layer. 338 * request to change from the FS layer.
339 * 339 *
340 * Derek Atkins <warlord@MIT.EDU> 94-10-20 340 * Derek Atkins <warlord@MIT.EDU> 94-10-20
341 */ 341 */
342 struct iattr { 342 struct iattr {
343 unsigned int ia_valid; 343 unsigned int ia_valid;
344 umode_t ia_mode; 344 umode_t ia_mode;
345 uid_t ia_uid; 345 uid_t ia_uid;
346 gid_t ia_gid; 346 gid_t ia_gid;
347 loff_t ia_size; 347 loff_t ia_size;
348 struct timespec ia_atime; 348 struct timespec ia_atime;
349 struct timespec ia_mtime; 349 struct timespec ia_mtime;
350 struct timespec ia_ctime; 350 struct timespec ia_ctime;
351 351
352 /* 352 /*
353 * Not an attribute, but an auxilary info for filesystems wanting to 353 * Not an attribute, but an auxilary info for filesystems wanting to
354 * implement an ftruncate() like method. NOTE: filesystem should 354 * implement an ftruncate() like method. NOTE: filesystem should
355 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL). 355 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
356 */ 356 */
357 struct file *ia_file; 357 struct file *ia_file;
358 }; 358 };
359 359
360 /* 360 /*
361 * Includes for diskquotas. 361 * Includes for diskquotas.
362 */ 362 */
363 #include <linux/quota.h> 363 #include <linux/quota.h>
364 364
365 /** 365 /**
366 * enum positive_aop_returns - aop return codes with specific semantics 366 * enum positive_aop_returns - aop return codes with specific semantics
367 * 367 *
368 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has 368 * @AOP_WRITEPAGE_ACTIVATE: Informs the caller that page writeback has
369 * completed, that the page is still locked, and 369 * completed, that the page is still locked, and
370 * should be considered active. The VM uses this hint 370 * should be considered active. The VM uses this hint
371 * to return the page to the active list -- it won't 371 * to return the page to the active list -- it won't
372 * be a candidate for writeback again in the near 372 * be a candidate for writeback again in the near
373 * future. Other callers must be careful to unlock 373 * future. Other callers must be careful to unlock
374 * the page if they get this return. Returned by 374 * the page if they get this return. Returned by
375 * writepage(); 375 * writepage();
376 * 376 *
377 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has 377 * @AOP_TRUNCATED_PAGE: The AOP method that was handed a locked page has
378 * unlocked it and the page might have been truncated. 378 * unlocked it and the page might have been truncated.
379 * The caller should back up to acquiring a new page and 379 * The caller should back up to acquiring a new page and
380 * trying again. The aop will be taking reasonable 380 * trying again. The aop will be taking reasonable
381 * precautions not to livelock. If the caller held a page 381 * precautions not to livelock. If the caller held a page
382 * reference, it should drop it before retrying. Returned 382 * reference, it should drop it before retrying. Returned
383 * by readpage(). 383 * by readpage().
384 * 384 *
385 * address_space_operation functions return these large constants to indicate 385 * address_space_operation functions return these large constants to indicate
386 * special semantics to the caller. These are much larger than the bytes in a 386 * special semantics to the caller. These are much larger than the bytes in a
387 * page to allow for functions that return the number of bytes operated on in a 387 * page to allow for functions that return the number of bytes operated on in a
388 * given page. 388 * given page.
389 */ 389 */
390 390
391 enum positive_aop_returns { 391 enum positive_aop_returns {
392 AOP_WRITEPAGE_ACTIVATE = 0x80000, 392 AOP_WRITEPAGE_ACTIVATE = 0x80000,
393 AOP_TRUNCATED_PAGE = 0x80001, 393 AOP_TRUNCATED_PAGE = 0x80001,
394 }; 394 };
395 395
396 #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */ 396 #define AOP_FLAG_UNINTERRUPTIBLE 0x0001 /* will not do a short write */
397 #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */ 397 #define AOP_FLAG_CONT_EXPAND 0x0002 /* called from cont_expand */
398 398
399 /* 399 /*
400 * oh the beauties of C type declarations. 400 * oh the beauties of C type declarations.
401 */ 401 */
402 struct page; 402 struct page;
403 struct address_space; 403 struct address_space;
404 struct writeback_control; 404 struct writeback_control;
405 405
406 struct iov_iter { 406 struct iov_iter {
407 const struct iovec *iov; 407 const struct iovec *iov;
408 unsigned long nr_segs; 408 unsigned long nr_segs;
409 size_t iov_offset; 409 size_t iov_offset;
410 size_t count; 410 size_t count;
411 }; 411 };
412 412
413 size_t iov_iter_copy_from_user_atomic(struct page *page, 413 size_t iov_iter_copy_from_user_atomic(struct page *page,
414 struct iov_iter *i, unsigned long offset, size_t bytes); 414 struct iov_iter *i, unsigned long offset, size_t bytes);
415 size_t iov_iter_copy_from_user(struct page *page, 415 size_t iov_iter_copy_from_user(struct page *page,
416 struct iov_iter *i, unsigned long offset, size_t bytes); 416 struct iov_iter *i, unsigned long offset, size_t bytes);
417 void iov_iter_advance(struct iov_iter *i, size_t bytes); 417 void iov_iter_advance(struct iov_iter *i, size_t bytes);
418 int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes); 418 int iov_iter_fault_in_readable(struct iov_iter *i, size_t bytes);
419 size_t iov_iter_single_seg_count(struct iov_iter *i); 419 size_t iov_iter_single_seg_count(struct iov_iter *i);
420 420
421 static inline void iov_iter_init(struct iov_iter *i, 421 static inline void iov_iter_init(struct iov_iter *i,
422 const struct iovec *iov, unsigned long nr_segs, 422 const struct iovec *iov, unsigned long nr_segs,
423 size_t count, size_t written) 423 size_t count, size_t written)
424 { 424 {
425 i->iov = iov; 425 i->iov = iov;
426 i->nr_segs = nr_segs; 426 i->nr_segs = nr_segs;
427 i->iov_offset = 0; 427 i->iov_offset = 0;
428 i->count = count + written; 428 i->count = count + written;
429 429
430 iov_iter_advance(i, written); 430 iov_iter_advance(i, written);
431 } 431 }
432 432
433 static inline size_t iov_iter_count(struct iov_iter *i) 433 static inline size_t iov_iter_count(struct iov_iter *i)
434 { 434 {
435 return i->count; 435 return i->count;
436 } 436 }
437 437
438 438
439 struct address_space_operations { 439 struct address_space_operations {
440 int (*writepage)(struct page *page, struct writeback_control *wbc); 440 int (*writepage)(struct page *page, struct writeback_control *wbc);
441 int (*readpage)(struct file *, struct page *); 441 int (*readpage)(struct file *, struct page *);
442 void (*sync_page)(struct page *); 442 void (*sync_page)(struct page *);
443 443
444 /* Write back some dirty pages from this mapping. */ 444 /* Write back some dirty pages from this mapping. */
445 int (*writepages)(struct address_space *, struct writeback_control *); 445 int (*writepages)(struct address_space *, struct writeback_control *);
446 446
447 /* Set a page dirty. Return true if this dirtied it */ 447 /* Set a page dirty. Return true if this dirtied it */
448 int (*set_page_dirty)(struct page *page); 448 int (*set_page_dirty)(struct page *page);
449 449
450 int (*readpages)(struct file *filp, struct address_space *mapping, 450 int (*readpages)(struct file *filp, struct address_space *mapping,
451 struct list_head *pages, unsigned nr_pages); 451 struct list_head *pages, unsigned nr_pages);
452 452
453 /* 453 /*
454 * ext3 requires that a successful prepare_write() call be followed 454 * ext3 requires that a successful prepare_write() call be followed
455 * by a commit_write() call - they must be balanced 455 * by a commit_write() call - they must be balanced
456 */ 456 */
457 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned); 457 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
458 int (*commit_write)(struct file *, struct page *, unsigned, unsigned); 458 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
459 459
460 int (*write_begin)(struct file *, struct address_space *mapping, 460 int (*write_begin)(struct file *, struct address_space *mapping,
461 loff_t pos, unsigned len, unsigned flags, 461 loff_t pos, unsigned len, unsigned flags,
462 struct page **pagep, void **fsdata); 462 struct page **pagep, void **fsdata);
463 int (*write_end)(struct file *, struct address_space *mapping, 463 int (*write_end)(struct file *, struct address_space *mapping,
464 loff_t pos, unsigned len, unsigned copied, 464 loff_t pos, unsigned len, unsigned copied,
465 struct page *page, void *fsdata); 465 struct page *page, void *fsdata);
466 466
467 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */ 467 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
468 sector_t (*bmap)(struct address_space *, sector_t); 468 sector_t (*bmap)(struct address_space *, sector_t);
469 void (*invalidatepage) (struct page *, unsigned long); 469 void (*invalidatepage) (struct page *, unsigned long);
470 int (*releasepage) (struct page *, gfp_t); 470 int (*releasepage) (struct page *, gfp_t);
471 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov, 471 ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
472 loff_t offset, unsigned long nr_segs); 472 loff_t offset, unsigned long nr_segs);
473 struct page* (*get_xip_page)(struct address_space *, sector_t, 473 struct page* (*get_xip_page)(struct address_space *, sector_t,
474 int); 474 int);
475 /* migrate the contents of a page to the specified target */ 475 /* migrate the contents of a page to the specified target */
476 int (*migratepage) (struct address_space *, 476 int (*migratepage) (struct address_space *,
477 struct page *, struct page *); 477 struct page *, struct page *);
478 int (*launder_page) (struct page *); 478 int (*launder_page) (struct page *);
479 }; 479 };
480 480
481 /* 481 /*
482 * pagecache_write_begin/pagecache_write_end must be used by general code 482 * pagecache_write_begin/pagecache_write_end must be used by general code
483 * to write into the pagecache. 483 * to write into the pagecache.
484 */ 484 */
485 int pagecache_write_begin(struct file *, struct address_space *mapping, 485 int pagecache_write_begin(struct file *, struct address_space *mapping,
486 loff_t pos, unsigned len, unsigned flags, 486 loff_t pos, unsigned len, unsigned flags,
487 struct page **pagep, void **fsdata); 487 struct page **pagep, void **fsdata);
488 488
489 int pagecache_write_end(struct file *, struct address_space *mapping, 489 int pagecache_write_end(struct file *, struct address_space *mapping,
490 loff_t pos, unsigned len, unsigned copied, 490 loff_t pos, unsigned len, unsigned copied,
491 struct page *page, void *fsdata); 491 struct page *page, void *fsdata);
492 492
493 struct backing_dev_info; 493 struct backing_dev_info;
494 struct address_space { 494 struct address_space {
495 struct inode *host; /* owner: inode, block_device */ 495 struct inode *host; /* owner: inode, block_device */
496 struct radix_tree_root page_tree; /* radix tree of all pages */ 496 struct radix_tree_root page_tree; /* radix tree of all pages */
497 rwlock_t tree_lock; /* and rwlock protecting it */ 497 rwlock_t tree_lock; /* and rwlock protecting it */
498 unsigned int i_mmap_writable;/* count VM_SHARED mappings */ 498 unsigned int i_mmap_writable;/* count VM_SHARED mappings */
499 struct prio_tree_root i_mmap; /* tree of private and shared mappings */ 499 struct prio_tree_root i_mmap; /* tree of private and shared mappings */
500 struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */ 500 struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
501 spinlock_t i_mmap_lock; /* protect tree, count, list */ 501 spinlock_t i_mmap_lock; /* protect tree, count, list */
502 unsigned int truncate_count; /* Cover race condition with truncate */ 502 unsigned int truncate_count; /* Cover race condition with truncate */
503 unsigned long nrpages; /* number of total pages */ 503 unsigned long nrpages; /* number of total pages */
504 pgoff_t writeback_index;/* writeback starts here */ 504 pgoff_t writeback_index;/* writeback starts here */
505 const struct address_space_operations *a_ops; /* methods */ 505 const struct address_space_operations *a_ops; /* methods */
506 unsigned long flags; /* error bits/gfp mask */ 506 unsigned long flags; /* error bits/gfp mask */
507 struct backing_dev_info *backing_dev_info; /* device readahead, etc */ 507 struct backing_dev_info *backing_dev_info; /* device readahead, etc */
508 spinlock_t private_lock; /* for use by the address_space */ 508 spinlock_t private_lock; /* for use by the address_space */
509 struct list_head private_list; /* ditto */ 509 struct list_head private_list; /* ditto */
510 struct address_space *assoc_mapping; /* ditto */ 510 struct address_space *assoc_mapping; /* ditto */
511 } __attribute__((aligned(sizeof(long)))); 511 } __attribute__((aligned(sizeof(long))));
512 /* 512 /*
513 * On most architectures that alignment is already the case; but 513 * On most architectures that alignment is already the case; but
514 * must be enforced here for CRIS, to let the least signficant bit 514 * must be enforced here for CRIS, to let the least signficant bit
515 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON. 515 * of struct page's "mapping" pointer be used for PAGE_MAPPING_ANON.
516 */ 516 */
517 517
518 struct block_device { 518 struct block_device {
519 dev_t bd_dev; /* not a kdev_t - it's a search key */ 519 dev_t bd_dev; /* not a kdev_t - it's a search key */
520 struct inode * bd_inode; /* will die */ 520 struct inode * bd_inode; /* will die */
521 int bd_openers; 521 int bd_openers;
522 struct mutex bd_mutex; /* open/close mutex */ 522 struct mutex bd_mutex; /* open/close mutex */
523 struct semaphore bd_mount_sem; 523 struct semaphore bd_mount_sem;
524 struct list_head bd_inodes; 524 struct list_head bd_inodes;
525 void * bd_holder; 525 void * bd_holder;
526 int bd_holders; 526 int bd_holders;
527 #ifdef CONFIG_SYSFS 527 #ifdef CONFIG_SYSFS
528 struct list_head bd_holder_list; 528 struct list_head bd_holder_list;
529 #endif 529 #endif
530 struct block_device * bd_contains; 530 struct block_device * bd_contains;
531 unsigned bd_block_size; 531 unsigned bd_block_size;
532 struct hd_struct * bd_part; 532 struct hd_struct * bd_part;
533 /* number of times partitions within this device have been opened. */ 533 /* number of times partitions within this device have been opened. */
534 unsigned bd_part_count; 534 unsigned bd_part_count;
535 int bd_invalidated; 535 int bd_invalidated;
536 struct gendisk * bd_disk; 536 struct gendisk * bd_disk;
537 struct list_head bd_list; 537 struct list_head bd_list;
538 struct backing_dev_info *bd_inode_backing_dev_info; 538 struct backing_dev_info *bd_inode_backing_dev_info;
539 /* 539 /*
540 * Private data. You must have bd_claim'ed the block_device 540 * Private data. You must have bd_claim'ed the block_device
541 * to use this. NOTE: bd_claim allows an owner to claim 541 * to use this. NOTE: bd_claim allows an owner to claim
542 * the same device multiple times, the owner must take special 542 * the same device multiple times, the owner must take special
543 * care to not mess up bd_private for that case. 543 * care to not mess up bd_private for that case.
544 */ 544 */
545 unsigned long bd_private; 545 unsigned long bd_private;
546 }; 546 };
547 547
548 /* 548 /*
549 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache 549 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
550 * radix trees 550 * radix trees
551 */ 551 */
552 #define PAGECACHE_TAG_DIRTY 0 552 #define PAGECACHE_TAG_DIRTY 0
553 #define PAGECACHE_TAG_WRITEBACK 1 553 #define PAGECACHE_TAG_WRITEBACK 1
554 554
555 int mapping_tagged(struct address_space *mapping, int tag); 555 int mapping_tagged(struct address_space *mapping, int tag);
556 556
557 /* 557 /*
558 * Might pages of this file be mapped into userspace? 558 * Might pages of this file be mapped into userspace?
559 */ 559 */
560 static inline int mapping_mapped(struct address_space *mapping) 560 static inline int mapping_mapped(struct address_space *mapping)
561 { 561 {
562 return !prio_tree_empty(&mapping->i_mmap) || 562 return !prio_tree_empty(&mapping->i_mmap) ||
563 !list_empty(&mapping->i_mmap_nonlinear); 563 !list_empty(&mapping->i_mmap_nonlinear);
564 } 564 }
565 565
566 /* 566 /*
567 * Might pages of this file have been modified in userspace? 567 * Might pages of this file have been modified in userspace?
568 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff 568 * Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap_pgoff
569 * marks vma as VM_SHARED if it is shared, and the file was opened for 569 * marks vma as VM_SHARED if it is shared, and the file was opened for
570 * writing i.e. vma may be mprotected writable even if now readonly. 570 * writing i.e. vma may be mprotected writable even if now readonly.
571 */ 571 */
572 static inline int mapping_writably_mapped(struct address_space *mapping) 572 static inline int mapping_writably_mapped(struct address_space *mapping)
573 { 573 {
574 return mapping->i_mmap_writable != 0; 574 return mapping->i_mmap_writable != 0;
575 } 575 }
576 576
577 /* 577 /*
578 * Use sequence counter to get consistent i_size on 32-bit processors. 578 * Use sequence counter to get consistent i_size on 32-bit processors.
579 */ 579 */
580 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 580 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
581 #include <linux/seqlock.h> 581 #include <linux/seqlock.h>
582 #define __NEED_I_SIZE_ORDERED 582 #define __NEED_I_SIZE_ORDERED
583 #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount) 583 #define i_size_ordered_init(inode) seqcount_init(&inode->i_size_seqcount)
584 #else 584 #else
585 #define i_size_ordered_init(inode) do { } while (0) 585 #define i_size_ordered_init(inode) do { } while (0)
586 #endif 586 #endif
587 587
588 struct inode { 588 struct inode {
589 struct hlist_node i_hash; 589 struct hlist_node i_hash;
590 struct list_head i_list; 590 struct list_head i_list;
591 struct list_head i_sb_list; 591 struct list_head i_sb_list;
592 struct list_head i_dentry; 592 struct list_head i_dentry;
593 unsigned long i_ino; 593 unsigned long i_ino;
594 atomic_t i_count; 594 atomic_t i_count;
595 unsigned int i_nlink; 595 unsigned int i_nlink;
596 uid_t i_uid; 596 uid_t i_uid;
597 gid_t i_gid; 597 gid_t i_gid;
598 dev_t i_rdev; 598 dev_t i_rdev;
599 unsigned long i_version; 599 unsigned long i_version;
600 loff_t i_size; 600 loff_t i_size;
601 #ifdef __NEED_I_SIZE_ORDERED 601 #ifdef __NEED_I_SIZE_ORDERED
602 seqcount_t i_size_seqcount; 602 seqcount_t i_size_seqcount;
603 #endif 603 #endif
604 struct timespec i_atime; 604 struct timespec i_atime;
605 struct timespec i_mtime; 605 struct timespec i_mtime;
606 struct timespec i_ctime; 606 struct timespec i_ctime;
607 unsigned int i_blkbits; 607 unsigned int i_blkbits;
608 blkcnt_t i_blocks; 608 blkcnt_t i_blocks;
609 unsigned short i_bytes; 609 unsigned short i_bytes;
610 umode_t i_mode; 610 umode_t i_mode;
611 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */ 611 spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
612 struct mutex i_mutex; 612 struct mutex i_mutex;
613 struct rw_semaphore i_alloc_sem; 613 struct rw_semaphore i_alloc_sem;
614 const struct inode_operations *i_op; 614 const struct inode_operations *i_op;
615 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */ 615 const struct file_operations *i_fop; /* former ->i_op->default_file_ops */
616 struct super_block *i_sb; 616 struct super_block *i_sb;
617 struct file_lock *i_flock; 617 struct file_lock *i_flock;
618 struct address_space *i_mapping; 618 struct address_space *i_mapping;
619 struct address_space i_data; 619 struct address_space i_data;
620 #ifdef CONFIG_QUOTA 620 #ifdef CONFIG_QUOTA
621 struct dquot *i_dquot[MAXQUOTAS]; 621 struct dquot *i_dquot[MAXQUOTAS];
622 #endif 622 #endif
623 struct list_head i_devices; 623 struct list_head i_devices;
624 union { 624 union {
625 struct pipe_inode_info *i_pipe; 625 struct pipe_inode_info *i_pipe;
626 struct block_device *i_bdev; 626 struct block_device *i_bdev;
627 struct cdev *i_cdev; 627 struct cdev *i_cdev;
628 }; 628 };
629 int i_cindex; 629 int i_cindex;
630 630
631 __u32 i_generation; 631 __u32 i_generation;
632 632
633 #ifdef CONFIG_DNOTIFY 633 #ifdef CONFIG_DNOTIFY
634 unsigned long i_dnotify_mask; /* Directory notify events */ 634 unsigned long i_dnotify_mask; /* Directory notify events */
635 struct dnotify_struct *i_dnotify; /* for directory notifications */ 635 struct dnotify_struct *i_dnotify; /* for directory notifications */
636 #endif 636 #endif
637 637
638 #ifdef CONFIG_INOTIFY 638 #ifdef CONFIG_INOTIFY
639 struct list_head inotify_watches; /* watches on this inode */ 639 struct list_head inotify_watches; /* watches on this inode */
640 struct mutex inotify_mutex; /* protects the watches list */ 640 struct mutex inotify_mutex; /* protects the watches list */
641 #endif 641 #endif
642 642
643 unsigned long i_state; 643 unsigned long i_state;
644 unsigned long dirtied_when; /* jiffies of first dirtying */ 644 unsigned long dirtied_when; /* jiffies of first dirtying */
645 645
646 unsigned int i_flags; 646 unsigned int i_flags;
647 647
648 atomic_t i_writecount; 648 atomic_t i_writecount;
649 #ifdef CONFIG_SECURITY 649 #ifdef CONFIG_SECURITY
650 void *i_security; 650 void *i_security;
651 #endif 651 #endif
652 void *i_private; /* fs or device private pointer */ 652 void *i_private; /* fs or device private pointer */
653 }; 653 };
654 654
655 /* 655 /*
656 * inode->i_mutex nesting subclasses for the lock validator: 656 * inode->i_mutex nesting subclasses for the lock validator:
657 * 657 *
658 * 0: the object of the current VFS operation 658 * 0: the object of the current VFS operation
659 * 1: parent 659 * 1: parent
660 * 2: child/target 660 * 2: child/target
661 * 3: quota file 661 * 3: quota file
662 * 662 *
663 * The locking order between these classes is 663 * The locking order between these classes is
664 * parent -> child -> normal -> xattr -> quota 664 * parent -> child -> normal -> xattr -> quota
665 */ 665 */
666 enum inode_i_mutex_lock_class 666 enum inode_i_mutex_lock_class
667 { 667 {
668 I_MUTEX_NORMAL, 668 I_MUTEX_NORMAL,
669 I_MUTEX_PARENT, 669 I_MUTEX_PARENT,
670 I_MUTEX_CHILD, 670 I_MUTEX_CHILD,
671 I_MUTEX_XATTR, 671 I_MUTEX_XATTR,
672 I_MUTEX_QUOTA 672 I_MUTEX_QUOTA
673 }; 673 };
674 674
675 extern void inode_double_lock(struct inode *inode1, struct inode *inode2); 675 extern void inode_double_lock(struct inode *inode1, struct inode *inode2);
676 extern void inode_double_unlock(struct inode *inode1, struct inode *inode2); 676 extern void inode_double_unlock(struct inode *inode1, struct inode *inode2);
677 677
678 /* 678 /*
679 * NOTE: in a 32bit arch with a preemptable kernel and 679 * NOTE: in a 32bit arch with a preemptable kernel and
680 * an UP compile the i_size_read/write must be atomic 680 * an UP compile the i_size_read/write must be atomic
681 * with respect to the local cpu (unlike with preempt disabled), 681 * with respect to the local cpu (unlike with preempt disabled),
682 * but they don't need to be atomic with respect to other cpus like in 682 * but they don't need to be atomic with respect to other cpus like in
683 * true SMP (so they need either to either locally disable irq around 683 * true SMP (so they need either to either locally disable irq around
684 * the read or for example on x86 they can be still implemented as a 684 * the read or for example on x86 they can be still implemented as a
685 * cmpxchg8b without the need of the lock prefix). For SMP compiles 685 * cmpxchg8b without the need of the lock prefix). For SMP compiles
686 * and 64bit archs it makes no difference if preempt is enabled or not. 686 * and 64bit archs it makes no difference if preempt is enabled or not.
687 */ 687 */
688 static inline loff_t i_size_read(const struct inode *inode) 688 static inline loff_t i_size_read(const struct inode *inode)
689 { 689 {
690 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 690 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
691 loff_t i_size; 691 loff_t i_size;
692 unsigned int seq; 692 unsigned int seq;
693 693
694 do { 694 do {
695 seq = read_seqcount_begin(&inode->i_size_seqcount); 695 seq = read_seqcount_begin(&inode->i_size_seqcount);
696 i_size = inode->i_size; 696 i_size = inode->i_size;
697 } while (read_seqcount_retry(&inode->i_size_seqcount, seq)); 697 } while (read_seqcount_retry(&inode->i_size_seqcount, seq));
698 return i_size; 698 return i_size;
699 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) 699 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
700 loff_t i_size; 700 loff_t i_size;
701 701
702 preempt_disable(); 702 preempt_disable();
703 i_size = inode->i_size; 703 i_size = inode->i_size;
704 preempt_enable(); 704 preempt_enable();
705 return i_size; 705 return i_size;
706 #else 706 #else
707 return inode->i_size; 707 return inode->i_size;
708 #endif 708 #endif
709 } 709 }
710 710
711 /* 711 /*
712 * NOTE: unlike i_size_read(), i_size_write() does need locking around it 712 * NOTE: unlike i_size_read(), i_size_write() does need locking around it
713 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount 713 * (normally i_mutex), otherwise on 32bit/SMP an update of i_size_seqcount
714 * can be lost, resulting in subsequent i_size_read() calls spinning forever. 714 * can be lost, resulting in subsequent i_size_read() calls spinning forever.
715 */ 715 */
716 static inline void i_size_write(struct inode *inode, loff_t i_size) 716 static inline void i_size_write(struct inode *inode, loff_t i_size)
717 { 717 {
718 #if BITS_PER_LONG==32 && defined(CONFIG_SMP) 718 #if BITS_PER_LONG==32 && defined(CONFIG_SMP)
719 write_seqcount_begin(&inode->i_size_seqcount); 719 write_seqcount_begin(&inode->i_size_seqcount);
720 inode->i_size = i_size; 720 inode->i_size = i_size;
721 write_seqcount_end(&inode->i_size_seqcount); 721 write_seqcount_end(&inode->i_size_seqcount);
722 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT) 722 #elif BITS_PER_LONG==32 && defined(CONFIG_PREEMPT)
723 preempt_disable(); 723 preempt_disable();
724 inode->i_size = i_size; 724 inode->i_size = i_size;
725 preempt_enable(); 725 preempt_enable();
726 #else 726 #else
727 inode->i_size = i_size; 727 inode->i_size = i_size;
728 #endif 728 #endif
729 } 729 }
730 730
731 static inline unsigned iminor(const struct inode *inode) 731 static inline unsigned iminor(const struct inode *inode)
732 { 732 {
733 return MINOR(inode->i_rdev); 733 return MINOR(inode->i_rdev);
734 } 734 }
735 735
736 static inline unsigned imajor(const struct inode *inode) 736 static inline unsigned imajor(const struct inode *inode)
737 { 737 {
738 return MAJOR(inode->i_rdev); 738 return MAJOR(inode->i_rdev);
739 } 739 }
740 740
741 extern struct block_device *I_BDEV(struct inode *inode); 741 extern struct block_device *I_BDEV(struct inode *inode);
742 742
743 struct fown_struct { 743 struct fown_struct {
744 rwlock_t lock; /* protects pid, uid, euid fields */ 744 rwlock_t lock; /* protects pid, uid, euid fields */
745 struct pid *pid; /* pid or -pgrp where SIGIO should be sent */ 745 struct pid *pid; /* pid or -pgrp where SIGIO should be sent */
746 enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */ 746 enum pid_type pid_type; /* Kind of process group SIGIO should be sent to */
747 uid_t uid, euid; /* uid/euid of process setting the owner */ 747 uid_t uid, euid; /* uid/euid of process setting the owner */
748 int signum; /* posix.1b rt signal to be delivered on IO */ 748 int signum; /* posix.1b rt signal to be delivered on IO */
749 }; 749 };
750 750
751 /* 751 /*
752 * Track a single file's readahead state 752 * Track a single file's readahead state
753 */ 753 */
754 struct file_ra_state { 754 struct file_ra_state {
755 pgoff_t start; /* where readahead started */ 755 pgoff_t start; /* where readahead started */
756 unsigned int size; /* # of readahead pages */ 756 unsigned int size; /* # of readahead pages */
757 unsigned int async_size; /* do asynchronous readahead when 757 unsigned int async_size; /* do asynchronous readahead when
758 there are only # of pages ahead */ 758 there are only # of pages ahead */
759 759
760 unsigned int ra_pages; /* Maximum readahead window */ 760 unsigned int ra_pages; /* Maximum readahead window */
761 int mmap_miss; /* Cache miss stat for mmap accesses */ 761 int mmap_miss; /* Cache miss stat for mmap accesses */
762 loff_t prev_pos; /* Cache last read() position */ 762 loff_t prev_pos; /* Cache last read() position */
763 }; 763 };
764 764
765 /* 765 /*
766 * Check if @index falls in the readahead windows. 766 * Check if @index falls in the readahead windows.
767 */ 767 */
768 static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index) 768 static inline int ra_has_index(struct file_ra_state *ra, pgoff_t index)
769 { 769 {
770 return (index >= ra->start && 770 return (index >= ra->start &&
771 index < ra->start + ra->size); 771 index < ra->start + ra->size);
772 } 772 }
773 773
774 struct file { 774 struct file {
775 /* 775 /*
776 * fu_list becomes invalid after file_free is called and queued via 776 * fu_list becomes invalid after file_free is called and queued via
777 * fu_rcuhead for RCU freeing 777 * fu_rcuhead for RCU freeing
778 */ 778 */
779 union { 779 union {
780 struct list_head fu_list; 780 struct list_head fu_list;
781 struct rcu_head fu_rcuhead; 781 struct rcu_head fu_rcuhead;
782 } f_u; 782 } f_u;
783 struct path f_path; 783 struct path f_path;
784 #define f_dentry f_path.dentry 784 #define f_dentry f_path.dentry
785 #define f_vfsmnt f_path.mnt 785 #define f_vfsmnt f_path.mnt
786 const struct file_operations *f_op; 786 const struct file_operations *f_op;
787 atomic_t f_count; 787 atomic_t f_count;
788 unsigned int f_flags; 788 unsigned int f_flags;
789 mode_t f_mode; 789 mode_t f_mode;
790 loff_t f_pos; 790 loff_t f_pos;
791 struct fown_struct f_owner; 791 struct fown_struct f_owner;
792 unsigned int f_uid, f_gid; 792 unsigned int f_uid, f_gid;
793 struct file_ra_state f_ra; 793 struct file_ra_state f_ra;
794 794
795 u64 f_version; 795 u64 f_version;
796 #ifdef CONFIG_SECURITY 796 #ifdef CONFIG_SECURITY
797 void *f_security; 797 void *f_security;
798 #endif 798 #endif
799 /* needed for tty driver, and maybe others */ 799 /* needed for tty driver, and maybe others */
800 void *private_data; 800 void *private_data;
801 801
802 #ifdef CONFIG_EPOLL 802 #ifdef CONFIG_EPOLL
803 /* Used by fs/eventpoll.c to link all the hooks to this file */ 803 /* Used by fs/eventpoll.c to link all the hooks to this file */
804 struct list_head f_ep_links; 804 struct list_head f_ep_links;
805 spinlock_t f_ep_lock; 805 spinlock_t f_ep_lock;
806 #endif /* #ifdef CONFIG_EPOLL */ 806 #endif /* #ifdef CONFIG_EPOLL */
807 struct address_space *f_mapping; 807 struct address_space *f_mapping;
808 }; 808 };
809 extern spinlock_t files_lock; 809 extern spinlock_t files_lock;
810 #define file_list_lock() spin_lock(&files_lock); 810 #define file_list_lock() spin_lock(&files_lock);
811 #define file_list_unlock() spin_unlock(&files_lock); 811 #define file_list_unlock() spin_unlock(&files_lock);
812 812
813 #define get_file(x) atomic_inc(&(x)->f_count) 813 #define get_file(x) atomic_inc(&(x)->f_count)
814 #define file_count(x) atomic_read(&(x)->f_count) 814 #define file_count(x) atomic_read(&(x)->f_count)
815 815
816 #define MAX_NON_LFS ((1UL<<31) - 1) 816 #define MAX_NON_LFS ((1UL<<31) - 1)
817 817
818 /* Page cache limit. The filesystems should put that into their s_maxbytes 818 /* Page cache limit. The filesystems should put that into their s_maxbytes
819 limits, otherwise bad things can happen in VM. */ 819 limits, otherwise bad things can happen in VM. */
820 #if BITS_PER_LONG==32 820 #if BITS_PER_LONG==32
821 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) 821 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
822 #elif BITS_PER_LONG==64 822 #elif BITS_PER_LONG==64
823 #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL 823 #define MAX_LFS_FILESIZE 0x7fffffffffffffffUL
824 #endif 824 #endif
825 825
826 #define FL_POSIX 1 826 #define FL_POSIX 1
827 #define FL_FLOCK 2 827 #define FL_FLOCK 2
828 #define FL_ACCESS 8 /* not trying to lock, just looking */ 828 #define FL_ACCESS 8 /* not trying to lock, just looking */
829 #define FL_EXISTS 16 /* when unlocking, test for existence */ 829 #define FL_EXISTS 16 /* when unlocking, test for existence */
830 #define FL_LEASE 32 /* lease held on this file */ 830 #define FL_LEASE 32 /* lease held on this file */
831 #define FL_CLOSE 64 /* unlock on close */ 831 #define FL_CLOSE 64 /* unlock on close */
832 #define FL_SLEEP 128 /* A blocking lock */ 832 #define FL_SLEEP 128 /* A blocking lock */
833 833
834 /* 834 /*
835 * The POSIX file lock owner is determined by 835 * The POSIX file lock owner is determined by
836 * the "struct files_struct" in the thread group 836 * the "struct files_struct" in the thread group
837 * (or NULL for no owner - BSD locks). 837 * (or NULL for no owner - BSD locks).
838 * 838 *
839 * Lockd stuffs a "host" pointer into this. 839 * Lockd stuffs a "host" pointer into this.
840 */ 840 */
841 typedef struct files_struct *fl_owner_t; 841 typedef struct files_struct *fl_owner_t;
842 842
843 struct file_lock_operations { 843 struct file_lock_operations {
844 void (*fl_insert)(struct file_lock *); /* lock insertion callback */ 844 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
845 void (*fl_remove)(struct file_lock *); /* lock removal callback */ 845 void (*fl_remove)(struct file_lock *); /* lock removal callback */
846 void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 846 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
847 void (*fl_release_private)(struct file_lock *); 847 void (*fl_release_private)(struct file_lock *);
848 }; 848 };
849 849
850 struct lock_manager_operations { 850 struct lock_manager_operations {
851 int (*fl_compare_owner)(struct file_lock *, struct file_lock *); 851 int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
852 void (*fl_notify)(struct file_lock *); /* unblock callback */ 852 void (*fl_notify)(struct file_lock *); /* unblock callback */
853 int (*fl_grant)(struct file_lock *, struct file_lock *, int); 853 int (*fl_grant)(struct file_lock *, struct file_lock *, int);
854 void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 854 void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
855 void (*fl_release_private)(struct file_lock *); 855 void (*fl_release_private)(struct file_lock *);
856 void (*fl_break)(struct file_lock *); 856 void (*fl_break)(struct file_lock *);
857 int (*fl_mylease)(struct file_lock *, struct file_lock *); 857 int (*fl_mylease)(struct file_lock *, struct file_lock *);
858 int (*fl_change)(struct file_lock **, int); 858 int (*fl_change)(struct file_lock **, int);
859 }; 859 };
860 860
861 /* that will die - we need it for nfs_lock_info */ 861 /* that will die - we need it for nfs_lock_info */
862 #include <linux/nfs_fs_i.h> 862 #include <linux/nfs_fs_i.h>
863 863
864 struct file_lock { 864 struct file_lock {
865 struct file_lock *fl_next; /* singly linked list for this inode */ 865 struct file_lock *fl_next; /* singly linked list for this inode */
866 struct list_head fl_link; /* doubly linked list of all locks */ 866 struct list_head fl_link; /* doubly linked list of all locks */
867 struct list_head fl_block; /* circular list of blocked processes */ 867 struct list_head fl_block; /* circular list of blocked processes */
868 fl_owner_t fl_owner; 868 fl_owner_t fl_owner;
869 unsigned int fl_pid; 869 unsigned int fl_pid;
870 wait_queue_head_t fl_wait; 870 wait_queue_head_t fl_wait;
871 struct file *fl_file; 871 struct file *fl_file;
872 unsigned char fl_flags; 872 unsigned char fl_flags;
873 unsigned char fl_type; 873 unsigned char fl_type;
874 loff_t fl_start; 874 loff_t fl_start;
875 loff_t fl_end; 875 loff_t fl_end;
876 876
877 struct fasync_struct * fl_fasync; /* for lease break notifications */ 877 struct fasync_struct * fl_fasync; /* for lease break notifications */
878 unsigned long fl_break_time; /* for nonblocking lease breaks */ 878 unsigned long fl_break_time; /* for nonblocking lease breaks */
879 879
880 struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ 880 struct file_lock_operations *fl_ops; /* Callbacks for filesystems */
881 struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ 881 struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
882 union { 882 union {
883 struct nfs_lock_info nfs_fl; 883 struct nfs_lock_info nfs_fl;
884 struct nfs4_lock_info nfs4_fl; 884 struct nfs4_lock_info nfs4_fl;
885 struct { 885 struct {
886 struct list_head link; /* link in AFS vnode's pending_locks list */ 886 struct list_head link; /* link in AFS vnode's pending_locks list */
887 int state; /* state of grant or error if -ve */ 887 int state; /* state of grant or error if -ve */
888 } afs; 888 } afs;
889 } fl_u; 889 } fl_u;
890 }; 890 };
891 891
892 /* The following constant reflects the upper bound of the file/locking space */ 892 /* The following constant reflects the upper bound of the file/locking space */
893 #ifndef OFFSET_MAX 893 #ifndef OFFSET_MAX
894 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) 894 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
895 #define OFFSET_MAX INT_LIMIT(loff_t) 895 #define OFFSET_MAX INT_LIMIT(loff_t)
896 #define OFFT_OFFSET_MAX INT_LIMIT(off_t) 896 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
897 #endif 897 #endif
898 898
899 #include <linux/fcntl.h> 899 #include <linux/fcntl.h>
900 900
901 extern int fcntl_getlk(struct file *, struct flock __user *); 901 extern int fcntl_getlk(struct file *, struct flock __user *);
902 extern int fcntl_setlk(unsigned int, struct file *, unsigned int, 902 extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
903 struct flock __user *); 903 struct flock __user *);
904 904
905 #if BITS_PER_LONG == 32 905 #if BITS_PER_LONG == 32
906 extern int fcntl_getlk64(struct file *, struct flock64 __user *); 906 extern int fcntl_getlk64(struct file *, struct flock64 __user *);
907 extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, 907 extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
908 struct flock64 __user *); 908 struct flock64 __user *);
909 #endif 909 #endif
910 910
911 extern void send_sigio(struct fown_struct *fown, int fd, int band); 911 extern void send_sigio(struct fown_struct *fown, int fd, int band);
912 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); 912 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
913 extern int fcntl_getlease(struct file *filp); 913 extern int fcntl_getlease(struct file *filp);
914 914
915 /* fs/sync.c */ 915 /* fs/sync.c */
916 extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset, 916 extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
917 loff_t endbyte, unsigned int flags); 917 loff_t endbyte, unsigned int flags);
918 918
919 /* fs/locks.c */ 919 /* fs/locks.c */
920 extern void locks_init_lock(struct file_lock *); 920 extern void locks_init_lock(struct file_lock *);
921 extern void locks_copy_lock(struct file_lock *, struct file_lock *); 921 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
922 extern void locks_remove_posix(struct file *, fl_owner_t); 922 extern void locks_remove_posix(struct file *, fl_owner_t);
923 extern void locks_remove_flock(struct file *); 923 extern void locks_remove_flock(struct file *);
924 extern void posix_test_lock(struct file *, struct file_lock *); 924 extern void posix_test_lock(struct file *, struct file_lock *);
925 extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); 925 extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
926 extern int posix_lock_file_wait(struct file *, struct file_lock *); 926 extern int posix_lock_file_wait(struct file *, struct file_lock *);
927 extern int posix_unblock_lock(struct file *, struct file_lock *); 927 extern int posix_unblock_lock(struct file *, struct file_lock *);
928 extern int vfs_test_lock(struct file *, struct file_lock *); 928 extern int vfs_test_lock(struct file *, struct file_lock *);
929 extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); 929 extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
930 extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); 930 extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
931 extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl); 931 extern int flock_lock_file_wait(struct file *filp, struct file_lock *fl);
932 extern int __break_lease(struct inode *inode, unsigned int flags); 932 extern int __break_lease(struct inode *inode, unsigned int flags);
933 extern void lease_get_mtime(struct inode *, struct timespec *time); 933 extern void lease_get_mtime(struct inode *, struct timespec *time);
934 extern int generic_setlease(struct file *, long, struct file_lock **); 934 extern int generic_setlease(struct file *, long, struct file_lock **);
935 extern int vfs_setlease(struct file *, long, struct file_lock **); 935 extern int vfs_setlease(struct file *, long, struct file_lock **);
936 extern int lease_modify(struct file_lock **, int); 936 extern int lease_modify(struct file_lock **, int);
937 extern int lock_may_read(struct inode *, loff_t start, unsigned long count); 937 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
938 extern int lock_may_write(struct inode *, loff_t start, unsigned long count); 938 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
939 extern struct seq_operations locks_seq_operations; 939 extern struct seq_operations locks_seq_operations;
940 940
941 struct fasync_struct { 941 struct fasync_struct {
942 int magic; 942 int magic;
943 int fa_fd; 943 int fa_fd;
944 struct fasync_struct *fa_next; /* singly linked list */ 944 struct fasync_struct *fa_next; /* singly linked list */
945 struct file *fa_file; 945 struct file *fa_file;
946 }; 946 };
947 947
948 #define FASYNC_MAGIC 0x4601 948 #define FASYNC_MAGIC 0x4601
949 949
950 /* SMP safe fasync helpers: */ 950 /* SMP safe fasync helpers: */
951 extern int fasync_helper(int, struct file *, int, struct fasync_struct **); 951 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
952 /* can be called from interrupts */ 952 /* can be called from interrupts */
953 extern void kill_fasync(struct fasync_struct **, int, int); 953 extern void kill_fasync(struct fasync_struct **, int, int);
954 /* only for net: no internal synchronization */ 954 /* only for net: no internal synchronization */
955 extern void __kill_fasync(struct fasync_struct *, int, int); 955 extern void __kill_fasync(struct fasync_struct *, int, int);
956 956
957 extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force); 957 extern int __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
958 extern int f_setown(struct file *filp, unsigned long arg, int force); 958 extern int f_setown(struct file *filp, unsigned long arg, int force);
959 extern void f_delown(struct file *filp); 959 extern void f_delown(struct file *filp);
960 extern pid_t f_getown(struct file *filp); 960 extern pid_t f_getown(struct file *filp);
961 extern int send_sigurg(struct fown_struct *fown); 961 extern int send_sigurg(struct fown_struct *fown);
962 962
963 /* 963 /*
964 * Umount options 964 * Umount options
965 */ 965 */
966 966
967 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */ 967 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
968 #define MNT_DETACH 0x00000002 /* Just detach from the tree */ 968 #define MNT_DETACH 0x00000002 /* Just detach from the tree */
969 #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ 969 #define MNT_EXPIRE 0x00000004 /* Mark for expiry */
970 970
971 extern struct list_head super_blocks; 971 extern struct list_head super_blocks;
972 extern spinlock_t sb_lock; 972 extern spinlock_t sb_lock;
973 973
974 #define sb_entry(list) list_entry((list), struct super_block, s_list) 974 #define sb_entry(list) list_entry((list), struct super_block, s_list)
975 #define S_BIAS (1<<30) 975 #define S_BIAS (1<<30)
976 struct super_block { 976 struct super_block {
977 struct list_head s_list; /* Keep this first */ 977 struct list_head s_list; /* Keep this first */
978 dev_t s_dev; /* search index; _not_ kdev_t */ 978 dev_t s_dev; /* search index; _not_ kdev_t */
979 unsigned long s_blocksize; 979 unsigned long s_blocksize;
980 unsigned char s_blocksize_bits; 980 unsigned char s_blocksize_bits;
981 unsigned char s_dirt; 981 unsigned char s_dirt;
982 unsigned long long s_maxbytes; /* Max file size */ 982 unsigned long long s_maxbytes; /* Max file size */
983 struct file_system_type *s_type; 983 struct file_system_type *s_type;
984 const struct super_operations *s_op; 984 const struct super_operations *s_op;
985 struct dquot_operations *dq_op; 985 struct dquot_operations *dq_op;
986 struct quotactl_ops *s_qcop; 986 struct quotactl_ops *s_qcop;
987 struct export_operations *s_export_op; 987 struct export_operations *s_export_op;
988 unsigned long s_flags; 988 unsigned long s_flags;
989 unsigned long s_magic; 989 unsigned long s_magic;
990 struct dentry *s_root; 990 struct dentry *s_root;
991 struct rw_semaphore s_umount; 991 struct rw_semaphore s_umount;
992 struct mutex s_lock; 992 struct mutex s_lock;
993 int s_count; 993 int s_count;
994 int s_syncing; 994 int s_syncing;
995 int s_need_sync_fs; 995 int s_need_sync_fs;
996 atomic_t s_active; 996 atomic_t s_active;
997 #ifdef CONFIG_SECURITY 997 #ifdef CONFIG_SECURITY
998 void *s_security; 998 void *s_security;
999 #endif 999 #endif
1000 struct xattr_handler **s_xattr; 1000 struct xattr_handler **s_xattr;
1001 1001
1002 struct list_head s_inodes; /* all inodes */ 1002 struct list_head s_inodes; /* all inodes */
1003 struct list_head s_dirty; /* dirty inodes */ 1003 struct list_head s_dirty; /* dirty inodes */
1004 struct list_head s_io; /* parked for writeback */ 1004 struct list_head s_io; /* parked for writeback */
1005 struct list_head s_more_io; /* parked for more writeback */ 1005 struct list_head s_more_io; /* parked for more writeback */
1006 struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */ 1006 struct hlist_head s_anon; /* anonymous dentries for (nfs) exporting */
1007 struct list_head s_files; 1007 struct list_head s_files;
1008 1008
1009 struct block_device *s_bdev; 1009 struct block_device *s_bdev;
1010 struct mtd_info *s_mtd; 1010 struct mtd_info *s_mtd;
1011 struct list_head s_instances; 1011 struct list_head s_instances;
1012 struct quota_info s_dquot; /* Diskquota specific options */ 1012 struct quota_info s_dquot; /* Diskquota specific options */
1013 1013
1014 int s_frozen; 1014 int s_frozen;
1015 wait_queue_head_t s_wait_unfrozen; 1015 wait_queue_head_t s_wait_unfrozen;
1016 1016
1017 char s_id[32]; /* Informational name */ 1017 char s_id[32]; /* Informational name */
1018 1018
1019 void *s_fs_info; /* Filesystem private info */ 1019 void *s_fs_info; /* Filesystem private info */
1020 1020
1021 /* 1021 /*
1022 * The next field is for VFS *only*. No filesystems have any business 1022 * The next field is for VFS *only*. No filesystems have any business
1023 * even looking at it. You had been warned. 1023 * even looking at it. You had been warned.
1024 */ 1024 */
1025 struct mutex s_vfs_rename_mutex; /* Kludge */ 1025 struct mutex s_vfs_rename_mutex; /* Kludge */
1026 1026
1027 /* Granularity of c/m/atime in ns. 1027 /* Granularity of c/m/atime in ns.
1028 Cannot be worse than a second */ 1028 Cannot be worse than a second */
1029 u32 s_time_gran; 1029 u32 s_time_gran;
1030 1030
1031 /* 1031 /*
1032 * Filesystem subtype. If non-empty the filesystem type field 1032 * Filesystem subtype. If non-empty the filesystem type field
1033 * in /proc/mounts will be "type.subtype" 1033 * in /proc/mounts will be "type.subtype"
1034 */ 1034 */
1035 char *s_subtype; 1035 char *s_subtype;
1036 }; 1036 };
1037 1037
1038 extern struct timespec current_fs_time(struct super_block *sb); 1038 extern struct timespec current_fs_time(struct super_block *sb);
1039 1039
1040 /* 1040 /*
1041 * Snapshotting support. 1041 * Snapshotting support.
1042 */ 1042 */
1043 enum { 1043 enum {
1044 SB_UNFROZEN = 0, 1044 SB_UNFROZEN = 0,
1045 SB_FREEZE_WRITE = 1, 1045 SB_FREEZE_WRITE = 1,
1046 SB_FREEZE_TRANS = 2, 1046 SB_FREEZE_TRANS = 2,
1047 }; 1047 };
1048 1048
1049 #define vfs_check_frozen(sb, level) \ 1049 #define vfs_check_frozen(sb, level) \
1050 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) 1050 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
1051 1051
1052 #define get_fs_excl() atomic_inc(&current->fs_excl) 1052 #define get_fs_excl() atomic_inc(&current->fs_excl)
1053 #define put_fs_excl() atomic_dec(&current->fs_excl) 1053 #define put_fs_excl() atomic_dec(&current->fs_excl)
1054 #define has_fs_excl() atomic_read(&current->fs_excl) 1054 #define has_fs_excl() atomic_read(&current->fs_excl)
1055 1055
1056 #define is_owner_or_cap(inode) \ 1056 #define is_owner_or_cap(inode) \
1057 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER)) 1057 ((current->fsuid == (inode)->i_uid) || capable(CAP_FOWNER))
1058 1058
1059 /* not quite ready to be deprecated, but... */ 1059 /* not quite ready to be deprecated, but... */
1060 extern void lock_super(struct super_block *); 1060 extern void lock_super(struct super_block *);
1061 extern void unlock_super(struct super_block *); 1061 extern void unlock_super(struct super_block *);
1062 1062
1063 /* 1063 /*
1064 * VFS helper functions.. 1064 * VFS helper functions..
1065 */ 1065 */
1066 extern int vfs_permission(struct nameidata *, int); 1066 extern int vfs_permission(struct nameidata *, int);
1067 extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *); 1067 extern int vfs_create(struct inode *, struct dentry *, int, struct nameidata *);
1068 extern int vfs_mkdir(struct inode *, struct dentry *, int); 1068 extern int vfs_mkdir(struct inode *, struct dentry *, int);
1069 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t); 1069 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
1070 extern int vfs_symlink(struct inode *, struct dentry *, const char *, int); 1070 extern int vfs_symlink(struct inode *, struct dentry *, const char *, int);
1071 extern int vfs_link(struct dentry *, struct inode *, struct dentry *); 1071 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
1072 extern int vfs_rmdir(struct inode *, struct dentry *); 1072 extern int vfs_rmdir(struct inode *, struct dentry *);
1073 extern int vfs_unlink(struct inode *, struct dentry *); 1073 extern int vfs_unlink(struct inode *, struct dentry *);
1074 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 1074 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
1075 1075
1076 /* 1076 /*
1077 * VFS dentry helper functions. 1077 * VFS dentry helper functions.
1078 */ 1078 */
1079 extern void dentry_unhash(struct dentry *dentry); 1079 extern void dentry_unhash(struct dentry *dentry);
1080 1080
1081 /* 1081 /*
1082 * VFS file helper functions. 1082 * VFS file helper functions.
1083 */ 1083 */
1084 extern int file_permission(struct file *, int); 1084 extern int file_permission(struct file *, int);
1085 1085
1086 /* 1086 /*
1087 * File types 1087 * File types
1088 * 1088 *
1089 * NOTE! These match bits 12..15 of stat.st_mode 1089 * NOTE! These match bits 12..15 of stat.st_mode
1090 * (ie "(i_mode >> 12) & 15"). 1090 * (ie "(i_mode >> 12) & 15").
1091 */ 1091 */
1092 #define DT_UNKNOWN 0 1092 #define DT_UNKNOWN 0
1093 #define DT_FIFO 1 1093 #define DT_FIFO 1
1094 #define DT_CHR 2 1094 #define DT_CHR 2
1095 #define DT_DIR 4 1095 #define DT_DIR 4
1096 #define DT_BLK 6 1096 #define DT_BLK 6
1097 #define DT_REG 8 1097 #define DT_REG 8
1098 #define DT_LNK 10 1098 #define DT_LNK 10
1099 #define DT_SOCK 12 1099 #define DT_SOCK 12
1100 #define DT_WHT 14 1100 #define DT_WHT 14
1101 1101
1102 #define OSYNC_METADATA (1<<0) 1102 #define OSYNC_METADATA (1<<0)
1103 #define OSYNC_DATA (1<<1) 1103 #define OSYNC_DATA (1<<1)
1104 #define OSYNC_INODE (1<<2) 1104 #define OSYNC_INODE (1<<2)
1105 int generic_osync_inode(struct inode *, struct address_space *, int); 1105 int generic_osync_inode(struct inode *, struct address_space *, int);
1106 1106
1107 /* 1107 /*
1108 * This is the "filldir" function type, used by readdir() to let 1108 * This is the "filldir" function type, used by readdir() to let
1109 * the kernel specify what kind of dirent layout it wants to have. 1109 * the kernel specify what kind of dirent layout it wants to have.
1110 * This allows the kernel to read directories into kernel space or 1110 * This allows the kernel to read directories into kernel space or
1111 * to have different dirent layouts depending on the binary type. 1111 * to have different dirent layouts depending on the binary type.
1112 */ 1112 */
1113 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 1113 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
1114 1114
1115 struct block_device_operations { 1115 struct block_device_operations {
1116 int (*open) (struct inode *, struct file *); 1116 int (*open) (struct inode *, struct file *);
1117 int (*release) (struct inode *, struct file *); 1117 int (*release) (struct inode *, struct file *);
1118 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); 1118 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
1119 long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); 1119 long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
1120 long (*compat_ioctl) (struct file *, unsigned, unsigned long); 1120 long (*compat_ioctl) (struct file *, unsigned, unsigned long);
1121 int (*direct_access) (struct block_device *, sector_t, unsigned long *); 1121 int (*direct_access) (struct block_device *, sector_t, unsigned long *);
1122 int (*media_changed) (struct gendisk *); 1122 int (*media_changed) (struct gendisk *);
1123 int (*revalidate_disk) (struct gendisk *); 1123 int (*revalidate_disk) (struct gendisk *);
1124 int (*getgeo)(struct block_device *, struct hd_geometry *); 1124 int (*getgeo)(struct block_device *, struct hd_geometry *);
1125 struct module *owner; 1125 struct module *owner;
1126 }; 1126 };
1127 1127
1128 /* 1128 /*
1129 * "descriptor" for what we're up to with a read. 1129 * "descriptor" for what we're up to with a read.
1130 * This allows us to use the same read code yet 1130 * This allows us to use the same read code yet
1131 * have multiple different users of the data that 1131 * have multiple different users of the data that
1132 * we read from a file. 1132 * we read from a file.
1133 * 1133 *
1134 * The simplest case just copies the data to user 1134 * The simplest case just copies the data to user
1135 * mode. 1135 * mode.
1136 */ 1136 */
1137 typedef struct { 1137 typedef struct {
1138 size_t written; 1138 size_t written;
1139 size_t count; 1139 size_t count;
1140 union { 1140 union {
1141 char __user * buf; 1141 char __user * buf;
1142 void *data; 1142 void *data;
1143 } arg; 1143 } arg;
1144 int error; 1144 int error;
1145 } read_descriptor_t; 1145 } read_descriptor_t;
1146 1146
1147 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long); 1147 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1148 1148
1149 /* These macros are for out of kernel modules to test that 1149 /* These macros are for out of kernel modules to test that
1150 * the kernel supports the unlocked_ioctl and compat_ioctl 1150 * the kernel supports the unlocked_ioctl and compat_ioctl
1151 * fields in struct file_operations. */ 1151 * fields in struct file_operations. */
1152 #define HAVE_COMPAT_IOCTL 1 1152 #define HAVE_COMPAT_IOCTL 1
1153 #define HAVE_UNLOCKED_IOCTL 1 1153 #define HAVE_UNLOCKED_IOCTL 1
1154 1154
1155 /* 1155 /*
1156 * NOTE: 1156 * NOTE:
1157 * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl 1157 * read, write, poll, fsync, readv, writev, unlocked_ioctl and compat_ioctl
1158 * can be called without the big kernel lock held in all filesystems. 1158 * can be called without the big kernel lock held in all filesystems.
1159 */ 1159 */
1160 struct file_operations { 1160 struct file_operations {
1161 struct module *owner; 1161 struct module *owner;
1162 loff_t (*llseek) (struct file *, loff_t, int); 1162 loff_t (*llseek) (struct file *, loff_t, int);
1163 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *); 1163 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
1164 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *); 1164 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
1165 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1165 ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1166 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t); 1166 ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
1167 int (*readdir) (struct file *, void *, filldir_t); 1167 int (*readdir) (struct file *, void *, filldir_t);
1168 unsigned int (*poll) (struct file *, struct poll_table_struct *); 1168 unsigned int (*poll) (struct file *, struct poll_table_struct *);
1169 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); 1169 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
1170 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); 1170 long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
1171 long (*compat_ioctl) (struct file *, unsigned int, unsigned long); 1171 long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
1172 int (*mmap) (struct file *, struct vm_area_struct *); 1172 int (*mmap) (struct file *, struct vm_area_struct *);
1173 int (*open) (struct inode *, struct file *); 1173 int (*open) (struct inode *, struct file *);
1174 int (*flush) (struct file *, fl_owner_t id); 1174 int (*flush) (struct file *, fl_owner_t id);
1175 int (*release) (struct inode *, struct file *); 1175 int (*release) (struct inode *, struct file *);
1176 int (*fsync) (struct file *, struct dentry *, int datasync); 1176 int (*fsync) (struct file *, struct dentry *, int datasync);
1177 int (*aio_fsync) (struct kiocb *, int datasync); 1177 int (*aio_fsync) (struct kiocb *, int datasync);
1178 int (*fasync) (int, struct file *, int); 1178 int (*fasync) (int, struct file *, int);
1179 int (*lock) (struct file *, int, struct file_lock *); 1179 int (*lock) (struct file *, int, struct file_lock *);
1180 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); 1180 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
1181 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); 1181 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
1182 int (*check_flags)(int); 1182 int (*check_flags)(int);
1183 int (*dir_notify)(struct file *filp, unsigned long arg); 1183 int (*dir_notify)(struct file *filp, unsigned long arg);
1184 int (*flock) (struct file *, int, struct file_lock *); 1184 int (*flock) (struct file *, int, struct file_lock *);
1185 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); 1185 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
1186 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); 1186 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
1187 int (*setlease)(struct file *, long, struct file_lock **); 1187 int (*setlease)(struct file *, long, struct file_lock **);
1188 }; 1188 };
1189 1189
1190 struct inode_operations { 1190 struct inode_operations {
1191 int (*create) (struct inode *,struct dentry *,int, struct nameidata *); 1191 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
1192 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); 1192 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
1193 int (*link) (struct dentry *,struct inode *,struct dentry *); 1193 int (*link) (struct dentry *,struct inode *,struct dentry *);
1194 int (*unlink) (struct inode *,struct dentry *); 1194 int (*unlink) (struct inode *,struct dentry *);
1195 int (*symlink) (struct inode *,struct dentry *,const char *); 1195 int (*symlink) (struct inode *,struct dentry *,const char *);
1196 int (*mkdir) (struct inode *,struct dentry *,int); 1196 int (*mkdir) (struct inode *,struct dentry *,int);
1197 int (*rmdir) (struct inode *,struct dentry *); 1197 int (*rmdir) (struct inode *,struct dentry *);
1198 int (*mknod) (struct inode *,struct dentry *,int,dev_t); 1198 int (*mknod) (struct inode *,struct dentry *,int,dev_t);
1199 int (*rename) (struct inode *, struct dentry *, 1199 int (*rename) (struct inode *, struct dentry *,
1200 struct inode *, struct dentry *); 1200 struct inode *, struct dentry *);
1201 int (*readlink) (struct dentry *, char __user *,int); 1201 int (*readlink) (struct dentry *, char __user *,int);
1202 void * (*follow_link) (struct dentry *, struct nameidata *); 1202 void * (*follow_link) (struct dentry *, struct nameidata *);
1203 void (*put_link) (struct dentry *, struct nameidata *, void *); 1203 void (*put_link) (struct dentry *, struct nameidata *, void *);
1204 void (*truncate) (struct inode *); 1204 void (*truncate) (struct inode *);
1205 int (*permission) (struct inode *, int, struct nameidata *); 1205 int (*permission) (struct inode *, int, struct nameidata *);
1206 int (*setattr) (struct dentry *, struct iattr *); 1206 int (*setattr) (struct dentry *, struct iattr *);
1207 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *); 1207 int (*getattr) (struct vfsmount *mnt, struct dentry *, struct kstat *);
1208 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int); 1208 int (*setxattr) (struct dentry *, const char *,const void *,size_t,int);
1209 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); 1209 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
1210 ssize_t (*listxattr) (struct dentry *, char *, size_t); 1210 ssize_t (*listxattr) (struct dentry *, char *, size_t);
1211 int (*removexattr) (struct dentry *, const char *); 1211 int (*removexattr) (struct dentry *, const char *);
1212 void (*truncate_range)(struct inode *, loff_t, loff_t); 1212 void (*truncate_range)(struct inode *, loff_t, loff_t);
1213 long (*fallocate)(struct inode *inode, int mode, loff_t offset, 1213 long (*fallocate)(struct inode *inode, int mode, loff_t offset,
1214 loff_t len); 1214 loff_t len);
1215 }; 1215 };
1216 1216
1217 struct seq_file; 1217 struct seq_file;
1218 1218
1219 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, 1219 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
1220 unsigned long nr_segs, unsigned long fast_segs, 1220 unsigned long nr_segs, unsigned long fast_segs,
1221 struct iovec *fast_pointer, 1221 struct iovec *fast_pointer,
1222 struct iovec **ret_pointer); 1222 struct iovec **ret_pointer);
1223 1223
1224 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); 1224 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
1225 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); 1225 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
1226 extern ssize_t vfs_readv(struct file *, const struct iovec __user *, 1226 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
1227 unsigned long, loff_t *); 1227 unsigned long, loff_t *);
1228 extern ssize_t vfs_writev(struct file *, const struct iovec __user *, 1228 extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
1229 unsigned long, loff_t *); 1229 unsigned long, loff_t *);
1230 1230
1231 /* 1231 /*
1232 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called 1232 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
1233 * without the big kernel lock held in all filesystems. 1233 * without the big kernel lock held in all filesystems.
1234 */ 1234 */
1235 struct super_operations { 1235 struct super_operations {
1236 struct inode *(*alloc_inode)(struct super_block *sb); 1236 struct inode *(*alloc_inode)(struct super_block *sb);
1237 void (*destroy_inode)(struct inode *); 1237 void (*destroy_inode)(struct inode *);
1238 1238
1239 void (*read_inode) (struct inode *); 1239 void (*read_inode) (struct inode *);
1240 1240
1241 void (*dirty_inode) (struct inode *); 1241 void (*dirty_inode) (struct inode *);
1242 int (*write_inode) (struct inode *, int); 1242 int (*write_inode) (struct inode *, int);
1243 void (*put_inode) (struct inode *); 1243 void (*put_inode) (struct inode *);
1244 void (*drop_inode) (struct inode *); 1244 void (*drop_inode) (struct inode *);
1245 void (*delete_inode) (struct inode *); 1245 void (*delete_inode) (struct inode *);
1246 void (*put_super) (struct super_block *); 1246 void (*put_super) (struct super_block *);
1247 void (*write_super) (struct super_block *); 1247 void (*write_super) (struct super_block *);
1248 int (*sync_fs)(struct super_block *sb, int wait); 1248 int (*sync_fs)(struct super_block *sb, int wait);
1249 void (*write_super_lockfs) (struct super_block *); 1249 void (*write_super_lockfs) (struct super_block *);
1250 void (*unlockfs) (struct super_block *); 1250 void (*unlockfs) (struct super_block *);
1251 int (*statfs) (struct dentry *, struct kstatfs *); 1251 int (*statfs) (struct dentry *, struct kstatfs *);
1252 int (*remount_fs) (struct super_block *, int *, char *); 1252 int (*remount_fs) (struct super_block *, int *, char *);
1253 void (*clear_inode) (struct inode *); 1253 void (*clear_inode) (struct inode *);
1254 void (*umount_begin) (struct vfsmount *, int); 1254 void (*umount_begin) (struct vfsmount *, int);
1255 1255
1256 int (*show_options)(struct seq_file *, struct vfsmount *); 1256 int (*show_options)(struct seq_file *, struct vfsmount *);
1257 int (*show_stats)(struct seq_file *, struct vfsmount *); 1257 int (*show_stats)(struct seq_file *, struct vfsmount *);
1258 #ifdef CONFIG_QUOTA 1258 #ifdef CONFIG_QUOTA
1259 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); 1259 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
1260 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 1260 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
1261 #endif 1261 #endif
1262 }; 1262 };
1263 1263
1264 /* Inode state bits. Protected by inode_lock. */ 1264 /* Inode state bits. Protected by inode_lock. */
1265 #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */ 1265 #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
1266 #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */ 1266 #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
1267 #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */ 1267 #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
1268 #define __I_LOCK 3 1268 #define __I_LOCK 3
1269 #define I_LOCK (1 << __I_LOCK) 1269 #define I_LOCK (1 << __I_LOCK)
1270 #define I_FREEING 16 1270 #define I_FREEING 16
1271 #define I_CLEAR 32 1271 #define I_CLEAR 32
1272 #define I_NEW 64 1272 #define I_NEW 64
1273 #define I_WILL_FREE 128 1273 #define I_WILL_FREE 128
1274 1274
1275 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES) 1275 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
1276 1276
1277 extern void __mark_inode_dirty(struct inode *, int); 1277 extern void __mark_inode_dirty(struct inode *, int);
1278 static inline void mark_inode_dirty(struct inode *inode) 1278 static inline void mark_inode_dirty(struct inode *inode)
1279 { 1279 {
1280 __mark_inode_dirty(inode, I_DIRTY); 1280 __mark_inode_dirty(inode, I_DIRTY);
1281 } 1281 }
1282 1282
1283 static inline void mark_inode_dirty_sync(struct inode *inode) 1283 static inline void mark_inode_dirty_sync(struct inode *inode)
1284 { 1284 {
1285 __mark_inode_dirty(inode, I_DIRTY_SYNC); 1285 __mark_inode_dirty(inode, I_DIRTY_SYNC);
1286 } 1286 }
1287 1287
1288 /** 1288 /**
1289 * inc_nlink - directly increment an inode's link count 1289 * inc_nlink - directly increment an inode's link count
1290 * @inode: inode 1290 * @inode: inode
1291 * 1291 *
1292 * This is a low-level filesystem helper to replace any 1292 * This is a low-level filesystem helper to replace any
1293 * direct filesystem manipulation of i_nlink. Currently, 1293 * direct filesystem manipulation of i_nlink. Currently,
1294 * it is only here for parity with dec_nlink(). 1294 * it is only here for parity with dec_nlink().
1295 */ 1295 */
1296 static inline void inc_nlink(struct inode *inode) 1296 static inline void inc_nlink(struct inode *inode)
1297 { 1297 {
1298 inode->i_nlink++; 1298 inode->i_nlink++;
1299 } 1299 }
1300 1300
1301 static inline void inode_inc_link_count(struct inode *inode) 1301 static inline void inode_inc_link_count(struct inode *inode)
1302 { 1302 {
1303 inc_nlink(inode); 1303 inc_nlink(inode);
1304 mark_inode_dirty(inode); 1304 mark_inode_dirty(inode);
1305 } 1305 }
1306 1306
1307 /** 1307 /**
1308 * drop_nlink - directly drop an inode's link count 1308 * drop_nlink - directly drop an inode's link count
1309 * @inode: inode 1309 * @inode: inode
1310 * 1310 *
1311 * This is a low-level filesystem helper to replace any 1311 * This is a low-level filesystem helper to replace any
1312 * direct filesystem manipulation of i_nlink. In cases 1312 * direct filesystem manipulation of i_nlink. In cases
1313 * where we are attempting to track writes to the 1313 * where we are attempting to track writes to the
1314 * filesystem, a decrement to zero means an imminent 1314 * filesystem, a decrement to zero means an imminent
1315 * write when the file is truncated and actually unlinked 1315 * write when the file is truncated and actually unlinked
1316 * on the filesystem. 1316 * on the filesystem.
1317 */ 1317 */
1318 static inline void drop_nlink(struct inode *inode) 1318 static inline void drop_nlink(struct inode *inode)
1319 { 1319 {
1320 inode->i_nlink--; 1320 inode->i_nlink--;
1321 } 1321 }
1322 1322
1323 /** 1323 /**
1324 * clear_nlink - directly zero an inode's link count 1324 * clear_nlink - directly zero an inode's link count
1325 * @inode: inode 1325 * @inode: inode
1326 * 1326 *
1327 * This is a low-level filesystem helper to replace any 1327 * This is a low-level filesystem helper to replace any
1328 * direct filesystem manipulation of i_nlink. See 1328 * direct filesystem manipulation of i_nlink. See
1329 * drop_nlink() for why we care about i_nlink hitting zero. 1329 * drop_nlink() for why we care about i_nlink hitting zero.
1330 */ 1330 */
1331 static inline void clear_nlink(struct inode *inode) 1331 static inline void clear_nlink(struct inode *inode)
1332 { 1332 {
1333 inode->i_nlink = 0; 1333 inode->i_nlink = 0;
1334 } 1334 }
1335 1335
1336 static inline void inode_dec_link_count(struct inode *inode) 1336 static inline void inode_dec_link_count(struct inode *inode)
1337 { 1337 {
1338 drop_nlink(inode); 1338 drop_nlink(inode);
1339 mark_inode_dirty(inode); 1339 mark_inode_dirty(inode);
1340 } 1340 }
1341 1341
1342 extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry); 1342 extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry);
1343 static inline void file_accessed(struct file *file) 1343 static inline void file_accessed(struct file *file)
1344 { 1344 {
1345 if (!(file->f_flags & O_NOATIME)) 1345 if (!(file->f_flags & O_NOATIME))
1346 touch_atime(file->f_path.mnt, file->f_path.dentry); 1346 touch_atime(file->f_path.mnt, file->f_path.dentry);
1347 } 1347 }
1348 1348
1349 int sync_inode(struct inode *inode, struct writeback_control *wbc); 1349 int sync_inode(struct inode *inode, struct writeback_control *wbc);
1350 1350
1351 struct file_system_type { 1351 struct file_system_type {
1352 const char *name; 1352 const char *name;
1353 int fs_flags; 1353 int fs_flags;
1354 int (*get_sb) (struct file_system_type *, int, 1354 int (*get_sb) (struct file_system_type *, int,
1355 const char *, void *, struct vfsmount *); 1355 const char *, void *, struct vfsmount *);
1356 void (*kill_sb) (struct super_block *); 1356 void (*kill_sb) (struct super_block *);
1357 struct module *owner; 1357 struct module *owner;
1358 struct file_system_type * next; 1358 struct file_system_type * next;
1359 struct list_head fs_supers; 1359 struct list_head fs_supers;
1360 1360
1361 struct lock_class_key s_lock_key; 1361 struct lock_class_key s_lock_key;
1362 struct lock_class_key s_umount_key; 1362 struct lock_class_key s_umount_key;
1363 1363
1364 struct lock_class_key i_lock_key; 1364 struct lock_class_key i_lock_key;
1365 struct lock_class_key i_mutex_key; 1365 struct lock_class_key i_mutex_key;
1366 struct lock_class_key i_mutex_dir_key; 1366 struct lock_class_key i_mutex_dir_key;
1367 struct lock_class_key i_alloc_sem_key; 1367 struct lock_class_key i_alloc_sem_key;
1368 }; 1368 };
1369 1369
1370 extern int get_sb_bdev(struct file_system_type *fs_type, 1370 extern int get_sb_bdev(struct file_system_type *fs_type,
1371 int flags, const char *dev_name, void *data, 1371 int flags, const char *dev_name, void *data,
1372 int (*fill_super)(struct super_block *, void *, int), 1372 int (*fill_super)(struct super_block *, void *, int),
1373 struct vfsmount *mnt); 1373 struct vfsmount *mnt);
1374 extern int get_sb_single(struct file_system_type *fs_type, 1374 extern int get_sb_single(struct file_system_type *fs_type,
1375 int flags, void *data, 1375 int flags, void *data,
1376 int (*fill_super)(struct super_block *, void *, int), 1376 int (*fill_super)(struct super_block *, void *, int),
1377 struct vfsmount *mnt); 1377 struct vfsmount *mnt);
1378 extern int get_sb_nodev(struct file_system_type *fs_type, 1378 extern int get_sb_nodev(struct file_system_type *fs_type,
1379 int flags, void *data, 1379 int flags, void *data,
1380 int (*fill_super)(struct super_block *, void *, int), 1380 int (*fill_super)(struct super_block *, void *, int),
1381 struct vfsmount *mnt); 1381 struct vfsmount *mnt);
1382 void generic_shutdown_super(struct super_block *sb); 1382 void generic_shutdown_super(struct super_block *sb);
1383 void kill_block_super(struct super_block *sb); 1383 void kill_block_super(struct super_block *sb);
1384 void kill_anon_super(struct super_block *sb); 1384 void kill_anon_super(struct super_block *sb);
1385 void kill_litter_super(struct super_block *sb); 1385 void kill_litter_super(struct super_block *sb);
1386 void deactivate_super(struct super_block *sb); 1386 void deactivate_super(struct super_block *sb);
1387 int set_anon_super(struct super_block *s, void *data); 1387 int set_anon_super(struct super_block *s, void *data);
1388 struct super_block *sget(struct file_system_type *type, 1388 struct super_block *sget(struct file_system_type *type,
1389 int (*test)(struct super_block *,void *), 1389 int (*test)(struct super_block *,void *),
1390 int (*set)(struct super_block *,void *), 1390 int (*set)(struct super_block *,void *),
1391 void *data); 1391 void *data);
1392 extern int get_sb_pseudo(struct file_system_type *, char *, 1392 extern int get_sb_pseudo(struct file_system_type *, char *,
1393 const struct super_operations *ops, unsigned long, 1393 const struct super_operations *ops, unsigned long,
1394 struct vfsmount *mnt); 1394 struct vfsmount *mnt);
1395 extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb); 1395 extern int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb);
1396 int __put_super(struct super_block *sb); 1396 int __put_super(struct super_block *sb);
1397 int __put_super_and_need_restart(struct super_block *sb); 1397 int __put_super_and_need_restart(struct super_block *sb);
1398 void unnamed_dev_init(void); 1398 void unnamed_dev_init(void);
1399 1399
1400 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */ 1400 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
1401 #define fops_get(fops) \ 1401 #define fops_get(fops) \
1402 (((fops) && try_module_get((fops)->owner) ? (fops) : NULL)) 1402 (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
1403 #define fops_put(fops) \ 1403 #define fops_put(fops) \
1404 do { if (fops) module_put((fops)->owner); } while(0) 1404 do { if (fops) module_put((fops)->owner); } while(0)
1405 1405
1406 extern int register_filesystem(struct file_system_type *); 1406 extern int register_filesystem(struct file_system_type *);
1407 extern int unregister_filesystem(struct file_system_type *); 1407 extern int unregister_filesystem(struct file_system_type *);
1408 extern struct vfsmount *kern_mount(struct file_system_type *); 1408 extern struct vfsmount *kern_mount(struct file_system_type *);
1409 extern int may_umount_tree(struct vfsmount *); 1409 extern int may_umount_tree(struct vfsmount *);
1410 extern int may_umount(struct vfsmount *); 1410 extern int may_umount(struct vfsmount *);
1411 extern void umount_tree(struct vfsmount *, int, struct list_head *); 1411 extern void umount_tree(struct vfsmount *, int, struct list_head *);
1412 extern void release_mounts(struct list_head *); 1412 extern void release_mounts(struct list_head *);
1413 extern long do_mount(char *, char *, char *, unsigned long, void *); 1413 extern long do_mount(char *, char *, char *, unsigned long, void *);
1414 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); 1414 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int);
1415 extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *, 1415 extern void mnt_set_mountpoint(struct vfsmount *, struct dentry *,
1416 struct vfsmount *); 1416 struct vfsmount *);
1417 1417
1418 extern int vfs_statfs(struct dentry *, struct kstatfs *); 1418 extern int vfs_statfs(struct dentry *, struct kstatfs *);
1419 1419
1420 /* /sys/fs */ 1420 /* /sys/fs */
1421 extern struct kset fs_subsys; 1421 extern struct kset fs_subsys;
1422 1422
1423 #define FLOCK_VERIFY_READ 1 1423 #define FLOCK_VERIFY_READ 1
1424 #define FLOCK_VERIFY_WRITE 2 1424 #define FLOCK_VERIFY_WRITE 2
1425 1425
1426 extern int locks_mandatory_locked(struct inode *); 1426 extern int locks_mandatory_locked(struct inode *);
1427 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); 1427 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
1428 1428
1429 /* 1429 /*
1430 * Candidates for mandatory locking have the setgid bit set 1430 * Candidates for mandatory locking have the setgid bit set
1431 * but no group execute bit - an otherwise meaningless combination. 1431 * but no group execute bit - an otherwise meaningless combination.
1432 */ 1432 */
1433 1433
1434 static inline int __mandatory_lock(struct inode *ino) 1434 static inline int __mandatory_lock(struct inode *ino)
1435 { 1435 {
1436 return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID; 1436 return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID;
1437 } 1437 }
1438 1438
1439 /* 1439 /*
1440 * ... and these candidates should be on MS_MANDLOCK mounted fs, 1440 * ... and these candidates should be on MS_MANDLOCK mounted fs,
1441 * otherwise these will be advisory locks 1441 * otherwise these will be advisory locks
1442 */ 1442 */
1443 1443
1444 static inline int mandatory_lock(struct inode *ino) 1444 static inline int mandatory_lock(struct inode *ino)
1445 { 1445 {
1446 return IS_MANDLOCK(ino) && __mandatory_lock(ino); 1446 return IS_MANDLOCK(ino) && __mandatory_lock(ino);
1447 } 1447 }
1448 1448
1449 static inline int locks_verify_locked(struct inode *inode) 1449 static inline int locks_verify_locked(struct inode *inode)
1450 { 1450 {
1451 if (mandatory_lock(inode)) 1451 if (mandatory_lock(inode))
1452 return locks_mandatory_locked(inode); 1452 return locks_mandatory_locked(inode);
1453 return 0; 1453 return 0;
1454 } 1454 }
1455 1455
1456 extern int rw_verify_area(int, struct file *, loff_t *, size_t); 1456 extern int rw_verify_area(int, struct file *, loff_t *, size_t);
1457 1457
1458 static inline int locks_verify_truncate(struct inode *inode, 1458 static inline int locks_verify_truncate(struct inode *inode,
1459 struct file *filp, 1459 struct file *filp,
1460 loff_t size) 1460 loff_t size)
1461 { 1461 {
1462 if (inode->i_flock && mandatory_lock(inode)) 1462 if (inode->i_flock && mandatory_lock(inode))
1463 return locks_mandatory_area( 1463 return locks_mandatory_area(
1464 FLOCK_VERIFY_WRITE, inode, filp, 1464 FLOCK_VERIFY_WRITE, inode, filp,
1465 size < inode->i_size ? size : inode->i_size, 1465 size < inode->i_size ? size : inode->i_size,
1466 (size < inode->i_size ? inode->i_size - size 1466 (size < inode->i_size ? inode->i_size - size
1467 : size - inode->i_size) 1467 : size - inode->i_size)
1468 ); 1468 );
1469 return 0; 1469 return 0;
1470 } 1470 }
1471 1471
1472 static inline int break_lease(struct inode *inode, unsigned int mode) 1472 static inline int break_lease(struct inode *inode, unsigned int mode)
1473 { 1473 {
1474 if (inode->i_flock) 1474 if (inode->i_flock)
1475 return __break_lease(inode, mode); 1475 return __break_lease(inode, mode);
1476 return 0; 1476 return 0;
1477 } 1477 }
1478 1478
1479 /* fs/open.c */ 1479 /* fs/open.c */
1480 1480
1481 extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs, 1481 extern int do_truncate(struct dentry *, loff_t start, unsigned int time_attrs,
1482 struct file *filp); 1482 struct file *filp);
1483 extern long do_sys_open(int fdf, const char __user *filename, int flags, 1483 extern long do_sys_open(int fdf, const char __user *filename, int flags,
1484 int mode); 1484 int mode);
1485 extern struct file *filp_open(const char *, int, int); 1485 extern struct file *filp_open(const char *, int, int);
1486 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int); 1486 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1487 extern int filp_close(struct file *, fl_owner_t id); 1487 extern int filp_close(struct file *, fl_owner_t id);
1488 extern char * getname(const char __user *); 1488 extern char * getname(const char __user *);
1489 1489
1490 /* fs/dcache.c */ 1490 /* fs/dcache.c */
1491 extern void __init vfs_caches_init_early(void); 1491 extern void __init vfs_caches_init_early(void);
1492 extern void __init vfs_caches_init(unsigned long); 1492 extern void __init vfs_caches_init(unsigned long);
1493 1493
1494 extern struct kmem_cache *names_cachep; 1494 extern struct kmem_cache *names_cachep;
1495 1495
1496 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) 1496 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL)
1497 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) 1497 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name))
1498 #ifndef CONFIG_AUDITSYSCALL 1498 #ifndef CONFIG_AUDITSYSCALL
1499 #define putname(name) __putname(name) 1499 #define putname(name) __putname(name)
1500 #else 1500 #else
1501 extern void putname(const char *name); 1501 extern void putname(const char *name);
1502 #endif 1502 #endif
1503 1503
1504 #ifdef CONFIG_BLOCK 1504 #ifdef CONFIG_BLOCK
1505 extern int register_blkdev(unsigned int, const char *); 1505 extern int register_blkdev(unsigned int, const char *);
1506 extern void unregister_blkdev(unsigned int, const char *); 1506 extern void unregister_blkdev(unsigned int, const char *);
1507 extern struct block_device *bdget(dev_t); 1507 extern struct block_device *bdget(dev_t);
1508 extern void bd_set_size(struct block_device *, loff_t size); 1508 extern void bd_set_size(struct block_device *, loff_t size);
1509 extern void bd_forget(struct inode *inode); 1509 extern void bd_forget(struct inode *inode);
1510 extern void bdput(struct block_device *); 1510 extern void bdput(struct block_device *);
1511 extern struct block_device *open_by_devnum(dev_t, unsigned); 1511 extern struct block_device *open_by_devnum(dev_t, unsigned);
1512 extern const struct address_space_operations def_blk_aops; 1512 extern const struct address_space_operations def_blk_aops;
1513 #else 1513 #else
1514 static inline void bd_forget(struct inode *inode) {} 1514 static inline void bd_forget(struct inode *inode) {}
1515 #endif 1515 #endif
1516 extern const struct file_operations def_blk_fops; 1516 extern const struct file_operations def_blk_fops;
1517 extern const struct file_operations def_chr_fops; 1517 extern const struct file_operations def_chr_fops;
1518 extern const struct file_operations bad_sock_fops; 1518 extern const struct file_operations bad_sock_fops;
1519 extern const struct file_operations def_fifo_fops; 1519 extern const struct file_operations def_fifo_fops;
1520 #ifdef CONFIG_BLOCK 1520 #ifdef CONFIG_BLOCK
1521 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); 1521 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1522 extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); 1522 extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long);
1523 extern int blkdev_driver_ioctl(struct inode *inode, struct file *file, 1523 extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1524 struct gendisk *disk, unsigned cmd, 1524 struct gendisk *disk, unsigned cmd,
1525 unsigned long arg); 1525 unsigned long arg);
1526 extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1526 extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1527 extern int blkdev_get(struct block_device *, mode_t, unsigned); 1527 extern int blkdev_get(struct block_device *, mode_t, unsigned);
1528 extern int blkdev_put(struct block_device *); 1528 extern int blkdev_put(struct block_device *);
1529 extern int bd_claim(struct block_device *, void *); 1529 extern int bd_claim(struct block_device *, void *);
1530 extern void bd_release(struct block_device *); 1530 extern void bd_release(struct block_device *);
1531 #ifdef CONFIG_SYSFS 1531 #ifdef CONFIG_SYSFS
1532 extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *); 1532 extern int bd_claim_by_disk(struct block_device *, void *, struct gendisk *);
1533 extern void bd_release_from_disk(struct block_device *, struct gendisk *); 1533 extern void bd_release_from_disk(struct block_device *, struct gendisk *);
1534 #else 1534 #else
1535 #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder) 1535 #define bd_claim_by_disk(bdev, holder, disk) bd_claim(bdev, holder)
1536 #define bd_release_from_disk(bdev, disk) bd_release(bdev) 1536 #define bd_release_from_disk(bdev, disk) bd_release(bdev)
1537 #endif 1537 #endif
1538 #endif 1538 #endif
1539 1539
1540 /* fs/char_dev.c */ 1540 /* fs/char_dev.c */
1541 #define CHRDEV_MAJOR_HASH_SIZE 255 1541 #define CHRDEV_MAJOR_HASH_SIZE 255
1542 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *); 1542 extern int alloc_chrdev_region(dev_t *, unsigned, unsigned, const char *);
1543 extern int register_chrdev_region(dev_t, unsigned, const char *); 1543 extern int register_chrdev_region(dev_t, unsigned, const char *);
1544 extern int register_chrdev(unsigned int, const char *, 1544 extern int register_chrdev(unsigned int, const char *,
1545 const struct file_operations *); 1545 const struct file_operations *);
1546 extern void unregister_chrdev(unsigned int, const char *); 1546 extern void unregister_chrdev(unsigned int, const char *);
1547 extern void unregister_chrdev_region(dev_t, unsigned); 1547 extern void unregister_chrdev_region(dev_t, unsigned);
1548 extern int chrdev_open(struct inode *, struct file *); 1548 extern int chrdev_open(struct inode *, struct file *);
1549 extern void chrdev_show(struct seq_file *,off_t); 1549 extern void chrdev_show(struct seq_file *,off_t);
1550 1550
1551 /* fs/block_dev.c */ 1551 /* fs/block_dev.c */
1552 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ 1552 #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
1553 1553
1554 #ifdef CONFIG_BLOCK 1554 #ifdef CONFIG_BLOCK
1555 #define BLKDEV_MAJOR_HASH_SIZE 255 1555 #define BLKDEV_MAJOR_HASH_SIZE 255
1556 extern const char *__bdevname(dev_t, char *buffer); 1556 extern const char *__bdevname(dev_t, char *buffer);
1557 extern const char *bdevname(struct block_device *bdev, char *buffer); 1557 extern const char *bdevname(struct block_device *bdev, char *buffer);
1558 extern struct block_device *lookup_bdev(const char *); 1558 extern struct block_device *lookup_bdev(const char *);
1559 extern struct block_device *open_bdev_excl(const char *, int, void *); 1559 extern struct block_device *open_bdev_excl(const char *, int, void *);
1560 extern void close_bdev_excl(struct block_device *); 1560 extern void close_bdev_excl(struct block_device *);
1561 extern void blkdev_show(struct seq_file *,off_t); 1561 extern void blkdev_show(struct seq_file *,off_t);
1562 #else 1562 #else
1563 #define BLKDEV_MAJOR_HASH_SIZE 0 1563 #define BLKDEV_MAJOR_HASH_SIZE 0
1564 #endif 1564 #endif
1565 1565
1566 extern void init_special_inode(struct inode *, umode_t, dev_t); 1566 extern void init_special_inode(struct inode *, umode_t, dev_t);
1567 1567
1568 /* Invalid inode operations -- fs/bad_inode.c */ 1568 /* Invalid inode operations -- fs/bad_inode.c */
1569 extern void make_bad_inode(struct inode *); 1569 extern void make_bad_inode(struct inode *);
1570 extern int is_bad_inode(struct inode *); 1570 extern int is_bad_inode(struct inode *);
1571 1571
1572 extern const struct file_operations read_fifo_fops; 1572 extern const struct file_operations read_fifo_fops;
1573 extern const struct file_operations write_fifo_fops; 1573 extern const struct file_operations write_fifo_fops;
1574 extern const struct file_operations rdwr_fifo_fops; 1574 extern const struct file_operations rdwr_fifo_fops;
1575 1575
1576 extern int fs_may_remount_ro(struct super_block *); 1576 extern int fs_may_remount_ro(struct super_block *);
1577 1577
1578 #ifdef CONFIG_BLOCK 1578 #ifdef CONFIG_BLOCK
1579 /* 1579 /*
1580 * return READ, READA, or WRITE 1580 * return READ, READA, or WRITE
1581 */ 1581 */
1582 #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK)) 1582 #define bio_rw(bio) ((bio)->bi_rw & (RW_MASK | RWA_MASK))
1583 1583
1584 /* 1584 /*
1585 * return data direction, READ or WRITE 1585 * return data direction, READ or WRITE
1586 */ 1586 */
1587 #define bio_data_dir(bio) ((bio)->bi_rw & 1) 1587 #define bio_data_dir(bio) ((bio)->bi_rw & 1)
1588 1588
1589 extern int check_disk_change(struct block_device *); 1589 extern int check_disk_change(struct block_device *);
1590 extern int __invalidate_device(struct block_device *); 1590 extern int __invalidate_device(struct block_device *);
1591 extern int invalidate_partition(struct gendisk *, int); 1591 extern int invalidate_partition(struct gendisk *, int);
1592 #endif 1592 #endif
1593 extern int invalidate_inodes(struct super_block *); 1593 extern int invalidate_inodes(struct super_block *);
1594 unsigned long __invalidate_mapping_pages(struct address_space *mapping, 1594 unsigned long __invalidate_mapping_pages(struct address_space *mapping,
1595 pgoff_t start, pgoff_t end, 1595 pgoff_t start, pgoff_t end,
1596 bool be_atomic); 1596 bool be_atomic);
1597 unsigned long invalidate_mapping_pages(struct address_space *mapping, 1597 unsigned long invalidate_mapping_pages(struct address_space *mapping,
1598 pgoff_t start, pgoff_t end); 1598 pgoff_t start, pgoff_t end);
1599 1599
1600 static inline unsigned long __deprecated 1600 static inline unsigned long __deprecated
1601 invalidate_inode_pages(struct address_space *mapping) 1601 invalidate_inode_pages(struct address_space *mapping)
1602 { 1602 {
1603 return invalidate_mapping_pages(mapping, 0, ~0UL); 1603 return invalidate_mapping_pages(mapping, 0, ~0UL);
1604 } 1604 }
1605 1605
1606 static inline void invalidate_remote_inode(struct inode *inode) 1606 static inline void invalidate_remote_inode(struct inode *inode)
1607 { 1607 {
1608 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1608 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
1609 S_ISLNK(inode->i_mode)) 1609 S_ISLNK(inode->i_mode))
1610 invalidate_mapping_pages(inode->i_mapping, 0, -1); 1610 invalidate_mapping_pages(inode->i_mapping, 0, -1);
1611 } 1611 }
1612 extern int invalidate_inode_pages2(struct address_space *mapping); 1612 extern int invalidate_inode_pages2(struct address_space *mapping);
1613 extern int invalidate_inode_pages2_range(struct address_space *mapping, 1613 extern int invalidate_inode_pages2_range(struct address_space *mapping,
1614 pgoff_t start, pgoff_t end); 1614 pgoff_t start, pgoff_t end);
1615 extern int write_inode_now(struct inode *, int); 1615 extern int write_inode_now(struct inode *, int);
1616 extern int filemap_fdatawrite(struct address_space *); 1616 extern int filemap_fdatawrite(struct address_space *);
1617 extern int filemap_flush(struct address_space *); 1617 extern int filemap_flush(struct address_space *);
1618 extern int filemap_fdatawait(struct address_space *); 1618 extern int filemap_fdatawait(struct address_space *);
1619 extern int filemap_write_and_wait(struct address_space *mapping); 1619 extern int filemap_write_and_wait(struct address_space *mapping);
1620 extern int filemap_write_and_wait_range(struct address_space *mapping, 1620 extern int filemap_write_and_wait_range(struct address_space *mapping,
1621 loff_t lstart, loff_t lend); 1621 loff_t lstart, loff_t lend);
1622 extern int wait_on_page_writeback_range(struct address_space *mapping, 1622 extern int wait_on_page_writeback_range(struct address_space *mapping,
1623 pgoff_t start, pgoff_t end); 1623 pgoff_t start, pgoff_t end);
1624 extern int __filemap_fdatawrite_range(struct address_space *mapping, 1624 extern int __filemap_fdatawrite_range(struct address_space *mapping,
1625 loff_t start, loff_t end, int sync_mode); 1625 loff_t start, loff_t end, int sync_mode);
1626 1626
1627 extern long do_fsync(struct file *file, int datasync); 1627 extern long do_fsync(struct file *file, int datasync);
1628 extern void sync_supers(void); 1628 extern void sync_supers(void);
1629 extern void sync_filesystems(int wait); 1629 extern void sync_filesystems(int wait);
1630 extern void __fsync_super(struct super_block *sb); 1630 extern void __fsync_super(struct super_block *sb);
1631 extern void emergency_sync(void); 1631 extern void emergency_sync(void);
1632 extern void emergency_remount(void); 1632 extern void emergency_remount(void);
1633 extern int do_remount_sb(struct super_block *sb, int flags, 1633 extern int do_remount_sb(struct super_block *sb, int flags,
1634 void *data, int force); 1634 void *data, int force);
1635 #ifdef CONFIG_BLOCK 1635 #ifdef CONFIG_BLOCK
1636 extern sector_t bmap(struct inode *, sector_t); 1636 extern sector_t bmap(struct inode *, sector_t);
1637 #endif 1637 #endif
1638 extern int notify_change(struct dentry *, struct iattr *); 1638 extern int notify_change(struct dentry *, struct iattr *);
1639 extern int permission(struct inode *, int, struct nameidata *); 1639 extern int permission(struct inode *, int, struct nameidata *);
1640 extern int generic_permission(struct inode *, int, 1640 extern int generic_permission(struct inode *, int,
1641 int (*check_acl)(struct inode *, int)); 1641 int (*check_acl)(struct inode *, int));
1642 1642
1643 extern int get_write_access(struct inode *); 1643 extern int get_write_access(struct inode *);
1644 extern int deny_write_access(struct file *); 1644 extern int deny_write_access(struct file *);
1645 static inline void put_write_access(struct inode * inode) 1645 static inline void put_write_access(struct inode * inode)
1646 { 1646 {
1647 atomic_dec(&inode->i_writecount); 1647 atomic_dec(&inode->i_writecount);
1648 } 1648 }
1649 static inline void allow_write_access(struct file *file) 1649 static inline void allow_write_access(struct file *file)
1650 { 1650 {
1651 if (file) 1651 if (file)
1652 atomic_inc(&file->f_path.dentry->d_inode->i_writecount); 1652 atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
1653 } 1653 }
1654 extern int do_pipe(int *); 1654 extern int do_pipe(int *);
1655 extern struct file *create_read_pipe(struct file *f); 1655 extern struct file *create_read_pipe(struct file *f);
1656 extern struct file *create_write_pipe(void); 1656 extern struct file *create_write_pipe(void);
1657 extern void free_write_pipe(struct file *); 1657 extern void free_write_pipe(struct file *);
1658 1658
1659 extern int open_namei(int dfd, const char *, int, int, struct nameidata *); 1659 extern int open_namei(int dfd, const char *, int, int, struct nameidata *);
1660 extern int may_open(struct nameidata *, int, int); 1660 extern int may_open(struct nameidata *, int, int);
1661 1661
1662 extern int kernel_read(struct file *, unsigned long, char *, unsigned long); 1662 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1663 extern struct file * open_exec(const char *); 1663 extern struct file * open_exec(const char *);
1664 1664
1665 /* fs/dcache.c -- generic fs support functions */ 1665 /* fs/dcache.c -- generic fs support functions */
1666 extern int is_subdir(struct dentry *, struct dentry *); 1666 extern int is_subdir(struct dentry *, struct dentry *);
1667 extern ino_t find_inode_number(struct dentry *, struct qstr *); 1667 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1668 1668
1669 #include <linux/err.h> 1669 #include <linux/err.h>
1670 1670
1671 /* needed for stackable file system support */ 1671 /* needed for stackable file system support */
1672 extern loff_t default_llseek(struct file *file, loff_t offset, int origin); 1672 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1673 1673
1674 extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin); 1674 extern loff_t vfs_llseek(struct file *file, loff_t offset, int origin);
1675 1675
1676 extern void inode_init_once(struct inode *); 1676 extern void inode_init_once(struct inode *);
1677 extern void iput(struct inode *); 1677 extern void iput(struct inode *);
1678 extern struct inode * igrab(struct inode *); 1678 extern struct inode * igrab(struct inode *);
1679 extern ino_t iunique(struct super_block *, ino_t); 1679 extern ino_t iunique(struct super_block *, ino_t);
1680 extern int inode_needs_sync(struct inode *inode); 1680 extern int inode_needs_sync(struct inode *inode);
1681 extern void generic_delete_inode(struct inode *inode); 1681 extern void generic_delete_inode(struct inode *inode);
1682 extern void generic_drop_inode(struct inode *inode); 1682 extern void generic_drop_inode(struct inode *inode);
1683 1683
1684 extern struct inode *ilookup5_nowait(struct super_block *sb, 1684 extern struct inode *ilookup5_nowait(struct super_block *sb,
1685 unsigned long hashval, int (*test)(struct inode *, void *), 1685 unsigned long hashval, int (*test)(struct inode *, void *),
1686 void *data); 1686 void *data);
1687 extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval, 1687 extern struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
1688 int (*test)(struct inode *, void *), void *data); 1688 int (*test)(struct inode *, void *), void *data);
1689 extern struct inode *ilookup(struct super_block *sb, unsigned long ino); 1689 extern struct inode *ilookup(struct super_block *sb, unsigned long ino);
1690 1690
1691 extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *); 1691 extern struct inode * iget5_locked(struct super_block *, unsigned long, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *);
1692 extern struct inode * iget_locked(struct super_block *, unsigned long); 1692 extern struct inode * iget_locked(struct super_block *, unsigned long);
1693 extern void unlock_new_inode(struct inode *); 1693 extern void unlock_new_inode(struct inode *);
1694 1694
1695 static inline struct inode *iget(struct super_block *sb, unsigned long ino) 1695 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1696 { 1696 {
1697 struct inode *inode = iget_locked(sb, ino); 1697 struct inode *inode = iget_locked(sb, ino);
1698 1698
1699 if (inode && (inode->i_state & I_NEW)) { 1699 if (inode && (inode->i_state & I_NEW)) {
1700 sb->s_op->read_inode(inode); 1700 sb->s_op->read_inode(inode);
1701 unlock_new_inode(inode); 1701 unlock_new_inode(inode);
1702 } 1702 }
1703 1703
1704 return inode; 1704 return inode;
1705 } 1705 }
1706 1706
1707 extern void __iget(struct inode * inode); 1707 extern void __iget(struct inode * inode);
1708 extern void clear_inode(struct inode *); 1708 extern void clear_inode(struct inode *);
1709 extern void destroy_inode(struct inode *); 1709 extern void destroy_inode(struct inode *);
1710 extern struct inode *new_inode(struct super_block *); 1710 extern struct inode *new_inode(struct super_block *);
1711 extern int __remove_suid(struct dentry *, int); 1711 extern int __remove_suid(struct dentry *, int);
1712 extern int should_remove_suid(struct dentry *); 1712 extern int should_remove_suid(struct dentry *);
1713 extern int remove_suid(struct dentry *); 1713 extern int remove_suid(struct dentry *);
1714 1714
1715 extern void __insert_inode_hash(struct inode *, unsigned long hashval); 1715 extern void __insert_inode_hash(struct inode *, unsigned long hashval);
1716 extern void remove_inode_hash(struct inode *); 1716 extern void remove_inode_hash(struct inode *);
1717 static inline void insert_inode_hash(struct inode *inode) { 1717 static inline void insert_inode_hash(struct inode *inode) {
1718 __insert_inode_hash(inode, inode->i_ino); 1718 __insert_inode_hash(inode, inode->i_ino);
1719 } 1719 }
1720 1720
1721 extern struct file * get_empty_filp(void); 1721 extern struct file * get_empty_filp(void);
1722 extern void file_move(struct file *f, struct list_head *list); 1722 extern void file_move(struct file *f, struct list_head *list);
1723 extern void file_kill(struct file *f); 1723 extern void file_kill(struct file *f);
1724 #ifdef CONFIG_BLOCK 1724 #ifdef CONFIG_BLOCK
1725 struct bio; 1725 struct bio;
1726 extern void submit_bio(int, struct bio *); 1726 extern void submit_bio(int, struct bio *);
1727 extern int bdev_read_only(struct block_device *); 1727 extern int bdev_read_only(struct block_device *);
1728 #endif 1728 #endif
1729 extern int set_blocksize(struct block_device *, int); 1729 extern int set_blocksize(struct block_device *, int);
1730 extern int sb_set_blocksize(struct super_block *, int); 1730 extern int sb_set_blocksize(struct super_block *, int);
1731 extern int sb_min_blocksize(struct super_block *, int); 1731 extern int sb_min_blocksize(struct super_block *, int);
1732 extern int sb_has_dirty_inodes(struct super_block *);
1732 1733
1733 extern int generic_file_mmap(struct file *, struct vm_area_struct *); 1734 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1734 extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); 1735 extern int generic_file_readonly_mmap(struct file *, struct vm_area_struct *);
1735 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size); 1736 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1736 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk); 1737 int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk);
1737 extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); 1738 extern ssize_t generic_file_aio_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
1738 extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); 1739 extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
1739 extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *, 1740 extern ssize_t generic_file_aio_write_nolock(struct kiocb *, const struct iovec *,
1740 unsigned long, loff_t); 1741 unsigned long, loff_t);
1741 extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, 1742 extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
1742 unsigned long *, loff_t, loff_t *, size_t, size_t); 1743 unsigned long *, loff_t, loff_t *, size_t, size_t);
1743 extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, 1744 extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
1744 unsigned long, loff_t, loff_t *, size_t, ssize_t); 1745 unsigned long, loff_t, loff_t *, size_t, ssize_t);
1745 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); 1746 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
1746 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); 1747 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
1747 extern void do_generic_mapping_read(struct address_space *mapping, 1748 extern void do_generic_mapping_read(struct address_space *mapping,
1748 struct file_ra_state *, struct file *, 1749 struct file_ra_state *, struct file *,
1749 loff_t *, read_descriptor_t *, read_actor_t); 1750 loff_t *, read_descriptor_t *, read_actor_t);
1750 extern int generic_segment_checks(const struct iovec *iov, 1751 extern int generic_segment_checks(const struct iovec *iov,
1751 unsigned long *nr_segs, size_t *count, int access_flags); 1752 unsigned long *nr_segs, size_t *count, int access_flags);
1752 1753
1753 /* fs/splice.c */ 1754 /* fs/splice.c */
1754 extern ssize_t generic_file_splice_read(struct file *, loff_t *, 1755 extern ssize_t generic_file_splice_read(struct file *, loff_t *,
1755 struct pipe_inode_info *, size_t, unsigned int); 1756 struct pipe_inode_info *, size_t, unsigned int);
1756 extern ssize_t generic_file_splice_write(struct pipe_inode_info *, 1757 extern ssize_t generic_file_splice_write(struct pipe_inode_info *,
1757 struct file *, loff_t *, size_t, unsigned int); 1758 struct file *, loff_t *, size_t, unsigned int);
1758 extern ssize_t generic_file_splice_write_nolock(struct pipe_inode_info *, 1759 extern ssize_t generic_file_splice_write_nolock(struct pipe_inode_info *,
1759 struct file *, loff_t *, size_t, unsigned int); 1760 struct file *, loff_t *, size_t, unsigned int);
1760 extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, 1761 extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
1761 struct file *out, loff_t *, size_t len, unsigned int flags); 1762 struct file *out, loff_t *, size_t len, unsigned int flags);
1762 extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out, 1763 extern long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1763 size_t len, unsigned int flags); 1764 size_t len, unsigned int flags);
1764 1765
1765 extern void 1766 extern void
1766 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping); 1767 file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping);
1767 extern loff_t no_llseek(struct file *file, loff_t offset, int origin); 1768 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
1768 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); 1769 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
1769 extern loff_t remote_llseek(struct file *file, loff_t offset, int origin); 1770 extern loff_t remote_llseek(struct file *file, loff_t offset, int origin);
1770 extern int generic_file_open(struct inode * inode, struct file * filp); 1771 extern int generic_file_open(struct inode * inode, struct file * filp);
1771 extern int nonseekable_open(struct inode * inode, struct file * filp); 1772 extern int nonseekable_open(struct inode * inode, struct file * filp);
1772 1773
1773 #ifdef CONFIG_FS_XIP 1774 #ifdef CONFIG_FS_XIP
1774 extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len, 1775 extern ssize_t xip_file_read(struct file *filp, char __user *buf, size_t len,
1775 loff_t *ppos); 1776 loff_t *ppos);
1776 extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma); 1777 extern int xip_file_mmap(struct file * file, struct vm_area_struct * vma);
1777 extern ssize_t xip_file_write(struct file *filp, const char __user *buf, 1778 extern ssize_t xip_file_write(struct file *filp, const char __user *buf,
1778 size_t len, loff_t *ppos); 1779 size_t len, loff_t *ppos);
1779 extern int xip_truncate_page(struct address_space *mapping, loff_t from); 1780 extern int xip_truncate_page(struct address_space *mapping, loff_t from);
1780 #else 1781 #else
1781 static inline int xip_truncate_page(struct address_space *mapping, loff_t from) 1782 static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
1782 { 1783 {
1783 return 0; 1784 return 0;
1784 } 1785 }
1785 #endif 1786 #endif
1786 1787
1787 static inline void do_generic_file_read(struct file * filp, loff_t *ppos, 1788 static inline void do_generic_file_read(struct file * filp, loff_t *ppos,
1788 read_descriptor_t * desc, 1789 read_descriptor_t * desc,
1789 read_actor_t actor) 1790 read_actor_t actor)
1790 { 1791 {
1791 do_generic_mapping_read(filp->f_mapping, 1792 do_generic_mapping_read(filp->f_mapping,
1792 &filp->f_ra, 1793 &filp->f_ra,
1793 filp, 1794 filp,
1794 ppos, 1795 ppos,
1795 desc, 1796 desc,
1796 actor); 1797 actor);
1797 } 1798 }
1798 1799
1799 #ifdef CONFIG_BLOCK 1800 #ifdef CONFIG_BLOCK
1800 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode, 1801 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1801 struct block_device *bdev, const struct iovec *iov, loff_t offset, 1802 struct block_device *bdev, const struct iovec *iov, loff_t offset,
1802 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io, 1803 unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
1803 int lock_type); 1804 int lock_type);
1804 1805
1805 enum { 1806 enum {
1806 DIO_LOCKING = 1, /* need locking between buffered and direct access */ 1807 DIO_LOCKING = 1, /* need locking between buffered and direct access */
1807 DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */ 1808 DIO_NO_LOCKING, /* bdev; no locking at all between buffered/direct */
1808 DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */ 1809 DIO_OWN_LOCKING, /* filesystem locks buffered and direct internally */
1809 }; 1810 };
1810 1811
1811 static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb, 1812 static inline ssize_t blockdev_direct_IO(int rw, struct kiocb *iocb,
1812 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1813 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1813 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1814 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1814 dio_iodone_t end_io) 1815 dio_iodone_t end_io)
1815 { 1816 {
1816 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1817 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1817 nr_segs, get_block, end_io, DIO_LOCKING); 1818 nr_segs, get_block, end_io, DIO_LOCKING);
1818 } 1819 }
1819 1820
1820 static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb, 1821 static inline ssize_t blockdev_direct_IO_no_locking(int rw, struct kiocb *iocb,
1821 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1822 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1822 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1823 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1823 dio_iodone_t end_io) 1824 dio_iodone_t end_io)
1824 { 1825 {
1825 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1826 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1826 nr_segs, get_block, end_io, DIO_NO_LOCKING); 1827 nr_segs, get_block, end_io, DIO_NO_LOCKING);
1827 } 1828 }
1828 1829
1829 static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb, 1830 static inline ssize_t blockdev_direct_IO_own_locking(int rw, struct kiocb *iocb,
1830 struct inode *inode, struct block_device *bdev, const struct iovec *iov, 1831 struct inode *inode, struct block_device *bdev, const struct iovec *iov,
1831 loff_t offset, unsigned long nr_segs, get_block_t get_block, 1832 loff_t offset, unsigned long nr_segs, get_block_t get_block,
1832 dio_iodone_t end_io) 1833 dio_iodone_t end_io)
1833 { 1834 {
1834 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset, 1835 return __blockdev_direct_IO(rw, iocb, inode, bdev, iov, offset,
1835 nr_segs, get_block, end_io, DIO_OWN_LOCKING); 1836 nr_segs, get_block, end_io, DIO_OWN_LOCKING);
1836 } 1837 }
1837 #endif 1838 #endif
1838 1839
1839 extern const struct file_operations generic_ro_fops; 1840 extern const struct file_operations generic_ro_fops;
1840 1841
1841 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) 1842 #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m))
1842 1843
1843 extern int vfs_readlink(struct dentry *, char __user *, int, const char *); 1844 extern int vfs_readlink(struct dentry *, char __user *, int, const char *);
1844 extern int vfs_follow_link(struct nameidata *, const char *); 1845 extern int vfs_follow_link(struct nameidata *, const char *);
1845 extern int page_readlink(struct dentry *, char __user *, int); 1846 extern int page_readlink(struct dentry *, char __user *, int);
1846 extern void *page_follow_link_light(struct dentry *, struct nameidata *); 1847 extern void *page_follow_link_light(struct dentry *, struct nameidata *);
1847 extern void page_put_link(struct dentry *, struct nameidata *, void *); 1848 extern void page_put_link(struct dentry *, struct nameidata *, void *);
1848 extern int __page_symlink(struct inode *inode, const char *symname, int len, 1849 extern int __page_symlink(struct inode *inode, const char *symname, int len,
1849 gfp_t gfp_mask); 1850 gfp_t gfp_mask);
1850 extern int page_symlink(struct inode *inode, const char *symname, int len); 1851 extern int page_symlink(struct inode *inode, const char *symname, int len);
1851 extern const struct inode_operations page_symlink_inode_operations; 1852 extern const struct inode_operations page_symlink_inode_operations;
1852 extern int generic_readlink(struct dentry *, char __user *, int); 1853 extern int generic_readlink(struct dentry *, char __user *, int);
1853 extern void generic_fillattr(struct inode *, struct kstat *); 1854 extern void generic_fillattr(struct inode *, struct kstat *);
1854 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 1855 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1855 void inode_add_bytes(struct inode *inode, loff_t bytes); 1856 void inode_add_bytes(struct inode *inode, loff_t bytes);
1856 void inode_sub_bytes(struct inode *inode, loff_t bytes); 1857 void inode_sub_bytes(struct inode *inode, loff_t bytes);
1857 loff_t inode_get_bytes(struct inode *inode); 1858 loff_t inode_get_bytes(struct inode *inode);
1858 void inode_set_bytes(struct inode *inode, loff_t bytes); 1859 void inode_set_bytes(struct inode *inode, loff_t bytes);
1859 1860
1860 extern int vfs_readdir(struct file *, filldir_t, void *); 1861 extern int vfs_readdir(struct file *, filldir_t, void *);
1861 1862
1862 extern int vfs_stat(char __user *, struct kstat *); 1863 extern int vfs_stat(char __user *, struct kstat *);
1863 extern int vfs_lstat(char __user *, struct kstat *); 1864 extern int vfs_lstat(char __user *, struct kstat *);
1864 extern int vfs_stat_fd(int dfd, char __user *, struct kstat *); 1865 extern int vfs_stat_fd(int dfd, char __user *, struct kstat *);
1865 extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *); 1866 extern int vfs_lstat_fd(int dfd, char __user *, struct kstat *);
1866 extern int vfs_fstat(unsigned int, struct kstat *); 1867 extern int vfs_fstat(unsigned int, struct kstat *);
1867 1868
1868 extern int vfs_ioctl(struct file *, unsigned int, unsigned int, unsigned long); 1869 extern int vfs_ioctl(struct file *, unsigned int, unsigned int, unsigned long);
1869 1870
1870 extern struct file_system_type *get_fs_type(const char *name); 1871 extern struct file_system_type *get_fs_type(const char *name);
1871 extern struct super_block *get_super(struct block_device *); 1872 extern struct super_block *get_super(struct block_device *);
1872 extern struct super_block *user_get_super(dev_t); 1873 extern struct super_block *user_get_super(dev_t);
1873 extern void drop_super(struct super_block *sb); 1874 extern void drop_super(struct super_block *sb);
1874 1875
1875 extern int dcache_dir_open(struct inode *, struct file *); 1876 extern int dcache_dir_open(struct inode *, struct file *);
1876 extern int dcache_dir_close(struct inode *, struct file *); 1877 extern int dcache_dir_close(struct inode *, struct file *);
1877 extern loff_t dcache_dir_lseek(struct file *, loff_t, int); 1878 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
1878 extern int dcache_readdir(struct file *, void *, filldir_t); 1879 extern int dcache_readdir(struct file *, void *, filldir_t);
1879 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *); 1880 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1880 extern int simple_statfs(struct dentry *, struct kstatfs *); 1881 extern int simple_statfs(struct dentry *, struct kstatfs *);
1881 extern int simple_link(struct dentry *, struct inode *, struct dentry *); 1882 extern int simple_link(struct dentry *, struct inode *, struct dentry *);
1882 extern int simple_unlink(struct inode *, struct dentry *); 1883 extern int simple_unlink(struct inode *, struct dentry *);
1883 extern int simple_rmdir(struct inode *, struct dentry *); 1884 extern int simple_rmdir(struct inode *, struct dentry *);
1884 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 1885 extern int simple_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
1885 extern int simple_sync_file(struct file *, struct dentry *, int); 1886 extern int simple_sync_file(struct file *, struct dentry *, int);
1886 extern int simple_empty(struct dentry *); 1887 extern int simple_empty(struct dentry *);
1887 extern int simple_readpage(struct file *file, struct page *page); 1888 extern int simple_readpage(struct file *file, struct page *page);
1888 extern int simple_prepare_write(struct file *file, struct page *page, 1889 extern int simple_prepare_write(struct file *file, struct page *page,
1889 unsigned offset, unsigned to); 1890 unsigned offset, unsigned to);
1890 extern int simple_write_begin(struct file *file, struct address_space *mapping, 1891 extern int simple_write_begin(struct file *file, struct address_space *mapping,
1891 loff_t pos, unsigned len, unsigned flags, 1892 loff_t pos, unsigned len, unsigned flags,
1892 struct page **pagep, void **fsdata); 1893 struct page **pagep, void **fsdata);
1893 extern int simple_write_end(struct file *file, struct address_space *mapping, 1894 extern int simple_write_end(struct file *file, struct address_space *mapping,
1894 loff_t pos, unsigned len, unsigned copied, 1895 loff_t pos, unsigned len, unsigned copied,
1895 struct page *page, void *fsdata); 1896 struct page *page, void *fsdata);
1896 1897
1897 extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); 1898 extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *);
1898 extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); 1899 extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
1899 extern const struct file_operations simple_dir_operations; 1900 extern const struct file_operations simple_dir_operations;
1900 extern const struct inode_operations simple_dir_inode_operations; 1901 extern const struct inode_operations simple_dir_inode_operations;
1901 struct tree_descr { char *name; const struct file_operations *ops; int mode; }; 1902 struct tree_descr { char *name; const struct file_operations *ops; int mode; };
1902 struct dentry *d_alloc_name(struct dentry *, const char *); 1903 struct dentry *d_alloc_name(struct dentry *, const char *);
1903 extern int simple_fill_super(struct super_block *, int, struct tree_descr *); 1904 extern int simple_fill_super(struct super_block *, int, struct tree_descr *);
1904 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); 1905 extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count);
1905 extern void simple_release_fs(struct vfsmount **mount, int *count); 1906 extern void simple_release_fs(struct vfsmount **mount, int *count);
1906 1907
1907 extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t); 1908 extern ssize_t simple_read_from_buffer(void __user *, size_t, loff_t *, const void *, size_t);
1908 1909
1909 #ifdef CONFIG_MIGRATION 1910 #ifdef CONFIG_MIGRATION
1910 extern int buffer_migrate_page(struct address_space *, 1911 extern int buffer_migrate_page(struct address_space *,
1911 struct page *, struct page *); 1912 struct page *, struct page *);
1912 #else 1913 #else
1913 #define buffer_migrate_page NULL 1914 #define buffer_migrate_page NULL
1914 #endif 1915 #endif
1915 1916
1916 extern int inode_change_ok(struct inode *, struct iattr *); 1917 extern int inode_change_ok(struct inode *, struct iattr *);
1917 extern int __must_check inode_setattr(struct inode *, struct iattr *); 1918 extern int __must_check inode_setattr(struct inode *, struct iattr *);
1918 1919
1919 extern void file_update_time(struct file *file); 1920 extern void file_update_time(struct file *file);
1920 1921
1921 static inline ino_t parent_ino(struct dentry *dentry) 1922 static inline ino_t parent_ino(struct dentry *dentry)
1922 { 1923 {
1923 ino_t res; 1924 ino_t res;
1924 1925
1925 spin_lock(&dentry->d_lock); 1926 spin_lock(&dentry->d_lock);
1926 res = dentry->d_parent->d_inode->i_ino; 1927 res = dentry->d_parent->d_inode->i_ino;
1927 spin_unlock(&dentry->d_lock); 1928 spin_unlock(&dentry->d_lock);
1928 return res; 1929 return res;
1929 } 1930 }
1930 1931
1931 /* kernel/fork.c */ 1932 /* kernel/fork.c */
1932 extern int unshare_files(void); 1933 extern int unshare_files(void);
1933 1934
1934 /* Transaction based IO helpers */ 1935 /* Transaction based IO helpers */
1935 1936
1936 /* 1937 /*
1937 * An argresp is stored in an allocated page and holds the 1938 * An argresp is stored in an allocated page and holds the
1938 * size of the argument or response, along with its content 1939 * size of the argument or response, along with its content
1939 */ 1940 */
1940 struct simple_transaction_argresp { 1941 struct simple_transaction_argresp {
1941 ssize_t size; 1942 ssize_t size;
1942 char data[0]; 1943 char data[0];
1943 }; 1944 };
1944 1945
1945 #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp)) 1946 #define SIMPLE_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct simple_transaction_argresp))
1946 1947
1947 char *simple_transaction_get(struct file *file, const char __user *buf, 1948 char *simple_transaction_get(struct file *file, const char __user *buf,
1948 size_t size); 1949 size_t size);
1949 ssize_t simple_transaction_read(struct file *file, char __user *buf, 1950 ssize_t simple_transaction_read(struct file *file, char __user *buf,
1950 size_t size, loff_t *pos); 1951 size_t size, loff_t *pos);
1951 int simple_transaction_release(struct inode *inode, struct file *file); 1952 int simple_transaction_release(struct inode *inode, struct file *file);
1952 1953
1953 static inline void simple_transaction_set(struct file *file, size_t n) 1954 static inline void simple_transaction_set(struct file *file, size_t n)
1954 { 1955 {
1955 struct simple_transaction_argresp *ar = file->private_data; 1956 struct simple_transaction_argresp *ar = file->private_data;
1956 1957
1957 BUG_ON(n > SIMPLE_TRANSACTION_LIMIT); 1958 BUG_ON(n > SIMPLE_TRANSACTION_LIMIT);
1958 1959
1959 /* 1960 /*
1960 * The barrier ensures that ar->size will really remain zero until 1961 * The barrier ensures that ar->size will really remain zero until
1961 * ar->data is ready for reading. 1962 * ar->data is ready for reading.
1962 */ 1963 */
1963 smp_mb(); 1964 smp_mb();
1964 ar->size = n; 1965 ar->size = n;
1965 } 1966 }
1966 1967
1967 /* 1968 /*
1968 * simple attribute files 1969 * simple attribute files
1969 * 1970 *
1970 * These attributes behave similar to those in sysfs: 1971 * These attributes behave similar to those in sysfs:
1971 * 1972 *
1972 * Writing to an attribute immediately sets a value, an open file can be 1973 * Writing to an attribute immediately sets a value, an open file can be
1973 * written to multiple times. 1974 * written to multiple times.
1974 * 1975 *
1975 * Reading from an attribute creates a buffer from the value that might get 1976 * Reading from an attribute creates a buffer from the value that might get
1976 * read with multiple read calls. When the attribute has been read 1977 * read with multiple read calls. When the attribute has been read
1977 * completely, no further read calls are possible until the file is opened 1978 * completely, no further read calls are possible until the file is opened
1978 * again. 1979 * again.
1979 * 1980 *
1980 * All attributes contain a text representation of a numeric value 1981 * All attributes contain a text representation of a numeric value
1981 * that are accessed with the get() and set() functions. 1982 * that are accessed with the get() and set() functions.
1982 */ 1983 */
1983 #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \ 1984 #define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
1984 static int __fops ## _open(struct inode *inode, struct file *file) \ 1985 static int __fops ## _open(struct inode *inode, struct file *file) \
1985 { \ 1986 { \
1986 __simple_attr_check_format(__fmt, 0ull); \ 1987 __simple_attr_check_format(__fmt, 0ull); \
1987 return simple_attr_open(inode, file, __get, __set, __fmt); \ 1988 return simple_attr_open(inode, file, __get, __set, __fmt); \
1988 } \ 1989 } \
1989 static struct file_operations __fops = { \ 1990 static struct file_operations __fops = { \
1990 .owner = THIS_MODULE, \ 1991 .owner = THIS_MODULE, \
1991 .open = __fops ## _open, \ 1992 .open = __fops ## _open, \
1992 .release = simple_attr_close, \ 1993 .release = simple_attr_close, \
1993 .read = simple_attr_read, \ 1994 .read = simple_attr_read, \
1994 .write = simple_attr_write, \ 1995 .write = simple_attr_write, \
1995 }; 1996 };
1996 1997
1997 static inline void __attribute__((format(printf, 1, 2))) 1998 static inline void __attribute__((format(printf, 1, 2)))
1998 __simple_attr_check_format(const char *fmt, ...) 1999 __simple_attr_check_format(const char *fmt, ...)
1999 { 2000 {
2000 /* don't do anything, just let the compiler check the arguments; */ 2001 /* don't do anything, just let the compiler check the arguments; */
2001 } 2002 }
2002 2003
2003 int simple_attr_open(struct inode *inode, struct file *file, 2004 int simple_attr_open(struct inode *inode, struct file *file,
2004 u64 (*get)(void *), void (*set)(void *, u64), 2005 u64 (*get)(void *), void (*set)(void *, u64),
2005 const char *fmt); 2006 const char *fmt);
2006 int simple_attr_close(struct inode *inode, struct file *file); 2007 int simple_attr_close(struct inode *inode, struct file *file);
2007 ssize_t simple_attr_read(struct file *file, char __user *buf, 2008 ssize_t simple_attr_read(struct file *file, char __user *buf,
2008 size_t len, loff_t *ppos); 2009 size_t len, loff_t *ppos);
2009 ssize_t simple_attr_write(struct file *file, const char __user *buf, 2010 ssize_t simple_attr_write(struct file *file, const char __user *buf,
2010 size_t len, loff_t *ppos); 2011 size_t len, loff_t *ppos);
2011 2012
2012 2013
2013 #ifdef CONFIG_SECURITY 2014 #ifdef CONFIG_SECURITY
2014 static inline char *alloc_secdata(void) 2015 static inline char *alloc_secdata(void)
2015 { 2016 {
2016 return (char *)get_zeroed_page(GFP_KERNEL); 2017 return (char *)get_zeroed_page(GFP_KERNEL);
2017 } 2018 }
2018 2019
2019 static inline void free_secdata(void *secdata) 2020 static inline void free_secdata(void *secdata)
2020 { 2021 {
2021 free_page((unsigned long)secdata); 2022 free_page((unsigned long)secdata);
2022 } 2023 }
2023 #else 2024 #else
2024 static inline char *alloc_secdata(void) 2025 static inline char *alloc_secdata(void)
2025 { 2026 {
2026 return (char *)1; 2027 return (char *)1;
2027 } 2028 }
2028 2029
2029 static inline void free_secdata(void *secdata) 2030 static inline void free_secdata(void *secdata)
2030 { } 2031 { }
2031 #endif /* CONFIG_SECURITY */ 2032 #endif /* CONFIG_SECURITY */
2032 2033
2033 struct ctl_table; 2034 struct ctl_table;
2034 int proc_nr_files(struct ctl_table *table, int write, struct file *filp, 2035 int proc_nr_files(struct ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos); 2036 void __user *buffer, size_t *lenp, loff_t *ppos);
2036 2037
2037 2038
2038 #endif /* __KERNEL__ */ 2039 #endif /* __KERNEL__ */
2039 #endif /* _LINUX_FS_H */ 2040 #endif /* _LINUX_FS_H */
2040 2041