Commit 4085e155b14a89ee36f7bfc5bd07294b0c34b0e6

Authored by Al Viro
1 parent 185553b224

hpfs: get rid of bitfields endianness wanking in extended_attribute

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 3 changed files with 35 additions and 34 deletions Side-by-side Diff

... ... @@ -483,8 +483,8 @@
483 483 else hpfs_remove_dtree(s, le32_to_cpu(fnode->u.external[0].disk_secno));
484 484 ea_end = fnode_end_ea(fnode);
485 485 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
486   - if (ea->indirect)
487   - hpfs_ea_remove(s, ea_sec(ea), ea->anode, ea_len(ea));
  486 + if (ea_indirect(ea))
  487 + hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
488 488 hpfs_ea_ext_remove(s, le32_to_cpu(fnode->ea_secno), fnode->ea_anode, le32_to_cpu(fnode->ea_size_l));
489 489 brelse(bh);
490 490 hpfs_free_sectors(s, fno, 1);
... ... @@ -23,15 +23,15 @@
23 23 return;
24 24 }
25 25 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
26   - if (ea->indirect) {
  26 + if (ea_indirect(ea)) {
27 27 if (ea_valuelen(ea) != 8) {
28   - hpfs_error(s, "ea->indirect set while ea->valuelen!=8, %s %08x, pos %08x",
  28 + hpfs_error(s, "ea_indirect(ea) set while ea->valuelen!=8, %s %08x, pos %08x",
29 29 ano ? "anode" : "sectors", a, pos);
30 30 return;
31 31 }
32 32 if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 9, ex+4))
33 33 return;
34   - hpfs_ea_remove(s, ea_sec(ea), ea->anode, ea_len(ea));
  34 + hpfs_ea_remove(s, ea_sec(ea), ea_in_anode(ea), ea_len(ea));
35 35 }
36 36 pos += ea->namelen + ea_valuelen(ea) + 5;
37 37 }
... ... @@ -81,7 +81,7 @@
81 81 struct extended_attribute *ea_end = fnode_end_ea(fnode);
82 82 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
83 83 if (!strcmp(ea->name, key)) {
84   - if (ea->indirect)
  84 + if (ea_indirect(ea))
85 85 goto indirect;
86 86 if (ea_valuelen(ea) >= size)
87 87 return -EINVAL;
88 88  
... ... @@ -101,10 +101,10 @@
101 101 return -EIO;
102 102 }
103 103 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return -EIO;
104   - if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4))
  104 + if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
105 105 return -EIO;
106 106 if (!strcmp(ea->name, key)) {
107   - if (ea->indirect)
  107 + if (ea_indirect(ea))
108 108 goto indirect;
109 109 if (ea_valuelen(ea) >= size)
110 110 return -EINVAL;
... ... @@ -119,7 +119,7 @@
119 119 indirect:
120 120 if (ea_len(ea) >= size)
121 121 return -EINVAL;
122   - if (hpfs_ea_read(s, ea_sec(ea), ea->anode, 0, ea_len(ea), buf))
  122 + if (hpfs_ea_read(s, ea_sec(ea), ea_in_anode(ea), 0, ea_len(ea), buf))
123 123 return -EIO;
124 124 buf[ea_len(ea)] = 0;
125 125 return 0;
... ... @@ -136,8 +136,8 @@
136 136 struct extended_attribute *ea_end = fnode_end_ea(fnode);
137 137 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
138 138 if (!strcmp(ea->name, key)) {
139   - if (ea->indirect)
140   - return get_indirect_ea(s, ea->anode, ea_sec(ea), *size = ea_len(ea));
  139 + if (ea_indirect(ea))
  140 + return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
141 141 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
142 142 printk("HPFS: out of memory for EA\n");
143 143 return NULL;
144 144  
... ... @@ -159,11 +159,11 @@
159 159 return NULL;
160 160 }
161 161 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return NULL;
162   - if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4))
  162 + if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
163 163 return NULL;
164 164 if (!strcmp(ea->name, key)) {
165   - if (ea->indirect)
166   - return get_indirect_ea(s, ea->anode, ea_sec(ea), *size = ea_len(ea));
  165 + if (ea_indirect(ea))
  166 + return get_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), *size = ea_len(ea));
