Lines Matching +full:se +full:- +full:pos

1 // SPDX-License-Identifier: GPL-2.0
5 * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
18 anode_secno a = -1; in hpfs_bplus_lookup()
23 if (hpfs_sb(s)->sb_chk) if (hpfs_stop_cycles(s, a, &c1, &c2, "hpfs_bplus_lookup")) return -1; in hpfs_bplus_lookup()
25 for (i = 0; i < btree->n_used_nodes; i++) in hpfs_bplus_lookup()
26 if (le32_to_cpu(btree->u.internal[i].file_secno) > sec) { in hpfs_bplus_lookup()
27 a = le32_to_cpu(btree->u.internal[i].down); in hpfs_bplus_lookup()
29 if (!(anode = hpfs_map_anode(s, a, &bh))) return -1; in hpfs_bplus_lookup()
30 btree = &anode->btree; in hpfs_bplus_lookup()
35 return -1; in hpfs_bplus_lookup()
37 for (i = 0; i < btree->n_used_nodes; i++) in hpfs_bplus_lookup()
38 if (le32_to_cpu(btree->u.external[i].file_secno) <= sec && in hpfs_bplus_lookup()
39 … le32_to_cpu(btree->u.external[i].file_secno) + le32_to_cpu(btree->u.external[i].length) > sec) { in hpfs_bplus_lookup()
40 …a = le32_to_cpu(btree->u.external[i].disk_secno) + sec - le32_to_cpu(btree->u.external[i].file_sec… in hpfs_bplus_lookup()
41 if (hpfs_sb(s)->sb_chk) if (hpfs_chk_sectors(s, a, 1, "data")) { in hpfs_bplus_lookup()
43 return -1; in hpfs_bplus_lookup()
47 hpfs_inode->i_file_sec = le32_to_cpu(btree->u.external[i].file_secno); in hpfs_bplus_lookup()
48 hpfs_inode->i_disk_sec = le32_to_cpu(btree->u.external[i].disk_secno); in hpfs_bplus_lookup()
49 hpfs_inode->i_n_secs = le32_to_cpu(btree->u.external[i].length); in hpfs_bplus_lookup()
56 return -1; in hpfs_bplus_lookup()
66 anode_secno a, na = -1, ra, up = -1; in hpfs_add_sector_to_btree()
67 secno se; in hpfs_add_sector_to_btree() local
73 if (!(fnode = hpfs_map_fnode(s, node, &bh))) return -1; in hpfs_add_sector_to_btree()
74 btree = &fnode->btree; in hpfs_add_sector_to_btree()
76 if (!(anode = hpfs_map_anode(s, node, &bh))) return -1; in hpfs_add_sector_to_btree()
77 btree = &anode->btree; in hpfs_add_sector_to_btree()
81 if ((n = btree->n_used_nodes - 1) < -!!fnod) { in hpfs_add_sector_to_btree()
84 return -1; in hpfs_add_sector_to_btree()
87 a = le32_to_cpu(btree->u.internal[n].down); in hpfs_add_sector_to_btree()
88 btree->u.internal[n].file_secno = cpu_to_le32(-1); in hpfs_add_sector_to_btree()
91 if (hpfs_sb(s)->sb_chk) in hpfs_add_sector_to_btree()
92 if (hpfs_stop_cycles(s, a, &c1, &c2, "hpfs_add_sector_to_btree #1")) return -1; in hpfs_add_sector_to_btree()
93 if (!(anode = hpfs_map_anode(s, a, &bh))) return -1; in hpfs_add_sector_to_btree()
94 btree = &anode->btree; in hpfs_add_sector_to_btree()
98 …if (le32_to_cpu(btree->u.external[n].file_secno) + le32_to_cpu(btree->u.external[n].length) != fse… in hpfs_add_sector_to_btree()
100 le32_to_cpu(btree->u.external[n].file_secno) + le32_to_cpu(btree->u.external[n].length), fsecno, in hpfs_add_sector_to_btree()
103 return -1; in hpfs_add_sector_to_btree()
105 …if (hpfs_alloc_if_possible(s, se = le32_to_cpu(btree->u.external[n].disk_secno) + le32_to_cpu(btre… in hpfs_add_sector_to_btree()
106 le32_add_cpu(&btree->u.external[n].length, 1); in hpfs_add_sector_to_btree()
109 return se; in hpfs_add_sector_to_btree()
115 return -1; in hpfs_add_sector_to_btree()
117 se = !fnod ? node : (node + 16384) & ~16383; in hpfs_add_sector_to_btree()
119 …if (!(se = hpfs_alloc_sector(s, se, 1, fsecno*ALLOC_M>ALLOC_FWD_MAX ? ALLOC_FWD_MAX : fsecno*ALLOC… in hpfs_add_sector_to_btree()
121 return -1; in hpfs_add_sector_to_btree()
123 …fs = n < 0 ? 0 : le32_to_cpu(btree->u.external[n].file_secno) + le32_to_cpu(btree->u.external[n].l… in hpfs_add_sector_to_btree()
124 if (!btree->n_free_nodes) { in hpfs_add_sector_to_btree()
125 up = a != node ? le32_to_cpu(anode->up) : -1; in hpfs_add_sector_to_btree()
128 hpfs_free_sectors(s, se, 1); in hpfs_add_sector_to_btree()
129 return -1; in hpfs_add_sector_to_btree()
132 anode->up = cpu_to_le32(node); in hpfs_add_sector_to_btree()
133 anode->btree.flags |= BP_fnode_parent; in hpfs_add_sector_to_btree()
134 anode->btree.n_used_nodes = btree->n_used_nodes; in hpfs_add_sector_to_btree()
135 anode->btree.first_free = btree->first_free; in hpfs_add_sector_to_btree()
136 anode->btree.n_free_nodes = 40 - anode->btree.n_used_nodes; in hpfs_add_sector_to_btree()
137 memcpy(&anode->u, &btree->u, btree->n_used_nodes * 12); in hpfs_add_sector_to_btree()
138 btree->flags |= BP_internal; in hpfs_add_sector_to_btree()
139 btree->n_free_nodes = 11; in hpfs_add_sector_to_btree()
140 btree->n_used_nodes = 1; in hpfs_add_sector_to_btree()
141 btree->first_free = cpu_to_le16((char *)&(btree->u.internal[1]) - (char *)btree); in hpfs_add_sector_to_btree()
142 btree->u.internal[0].file_secno = cpu_to_le32(-1); in hpfs_add_sector_to_btree()
143 btree->u.internal[0].down = cpu_to_le32(na); in hpfs_add_sector_to_btree()
148 hpfs_free_sectors(s, se, 1); in hpfs_add_sector_to_btree()
150 return -1; in hpfs_add_sector_to_btree()
154 btree = &anode->btree; in hpfs_add_sector_to_btree()
156 btree->n_free_nodes--; n = btree->n_used_nodes++; in hpfs_add_sector_to_btree()
157 le16_add_cpu(&btree->first_free, 12); in hpfs_add_sector_to_btree()
158 btree->u.external[n].disk_secno = cpu_to_le32(se); in hpfs_add_sector_to_btree()
159 btree->u.external[n].file_secno = cpu_to_le32(fs); in hpfs_add_sector_to_btree()
160 btree->u.external[n].length = cpu_to_le32(1); in hpfs_add_sector_to_btree()
163 if ((a == node && fnod) || na == -1) return se; in hpfs_add_sector_to_btree()
165 while (up != (anode_secno)-1) { in hpfs_add_sector_to_btree()
167 if (hpfs_sb(s)->sb_chk) in hpfs_add_sector_to_btree()
168 if (hpfs_stop_cycles(s, up, &c1, &c2, "hpfs_add_sector_to_btree #2")) return -1; in hpfs_add_sector_to_btree()
170 if (!(anode = hpfs_map_anode(s, up, &bh))) return -1; in hpfs_add_sector_to_btree()
171 btree = &anode->btree; in hpfs_add_sector_to_btree()
173 if (!(fnode = hpfs_map_fnode(s, up, &bh))) return -1; in hpfs_add_sector_to_btree()
174 btree = &fnode->btree; in hpfs_add_sector_to_btree()
176 if (btree->n_free_nodes) { in hpfs_add_sector_to_btree()
177 btree->n_free_nodes--; n = btree->n_used_nodes++; in hpfs_add_sector_to_btree()
178 le16_add_cpu(&btree->first_free, 8); in hpfs_add_sector_to_btree()
179 btree->u.internal[n].file_secno = cpu_to_le32(-1); in hpfs_add_sector_to_btree()
180 btree->u.internal[n].down = cpu_to_le32(na); in hpfs_add_sector_to_btree()
181 btree->u.internal[n-1].file_secno = cpu_to_le32(fs); in hpfs_add_sector_to_btree()
187 anode->up = cpu_to_le32(up); in hpfs_add_sector_to_btree()
189 anode->btree.flags |= BP_fnode_parent; in hpfs_add_sector_to_btree()
191 anode->btree.flags &= ~BP_fnode_parent; in hpfs_add_sector_to_btree()
195 return se; in hpfs_add_sector_to_btree()
197 up = up != node ? le32_to_cpu(anode->up) : -1; in hpfs_add_sector_to_btree()
198 btree->u.internal[btree->n_used_nodes - 1].file_secno = cpu_to_le32(/*fs*/-1); in hpfs_add_sector_to_btree()
204 /*anode->up = cpu_to_le32(up != -1 ? up : ra);*/ in hpfs_add_sector_to_btree()
205 anode->btree.flags |= BP_internal; in hpfs_add_sector_to_btree()
206 anode->btree.n_used_nodes = 1; in hpfs_add_sector_to_btree()
207 anode->btree.n_free_nodes = 59; in hpfs_add_sector_to_btree()
208 anode->btree.first_free = cpu_to_le16(16); in hpfs_add_sector_to_btree()
209 anode->btree.u.internal[0].down = cpu_to_le32(a); in hpfs_add_sector_to_btree()
210 anode->btree.u.internal[0].file_secno = cpu_to_le32(-1); in hpfs_add_sector_to_btree()
214 anode->up = cpu_to_le32(na); in hpfs_add_sector_to_btree()
221 anode->up = cpu_to_le32(node); in hpfs_add_sector_to_btree()
223 anode->btree.flags |= BP_fnode_parent; in hpfs_add_sector_to_btree()
230 return -1; in hpfs_add_sector_to_btree()
232 btree = &anode->btree; in hpfs_add_sector_to_btree()
236 return -1; in hpfs_add_sector_to_btree()
238 btree = &fnode->btree; in hpfs_add_sector_to_btree()
240 ranode->up = cpu_to_le32(node); in hpfs_add_sector_to_btree()
241 memcpy(&ranode->btree, btree, le16_to_cpu(btree->first_free)); in hpfs_add_sector_to_btree()
243 ranode->btree.flags |= BP_fnode_parent; in hpfs_add_sector_to_btree()
244 ranode->btree.n_free_nodes = (bp_internal(&ranode->btree) ? 60 : 40) - ranode->btree.n_used_nodes; in hpfs_add_sector_to_btree()
245 if (bp_internal(&ranode->btree)) for (n = 0; n < ranode->btree.n_used_nodes; n++) { in hpfs_add_sector_to_btree()
247 if ((unode = hpfs_map_anode(s, le32_to_cpu(ranode->u.internal[n].down), &bh1))) { in hpfs_add_sector_to_btree()
248 unode->up = cpu_to_le32(ra); in hpfs_add_sector_to_btree()
249 unode->btree.flags &= ~BP_fnode_parent; in hpfs_add_sector_to_btree()
254 btree->flags |= BP_internal; in hpfs_add_sector_to_btree()
255 btree->n_free_nodes = fnod ? 10 : 58; in hpfs_add_sector_to_btree()
256 btree->n_used_nodes = 2; in hpfs_add_sector_to_btree()
257 btree->first_free = cpu_to_le16((char *)&btree->u.internal[2] - (char *)btree); in hpfs_add_sector_to_btree()
258 btree->u.internal[0].file_secno = cpu_to_le32(fs); in hpfs_add_sector_to_btree()
259 btree->u.internal[0].down = cpu_to_le32(ra); in hpfs_add_sector_to_btree()
260 btree->u.internal[1].file_secno = cpu_to_le32(-1); in hpfs_add_sector_to_btree()
261 btree->u.internal[1].down = cpu_to_le32(na); in hpfs_add_sector_to_btree()
266 return se; in hpfs_add_sector_to_btree()
281 int pos = 0; in hpfs_remove_btree() local
288 ano = le32_to_cpu(btree1->u.internal[pos].down); in hpfs_remove_btree()
290 if (hpfs_sb(s)->sb_chk) in hpfs_remove_btree()
294 btree1 = &anode->btree; in hpfs_remove_btree()
296 pos = 0; in hpfs_remove_btree()
298 for (i = 0; i < btree1->n_used_nodes; i++) in hpfs_remove_btree()
299 …hpfs_free_sectors(s, le32_to_cpu(btree1->u.external[i].disk_secno), le32_to_cpu(btree1->u.external… in hpfs_remove_btree()
303 if (hpfs_sb(s)->sb_chk) in hpfs_remove_btree()
307 ano = le32_to_cpu(anode->up); in hpfs_remove_btree()
308 if (--level) { in hpfs_remove_btree()
310 btree1 = &anode->btree; in hpfs_remove_btree()
312 for (i = 0; i < btree1->n_used_nodes; i++) { in hpfs_remove_btree()
313 if (le32_to_cpu(btree1->u.internal[i].down) == oano) { in hpfs_remove_btree()
314 if ((pos = i + 1) < btree1->n_used_nodes) in hpfs_remove_btree()
323 oano, level ? ano : -1); in hpfs_remove_btree()
334 if (!(anode = hpfs_map_anode(s, a, &bh))) return -1; in anode_lookup()
335 return hpfs_bplus_lookup(s, NULL, &anode->btree, sec, bh); in anode_lookup()
338 int hpfs_ea_read(struct super_block *s, secno a, int ano, unsigned pos, in hpfs_ea_read() argument
347 if ((sec = anode_lookup(s, a, pos >> 9)) == -1) in hpfs_ea_read()
348 return -1; in hpfs_ea_read()
349 } else sec = a + (pos >> 9); in hpfs_ea_read()
350 if (hpfs_sb(s)->sb_chk) if (hpfs_chk_sectors(s, sec, 1, "ea #1")) return -1; in hpfs_ea_read()
351 if (!(data = hpfs_map_sector(s, sec, &bh, (len - 1) >> 9))) in hpfs_ea_read()
352 return -1; in hpfs_ea_read()
353 l = 0x200 - (pos & 0x1ff); if (l > len) l = len; in hpfs_ea_read()
354 memcpy(buf, data + (pos & 0x1ff), l); in hpfs_ea_read()
356 buf += l; pos += l; len -= l; in hpfs_ea_read()
361 int hpfs_ea_write(struct super_block *s, secno a, int ano, unsigned pos, in hpfs_ea_write() argument
370 if ((sec = anode_lookup(s, a, pos >> 9)) == -1) in hpfs_ea_write()
371 return -1; in hpfs_ea_write()
372 } else sec = a + (pos >> 9); in hpfs_ea_write()
373 if (hpfs_sb(s)->sb_chk) if (hpfs_chk_sectors(s, sec, 1, "ea #2")) return -1; in hpfs_ea_write()
374 if (!(data = hpfs_map_sector(s, sec, &bh, (len - 1) >> 9))) in hpfs_ea_write()
375 return -1; in hpfs_ea_write()
376 l = 0x200 - (pos & 0x1ff); if (l > len) l = len; in hpfs_ea_write()
377 memcpy(data + (pos & 0x1ff), buf, l); in hpfs_ea_write()
380 buf += l; pos += l; len -= l; in hpfs_ea_write()
391 hpfs_remove_btree(s, &anode->btree); in hpfs_ea_remove()
397 /* Truncate allocation tree. Doesn't join anodes - I hope it doesn't matter */
410 btree = &fnode->btree; in hpfs_truncate_btree()
413 btree = &anode->btree; in hpfs_truncate_btree()
418 btree->n_free_nodes = 8; in hpfs_truncate_btree()
419 btree->n_used_nodes = 0; in hpfs_truncate_btree()
420 btree->first_free = cpu_to_le16(8); in hpfs_truncate_btree()
421 btree->flags &= ~BP_internal; in hpfs_truncate_btree()
428 nodes = btree->n_used_nodes + btree->n_free_nodes; in hpfs_truncate_btree()
429 for (i = 0; i < btree->n_used_nodes; i++) in hpfs_truncate_btree()
430 if (le32_to_cpu(btree->u.internal[i].file_secno) >= secs) goto f; in hpfs_truncate_btree()
432 hpfs_error(s, "internal btree %08x doesn't end with -1", node); in hpfs_truncate_btree()
435 for (j = i + 1; j < btree->n_used_nodes; j++) in hpfs_truncate_btree()
436 hpfs_ea_remove(s, le32_to_cpu(btree->u.internal[j].down), 1, 0); in hpfs_truncate_btree()
437 btree->n_used_nodes = i + 1; in hpfs_truncate_btree()
438 btree->n_free_nodes = nodes - btree->n_used_nodes; in hpfs_truncate_btree()
439 btree->first_free = cpu_to_le16(8 + 8 * btree->n_used_nodes); in hpfs_truncate_btree()
441 if (btree->u.internal[i].file_secno == cpu_to_le32(secs)) { in hpfs_truncate_btree()
445 node = le32_to_cpu(btree->u.internal[i].down); in hpfs_truncate_btree()
447 if (hpfs_sb(s)->sb_chk) in hpfs_truncate_btree()
451 btree = &anode->btree; in hpfs_truncate_btree()
453 nodes = btree->n_used_nodes + btree->n_free_nodes; in hpfs_truncate_btree()
454 for (i = 0; i < btree->n_used_nodes; i++) in hpfs_truncate_btree()
455 …if (le32_to_cpu(btree->u.external[i].file_secno) + le32_to_cpu(btree->u.external[i].length) >= sec… in hpfs_truncate_btree()
459 if (secs <= le32_to_cpu(btree->u.external[i].file_secno)) { in hpfs_truncate_btree()
461 if (i) i--; in hpfs_truncate_btree()
463 …else if (le32_to_cpu(btree->u.external[i].file_secno) + le32_to_cpu(btree->u.external[i].length) >… in hpfs_truncate_btree()
464 hpfs_free_sectors(s, le32_to_cpu(btree->u.external[i].disk_secno) + secs - in hpfs_truncate_btree()
465 le32_to_cpu(btree->u.external[i].file_secno), le32_to_cpu(btree->u.external[i].length) in hpfs_truncate_btree()
466 - secs + le32_to_cpu(btree->u.external[i].file_secno)); /* I hope gcc optimizes this :-) */ in hpfs_truncate_btree()
467 btree->u.external[i].length = cpu_to_le32(secs - le32_to_cpu(btree->u.external[i].file_secno)); in hpfs_truncate_btree()
469 for (j = i + 1; j < btree->n_used_nodes; j++) in hpfs_truncate_btree()
470 …hpfs_free_sectors(s, le32_to_cpu(btree->u.external[j].disk_secno), le32_to_cpu(btree->u.external[j… in hpfs_truncate_btree()
471 btree->n_used_nodes = i + 1; in hpfs_truncate_btree()
472 btree->n_free_nodes = nodes - btree->n_used_nodes; in hpfs_truncate_btree()
473 btree->first_free = cpu_to_le16(8 + 12 * btree->n_used_nodes); in hpfs_truncate_btree()
478 /* Remove file or directory and it's eas - note that directory must
488 if (!fnode_is_dir(fnode)) hpfs_remove_btree(s, &fnode->btree); in hpfs_remove_fnode()
489 else hpfs_remove_dtree(s, le32_to_cpu(fnode->u.external[0].disk_secno)); in hpfs_remove_fnode()
494 …hpfs_ea_ext_remove(s, le32_to_cpu(fnode->ea_secno), fnode_in_anode(fnode), le32_to_cpu(fnode->ea_s… in hpfs_remove_fnode()