blob: ce3f98ba993ac220f379c0834288e4b4a2cd2b04 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/hpfs/ea.c
3 *
4 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
5 *
6 * handling extended attributes
7 */
8
9#include "hpfs_fn.h"
10
11/* Remove external extended attributes. ano specifies whether a is a
12 direct sector where eas starts or an anode */
13
14void hpfs_ea_ext_remove(struct super_block *s, secno a, int ano, unsigned len)
15{
16 unsigned pos = 0;
17 while (pos < len) {
18 char ex[4 + 255 + 1 + 8];
19 struct extended_attribute *ea = (struct extended_attribute *)ex;
20 if (pos + 4 > len) {
21 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
22 ano ? "anode" : "sectors", a, len);
23 return;
24 }
25 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
Al Viro4085e152012-04-06 13:21:09 -040026 if (ea_indirect(ea)) {
Mikulas Patockad0969d12011-05-08 20:44:32 +020027 if (ea_valuelen(ea) != 8) {
Al Viro4085e152012-04-06 13:21:09 -040028 hpfs_error(s, "ea_indirect(ea) set while ea->valuelen!=8, %s %08x, pos %08x",
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 ano ? "anode" : "sectors", a, pos);
30 return;
31 }
32 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 9, ex+4))
33 return;
Al Viro4085e152012-04-06 13:21:09 -040034 hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 }
Mikulas Patockad0969d12011-05-08 20:44:32 +020036 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 }
38 if (!ano) hpfs_free_sectors(s, a, (len+511) >> 9);
39 else {
40 struct buffer_head *bh;
41 struct anode *anode;
42 if ((anode = hpfs_map_anode(s, a, &bh))) {
43 hpfs_remove_btree(s, &anode->btree);
44 brelse(bh);
45 hpfs_free_sectors(s, a, 1);
46 }
47 }
48}
49
50static char *get_indirect_ea(struct super_block *s, int ano, secno a, int size)
51{
52 char *ret;
53 if (!(ret = kmalloc(size + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -070054 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return NULL;
56 }
57 if (hpfs_ea_read(s, a, ano, 0, size, ret)) {
58 kfree(ret);
59 return NULL;
60 }
61 ret[size] = 0;
62 return ret;
63}
64
Al Viro7e7742e2010-01-31 17:09:29 -050065static void set_indirect_ea(struct super_block *s, int ano, secno a,
66 const char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 hpfs_ea_write(s, a, ano, 0, size, data);
69}
70
71/* Read an extended attribute named 'key' into the provided buffer */
72
73int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
74 char *buf, int size)
75{
76 unsigned pos;
77 int ano, len;
78 secno a;
Mikulas Patockac3514812011-05-08 20:44:38 +020079 char ex[4 + 255 + 1 + 8];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 struct extended_attribute *ea;
81 struct extended_attribute *ea_end = fnode_end_ea(fnode);
82 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
83 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -040084 if (ea_indirect(ea))
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 goto indirect;
Mikulas Patockad0969d12011-05-08 20:44:32 +020086 if (ea_valuelen(ea) >= size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return -EINVAL;
Mikulas Patockad0969d12011-05-08 20:44:32 +020088 memcpy(buf, ea_data(ea), ea_valuelen(ea));
89 buf[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 return 0;
91 }
Mikulas Patocka0b697602011-05-08 20:44:26 +020092 a = le32_to_cpu(fnode->ea_secno);
93 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -040094 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 pos = 0;
96 while (pos < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 ea = (struct extended_attribute *)ex;
98 if (pos + 4 > len) {
99 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
100 ano ? "anode" : "sectors", a, len);
101 return -EIO;
102 }
103 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return -EIO;
Al Viro4085e152012-04-06 13:21:09 -0400104 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return -EIO;
106 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400107 if (ea_indirect(ea))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 goto indirect;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200109 if (ea_valuelen(ea) >= size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EINVAL;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200111 if (hpfs_ea_read(s, a, ano, pos + 4 + ea->namelen + 1, ea_valuelen(ea), buf))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return -EIO;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200113 buf[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return 0;
115 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200116 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118 return -ENOENT;
119indirect:
120 if (ea_len(ea) >= size)
121 return -EINVAL;
Al Viro4085e152012-04-06 13:21:09 -0400122 if (hpfs_ea_read(s, ea_sec(ea), ea_in_anode(ea), 0, ea_len(ea), buf))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return -EIO;
124 buf[ea_len(ea)] = 0;
125 return 0;
126}
127
128/* Read an extended attribute named 'key' */
129char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *size)
130{
131 char *ret;
132 unsigned pos;
133 int ano, len;
134 secno a;
135 struct extended_attribute *ea;
136 struct extended_attribute *ea_end = fnode_end_ea(fnode);
137 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
138 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400139 if (ea_indirect(ea))
140 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
Mikulas Patockad0969d12011-05-08 20:44:32 +0200141 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -0700142 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return NULL;
144 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200145 memcpy(ret, ea_data(ea), ea_valuelen(ea));
146 ret[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return ret;
148 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200149 a = le32_to_cpu(fnode->ea_secno);
150 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -0400151 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 pos = 0;
153 while (pos < len) {
154 char ex[4 + 255 + 1 + 8];
155 ea = (struct extended_attribute *)ex;
156 if (pos + 4 > len) {
157 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
158 ano ? "anode" : "sectors", a, len);
159 return NULL;
160 }
161 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return NULL;
Al Viro4085e152012-04-06 13:21:09 -0400162 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return NULL;
164 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400165 if (ea_indirect(ea))
166 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
Mikulas Patockad0969d12011-05-08 20:44:32 +0200167 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -0700168 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return NULL;
170 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200171 if (hpfs_ea_read(s, a, ano, pos + 4 + ea->namelen + 1, ea_valuelen(ea), ret)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 kfree(ret);
173 return NULL;
174 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200175 ret[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 return ret;
177 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200178 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180 return NULL;
181}
182
183/*
184 * Update or create extended attribute 'key' with value 'data'. Note that
185 * when this ea exists, it MUST have the same size as size of data.
186 * This driver can't change sizes of eas ('cause I just don't need it).
187 */
188
Al Viro7e7742e2010-01-31 17:09:29 -0500189void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
190 const char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191{
192 fnode_secno fno = inode->i_ino;
193 struct super_block *s = inode->i_sb;
194 unsigned pos;
195 int ano, len;
196 secno a;
197 unsigned char h[4];
198 struct extended_attribute *ea;
199 struct extended_attribute *ea_end = fnode_end_ea(fnode);
200 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
201 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400202 if (ea_indirect(ea)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (ea_len(ea) == size)
Al Viro4085e152012-04-06 13:21:09 -0400204 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
Mikulas Patockad0969d12011-05-08 20:44:32 +0200205 } else if (ea_valuelen(ea) == size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 memcpy(ea_data(ea), data, size);
207 }
208 return;
209 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200210 a = le32_to_cpu(fnode->ea_secno);
211 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -0400212 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 pos = 0;
214 while (pos < len) {
215 char ex[4 + 255 + 1 + 8];
216 ea = (struct extended_attribute *)ex;
217 if (pos + 4 > len) {
218 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
219 ano ? "anode" : "sectors", a, len);
220 return;
221 }
222 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
Al Viro4085e152012-04-06 13:21:09 -0400223 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return;
225 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400226 if (ea_indirect(ea)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (ea_len(ea) == size)
Al Viro4085e152012-04-06 13:21:09 -0400228 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
230 else {
Mikulas Patockad0969d12011-05-08 20:44:32 +0200231 if (ea_valuelen(ea) == size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 hpfs_ea_write(s, a, ano, pos + 4 + ea->namelen + 1, size, data);
233 }
234 return;
235 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200236 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200238 if (!le16_to_cpu(fnode->ea_offs)) {
239 /*if (le16_to_cpu(fnode->ea_size_s)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 hpfs_error(s, "fnode %08x: ea_size_s == %03x, ea_offs == 0",
Mikulas Patocka0b697602011-05-08 20:44:26 +0200241 inode->i_ino, le16_to_cpu(fnode->ea_size_s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return;
243 }*/
Mikulas Patocka0b697602011-05-08 20:44:26 +0200244 fnode->ea_offs = cpu_to_le16(0xc4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200246 if (le16_to_cpu(fnode->ea_offs) < 0xc4 || le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) > 0x200) {
Randy Dunlap18debbb2006-12-06 20:37:05 -0800247 hpfs_error(s, "fnode %08lx: ea_offs == %03x, ea_size_s == %03x",
248 (unsigned long)inode->i_ino,
Al Virode5e2b32012-04-13 01:24:37 -0400249 le16_to_cpu(fnode->ea_offs), le16_to_cpu(fnode->ea_size_s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return;
251 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200252 if ((le16_to_cpu(fnode->ea_size_s) || !le32_to_cpu(fnode->ea_size_l)) &&
253 le16_to_cpu(fnode->ea_offs) + le16_to_cpu(fnode->acl_size_s) + le16_to_cpu(fnode->ea_size_s) + strlen(key) + size + 5 <= 0x200) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 ea = fnode_end_ea(fnode);
255 *(char *)ea = 0;
256 ea->namelen = strlen(key);
Mikulas Patockad0969d12011-05-08 20:44:32 +0200257 ea->valuelen_lo = size;
258 ea->valuelen_hi = size >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 strcpy(ea->name, key);
260 memcpy(ea_data(ea), data, size);
Mikulas Patocka0b697602011-05-08 20:44:26 +0200261 fnode->ea_size_s = cpu_to_le16(le16_to_cpu(fnode->ea_size_s) + strlen(key) + size + 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 goto ret;
263 }
264 /* Most the code here is 99.9993422% unused. I hope there are no bugs.
265 But what .. HPFS.IFS has also bugs in ea management. */
Mikulas Patocka0b697602011-05-08 20:44:26 +0200266 if (le16_to_cpu(fnode->ea_size_s) && !le32_to_cpu(fnode->ea_size_l)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 secno n;
268 struct buffer_head *bh;
269 char *data;
Mikulas Patocka7d23ce32011-05-08 20:43:06 +0200270 if (!(n = hpfs_alloc_sector(s, fno, 1, 0))) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (!(data = hpfs_get_sector(s, n, &bh))) {
272 hpfs_free_sectors(s, n, 1);
273 return;
274 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200275 memcpy(data, fnode_ea(fnode), le16_to_cpu(fnode->ea_size_s));
276 fnode->ea_size_l = cpu_to_le32(le16_to_cpu(fnode->ea_size_s));
277 fnode->ea_size_s = cpu_to_le16(0);
278 fnode->ea_secno = cpu_to_le32(n);
Al Viroc4c99542012-04-06 14:30:07 -0400279 fnode->flags &= ~FNODE_anode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 mark_buffer_dirty(bh);
281 brelse(bh);
282 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200283 pos = le32_to_cpu(fnode->ea_size_l) + 5 + strlen(key) + size;
284 len = (le32_to_cpu(fnode->ea_size_l) + 511) >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (pos >= 30000) goto bail;
286 while (((pos + 511) >> 9) > len) {
287 if (!len) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200288 secno q = hpfs_alloc_sector(s, fno, 1, 0);
289 if (!q) goto bail;
290 fnode->ea_secno = cpu_to_le32(q);
Al Viroc4c99542012-04-06 14:30:07 -0400291 fnode->flags &= ~FNODE_anode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 len++;
Al Viroc4c99542012-04-06 14:30:07 -0400293 } else if (!fnode_in_anode(fnode)) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200294 if (hpfs_alloc_if_possible(s, le32_to_cpu(fnode->ea_secno) + len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 len++;
296 } else {
297 /* Aargh... don't know how to create ea anodes :-( */
298 /*struct buffer_head *bh;
299 struct anode *anode;
300 anode_secno a_s;
301 if (!(anode = hpfs_alloc_anode(s, fno, &a_s, &bh)))
302 goto bail;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200303 anode->up = cpu_to_le32(fno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 anode->btree.fnode_parent = 1;
305 anode->btree.n_free_nodes--;
306 anode->btree.n_used_nodes++;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200307 anode->btree.first_free = cpu_to_le16(le16_to_cpu(anode->btree.first_free) + 12);
308 anode->u.external[0].disk_secno = cpu_to_le32(le32_to_cpu(fnode->ea_secno));
309 anode->u.external[0].file_secno = cpu_to_le32(0);
310 anode->u.external[0].length = cpu_to_le32(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 mark_buffer_dirty(bh);
312 brelse(bh);
Al Viroc4c99542012-04-06 14:30:07 -0400313 fnode->flags |= FNODE_anode;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200314 fnode->ea_secno = cpu_to_le32(a_s);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 secno new_sec;
316 int i;
Mikulas Patocka7d23ce32011-05-08 20:43:06 +0200317 if (!(new_sec = hpfs_alloc_sector(s, fno, 1, 1 - ((pos + 511) >> 9))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 goto bail;
319 for (i = 0; i < len; i++) {
320 struct buffer_head *bh1, *bh2;
321 void *b1, *b2;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200322 if (!(b1 = hpfs_map_sector(s, le32_to_cpu(fnode->ea_secno) + i, &bh1, len - i - 1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 hpfs_free_sectors(s, new_sec, (pos + 511) >> 9);
324 goto bail;
325 }
326 if (!(b2 = hpfs_get_sector(s, new_sec + i, &bh2))) {
327 brelse(bh1);
328 hpfs_free_sectors(s, new_sec, (pos + 511) >> 9);
329 goto bail;
330 }
331 memcpy(b2, b1, 512);
332 brelse(bh1);
333 mark_buffer_dirty(bh2);
334 brelse(bh2);
335 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200336 hpfs_free_sectors(s, le32_to_cpu(fnode->ea_secno), len);
337 fnode->ea_secno = cpu_to_le32(new_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 len = (pos + 511) >> 9;
339 }
340 }
Al Viroc4c99542012-04-06 14:30:07 -0400341 if (fnode_in_anode(fnode)) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200342 if (hpfs_add_sector_to_btree(s, le32_to_cpu(fnode->ea_secno),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 0, len) != -1) {
344 len++;
345 } else {
346 goto bail;
347 }
348 }
349 }
350 h[0] = 0;
351 h[1] = strlen(key);
352 h[2] = size & 0xff;
353 h[3] = size >> 8;
Al Viroc4c99542012-04-06 14:30:07 -0400354 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l), 4, h)) goto bail;
355 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l) + 4, h[1] + 1, key)) goto bail;
356 if (hpfs_ea_write(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_size_l) + 5 + h[1], size, data)) goto bail;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200357 fnode->ea_size_l = cpu_to_le32(pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 ret:
359 hpfs_i(inode)->i_ea_size += 5 + strlen(key) + size;
360 return;
361 bail:
Mikulas Patocka0b697602011-05-08 20:44:26 +0200362 if (le32_to_cpu(fnode->ea_secno))
Al Viroc4c99542012-04-06 14:30:07 -0400363 if (fnode_in_anode(fnode)) hpfs_truncate_btree(s, le32_to_cpu(fnode->ea_secno), 1, (le32_to_cpu(fnode->ea_size_l) + 511) >> 9);
Mikulas Patocka0b697602011-05-08 20:44:26 +0200364 else hpfs_free_sectors(s, le32_to_cpu(fnode->ea_secno) + ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9), len - ((le32_to_cpu(fnode->ea_size_l) + 511) >> 9));
365 else fnode->ea_secno = fnode->ea_size_l = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367