167 167 if (!(ret = kmalloc((*size = ea_valuelen(ea)) + 1, GFP_NOFS))) {
168 168 printk("HPFS: out of memory for EA\n");
169 169 return NULL;
170 170  
... ... @@ -199,9 +199,9 @@
199 199 struct extended_attribute *ea_end = fnode_end_ea(fnode);
200 200 for (ea = fnode_ea(fnode); ea < ea_end; ea = next_ea(ea))
201 201 if (!strcmp(ea->name, key)) {
202   - if (ea->indirect) {
  202 + if (ea_indirect(ea)) {
203 203 if (ea_len(ea) == size)
204   - set_indirect_ea(s, ea->anode, ea_sec(ea), data, size);
  204 + set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
205 205 } else if (ea_valuelen(ea) == size) {
206 206 memcpy(ea_data(ea), data, size);
207 207 }
208 208  
209 209  
... ... @@ -220,12 +220,12 @@
220 220 return;
221 221 }
222 222 if (hpfs_ea_read(s, a, ano, pos, 4, ex)) return;
223   - if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea->indirect ? 8 : 0), ex + 4))
  223 + if (hpfs_ea_read(s, a, ano, pos + 4, ea->namelen + 1 + (ea_indirect(ea) ? 8 : 0), ex + 4))
224 224 return;
225 225 if (!strcmp(ea->name, key)) {
226   - if (ea->indirect) {
  226 + if (ea_indirect(ea)) {
227 227 if (ea_len(ea) == size)
228   - set_indirect_ea(s, ea->anode, ea_sec(ea), data, size);
  228 + set_indirect_ea(s, ea_in_anode(ea), ea_sec(ea), data, size);
229 229 }
230 230 else {
231 231 if (ea_valuelen(ea) == size)
... ... @@ -528,38 +528,39 @@
528 528 run, or in multiple runs. Flags in the fnode tell whether the EA list
529 529 is immediate, in a single run, or in multiple runs. */
530 530  
  531 +enum {EA_indirect = 1, EA_anode = 2, EA_needea = 128 };
531 532 struct extended_attribute
532 533 {
533   -#ifdef __LITTLE_ENDIAN
534   - u8 indirect: 1; /* 1 -> value gives sector number
  534 + u8 flags; /* bit 0 set -> value gives sector number
535 535 where real value starts */
536   - u8 anode: 1; /* 1 -> sector is an anode
  536 + /* bit 1 set -> sector is an anode
537 537 that points to fragmented value */
538   - u8 flag23456: 5;
539   - u8 needea: 1; /* required ea */
540   -#else
541   - u8 needea: 1; /* required ea */
542   - u8 flag23456: 5;
543   - u8 anode: 1; /* 1 -> sector is an anode
544   - that points to fragmented value */
545   - u8 indirect: 1; /* 1 -> value gives sector number
546   - where real value starts */
547   -#endif
  538 + /* bit 7 set -> required ea */
548 539 u8 namelen; /* length of name, bytes */
549 540 u8 valuelen_lo; /* length of value, bytes */
550 541 u8 valuelen_hi; /* length of value, bytes */
551   - u8 name[0];
  542 + u8 name[];
552 543 /*
553 544 u8 name[namelen]; ascii attrib name
554 545 u8 nul; terminating '\0', not counted
555 546 u8 value[valuelen]; value, arbitrary
556   - if this.indirect, valuelen is 8 and the value is
  547 + if this.flags & 1, valuelen is 8 and the value is
557 548 u32 length; real length of value, bytes
558 549 secno secno; sector address where it starts
559 550 if this.anode, the above sector number is the root of an anode tree
560 551 which points to the value.
561 552 */
562 553 };
  554 +
  555 +static inline bool ea_indirect(struct extended_attribute *ea)
  556 +{
  557 + return ea->flags & EA_indirect;
  558 +}
  559 +
  560 +static inline bool ea_in_anode(struct extended_attribute *ea)
  561 +{
  562 + return ea->flags & EA_anode;
  563 +}
563 564  
564 565 /*
565 566 Local Variables: