aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/xattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/xattr.c')
-rw-r--r--fs/ext4/xattr.c560
1 files changed, 280 insertions, 280 deletions
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index f86f2482f01d..d3a408154101 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * linux/fs/ext3/xattr.c 2 * linux/fs/ext4/xattr.c
3 * 3 *
4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> 4 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de>
5 * 5 *
6 * Fix by Harrison Xing <harrison@mountainviewdata.com>. 6 * Fix by Harrison Xing <harrison@mountainviewdata.com>.
7 * Ext3 code with a lot of help from Eric Jarman <ejarman@acm.org>. 7 * Ext4 code with a lot of help from Eric Jarman <ejarman@acm.org>.
8 * Extended attributes for symlinks and special files added per 8 * Extended attributes for symlinks and special files added per
9 * suggestion of Luka Renko <luka.renko@hermes.si>. 9 * suggestion of Luka Renko <luka.renko@hermes.si>.
10 * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>, 10 * xattr consolidation Copyright (c) 2004 James Morris <jmorris@redhat.com>,
@@ -43,7 +43,7 @@
43 * 43 *
44 * Locking strategy 44 * Locking strategy
45 * ---------------- 45 * ----------------
46 * EXT3_I(inode)->i_file_acl is protected by EXT3_I(inode)->xattr_sem. 46 * EXT4_I(inode)->i_file_acl is protected by EXT4_I(inode)->xattr_sem.
47 * EA blocks are only changed if they are exclusive to an inode, so 47 * EA blocks are only changed if they are exclusive to an inode, so
48 * holding xattr_sem also means that nothing but the EA block's reference 48 * holding xattr_sem also means that nothing but the EA block's reference
49 * count can change. Multiple writers to the same block are synchronized 49 * count can change. Multiple writers to the same block are synchronized
@@ -53,27 +53,27 @@
53#include <linux/init.h> 53#include <linux/init.h>
54#include <linux/fs.h> 54#include <linux/fs.h>
55#include <linux/slab.h> 55#include <linux/slab.h>
56#include <linux/ext3_jbd.h> 56#include <linux/ext4_jbd.h>
57#include <linux/ext3_fs.h> 57#include <linux/ext4_fs.h>
58#include <linux/mbcache.h> 58#include <linux/mbcache.h>
59#include <linux/quotaops.h> 59#include <linux/quotaops.h>
60#include <linux/rwsem.h> 60#include <linux/rwsem.h>
61#include "xattr.h" 61#include "xattr.h"
62#include "acl.h" 62#include "acl.h"
63 63
64#define BHDR(bh) ((struct ext3_xattr_header *)((bh)->b_data)) 64#define BHDR(bh) ((struct ext4_xattr_header *)((bh)->b_data))
65#define ENTRY(ptr) ((struct ext3_xattr_entry *)(ptr)) 65#define ENTRY(ptr) ((struct ext4_xattr_entry *)(ptr))
66#define BFIRST(bh) ENTRY(BHDR(bh)+1) 66#define BFIRST(bh) ENTRY(BHDR(bh)+1)
67#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) 67#define IS_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
68 68
69#define IHDR(inode, raw_inode) \ 69#define IHDR(inode, raw_inode) \
70 ((struct ext3_xattr_ibody_header *) \ 70 ((struct ext4_xattr_ibody_header *) \
71 ((void *)raw_inode + \ 71 ((void *)raw_inode + \
72 EXT3_GOOD_OLD_INODE_SIZE + \ 72 EXT4_GOOD_OLD_INODE_SIZE + \
73 EXT3_I(inode)->i_extra_isize)) 73 EXT4_I(inode)->i_extra_isize))
74#define IFIRST(hdr) ((struct ext3_xattr_entry *)((hdr)+1)) 74#define IFIRST(hdr) ((struct ext4_xattr_entry *)((hdr)+1))
75 75
76#ifdef EXT3_XATTR_DEBUG 76#ifdef EXT4_XATTR_DEBUG
77# define ea_idebug(inode, f...) do { \ 77# define ea_idebug(inode, f...) do { \
78 printk(KERN_DEBUG "inode %s:%lu: ", \ 78 printk(KERN_DEBUG "inode %s:%lu: ", \
79 inode->i_sb->s_id, inode->i_ino); \ 79 inode->i_sb->s_id, inode->i_ino); \
@@ -93,47 +93,47 @@
93# define ea_bdebug(f...) 93# define ea_bdebug(f...)
94#endif 94#endif
95 95
96static void ext3_xattr_cache_insert(struct buffer_head *); 96static void ext4_xattr_cache_insert(struct buffer_head *);
97static struct buffer_head *ext3_xattr_cache_find(struct inode *, 97static struct buffer_head *ext4_xattr_cache_find(struct inode *,
98 struct ext3_xattr_header *, 98 struct ext4_xattr_header *,
99 struct mb_cache_entry **); 99 struct mb_cache_entry **);
100static void ext3_xattr_rehash(struct ext3_xattr_header *, 100static void ext4_xattr_rehash(struct ext4_xattr_header *,
101 struct ext3_xattr_entry *); 101 struct ext4_xattr_entry *);
102 102
103static struct mb_cache *ext3_xattr_cache; 103static struct mb_cache *ext4_xattr_cache;
104 104
105static struct xattr_handler *ext3_xattr_handler_map[] = { 105static struct xattr_handler *ext4_xattr_handler_map[] = {
106 [EXT3_XATTR_INDEX_USER] = &ext3_xattr_user_handler, 106 [EXT4_XATTR_INDEX_USER] = &ext4_xattr_user_handler,
107#ifdef CONFIG_EXT3_FS_POSIX_ACL 107#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
108 [EXT3_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext3_xattr_acl_access_handler, 108 [EXT4_XATTR_INDEX_POSIX_ACL_ACCESS] = &ext4_xattr_acl_access_handler,
109 [EXT3_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext3_xattr_acl_default_handler, 109 [EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT] = &ext4_xattr_acl_default_handler,
110#endif 110#endif
111 [EXT3_XATTR_INDEX_TRUSTED] = &ext3_xattr_trusted_handler, 111 [EXT4_XATTR_INDEX_TRUSTED] = &ext4_xattr_trusted_handler,
112#ifdef CONFIG_EXT3_FS_SECURITY 112#ifdef CONFIG_EXT4DEV_FS_SECURITY
113 [EXT3_XATTR_INDEX_SECURITY] = &ext3_xattr_security_handler, 113 [EXT4_XATTR_INDEX_SECURITY] = &ext4_xattr_security_handler,
114#endif 114#endif
115}; 115};
116 116
117struct xattr_handler *ext3_xattr_handlers[] = { 117struct xattr_handler *ext4_xattr_handlers[] = {
118 &ext3_xattr_user_handler, 118 &ext4_xattr_user_handler,
119 &ext3_xattr_trusted_handler, 119 &ext4_xattr_trusted_handler,
120#ifdef CONFIG_EXT3_FS_POSIX_ACL 120#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL
121 &ext3_xattr_acl_access_handler, 121 &ext4_xattr_acl_access_handler,
122 &ext3_xattr_acl_default_handler, 122 &ext4_xattr_acl_default_handler,
123#endif 123#endif
124#ifdef CONFIG_EXT3_FS_SECURITY 124#ifdef CONFIG_EXT4DEV_FS_SECURITY
125 &ext3_xattr_security_handler, 125 &ext4_xattr_security_handler,
126#endif 126#endif
127 NULL 127 NULL
128}; 128};
129 129
130static inline struct xattr_handler * 130static inline struct xattr_handler *
131ext3_xattr_handler(int name_index) 131ext4_xattr_handler(int name_index)
132{ 132{
133 struct xattr_handler *handler = NULL; 133 struct xattr_handler *handler = NULL;
134 134
135 if (name_index > 0 && name_index < ARRAY_SIZE(ext3_xattr_handler_map)) 135 if (name_index > 0 && name_index < ARRAY_SIZE(ext4_xattr_handler_map))
136 handler = ext3_xattr_handler_map[name_index]; 136 handler = ext4_xattr_handler_map[name_index];
137 return handler; 137 return handler;
138} 138}
139 139
@@ -143,16 +143,16 @@ ext3_xattr_handler(int name_index)
143 * dentry->d_inode->i_mutex: don't care 143 * dentry->d_inode->i_mutex: don't care
144 */ 144 */
145ssize_t 145ssize_t
146ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) 146ext4_listxattr(struct dentry *dentry, char *buffer, size_t size)
147{ 147{
148 return ext3_xattr_list(dentry->d_inode, buffer, size); 148 return ext4_xattr_list(dentry->d_inode, buffer, size);
149} 149}
150 150
151static int 151static int
152ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end) 152ext4_xattr_check_names(struct ext4_xattr_entry *entry, void *end)
153{ 153{
154 while (!IS_LAST_ENTRY(entry)) { 154 while (!IS_LAST_ENTRY(entry)) {
155 struct ext3_xattr_entry *next = EXT3_XATTR_NEXT(entry); 155 struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(entry);
156 if ((void *)next >= end) 156 if ((void *)next >= end)
157 return -EIO; 157 return -EIO;
158 entry = next; 158 entry = next;
@@ -161,19 +161,19 @@ ext3_xattr_check_names(struct ext3_xattr_entry *entry, void *end)
161} 161}
162 162
163static inline int 163static inline int
164ext3_xattr_check_block(struct buffer_head *bh) 164ext4_xattr_check_block(struct buffer_head *bh)
165{ 165{
166 int error; 166 int error;
167 167
168 if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || 168 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
169 BHDR(bh)->h_blocks != cpu_to_le32(1)) 169 BHDR(bh)->h_blocks != cpu_to_le32(1))
170 return -EIO; 170 return -EIO;
171 error = ext3_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size); 171 error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size);
172 return error; 172 return error;
173} 173}
174 174
175static inline int 175static inline int
176ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size) 176ext4_xattr_check_entry(struct ext4_xattr_entry *entry, size_t size)
177{ 177{
178 size_t value_size = le32_to_cpu(entry->e_value_size); 178 size_t value_size = le32_to_cpu(entry->e_value_size);
179 179
@@ -184,10 +184,10 @@ ext3_xattr_check_entry(struct ext3_xattr_entry *entry, size_t size)
184} 184}
185 185
186static int 186static int
187ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index, 187ext4_xattr_find_entry(struct ext4_xattr_entry **pentry, int name_index,
188 const char *name, size_t size, int sorted) 188 const char *name, size_t size, int sorted)
189{ 189{
190 struct ext3_xattr_entry *entry; 190 struct ext4_xattr_entry *entry;
191 size_t name_len; 191 size_t name_len;
192 int cmp = 1; 192 int cmp = 1;
193 193
@@ -195,7 +195,7 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
195 return -EINVAL; 195 return -EINVAL;
196 name_len = strlen(name); 196 name_len = strlen(name);
197 entry = *pentry; 197 entry = *pentry;
198 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { 198 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
199 cmp = name_index - entry->e_name_index; 199 cmp = name_index - entry->e_name_index;
200 if (!cmp) 200 if (!cmp)
201 cmp = name_len - entry->e_name_len; 201 cmp = name_len - entry->e_name_len;
@@ -205,17 +205,17 @@ ext3_xattr_find_entry(struct ext3_xattr_entry **pentry, int name_index,
205 break; 205 break;
206 } 206 }
207 *pentry = entry; 207 *pentry = entry;
208 if (!cmp && ext3_xattr_check_entry(entry, size)) 208 if (!cmp && ext4_xattr_check_entry(entry, size))
209 return -EIO; 209 return -EIO;
210 return cmp ? -ENODATA : 0; 210 return cmp ? -ENODATA : 0;
211} 211}
212 212
213static int 213static int
214ext3_xattr_block_get(struct inode *inode, int name_index, const char *name, 214ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
215 void *buffer, size_t buffer_size) 215 void *buffer, size_t buffer_size)
216{ 216{
217 struct buffer_head *bh = NULL; 217 struct buffer_head *bh = NULL;
218 struct ext3_xattr_entry *entry; 218 struct ext4_xattr_entry *entry;
219 size_t size; 219 size_t size;
220 int error; 220 int error;
221 221
@@ -223,24 +223,24 @@ ext3_xattr_block_get(struct inode *inode, int name_index, const char *name,
223 name_index, name, buffer, (long)buffer_size); 223 name_index, name, buffer, (long)buffer_size);
224 224
225 error = -ENODATA; 225 error = -ENODATA;
226 if (!EXT3_I(inode)->i_file_acl) 226 if (!EXT4_I(inode)->i_file_acl)
227 goto cleanup; 227 goto cleanup;
228 ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); 228 ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
229 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 229 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
230 if (!bh) 230 if (!bh)
231 goto cleanup; 231 goto cleanup;
232 ea_bdebug(bh, "b_count=%d, refcount=%d", 232 ea_bdebug(bh, "b_count=%d, refcount=%d",
233 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 233 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
234 if (ext3_xattr_check_block(bh)) { 234 if (ext4_xattr_check_block(bh)) {
235bad_block: ext3_error(inode->i_sb, __FUNCTION__, 235bad_block: ext4_error(inode->i_sb, __FUNCTION__,
236 "inode %lu: bad block "E3FSBLK, inode->i_ino, 236 "inode %lu: bad block "E3FSBLK, inode->i_ino,
237 EXT3_I(inode)->i_file_acl); 237 EXT4_I(inode)->i_file_acl);
238 error = -EIO; 238 error = -EIO;
239 goto cleanup; 239 goto cleanup;
240 } 240 }
241 ext3_xattr_cache_insert(bh); 241 ext4_xattr_cache_insert(bh);
242 entry = BFIRST(bh); 242 entry = BFIRST(bh);
243 error = ext3_xattr_find_entry(&entry, name_index, name, bh->b_size, 1); 243 error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1);
244 if (error == -EIO) 244 if (error == -EIO)
245 goto bad_block; 245 goto bad_block;
246 if (error) 246 if (error)
@@ -261,30 +261,30 @@ cleanup:
261} 261}
262 262
263static int 263static int
264ext3_xattr_ibody_get(struct inode *inode, int name_index, const char *name, 264ext4_xattr_ibody_get(struct inode *inode, int name_index, const char *name,
265 void *buffer, size_t buffer_size) 265 void *buffer, size_t buffer_size)
266{ 266{
267 struct ext3_xattr_ibody_header *header; 267 struct ext4_xattr_ibody_header *header;
268 struct ext3_xattr_entry *entry; 268 struct ext4_xattr_entry *entry;
269 struct ext3_inode *raw_inode; 269 struct ext4_inode *raw_inode;
270 struct ext3_iloc iloc; 270 struct ext4_iloc iloc;
271 size_t size; 271 size_t size;
272 void *end; 272 void *end;
273 int error; 273 int error;
274 274
275 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 275 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
276 return -ENODATA; 276 return -ENODATA;
277 error = ext3_get_inode_loc(inode, &iloc); 277 error = ext4_get_inode_loc(inode, &iloc);
278 if (error) 278 if (error)
279 return error; 279 return error;
280 raw_inode = ext3_raw_inode(&iloc); 280 raw_inode = ext4_raw_inode(&iloc);
281 header = IHDR(inode, raw_inode); 281 header = IHDR(inode, raw_inode);
282 entry = IFIRST(header); 282 entry = IFIRST(header);
283 end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 283 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
284 error = ext3_xattr_check_names(entry, end); 284 error = ext4_xattr_check_names(entry, end);
285 if (error) 285 if (error)
286 goto cleanup; 286 goto cleanup;
287 error = ext3_xattr_find_entry(&entry, name_index, name, 287 error = ext4_xattr_find_entry(&entry, name_index, name,
288 end - (void *)entry, 0); 288 end - (void *)entry, 0);
289 if (error) 289 if (error)
290 goto cleanup; 290 goto cleanup;
@@ -304,7 +304,7 @@ cleanup:
304} 304}
305 305
306/* 306/*
307 * ext3_xattr_get() 307 * ext4_xattr_get()
308 * 308 *
309 * Copy an extended attribute into the buffer 309 * Copy an extended attribute into the buffer
310 * provided, or compute the buffer size required. 310 * provided, or compute the buffer size required.
@@ -314,30 +314,30 @@ cleanup:
314 * used / required on success. 314 * used / required on success.
315 */ 315 */
316int 316int
317ext3_xattr_get(struct inode *inode, int name_index, const char *name, 317ext4_xattr_get(struct inode *inode, int name_index, const char *name,
318 void *buffer, size_t buffer_size) 318 void *buffer, size_t buffer_size)
319{ 319{
320 int error; 320 int error;
321 321
322 down_read(&EXT3_I(inode)->xattr_sem); 322 down_read(&EXT4_I(inode)->xattr_sem);
323 error = ext3_xattr_ibody_get(inode, name_index, name, buffer, 323 error = ext4_xattr_ibody_get(inode, name_index, name, buffer,
324 buffer_size); 324 buffer_size);
325 if (error == -ENODATA) 325 if (error == -ENODATA)
326 error = ext3_xattr_block_get(inode, name_index, name, buffer, 326 error = ext4_xattr_block_get(inode, name_index, name, buffer,
327 buffer_size); 327 buffer_size);
328 up_read(&EXT3_I(inode)->xattr_sem); 328 up_read(&EXT4_I(inode)->xattr_sem);
329 return error; 329 return error;
330} 330}
331 331
332static int 332static int
333ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry, 333ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry,
334 char *buffer, size_t buffer_size) 334 char *buffer, size_t buffer_size)
335{ 335{
336 size_t rest = buffer_size; 336 size_t rest = buffer_size;
337 337
338 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) { 338 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
339 struct xattr_handler *handler = 339 struct xattr_handler *handler =
340 ext3_xattr_handler(entry->e_name_index); 340 ext4_xattr_handler(entry->e_name_index);
341 341
342 if (handler) { 342 if (handler) {
343 size_t size = handler->list(inode, buffer, rest, 343 size_t size = handler->list(inode, buffer, rest,
@@ -355,7 +355,7 @@ ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry,
355} 355}
356 356
357static int 357static int
358ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) 358ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
359{ 359{
360 struct buffer_head *bh = NULL; 360 struct buffer_head *bh = NULL;
361 int error; 361 int error;
@@ -364,24 +364,24 @@ ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size)
364 buffer, (long)buffer_size); 364 buffer, (long)buffer_size);
365 365
366 error = 0; 366 error = 0;
367 if (!EXT3_I(inode)->i_file_acl) 367 if (!EXT4_I(inode)->i_file_acl)
368 goto cleanup; 368 goto cleanup;
369 ea_idebug(inode, "reading block %u", EXT3_I(inode)->i_file_acl); 369 ea_idebug(inode, "reading block %u", EXT4_I(inode)->i_file_acl);
370 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 370 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
371 error = -EIO; 371 error = -EIO;
372 if (!bh) 372 if (!bh)
373 goto cleanup; 373 goto cleanup;
374 ea_bdebug(bh, "b_count=%d, refcount=%d", 374 ea_bdebug(bh, "b_count=%d, refcount=%d",
375 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount)); 375 atomic_read(&(bh->b_count)), le32_to_cpu(BHDR(bh)->h_refcount));
376 if (ext3_xattr_check_block(bh)) { 376 if (ext4_xattr_check_block(bh)) {
377 ext3_error(inode->i_sb, __FUNCTION__, 377 ext4_error(inode->i_sb, __FUNCTION__,
378 "inode %lu: bad block "E3FSBLK, inode->i_ino, 378 "inode %lu: bad block "E3FSBLK, inode->i_ino,
379 EXT3_I(inode)->i_file_acl); 379 EXT4_I(inode)->i_file_acl);
380 error = -EIO; 380 error = -EIO;
381 goto cleanup; 381 goto cleanup;
382 } 382 }
383 ext3_xattr_cache_insert(bh); 383 ext4_xattr_cache_insert(bh);
384 error = ext3_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); 384 error = ext4_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size);
385 385
386cleanup: 386cleanup:
387 brelse(bh); 387 brelse(bh);
@@ -390,26 +390,26 @@ cleanup:
390} 390}
391 391
392static int 392static int
393ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) 393ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size)
394{ 394{
395 struct ext3_xattr_ibody_header *header; 395 struct ext4_xattr_ibody_header *header;
396 struct ext3_inode *raw_inode; 396 struct ext4_inode *raw_inode;
397 struct ext3_iloc iloc; 397 struct ext4_iloc iloc;
398 void *end; 398 void *end;
399 int error; 399 int error;
400 400
401 if (!(EXT3_I(inode)->i_state & EXT3_STATE_XATTR)) 401 if (!(EXT4_I(inode)->i_state & EXT4_STATE_XATTR))
402 return 0; 402 return 0;
403 error = ext3_get_inode_loc(inode, &iloc); 403 error = ext4_get_inode_loc(inode, &iloc);
404 if (error) 404 if (error)
405 return error; 405 return error;
406 raw_inode = ext3_raw_inode(&iloc); 406 raw_inode = ext4_raw_inode(&iloc);
407 header = IHDR(inode, raw_inode); 407 header = IHDR(inode, raw_inode);
408 end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 408 end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
409 error = ext3_xattr_check_names(IFIRST(header), end); 409 error = ext4_xattr_check_names(IFIRST(header), end);
410 if (error) 410 if (error)
411 goto cleanup; 411 goto cleanup;
412 error = ext3_xattr_list_entries(inode, IFIRST(header), 412 error = ext4_xattr_list_entries(inode, IFIRST(header),
413 buffer, buffer_size); 413 buffer, buffer_size);
414 414
415cleanup: 415cleanup:
@@ -418,7 +418,7 @@ cleanup:
418} 418}
419 419
420/* 420/*
421 * ext3_xattr_list() 421 * ext4_xattr_list()
422 * 422 *
423 * Copy a list of attribute names into the buffer 423 * Copy a list of attribute names into the buffer
424 * provided, or compute the buffer size required. 424 * provided, or compute the buffer size required.
@@ -428,12 +428,12 @@ cleanup:
428 * used / required on success. 428 * used / required on success.
429 */ 429 */
430int 430int
431ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 431ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
432{ 432{
433 int i_error, b_error; 433 int i_error, b_error;
434 434
435 down_read(&EXT3_I(inode)->xattr_sem); 435 down_read(&EXT4_I(inode)->xattr_sem);
436 i_error = ext3_xattr_ibody_list(inode, buffer, buffer_size); 436 i_error = ext4_xattr_ibody_list(inode, buffer, buffer_size);
437 if (i_error < 0) { 437 if (i_error < 0) {
438 b_error = 0; 438 b_error = 0;
439 } else { 439 } else {
@@ -441,30 +441,30 @@ ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size)
441 buffer += i_error; 441 buffer += i_error;
442 buffer_size -= i_error; 442 buffer_size -= i_error;
443 } 443 }
444 b_error = ext3_xattr_block_list(inode, buffer, buffer_size); 444 b_error = ext4_xattr_block_list(inode, buffer, buffer_size);
445 if (b_error < 0) 445 if (b_error < 0)
446 i_error = 0; 446 i_error = 0;
447 } 447 }
448 up_read(&EXT3_I(inode)->xattr_sem); 448 up_read(&EXT4_I(inode)->xattr_sem);
449 return i_error + b_error; 449 return i_error + b_error;
450} 450}
451 451
452/* 452/*
453 * If the EXT3_FEATURE_COMPAT_EXT_ATTR feature of this file system is 453 * If the EXT4_FEATURE_COMPAT_EXT_ATTR feature of this file system is
454 * not set, set it. 454 * not set, set it.
455 */ 455 */
456static void ext3_xattr_update_super_block(handle_t *handle, 456static void ext4_xattr_update_super_block(handle_t *handle,
457 struct super_block *sb) 457 struct super_block *sb)
458{ 458{
459 if (EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_EXT_ATTR)) 459 if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_EXT_ATTR))
460 return; 460 return;
461 461
462 lock_super(sb); 462 lock_super(sb);
463 if (ext3_journal_get_write_access(handle, EXT3_SB(sb)->s_sbh) == 0) { 463 if (ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh) == 0) {
464 EXT3_SB(sb)->s_es->s_feature_compat |= 464 EXT4_SB(sb)->s_es->s_feature_compat |=
465 cpu_to_le32(EXT3_FEATURE_COMPAT_EXT_ATTR); 465 cpu_to_le32(EXT4_FEATURE_COMPAT_EXT_ATTR);
466 sb->s_dirt = 1; 466 sb->s_dirt = 1;
467 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 467 ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh);
468 } 468 }
469 unlock_super(sb); 469 unlock_super(sb);
470} 470}
@@ -474,25 +474,25 @@ static void ext3_xattr_update_super_block(handle_t *handle,
474 * it; otherwise free the block. 474 * it; otherwise free the block.
475 */ 475 */
476static void 476static void
477ext3_xattr_release_block(handle_t *handle, struct inode *inode, 477ext4_xattr_release_block(handle_t *handle, struct inode *inode,
478 struct buffer_head *bh) 478 struct buffer_head *bh)
479{ 479{
480 struct mb_cache_entry *ce = NULL; 480 struct mb_cache_entry *ce = NULL;
481 481
482 ce = mb_cache_entry_get(ext3_xattr_cache, bh->b_bdev, bh->b_blocknr); 482 ce = mb_cache_entry_get(ext4_xattr_cache, bh->b_bdev, bh->b_blocknr);
483 if (BHDR(bh)->h_refcount == cpu_to_le32(1)) { 483 if (BHDR(bh)->h_refcount == cpu_to_le32(1)) {
484 ea_bdebug(bh, "refcount now=0; freeing"); 484 ea_bdebug(bh, "refcount now=0; freeing");
485 if (ce) 485 if (ce)
486 mb_cache_entry_free(ce); 486 mb_cache_entry_free(ce);
487 ext3_free_blocks(handle, inode, bh->b_blocknr, 1); 487 ext4_free_blocks(handle, inode, bh->b_blocknr, 1);
488 get_bh(bh); 488 get_bh(bh);
489 ext3_forget(handle, 1, inode, bh, bh->b_blocknr); 489 ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
490 } else { 490 } else {
491 if (ext3_journal_get_write_access(handle, bh) == 0) { 491 if (ext4_journal_get_write_access(handle, bh) == 0) {
492 lock_buffer(bh); 492 lock_buffer(bh);
493 BHDR(bh)->h_refcount = cpu_to_le32( 493 BHDR(bh)->h_refcount = cpu_to_le32(
494 le32_to_cpu(BHDR(bh)->h_refcount) - 1); 494 le32_to_cpu(BHDR(bh)->h_refcount) - 1);
495 ext3_journal_dirty_metadata(handle, bh); 495 ext4_journal_dirty_metadata(handle, bh);
496 if (IS_SYNC(inode)) 496 if (IS_SYNC(inode))
497 handle->h_sync = 1; 497 handle->h_sync = 1;
498 DQUOT_FREE_BLOCK(inode, 1); 498 DQUOT_FREE_BLOCK(inode, 1);
@@ -505,30 +505,30 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
505 } 505 }
506} 506}
507 507
508struct ext3_xattr_info { 508struct ext4_xattr_info {
509 int name_index; 509 int name_index;
510 const char *name; 510 const char *name;
511 const void *value; 511 const void *value;
512 size_t value_len; 512 size_t value_len;
513}; 513};
514 514
515struct ext3_xattr_search { 515struct ext4_xattr_search {
516 struct ext3_xattr_entry *first; 516 struct ext4_xattr_entry *first;
517 void *base; 517 void *base;
518 void *end; 518 void *end;
519 struct ext3_xattr_entry *here; 519 struct ext4_xattr_entry *here;
520 int not_found; 520 int not_found;
521}; 521};
522 522
523static int 523static int
524ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s) 524ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
525{ 525{
526 struct ext3_xattr_entry *last; 526 struct ext4_xattr_entry *last;
527 size_t free, min_offs = s->end - s->base, name_len = strlen(i->name); 527 size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
528 528
529 /* Compute min_offs and last. */ 529 /* Compute min_offs and last. */
530 last = s->first; 530 last = s->first;
531 for (; !IS_LAST_ENTRY(last); last = EXT3_XATTR_NEXT(last)) { 531 for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
532 if (!last->e_value_block && last->e_value_size) { 532 if (!last->e_value_block && last->e_value_size) {
533 size_t offs = le16_to_cpu(last->e_value_offs); 533 size_t offs = le16_to_cpu(last->e_value_offs);
534 if (offs < min_offs) 534 if (offs < min_offs)
@@ -539,20 +539,20 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
539 if (!s->not_found) { 539 if (!s->not_found) {
540 if (!s->here->e_value_block && s->here->e_value_size) { 540 if (!s->here->e_value_block && s->here->e_value_size) {
541 size_t size = le32_to_cpu(s->here->e_value_size); 541 size_t size = le32_to_cpu(s->here->e_value_size);
542 free += EXT3_XATTR_SIZE(size); 542 free += EXT4_XATTR_SIZE(size);
543 } 543 }
544 free += EXT3_XATTR_LEN(name_len); 544 free += EXT4_XATTR_LEN(name_len);
545 } 545 }
546 if (i->value) { 546 if (i->value) {
547 if (free < EXT3_XATTR_SIZE(i->value_len) || 547 if (free < EXT4_XATTR_SIZE(i->value_len) ||
548 free < EXT3_XATTR_LEN(name_len) + 548 free < EXT4_XATTR_LEN(name_len) +
549 EXT3_XATTR_SIZE(i->value_len)) 549 EXT4_XATTR_SIZE(i->value_len))
550 return -ENOSPC; 550 return -ENOSPC;
551 } 551 }
552 552
553 if (i->value && s->not_found) { 553 if (i->value && s->not_found) {
554 /* Insert the new name. */ 554 /* Insert the new name. */
555 size_t size = EXT3_XATTR_LEN(name_len); 555 size_t size = EXT4_XATTR_LEN(name_len);
556 size_t rest = (void *)last - (void *)s->here + sizeof(__u32); 556 size_t rest = (void *)last - (void *)s->here + sizeof(__u32);
557 memmove((void *)s->here + size, s->here, rest); 557 memmove((void *)s->here + size, s->here, rest);
558 memset(s->here, 0, size); 558 memset(s->here, 0, size);
@@ -564,16 +564,16 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
564 void *first_val = s->base + min_offs; 564 void *first_val = s->base + min_offs;
565 size_t offs = le16_to_cpu(s->here->e_value_offs); 565 size_t offs = le16_to_cpu(s->here->e_value_offs);
566 void *val = s->base + offs; 566 void *val = s->base + offs;
567 size_t size = EXT3_XATTR_SIZE( 567 size_t size = EXT4_XATTR_SIZE(
568 le32_to_cpu(s->here->e_value_size)); 568 le32_to_cpu(s->here->e_value_size));
569 569
570 if (i->value && size == EXT3_XATTR_SIZE(i->value_len)) { 570 if (i->value && size == EXT4_XATTR_SIZE(i->value_len)) {
571 /* The old and the new value have the same 571 /* The old and the new value have the same
572 size. Just replace. */ 572 size. Just replace. */
573 s->here->e_value_size = 573 s->here->e_value_size =
574 cpu_to_le32(i->value_len); 574 cpu_to_le32(i->value_len);
575 memset(val + size - EXT3_XATTR_PAD, 0, 575 memset(val + size - EXT4_XATTR_PAD, 0,
576 EXT3_XATTR_PAD); /* Clear pad bytes. */ 576 EXT4_XATTR_PAD); /* Clear pad bytes. */
577 memcpy(val, i->value, i->value_len); 577 memcpy(val, i->value, i->value_len);
578 return 0; 578 return 0;
579 } 579 }
@@ -593,12 +593,12 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
593 last->e_value_size && o < offs) 593 last->e_value_size && o < offs)
594 last->e_value_offs = 594 last->e_value_offs =
595 cpu_to_le16(o + size); 595 cpu_to_le16(o + size);
596 last = EXT3_XATTR_NEXT(last); 596 last = EXT4_XATTR_NEXT(last);
597 } 597 }
598 } 598 }
599 if (!i->value) { 599 if (!i->value) {
600 /* Remove the old name. */ 600 /* Remove the old name. */
601 size_t size = EXT3_XATTR_LEN(name_len); 601 size_t size = EXT4_XATTR_LEN(name_len);
602 last = ENTRY((void *)last - size); 602 last = ENTRY((void *)last - size);
603 memmove(s->here, (void *)s->here + size, 603 memmove(s->here, (void *)s->here + size,
604 (void *)last - (void *)s->here + sizeof(__u32)); 604 (void *)last - (void *)s->here + sizeof(__u32));
@@ -610,25 +610,25 @@ ext3_xattr_set_entry(struct ext3_xattr_info *i, struct ext3_xattr_search *s)
610 /* Insert the new value. */ 610 /* Insert the new value. */
611 s->here->e_value_size = cpu_to_le32(i->value_len); 611 s->here->e_value_size = cpu_to_le32(i->value_len);
612 if (i->value_len) { 612 if (i->value_len) {
613 size_t size = EXT3_XATTR_SIZE(i->value_len); 613 size_t size = EXT4_XATTR_SIZE(i->value_len);
614 void *val = s->base + min_offs - size; 614 void *val = s->base + min_offs - size;
615 s->here->e_value_offs = cpu_to_le16(min_offs - size); 615 s->here->e_value_offs = cpu_to_le16(min_offs - size);
616 memset(val + size - EXT3_XATTR_PAD, 0, 616 memset(val + size - EXT4_XATTR_PAD, 0,
617 EXT3_XATTR_PAD); /* Clear the pad bytes. */ 617 EXT4_XATTR_PAD); /* Clear the pad bytes. */
618 memcpy(val, i->value, i->value_len); 618 memcpy(val, i->value, i->value_len);
619 } 619 }
620 } 620 }
621 return 0; 621 return 0;
622} 622}
623 623
624struct ext3_xattr_block_find { 624struct ext4_xattr_block_find {
625 struct ext3_xattr_search s; 625 struct ext4_xattr_search s;
626 struct buffer_head *bh; 626 struct buffer_head *bh;
627}; 627};
628 628
629static int 629static int
630ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i, 630ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
631 struct ext3_xattr_block_find *bs) 631 struct ext4_xattr_block_find *bs)
632{ 632{
633 struct super_block *sb = inode->i_sb; 633 struct super_block *sb = inode->i_sb;
634 int error; 634 int error;
@@ -636,19 +636,19 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
636 ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld", 636 ea_idebug(inode, "name=%d.%s, value=%p, value_len=%ld",
637 i->name_index, i->name, i->value, (long)i->value_len); 637 i->name_index, i->name, i->value, (long)i->value_len);
638 638
639 if (EXT3_I(inode)->i_file_acl) { 639 if (EXT4_I(inode)->i_file_acl) {
640 /* The inode already has an extended attribute block. */ 640 /* The inode already has an extended attribute block. */
641 bs->bh = sb_bread(sb, EXT3_I(inode)->i_file_acl); 641 bs->bh = sb_bread(sb, EXT4_I(inode)->i_file_acl);
642 error = -EIO; 642 error = -EIO;
643 if (!bs->bh) 643 if (!bs->bh)
644 goto cleanup; 644 goto cleanup;
645 ea_bdebug(bs->bh, "b_count=%d, refcount=%d", 645 ea_bdebug(bs->bh, "b_count=%d, refcount=%d",
646 atomic_read(&(bs->bh->b_count)), 646 atomic_read(&(bs->bh->b_count)),
647 le32_to_cpu(BHDR(bs->bh)->h_refcount)); 647 le32_to_cpu(BHDR(bs->bh)->h_refcount));
648 if (ext3_xattr_check_block(bs->bh)) { 648 if (ext4_xattr_check_block(bs->bh)) {
649 ext3_error(sb, __FUNCTION__, 649 ext4_error(sb, __FUNCTION__,
650 "inode %lu: bad block "E3FSBLK, inode->i_ino, 650 "inode %lu: bad block "E3FSBLK, inode->i_ino,
651 EXT3_I(inode)->i_file_acl); 651 EXT4_I(inode)->i_file_acl);
652 error = -EIO; 652 error = -EIO;
653 goto cleanup; 653 goto cleanup;
654 } 654 }
@@ -657,7 +657,7 @@ ext3_xattr_block_find(struct inode *inode, struct ext3_xattr_info *i,
657 bs->s.first = BFIRST(bs->bh); 657 bs->s.first = BFIRST(bs->bh);
658 bs->s.end = bs->bh->b_data + bs->bh->b_size; 658 bs->s.end = bs->bh->b_data + bs->bh->b_size;
659 bs->s.here = bs->s.first; 659 bs->s.here = bs->s.first;
660 error = ext3_xattr_find_entry(&bs->s.here, i->name_index, 660 error = ext4_xattr_find_entry(&bs->s.here, i->name_index,
661 i->name, bs->bh->b_size, 1); 661 i->name, bs->bh->b_size, 1);
662 if (error && error != -ENODATA) 662 if (error && error != -ENODATA)
663 goto cleanup; 663 goto cleanup;
@@ -670,22 +670,22 @@ cleanup:
670} 670}
671 671
672static int 672static int
673ext3_xattr_block_set(handle_t *handle, struct inode *inode, 673ext4_xattr_block_set(handle_t *handle, struct inode *inode,
674 struct ext3_xattr_info *i, 674 struct ext4_xattr_info *i,
675 struct ext3_xattr_block_find *bs) 675 struct ext4_xattr_block_find *bs)
676{ 676{
677 struct super_block *sb = inode->i_sb; 677 struct super_block *sb = inode->i_sb;
678 struct buffer_head *new_bh = NULL; 678 struct buffer_head *new_bh = NULL;
679 struct ext3_xattr_search *s = &bs->s; 679 struct ext4_xattr_search *s = &bs->s;
680 struct mb_cache_entry *ce = NULL; 680 struct mb_cache_entry *ce = NULL;
681 int error; 681 int error;
682 682
683#define header(x) ((struct ext3_xattr_header *)(x)) 683#define header(x) ((struct ext4_xattr_header *)(x))
684 684
685 if (i->value && i->value_len > sb->s_blocksize) 685 if (i->value && i->value_len > sb->s_blocksize)
686 return -ENOSPC; 686 return -ENOSPC;
687 if (s->base) { 687 if (s->base) {
688 ce = mb_cache_entry_get(ext3_xattr_cache, bs->bh->b_bdev, 688 ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
689 bs->bh->b_blocknr); 689 bs->bh->b_blocknr);
690 if (header(s->base)->h_refcount == cpu_to_le32(1)) { 690 if (header(s->base)->h_refcount == cpu_to_le32(1)) {
691 if (ce) { 691 if (ce) {
@@ -693,22 +693,22 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
693 ce = NULL; 693 ce = NULL;
694 } 694 }
695 ea_bdebug(bs->bh, "modifying in-place"); 695 ea_bdebug(bs->bh, "modifying in-place");
696 error = ext3_journal_get_write_access(handle, bs->bh); 696 error = ext4_journal_get_write_access(handle, bs->bh);
697 if (error) 697 if (error)
698 goto cleanup; 698 goto cleanup;
699 lock_buffer(bs->bh); 699 lock_buffer(bs->bh);
700 error = ext3_xattr_set_entry(i, s); 700 error = ext4_xattr_set_entry(i, s);
701 if (!error) { 701 if (!error) {
702 if (!IS_LAST_ENTRY(s->first)) 702 if (!IS_LAST_ENTRY(s->first))
703 ext3_xattr_rehash(header(s->base), 703 ext4_xattr_rehash(header(s->base),
704 s->here); 704 s->here);
705 ext3_xattr_cache_insert(bs->bh); 705 ext4_xattr_cache_insert(bs->bh);
706 } 706 }
707 unlock_buffer(bs->bh); 707 unlock_buffer(bs->bh);
708 if (error == -EIO) 708 if (error == -EIO)
709 goto bad_block; 709 goto bad_block;
710 if (!error) 710 if (!error)
711 error = ext3_journal_dirty_metadata(handle, 711 error = ext4_journal_dirty_metadata(handle,
712 bs->bh); 712 bs->bh);
713 if (error) 713 if (error)
714 goto cleanup; 714 goto cleanup;
@@ -739,7 +739,7 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
739 if (s->base == NULL) 739 if (s->base == NULL)
740 goto cleanup; 740 goto cleanup;
741 memset(s->base, 0, sb->s_blocksize); 741 memset(s->base, 0, sb->s_blocksize);
742 header(s->base)->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 742 header(s->base)->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
743 header(s->base)->h_blocks = cpu_to_le32(1); 743 header(s->base)->h_blocks = cpu_to_le32(1);
744 header(s->base)->h_refcount = cpu_to_le32(1); 744 header(s->base)->h_refcount = cpu_to_le32(1);
745 s->first = ENTRY(header(s->base)+1); 745 s->first = ENTRY(header(s->base)+1);
@@ -747,17 +747,17 @@ ext3_xattr_block_set(handle_t *handle, struct inode *inode,
747 s->end = s->base + sb->s_blocksize; 747 s->end = s->base + sb->s_blocksize;
748 } 748 }
749 749
750 error = ext3_xattr_set_entry(i, s); 750 error = ext4_xattr_set_entry(i, s);
751 if (error == -EIO) 751 if (error == -EIO)
752 goto bad_block; 752 goto bad_block;
753 if (error) 753 if (error)
754 goto cleanup; 754 goto cleanup;
755 if (!IS_LAST_ENTRY(s->first)) 755 if (!IS_LAST_ENTRY(s->first))
756 ext3_xattr_rehash(header(s->base), s->here); 756 ext4_xattr_rehash(header(s->base), s->here);
757 757
758inserted: 758inserted:
759 if (!IS_LAST_ENTRY(s->first)) { 759 if (!IS_LAST_ENTRY(s->first)) {
760 new_bh = ext3_xattr_cache_find(inode, header(s->base), &ce); 760 new_bh = ext4_xattr_cache_find(inode, header(s->base), &ce);
761 if (new_bh) { 761 if (new_bh) {
762 /* We found an identical block in the cache. */ 762 /* We found an identical block in the cache. */
763 if (new_bh == bs->bh) 763 if (new_bh == bs->bh)
@@ -768,7 +768,7 @@ inserted:
768 error = -EDQUOT; 768 error = -EDQUOT;
769 if (DQUOT_ALLOC_BLOCK(inode, 1)) 769 if (DQUOT_ALLOC_BLOCK(inode, 1))
770 goto cleanup; 770 goto cleanup;
771 error = ext3_journal_get_write_access(handle, 771 error = ext4_journal_get_write_access(handle,
772 new_bh); 772 new_bh);
773 if (error) 773 if (error)
774 goto cleanup_dquot; 774 goto cleanup_dquot;
@@ -778,7 +778,7 @@ inserted:
778 ea_bdebug(new_bh, "reusing; refcount now=%d", 778 ea_bdebug(new_bh, "reusing; refcount now=%d",
779 le32_to_cpu(BHDR(new_bh)->h_refcount)); 779 le32_to_cpu(BHDR(new_bh)->h_refcount));
780 unlock_buffer(new_bh); 780 unlock_buffer(new_bh);
781 error = ext3_journal_dirty_metadata(handle, 781 error = ext4_journal_dirty_metadata(handle,
782 new_bh); 782 new_bh);
783 if (error) 783 if (error)
784 goto cleanup_dquot; 784 goto cleanup_dquot;
@@ -792,11 +792,11 @@ inserted:
792 get_bh(new_bh); 792 get_bh(new_bh);
793 } else { 793 } else {
794 /* We need to allocate a new block */ 794 /* We need to allocate a new block */
795 ext3_fsblk_t goal = le32_to_cpu( 795 ext4_fsblk_t goal = le32_to_cpu(
796 EXT3_SB(sb)->s_es->s_first_data_block) + 796 EXT4_SB(sb)->s_es->s_first_data_block) +
797 (ext3_fsblk_t)EXT3_I(inode)->i_block_group * 797 (ext4_fsblk_t)EXT4_I(inode)->i_block_group *
798 EXT3_BLOCKS_PER_GROUP(sb); 798 EXT4_BLOCKS_PER_GROUP(sb);
799 ext3_fsblk_t block = ext3_new_block(handle, inode, 799 ext4_fsblk_t block = ext4_new_block(handle, inode,
800 goal, &error); 800 goal, &error);
801 if (error) 801 if (error)
802 goto cleanup; 802 goto cleanup;
@@ -805,12 +805,12 @@ inserted:
805 new_bh = sb_getblk(sb, block); 805 new_bh = sb_getblk(sb, block);
806 if (!new_bh) { 806 if (!new_bh) {
807getblk_failed: 807getblk_failed:
808 ext3_free_blocks(handle, inode, block, 1); 808 ext4_free_blocks(handle, inode, block, 1);
809 error = -EIO; 809 error = -EIO;
810 goto cleanup; 810 goto cleanup;
811 } 811 }
812 lock_buffer(new_bh); 812 lock_buffer(new_bh);
813 error = ext3_journal_get_create_access(handle, new_bh); 813 error = ext4_journal_get_create_access(handle, new_bh);
814 if (error) { 814 if (error) {
815 unlock_buffer(new_bh); 815 unlock_buffer(new_bh);
816 goto getblk_failed; 816 goto getblk_failed;
@@ -818,19 +818,19 @@ getblk_failed:
818 memcpy(new_bh->b_data, s->base, new_bh->b_size); 818 memcpy(new_bh->b_data, s->base, new_bh->b_size);
819 set_buffer_uptodate(new_bh); 819 set_buffer_uptodate(new_bh);
820 unlock_buffer(new_bh); 820 unlock_buffer(new_bh);
821 ext3_xattr_cache_insert(new_bh); 821 ext4_xattr_cache_insert(new_bh);
822 error = ext3_journal_dirty_metadata(handle, new_bh); 822 error = ext4_journal_dirty_metadata(handle, new_bh);
823 if (error) 823 if (error)
824 goto cleanup; 824 goto cleanup;
825 } 825 }
826 } 826 }
827 827
828 /* Update the inode. */ 828 /* Update the inode. */
829 EXT3_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0; 829 EXT4_I(inode)->i_file_acl = new_bh ? new_bh->b_blocknr : 0;
830 830
831 /* Drop the previous xattr block. */ 831 /* Drop the previous xattr block. */
832 if (bs->bh && bs->bh != new_bh) 832 if (bs->bh && bs->bh != new_bh)
833 ext3_xattr_release_block(handle, inode, bs->bh); 833 ext4_xattr_release_block(handle, inode, bs->bh);
834 error = 0; 834 error = 0;
835 835
836cleanup: 836cleanup:
@@ -847,40 +847,40 @@ cleanup_dquot:
847 goto cleanup; 847 goto cleanup;
848 848
849bad_block: 849bad_block:
850 ext3_error(inode->i_sb, __FUNCTION__, 850 ext4_error(inode->i_sb, __FUNCTION__,
851 "inode %lu: bad block "E3FSBLK, inode->i_ino, 851 "inode %lu: bad block "E3FSBLK, inode->i_ino,
852 EXT3_I(inode)->i_file_acl); 852 EXT4_I(inode)->i_file_acl);
853 goto cleanup; 853 goto cleanup;
854 854
855#undef header 855#undef header
856} 856}
857 857
858struct ext3_xattr_ibody_find { 858struct ext4_xattr_ibody_find {
859 struct ext3_xattr_search s; 859 struct ext4_xattr_search s;
860 struct ext3_iloc iloc; 860 struct ext4_iloc iloc;
861}; 861};
862 862
863static int 863static int
864ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i, 864ext4_xattr_ibody_find(struct inode *inode, struct ext4_xattr_info *i,
865 struct ext3_xattr_ibody_find *is) 865 struct ext4_xattr_ibody_find *is)
866{ 866{
867 struct ext3_xattr_ibody_header *header; 867 struct ext4_xattr_ibody_header *header;
868 struct ext3_inode *raw_inode; 868 struct ext4_inode *raw_inode;
869 int error; 869 int error;
870 870
871 if (EXT3_I(inode)->i_extra_isize == 0) 871 if (EXT4_I(inode)->i_extra_isize == 0)
872 return 0; 872 return 0;
873 raw_inode = ext3_raw_inode(&is->iloc); 873 raw_inode = ext4_raw_inode(&is->iloc);
874 header = IHDR(inode, raw_inode); 874 header = IHDR(inode, raw_inode);
875 is->s.base = is->s.first = IFIRST(header); 875 is->s.base = is->s.first = IFIRST(header);
876 is->s.here = is->s.first; 876 is->s.here = is->s.first;
877 is->s.end = (void *)raw_inode + EXT3_SB(inode->i_sb)->s_inode_size; 877 is->s.end = (void *)raw_inode + EXT4_SB(inode->i_sb)->s_inode_size;
878 if (EXT3_I(inode)->i_state & EXT3_STATE_XATTR) { 878 if (EXT4_I(inode)->i_state & EXT4_STATE_XATTR) {
879 error = ext3_xattr_check_names(IFIRST(header), is->s.end); 879 error = ext4_xattr_check_names(IFIRST(header), is->s.end);
880 if (error) 880 if (error)
881 return error; 881 return error;
882 /* Find the named attribute. */ 882 /* Find the named attribute. */
883 error = ext3_xattr_find_entry(&is->s.here, i->name_index, 883 error = ext4_xattr_find_entry(&is->s.here, i->name_index,
884 i->name, is->s.end - 884 i->name, is->s.end -
885 (void *)is->s.base, 0); 885 (void *)is->s.base, 0);
886 if (error && error != -ENODATA) 886 if (error && error != -ENODATA)
@@ -891,32 +891,32 @@ ext3_xattr_ibody_find(struct inode *inode, struct ext3_xattr_info *i,
891} 891}
892 892
893static int 893static int
894ext3_xattr_ibody_set(handle_t *handle, struct inode *inode, 894ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
895 struct ext3_xattr_info *i, 895 struct ext4_xattr_info *i,
896 struct ext3_xattr_ibody_find *is) 896 struct ext4_xattr_ibody_find *is)
897{ 897{
898 struct ext3_xattr_ibody_header *header; 898 struct ext4_xattr_ibody_header *header;
899 struct ext3_xattr_search *s = &is->s; 899 struct ext4_xattr_search *s = &is->s;
900 int error; 900 int error;
901 901
902 if (EXT3_I(inode)->i_extra_isize == 0) 902 if (EXT4_I(inode)->i_extra_isize == 0)
903 return -ENOSPC; 903 return -ENOSPC;
904 error = ext3_xattr_set_entry(i, s); 904 error = ext4_xattr_set_entry(i, s);
905 if (error) 905 if (error)
906 return error; 906 return error;
907 header = IHDR(inode, ext3_raw_inode(&is->iloc)); 907 header = IHDR(inode, ext4_raw_inode(&is->iloc));
908 if (!IS_LAST_ENTRY(s->first)) { 908 if (!IS_LAST_ENTRY(s->first)) {
909 header->h_magic = cpu_to_le32(EXT3_XATTR_MAGIC); 909 header->h_magic = cpu_to_le32(EXT4_XATTR_MAGIC);
910 EXT3_I(inode)->i_state |= EXT3_STATE_XATTR; 910 EXT4_I(inode)->i_state |= EXT4_STATE_XATTR;
911 } else { 911 } else {
912 header->h_magic = cpu_to_le32(0); 912 header->h_magic = cpu_to_le32(0);
913 EXT3_I(inode)->i_state &= ~EXT3_STATE_XATTR; 913 EXT4_I(inode)->i_state &= ~EXT4_STATE_XATTR;
914 } 914 }
915 return 0; 915 return 0;
916} 916}
917 917
918/* 918/*
919 * ext3_xattr_set_handle() 919 * ext4_xattr_set_handle()
920 * 920 *
921 * Create, replace or remove an extended attribute for this inode. Buffer 921 * Create, replace or remove an extended attribute for this inode. Buffer
922 * is NULL to remove an existing extended attribute, and non-NULL to 922 * is NULL to remove an existing extended attribute, and non-NULL to
@@ -928,21 +928,21 @@ ext3_xattr_ibody_set(handle_t *handle, struct inode *inode,
928 * Returns 0, or a negative error number on failure. 928 * Returns 0, or a negative error number on failure.
929 */ 929 */
930int 930int
931ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, 931ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
932 const char *name, const void *value, size_t value_len, 932 const char *name, const void *value, size_t value_len,
933 int flags) 933 int flags)
934{ 934{
935 struct ext3_xattr_info i = { 935 struct ext4_xattr_info i = {
936 .name_index = name_index, 936 .name_index = name_index,
937 .name = name, 937 .name = name,
938 .value = value, 938 .value = value,
939 .value_len = value_len, 939 .value_len = value_len,
940 940
941 }; 941 };
942 struct ext3_xattr_ibody_find is = { 942 struct ext4_xattr_ibody_find is = {
943 .s = { .not_found = -ENODATA, }, 943 .s = { .not_found = -ENODATA, },
944 }; 944 };
945 struct ext3_xattr_block_find bs = { 945 struct ext4_xattr_block_find bs = {
946 .s = { .not_found = -ENODATA, }, 946 .s = { .not_found = -ENODATA, },
947 }; 947 };
948 int error; 948 int error;
@@ -951,22 +951,22 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
951 return -EINVAL; 951 return -EINVAL;
952 if (strlen(name) > 255) 952 if (strlen(name) > 255)
953 return -ERANGE; 953 return -ERANGE;
954 down_write(&EXT3_I(inode)->xattr_sem); 954 down_write(&EXT4_I(inode)->xattr_sem);
955 error = ext3_get_inode_loc(inode, &is.iloc); 955 error = ext4_get_inode_loc(inode, &is.iloc);
956 if (error) 956 if (error)
957 goto cleanup; 957 goto cleanup;
958 958
959 if (EXT3_I(inode)->i_state & EXT3_STATE_NEW) { 959 if (EXT4_I(inode)->i_state & EXT4_STATE_NEW) {
960 struct ext3_inode *raw_inode = ext3_raw_inode(&is.iloc); 960 struct ext4_inode *raw_inode = ext4_raw_inode(&is.iloc);
961 memset(raw_inode, 0, EXT3_SB(inode->i_sb)->s_inode_size); 961 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
962 EXT3_I(inode)->i_state &= ~EXT3_STATE_NEW; 962 EXT4_I(inode)->i_state &= ~EXT4_STATE_NEW;
963 } 963 }
964 964
965 error = ext3_xattr_ibody_find(inode, &i, &is); 965 error = ext4_xattr_ibody_find(inode, &i, &is);
966 if (error) 966 if (error)
967 goto cleanup; 967 goto cleanup;
968 if (is.s.not_found) 968 if (is.s.not_found)
969 error = ext3_xattr_block_find(inode, &i, &bs); 969 error = ext4_xattr_block_find(inode, &i, &bs);
970 if (error) 970 if (error)
971 goto cleanup; 971 goto cleanup;
972 if (is.s.not_found && bs.s.not_found) { 972 if (is.s.not_found && bs.s.not_found) {
@@ -981,36 +981,36 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
981 if (flags & XATTR_CREATE) 981 if (flags & XATTR_CREATE)
982 goto cleanup; 982 goto cleanup;
983 } 983 }
984 error = ext3_journal_get_write_access(handle, is.iloc.bh); 984 error = ext4_journal_get_write_access(handle, is.iloc.bh);
985 if (error) 985 if (error)
986 goto cleanup; 986 goto cleanup;
987 if (!value) { 987 if (!value) {
988 if (!is.s.not_found) 988 if (!is.s.not_found)
989 error = ext3_xattr_ibody_set(handle, inode, &i, &is); 989 error = ext4_xattr_ibody_set(handle, inode, &i, &is);
990 else if (!bs.s.not_found) 990 else if (!bs.s.not_found)
991 error = ext3_xattr_block_set(handle, inode, &i, &bs); 991 error = ext4_xattr_block_set(handle, inode, &i, &bs);
992 } else { 992 } else {
993 error = ext3_xattr_ibody_set(handle, inode, &i, &is); 993 error = ext4_xattr_ibody_set(handle, inode, &i, &is);
994 if (!error && !bs.s.not_found) { 994 if (!error && !bs.s.not_found) {
995 i.value = NULL; 995 i.value = NULL;
996 error = ext3_xattr_block_set(handle, inode, &i, &bs); 996 error = ext4_xattr_block_set(handle, inode, &i, &bs);
997 } else if (error == -ENOSPC) { 997 } else if (error == -ENOSPC) {
998 error = ext3_xattr_block_set(handle, inode, &i, &bs); 998 error = ext4_xattr_block_set(handle, inode, &i, &bs);
999 if (error) 999 if (error)
1000 goto cleanup; 1000 goto cleanup;
1001 if (!is.s.not_found) { 1001 if (!is.s.not_found) {
1002 i.value = NULL; 1002 i.value = NULL;
1003 error = ext3_xattr_ibody_set(handle, inode, &i, 1003 error = ext4_xattr_ibody_set(handle, inode, &i,
1004 &is); 1004 &is);
1005 } 1005 }
1006 } 1006 }
1007 } 1007 }
1008 if (!error) { 1008 if (!error) {
1009 ext3_xattr_update_super_block(handle, inode->i_sb); 1009 ext4_xattr_update_super_block(handle, inode->i_sb);
1010 inode->i_ctime = CURRENT_TIME_SEC; 1010 inode->i_ctime = CURRENT_TIME_SEC;
1011 error = ext3_mark_iloc_dirty(handle, inode, &is.iloc); 1011 error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
1012 /* 1012 /*
1013 * The bh is consumed by ext3_mark_iloc_dirty, even with 1013 * The bh is consumed by ext4_mark_iloc_dirty, even with
1014 * error != 0. 1014 * error != 0.
1015 */ 1015 */
1016 is.iloc.bh = NULL; 1016 is.iloc.bh = NULL;
@@ -1021,37 +1021,37 @@ ext3_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
1021cleanup: 1021cleanup:
1022 brelse(is.iloc.bh); 1022 brelse(is.iloc.bh);
1023 brelse(bs.bh); 1023 brelse(bs.bh);
1024 up_write(&EXT3_I(inode)->xattr_sem); 1024 up_write(&EXT4_I(inode)->xattr_sem);
1025 return error; 1025 return error;
1026} 1026}
1027 1027
1028/* 1028/*
1029 * ext3_xattr_set() 1029 * ext4_xattr_set()
1030 * 1030 *
1031 * Like ext3_xattr_set_handle, but start from an inode. This extended 1031 * Like ext4_xattr_set_handle, but start from an inode. This extended
1032 * attribute modification is a filesystem transaction by itself. 1032 * attribute modification is a filesystem transaction by itself.
1033 * 1033 *
1034 * Returns 0, or a negative error number on failure. 1034 * Returns 0, or a negative error number on failure.
1035 */ 1035 */
1036int 1036int
1037ext3_xattr_set(struct inode *inode, int name_index, const char *name, 1037ext4_xattr_set(struct inode *inode, int name_index, const char *name,
1038 const void *value, size_t value_len, int flags) 1038 const void *value, size_t value_len, int flags)
1039{ 1039{
1040 handle_t *handle; 1040 handle_t *handle;
1041 int error, retries = 0; 1041 int error, retries = 0;
1042 1042
1043retry: 1043retry:
1044 handle = ext3_journal_start(inode, EXT3_DATA_TRANS_BLOCKS(inode->i_sb)); 1044 handle = ext4_journal_start(inode, EXT4_DATA_TRANS_BLOCKS(inode->i_sb));
1045 if (IS_ERR(handle)) { 1045 if (IS_ERR(handle)) {
1046 error = PTR_ERR(handle); 1046 error = PTR_ERR(handle);
1047 } else { 1047 } else {
1048 int error2; 1048 int error2;
1049 1049
1050 error = ext3_xattr_set_handle(handle, inode, name_index, name, 1050 error = ext4_xattr_set_handle(handle, inode, name_index, name,
1051 value, value_len, flags); 1051 value, value_len, flags);
1052 error2 = ext3_journal_stop(handle); 1052 error2 = ext4_journal_stop(handle);
1053 if (error == -ENOSPC && 1053 if (error == -ENOSPC &&
1054 ext3_should_retry_alloc(inode->i_sb, &retries)) 1054 ext4_should_retry_alloc(inode->i_sb, &retries))
1055 goto retry; 1055 goto retry;
1056 if (error == 0) 1056 if (error == 0)
1057 error = error2; 1057 error = error2;
@@ -1061,53 +1061,53 @@ retry:
1061} 1061}
1062 1062
1063/* 1063/*
1064 * ext3_xattr_delete_inode() 1064 * ext4_xattr_delete_inode()
1065 * 1065 *
1066 * Free extended attribute resources associated with this inode. This 1066 * Free extended attribute resources associated with this inode. This
1067 * is called immediately before an inode is freed. We have exclusive 1067 * is called immediately before an inode is freed. We have exclusive
1068 * access to the inode. 1068 * access to the inode.
1069 */ 1069 */
1070void 1070void
1071ext3_xattr_delete_inode(handle_t *handle, struct inode *inode) 1071ext4_xattr_delete_inode(handle_t *handle, struct inode *inode)
1072{ 1072{
1073 struct buffer_head *bh = NULL; 1073 struct buffer_head *bh = NULL;
1074 1074
1075 if (!EXT3_I(inode)->i_file_acl) 1075 if (!EXT4_I(inode)->i_file_acl)
1076 goto cleanup; 1076 goto cleanup;
1077 bh = sb_bread(inode->i_sb, EXT3_I(inode)->i_file_acl); 1077 bh = sb_bread(inode->i_sb, EXT4_I(inode)->i_file_acl);
1078 if (!bh) { 1078 if (!bh) {
1079 ext3_error(inode->i_sb, __FUNCTION__, 1079 ext4_error(inode->i_sb, __FUNCTION__,
1080 "inode %lu: block "E3FSBLK" read error", inode->i_ino, 1080 "inode %lu: block "E3FSBLK" read error", inode->i_ino,
1081 EXT3_I(inode)->i_file_acl); 1081 EXT4_I(inode)->i_file_acl);
1082 goto cleanup; 1082 goto cleanup;
1083 } 1083 }
1084 if (BHDR(bh)->h_magic != cpu_to_le32(EXT3_XATTR_MAGIC) || 1084 if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
1085 BHDR(bh)->h_blocks != cpu_to_le32(1)) { 1085 BHDR(bh)->h_blocks != cpu_to_le32(1)) {
1086 ext3_error(inode->i_sb, __FUNCTION__, 1086 ext4_error(inode->i_sb, __FUNCTION__,
1087 "inode %lu: bad block "E3FSBLK, inode->i_ino, 1087 "inode %lu: bad block "E3FSBLK, inode->i_ino,
1088 EXT3_I(inode)->i_file_acl); 1088 EXT4_I(inode)->i_file_acl);
1089 goto cleanup; 1089 goto cleanup;
1090 } 1090 }
1091 ext3_xattr_release_block(handle, inode, bh); 1091 ext4_xattr_release_block(handle, inode, bh);
1092 EXT3_I(inode)->i_file_acl = 0; 1092 EXT4_I(inode)->i_file_acl = 0;
1093 1093
1094cleanup: 1094cleanup:
1095 brelse(bh); 1095 brelse(bh);
1096} 1096}
1097 1097
1098/* 1098/*
1099 * ext3_xattr_put_super() 1099 * ext4_xattr_put_super()
1100 * 1100 *
1101 * This is called when a file system is unmounted. 1101 * This is called when a file system is unmounted.
1102 */ 1102 */
1103void 1103void
1104ext3_xattr_put_super(struct super_block *sb) 1104ext4_xattr_put_super(struct super_block *sb)
1105{ 1105{
1106 mb_cache_shrink(sb->s_bdev); 1106 mb_cache_shrink(sb->s_bdev);
1107} 1107}
1108 1108
1109/* 1109/*
1110 * ext3_xattr_cache_insert() 1110 * ext4_xattr_cache_insert()
1111 * 1111 *
1112 * Create a new entry in the extended attribute cache, and insert 1112 * Create a new entry in the extended attribute cache, and insert
1113 * it unless such an entry is already in the cache. 1113 * it unless such an entry is already in the cache.
@@ -1115,13 +1115,13 @@ ext3_xattr_put_super(struct super_block *sb)
1115 * Returns 0, or a negative error number on failure. 1115 * Returns 0, or a negative error number on failure.
1116 */ 1116 */
1117static void 1117static void
1118ext3_xattr_cache_insert(struct buffer_head *bh) 1118ext4_xattr_cache_insert(struct buffer_head *bh)
1119{ 1119{
1120 __u32 hash = le32_to_cpu(BHDR(bh)->h_hash); 1120 __u32 hash = le32_to_cpu(BHDR(bh)->h_hash);
1121 struct mb_cache_entry *ce; 1121 struct mb_cache_entry *ce;
1122 int error; 1122 int error;
1123 1123
1124 ce = mb_cache_entry_alloc(ext3_xattr_cache); 1124 ce = mb_cache_entry_alloc(ext4_xattr_cache);
1125 if (!ce) { 1125 if (!ce) {
1126 ea_bdebug(bh, "out of memory"); 1126 ea_bdebug(bh, "out of memory");
1127 return; 1127 return;
@@ -1140,7 +1140,7 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
1140} 1140}
1141 1141
1142/* 1142/*
1143 * ext3_xattr_cmp() 1143 * ext4_xattr_cmp()
1144 * 1144 *
1145 * Compare two extended attribute blocks for equality. 1145 * Compare two extended attribute blocks for equality.
1146 * 1146 *
@@ -1148,10 +1148,10 @@ ext3_xattr_cache_insert(struct buffer_head *bh)
1148 * a negative error number on errors. 1148 * a negative error number on errors.
1149 */ 1149 */
1150static int 1150static int
1151ext3_xattr_cmp(struct ext3_xattr_header *header1, 1151ext4_xattr_cmp(struct ext4_xattr_header *header1,
1152 struct ext3_xattr_header *header2) 1152 struct ext4_xattr_header *header2)
1153{ 1153{
1154 struct ext3_xattr_entry *entry1, *entry2; 1154 struct ext4_xattr_entry *entry1, *entry2;
1155 1155
1156 entry1 = ENTRY(header1+1); 1156 entry1 = ENTRY(header1+1);
1157 entry2 = ENTRY(header2+1); 1157 entry2 = ENTRY(header2+1);
@@ -1171,8 +1171,8 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1171 le32_to_cpu(entry1->e_value_size))) 1171 le32_to_cpu(entry1->e_value_size)))
1172 return 1; 1172 return 1;
1173 1173
1174 entry1 = EXT3_XATTR_NEXT(entry1); 1174 entry1 = EXT4_XATTR_NEXT(entry1);
1175 entry2 = EXT3_XATTR_NEXT(entry2); 1175 entry2 = EXT4_XATTR_NEXT(entry2);
1176 } 1176 }
1177 if (!IS_LAST_ENTRY(entry2)) 1177 if (!IS_LAST_ENTRY(entry2))
1178 return 1; 1178 return 1;
@@ -1180,7 +1180,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1180} 1180}
1181 1181
1182/* 1182/*
1183 * ext3_xattr_cache_find() 1183 * ext4_xattr_cache_find()
1184 * 1184 *
1185 * Find an identical extended attribute block. 1185 * Find an identical extended attribute block.
1186 * 1186 *
@@ -1188,7 +1188,7 @@ ext3_xattr_cmp(struct ext3_xattr_header *header1,
1188 * not found or an error occurred. 1188 * not found or an error occurred.
1189 */ 1189 */
1190static struct buffer_head * 1190static struct buffer_head *
1191ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header, 1191ext4_xattr_cache_find(struct inode *inode, struct ext4_xattr_header *header,
1192 struct mb_cache_entry **pce) 1192 struct mb_cache_entry **pce)
1193{ 1193{
1194 __u32 hash = le32_to_cpu(header->h_hash); 1194 __u32 hash = le32_to_cpu(header->h_hash);
@@ -1198,7 +1198,7 @@ ext3_xattr_cache_find(struct inode *inode, struct ext3_xattr_header *header,
1198 return NULL; /* never share */ 1198 return NULL; /* never share */
1199 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash); 1199 ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);
1200again: 1200again:
1201 ce = mb_cache_entry_find_first(ext3_xattr_cache, 0, 1201 ce = mb_cache_entry_find_first(ext4_xattr_cache, 0,
1202 inode->i_sb->s_bdev, hash); 1202 inode->i_sb->s_bdev, hash);
1203 while (ce) { 1203 while (ce) {
1204 struct buffer_head *bh; 1204 struct buffer_head *bh;
@@ -1210,16 +1210,16 @@ again:
1210 } 1210 }
1211 bh = sb_bread(inode->i_sb, ce->e_block); 1211 bh = sb_bread(inode->i_sb, ce->e_block);
1212 if (!bh) { 1212 if (!bh) {
1213 ext3_error(inode->i_sb, __FUNCTION__, 1213 ext4_error(inode->i_sb, __FUNCTION__,
1214 "inode %lu: block %lu read error", 1214 "inode %lu: block %lu read error",
1215 inode->i_ino, (unsigned long) ce->e_block); 1215 inode->i_ino, (unsigned long) ce->e_block);
1216 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >= 1216 } else if (le32_to_cpu(BHDR(bh)->h_refcount) >=
1217 EXT3_XATTR_REFCOUNT_MAX) { 1217 EXT4_XATTR_REFCOUNT_MAX) {
1218 ea_idebug(inode, "block %lu refcount %d>=%d", 1218 ea_idebug(inode, "block %lu refcount %d>=%d",
1219 (unsigned long) ce->e_block, 1219 (unsigned long) ce->e_block,
1220 le32_to_cpu(BHDR(bh)->h_refcount), 1220 le32_to_cpu(BHDR(bh)->h_refcount),
1221 EXT3_XATTR_REFCOUNT_MAX); 1221 EXT4_XATTR_REFCOUNT_MAX);
1222 } else if (ext3_xattr_cmp(header, BHDR(bh)) == 0) { 1222 } else if (ext4_xattr_cmp(header, BHDR(bh)) == 0) {
1223 *pce = ce; 1223 *pce = ce;
1224 return bh; 1224 return bh;
1225 } 1225 }
@@ -1233,12 +1233,12 @@ again:
1233#define VALUE_HASH_SHIFT 16 1233#define VALUE_HASH_SHIFT 16
1234 1234
1235/* 1235/*
1236 * ext3_xattr_hash_entry() 1236 * ext4_xattr_hash_entry()
1237 * 1237 *
1238 * Compute the hash of an extended attribute. 1238 * Compute the hash of an extended attribute.
1239 */ 1239 */
1240static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header, 1240static inline void ext4_xattr_hash_entry(struct ext4_xattr_header *header,
1241 struct ext3_xattr_entry *entry) 1241 struct ext4_xattr_entry *entry)
1242{ 1242{
1243 __u32 hash = 0; 1243 __u32 hash = 0;
1244 char *name = entry->e_name; 1244 char *name = entry->e_name;
@@ -1254,7 +1254,7 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1254 __le32 *value = (__le32 *)((char *)header + 1254 __le32 *value = (__le32 *)((char *)header +
1255 le16_to_cpu(entry->e_value_offs)); 1255 le16_to_cpu(entry->e_value_offs));
1256 for (n = (le32_to_cpu(entry->e_value_size) + 1256 for (n = (le32_to_cpu(entry->e_value_size) +
1257 EXT3_XATTR_ROUND) >> EXT3_XATTR_PAD_BITS; n; n--) { 1257 EXT4_XATTR_ROUND) >> EXT4_XATTR_PAD_BITS; n; n--) {
1258 hash = (hash << VALUE_HASH_SHIFT) ^ 1258 hash = (hash << VALUE_HASH_SHIFT) ^
1259 (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^ 1259 (hash >> (8*sizeof(hash) - VALUE_HASH_SHIFT)) ^
1260 le32_to_cpu(*value++); 1260 le32_to_cpu(*value++);
@@ -1269,17 +1269,17 @@ static inline void ext3_xattr_hash_entry(struct ext3_xattr_header *header,
1269#define BLOCK_HASH_SHIFT 16 1269#define BLOCK_HASH_SHIFT 16
1270 1270
1271/* 1271/*
1272 * ext3_xattr_rehash() 1272 * ext4_xattr_rehash()
1273 * 1273 *
1274 * Re-compute the extended attribute hash value after an entry has changed. 1274 * Re-compute the extended attribute hash value after an entry has changed.
1275 */ 1275 */
1276static void ext3_xattr_rehash(struct ext3_xattr_header *header, 1276static void ext4_xattr_rehash(struct ext4_xattr_header *header,
1277 struct ext3_xattr_entry *entry) 1277 struct ext4_xattr_entry *entry)
1278{ 1278{
1279 struct ext3_xattr_entry *here; 1279 struct ext4_xattr_entry *here;
1280 __u32 hash = 0; 1280 __u32 hash = 0;
1281 1281
1282 ext3_xattr_hash_entry(header, entry); 1282 ext4_xattr_hash_entry(header, entry);
1283 here = ENTRY(header+1); 1283 here = ENTRY(header+1);
1284 while (!IS_LAST_ENTRY(here)) { 1284 while (!IS_LAST_ENTRY(here)) {
1285 if (!here->e_hash) { 1285 if (!here->e_hash) {
@@ -1290,7 +1290,7 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1290 hash = (hash << BLOCK_HASH_SHIFT) ^ 1290 hash = (hash << BLOCK_HASH_SHIFT) ^
1291 (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^ 1291 (hash >> (8*sizeof(hash) - BLOCK_HASH_SHIFT)) ^
1292 le32_to_cpu(here->e_hash); 1292 le32_to_cpu(here->e_hash);
1293 here = EXT3_XATTR_NEXT(here); 1293 here = EXT4_XATTR_NEXT(here);
1294 } 1294 }
1295 header->h_hash = cpu_to_le32(hash); 1295 header->h_hash = cpu_to_le32(hash);
1296} 1296}
@@ -1298,20 +1298,20 @@ static void ext3_xattr_rehash(struct ext3_xattr_header *header,
1298#undef BLOCK_HASH_SHIFT 1298#undef BLOCK_HASH_SHIFT
1299 1299
1300int __init 1300int __init
1301init_ext3_xattr(void) 1301init_ext4_xattr(void)
1302{ 1302{
1303 ext3_xattr_cache = mb_cache_create("ext3_xattr", NULL, 1303 ext4_xattr_cache = mb_cache_create("ext4_xattr", NULL,
1304 sizeof(struct mb_cache_entry) + 1304 sizeof(struct mb_cache_entry) +
1305 sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6); 1305 sizeof(((struct mb_cache_entry *) 0)->e_indexes[0]), 1, 6);
1306 if (!ext3_xattr_cache) 1306 if (!ext4_xattr_cache)
1307 return -ENOMEM; 1307 return -ENOMEM;
1308 return 0; 1308 return 0;
1309} 1309}
1310 1310
1311void 1311void
1312exit_ext3_xattr(void) 1312exit_ext4_xattr(void)
1313{ 1313{
1314 if (ext3_xattr_cache) 1314 if (ext4_xattr_cache)
1315 mb_cache_destroy(ext3_xattr_cache); 1315 mb_cache_destroy(ext4_xattr_cache);
1316 ext3_xattr_cache = NULL; 1316 ext4_xattr_cache = NULL;
1317} 1317}