blob: 102ba18e561f6fbce6bcbeda94acd62a1300e211 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/fs/hpfs/ea.c
4 *
5 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
6 *
7 * handling extended attributes
8 */
9
10#include "hpfs_fn.h"
11
12/* Remove external extended attributes. ano specifies whether a is a
13 direct sector where eas starts or an anode */
14
15void hpfs_ea_ext_remove(struct super_block *s, secno a, int ano, unsigned len)
16{
17 unsigned pos = 0;
18 while (pos < len) {
19 char ex[4 + 255 + 1 + 8];
20 struct extended_attribute *ea = (struct extended_attribute *)ex;
21 if (pos + 4 > len) {
22 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
23 ano ? "anode" : "sectors", a, len);
24 return;
25 }
26 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
Al Viro4085e152012-04-06 13:21:09 -040027 if (ea_indirect(ea)) {
Mikulas Patockad0969d12011-05-08 20:44:32 +020028 if (ea_valuelen(ea) != 8) {
Al Viro4085e152012-04-06 13:21:09 -040029 hpfs_error(s, "ea_indirect(ea) set while ea->valuelen!=8, %s %08x, pos %08x",
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 ano ? "anode" : "sectors", a, pos);
31 return;
32 }
33 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 9, ex+4))
34 return;
Al Viro4085e152012-04-06 13:21:09 -040035 hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 }
Mikulas Patockad0969d12011-05-08 20:44:32 +020037 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 }
39 if (!ano) hpfs_free_sectors(s, a, (len+511) >> 9);
40 else {
41 struct buffer_head *bh;
42 struct anode *anode;
43 if ((anode = hpfs_map_anode(s, a, &bh))) {
44 hpfs_remove_btree(s, &anode->btree);
45 brelse(bh);
46 hpfs_free_sectors(s, a, 1);
47 }
48 }
49}
50
51static char *get_indirect_ea(struct super_block *s, int ano, secno a, int size)
52{
53 char *ret;
54 if (!(ret = kmalloc(size + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -070055 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return NULL;
57 }
58 if (hpfs_ea_read(s, a, ano, 0, size, ret)) {
59 kfree(ret);
60 return NULL;
61 }
62 ret[size] = 0;
63 return ret;
64}
65
Al Viro7e7742e2010-01-31 17:09:29 -050066static void set_indirect_ea(struct super_block *s, int ano, secno a,
67 const char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 hpfs_ea_write(s, a, ano, 0, size, data);
70}
71
72/* Read an extended attribute named 'key' into the provided buffer */
73
74int hpfs_read_ea(struct super_block *s, struct fnode *fnode, char *key,
75 char *buf, int size)
76{
77 unsigned pos;
78 int ano, len;
79 secno a;
Mikulas Patockac3514812011-05-08 20:44:38 +020080 char ex[4 + 255 + 1 + 8];
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 struct extended_attribute *ea;
82 struct extended_attribute *ea_end = fnode_end_ea(fnode);
83 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
84 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -040085 if (ea_indirect(ea))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 goto indirect;
Mikulas Patockad0969d12011-05-08 20:44:32 +020087 if (ea_valuelen(ea) >= size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 return -EINVAL;
Mikulas Patockad0969d12011-05-08 20:44:32 +020089 memcpy(buf, ea_data(ea), ea_valuelen(ea));
90 buf[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return 0;
92 }
Mikulas Patocka0b697602011-05-08 20:44:26 +020093 a = le32_to_cpu(fnode->ea_secno);
94 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -040095 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 pos = 0;
97 while (pos < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 ea = (struct extended_attribute *)ex;
99 if (pos + 4 > len) {
100 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
101 ano ? "anode" : "sectors", a, len);
102 return -EIO;
103 }
104 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return -EIO;
Al Viro4085e152012-04-06 13:21:09 -0400105 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 -0700106 return -EIO;
107 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400108 if (ea_indirect(ea))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 goto indirect;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200110 if (ea_valuelen(ea) >= size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return -EINVAL;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200112 if (hpfs_ea_read(s, a, ano, pos + 4 + ea->namelen + 1, ea_valuelen(ea), buf))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return -EIO;
Mikulas Patockad0969d12011-05-08 20:44:32 +0200114 buf[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return 0;
116 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200117 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119 return -ENOENT;
120indirect:
121 if (ea_len(ea) >= size)
122 return -EINVAL;
Al Viro4085e152012-04-06 13:21:09 -0400123 if (hpfs_ea_read(s, ea_sec(ea), ea_in_anode(ea), 0, ea_len(ea), buf))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return -EIO;
125 buf[ea_len(ea)] = 0;
126 return 0;
127}
128
129/* Read an extended attribute named 'key' */
130char *hpfs_get_ea(struct super_block *s, struct fnode *fnode, char *key, int *size)
131{
132 char *ret;
133 unsigned pos;
134 int ano, len;
135 secno a;
136 struct extended_attribute *ea;
137 struct extended_attribute *ea_end = fnode_end_ea(fnode);
138 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
139 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400140 if (ea_indirect(ea))
141 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
Mikulas Patockad0969d12011-05-08 20:44:32 +0200142 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -0700143 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return NULL;
145 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200146 memcpy(ret, ea_data(ea), ea_valuelen(ea));
147 ret[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return ret;
149 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200150 a = le32_to_cpu(fnode->ea_secno);
151 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -0400152 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 pos = 0;
154 while (pos < len) {
155 char ex[4 + 255 + 1 + 8];
156 ea = (struct extended_attribute *)ex;
157 if (pos + 4 > len) {
158 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
159 ano ? "anode" : "sectors", a, len);
160 return NULL;
161 }
162 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return NULL;
Al Viro4085e152012-04-06 13:21:09 -0400163 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 -0700164 return NULL;
165 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400166 if (ea_indirect(ea))
167 return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
Mikulas Patockad0969d12011-05-08 20:44:32 +0200168 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
Fabian Fredericka19189e2014-06-06 14:36:36 -0700169 pr_err("out of memory for EA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return NULL;
171 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200172 if (hpfs_ea_read(s, a, ano, pos + 4 + ea->namelen + 1, ea_valuelen(ea), ret)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 kfree(ret);
174 return NULL;
175 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200176 ret[ea_valuelen(ea)] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return ret;
178 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200179 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181 return NULL;
182}
183
184/*
185 * Update or create extended attribute 'key' with value 'data'. Note that
186 * when this ea exists, it MUST have the same size as size of data.
187 * This driver can't change sizes of eas ('cause I just don't need it).
188 */
189
Al Viro7e7742e2010-01-31 17:09:29 -0500190void hpfs_set_ea(struct inode *inode, struct fnode *fnode, const char *key,
191 const char *data, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
193 fnode_secno fno = inode->i_ino;
194 struct super_block *s = inode->i_sb;
195 unsigned pos;
196 int ano, len;
197 secno a;
198 unsigned char h[4];
199 struct extended_attribute *ea;
200 struct extended_attribute *ea_end = fnode_end_ea(fnode);
201 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
202 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400203 if (ea_indirect(ea)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (ea_len(ea) == size)
Al Viro4085e152012-04-06 13:21:09 -0400205 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
Mikulas Patockad0969d12011-05-08 20:44:32 +0200206 } else if (ea_valuelen(ea) == size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 memcpy(ea_data(ea), data, size);
208 }
209 return;
210 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200211 a = le32_to_cpu(fnode->ea_secno);
212 len = le32_to_cpu(fnode->ea_size_l);
Al Viroc4c99542012-04-06 14:30:07 -0400213 ano = fnode_in_anode(fnode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 pos = 0;
215 while (pos < len) {
216 char ex[4 + 255 + 1 + 8];
217 ea = (struct extended_attribute *)ex;
218 if (pos + 4 > len) {
219 hpfs_error(s, "EAs don't end correctly, %s %08x, len %08x",
220 ano ? "anode" : "sectors", a, len);
221 return;
222 }
223 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
Al Viro4085e152012-04-06 13:21:09 -0400224 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 -0700225 return;
226 if (!strcmp(ea->name, key)) {
Al Viro4085e152012-04-06 13:21:09 -0400227 if (ea_indirect(ea)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 if (ea_len(ea) == size)
Al Viro4085e152012-04-06 13:21:09 -0400229 set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
231 else {
Mikulas Patockad0969d12011-05-08 20:44:32 +0200232 if (ea_valuelen(ea) == size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 hpfs_ea_write(s, a, ano, pos + 4 + ea->namelen + 1, size, data);
234 }
235 return;
236 }
Mikulas Patockad0969d12011-05-08 20:44:32 +0200237 pos += ea->namelen + ea_valuelen(ea) + 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200239 if (!le16_to_cpu(fnode->ea_offs)) {
240 /*if (le16_to_cpu(fnode->ea_size_s)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 hpfs_error(s, "fnode %08x: ea_size_s == %03x, ea_offs == 0",
Mikulas Patocka0b697602011-05-08 20:44:26 +0200242 inode->i_ino, le16_to_cpu(fnode->ea_size_s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return;
244 }*/
Mikulas Patocka0b697602011-05-08 20:44:26 +0200245 fnode->ea_offs = cpu_to_le16(0xc4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200247 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 -0800248 hpfs_error(s, "fnode %08lx: ea_offs == %03x, ea_size_s == %03x",
249 (unsigned long)inode->i_ino,
Al Virode5e2b32012-04-13 01:24:37 -0400250 le16_to_cpu(fnode->ea_offs), le16_to_cpu(fnode->ea_size_s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return;
252 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200253 if ((le16_to_cpu(fnode->ea_size_s) || !le32_to_cpu(fnode->ea_size_l)) &&
254 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 -0700255 ea = fnode_end_ea(fnode);
256 *(char *)ea = 0;
257 ea->namelen = strlen(key);
Mikulas Patockad0969d12011-05-08 20:44:32 +0200258 ea->valuelen_lo = size;
259 ea->valuelen_hi = size >> 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 strcpy(ea->name, key);
261 memcpy(ea_data(ea), data, size);
Mikulas Patocka0b697602011-05-08 20:44:26 +0200262 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 -0700263 goto ret;
264 }
265 /* Most the code here is 99.9993422% unused. I hope there are no bugs.
266 But what .. HPFS.IFS has also bugs in ea management. */
Mikulas Patocka0b697602011-05-08 20:44:26 +0200267 if (le16_to_cpu(fnode->ea_size_s) && !le32_to_cpu(fnode->ea_size_l)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 secno n;
269 struct buffer_head *bh;
270 char *data;
Mikulas Patocka7d23ce32011-05-08 20:43:06 +0200271 if (!(n = hpfs_alloc_sector(s, fno, 1, 0))) return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (!(data = hpfs_get_sector(s, n, &bh))) {
273 hpfs_free_sectors(s, n, 1);
274 return;
275 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200276 memcpy(data, fnode_ea(fnode), le16_to_cpu(fnode->ea_size_s));
277 fnode->ea_size_l = cpu_to_le32(le16_to_cpu(fnode->ea_size_s));
278 fnode->ea_size_s = cpu_to_le16(0);
279 fnode->ea_secno = cpu_to_le32(n);
Al Viroc4c99542012-04-06 14:30:07 -0400280 fnode->flags &= ~FNODE_anode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 mark_buffer_dirty(bh);
282 brelse(bh);
283 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200284 pos = le32_to_cpu(fnode->ea_size_l) + 5 + strlen(key) + size;
285 len = (le32_to_cpu(fnode->ea_size_l) + 511) >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 if (pos >= 30000) goto bail;
287 while (((pos + 511) >> 9) > len) {
288 if (!len) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200289 secno q = hpfs_alloc_sector(s, fno, 1, 0);
290 if (!q) goto bail;
291 fnode->ea_secno = cpu_to_le32(q);
Al Viroc4c99542012-04-06 14:30:07 -0400292 fnode->flags &= ~FNODE_anode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 len++;
Al Viroc4c99542012-04-06 14:30:07 -0400294 } else if (!fnode_in_anode(fnode)) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200295 if (hpfs_alloc_if_possible(s, le32_to_cpu(fnode->ea_secno) + len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 len++;
297 } else {
298 /* Aargh... don't know how to create ea anodes :-( */
299 /*struct buffer_head *bh;
300 struct anode *anode;
301 anode_secno a_s;
302 if (!(anode = hpfs_alloc_anode(s, fno, &a_s, &bh)))
303 goto bail;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200304 anode->up = cpu_to_le32(fno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 anode->btree.fnode_parent = 1;
306 anode->btree.n_free_nodes--;
307 anode->btree.n_used_nodes++;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200308 anode->btree.first_free = cpu_to_le16(le16_to_cpu(anode->btree.first_free) + 12);
309 anode->u.external[0].disk_secno = cpu_to_le32(le32_to_cpu(fnode->ea_secno));
310 anode->u.external[0].file_secno = cpu_to_le32(0);
311 anode->u.external[0].length = cpu_to_le32(len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 mark_buffer_dirty(bh);
313 brelse(bh);
Al Viroc4c99542012-04-06 14:30:07 -0400314 fnode->flags |= FNODE_anode;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200315 fnode->ea_secno = cpu_to_le32(a_s);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 secno new_sec;
317 int i;
Mikulas Patocka7d23ce32011-05-08 20:43:06 +0200318 if (!(new_sec = hpfs_alloc_sector(s, fno, 1, 1 - ((pos + 511) >> 9))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 goto bail;
320 for (i = 0; i < len; i++) {
321 struct buffer_head *bh1, *bh2;
322 void *b1, *b2;
Mikulas Patocka0b697602011-05-08 20:44:26 +0200323 if (!(b1 = hpfs_map_sector(s, le32_to_cpu(fnode->ea_secno) + i, &bh1, len - i - 1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 hpfs_free_sectors(s, new_sec, (pos + 511) >> 9);
325 goto bail;
326 }
327 if (!(b2 = hpfs_get_sector(s, new_sec + i, &bh2))) {
328 brelse(bh1);
329 hpfs_free_sectors(s, new_sec, (pos + 511) >> 9);
330 goto bail;
331 }
332 memcpy(b2, b1, 512);
333 brelse(bh1);
334 mark_buffer_dirty(bh2);
335 brelse(bh2);
336 }
Mikulas Patocka0b697602011-05-08 20:44:26 +0200337 hpfs_free_sectors(s, le32_to_cpu(fnode->ea_secno), len);
338 fnode->ea_secno = cpu_to_le32(new_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 len = (pos + 511) >> 9;
340 }
341 }
Al Viroc4c99542012-04-06 14:30:07 -0400342 if (fnode_in_anode(fnode)) {
Mikulas Patocka0b697602011-05-08 20:44:26 +0200343 if (hpfs_add_sector_to_btree(s, le32_to_cpu(fnode->ea_secno),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 0, len) != -1) {
345 len++;
346 } else {
347 goto bail;
348 }
349 }
350 }
351 h[0] = 0;
352 h[1] = strlen(key);
353 h[2] = size & 0xff;
354 h[3] = size >> 8;
Al Viroc4c99542012-04-06 14:30:07 -0400355 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;
356 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;
357 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 +0200358 fnode->ea_size_l = cpu_to_le32(pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ret:
360 hpfs_i(inode)->i_ea_size += 5 + strlen(key) + size;
361 return;
362 bail:
Mikulas Patocka0b697602011-05-08 20:44:26 +0200363 if (le32_to_cpu(fnode->ea_secno))
Al Viroc4c99542012-04-06 14:30:07 -0400364 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 +0200365 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));
366 else fnode->ea_secno = fnode->ea_size_l = cpu_to_le32(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
368