/* * Check if sector(s) have proper number and additionally check if they're * allocated in bitmap.
*/
int hpfs_chk_sectors(struct super_block *s, secno start, int len, char *msg)
{ if (start + len < start || start < 0x12 ||
start + len > hpfs_sb(s)->sb_fs_size) {
hpfs_error(s, "sector(s) '%s' badly placed at %08x", msg, start); return 1;
} if (hpfs_sb(s)->sb_chk>=2) { int i; for (i = 0; i < len; i++) if (chk_if_allocated(s, start + i, msg)) return 1;
} return 0;
}
static secno alloc_in_bmp(struct super_block *s, secno near, unsigned n, unsigned forward)
{ struct quad_buffer_head qbh;
__le32 *bmp; unsigned bs = near & ~0x3fff; unsigned nr = (near & 0x3fff) & ~(n - 1); /*unsigned mnr;*/ unsigned i, q; int a, b;
secno ret = 0; if (n != 1 && n != 4) {
hpfs_error(s, "Bad allocation size: %d", n); return 0;
} if (bs != ~0x3fff) { if (!(bmp = hpfs_map_bitmap(s, near >> 14, &qbh, "aib"))) goto uls;
} else { if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto uls;
} if (!tstbits(bmp, nr, n + forward)) {
ret = bs + nr; goto rt;
}
q = nr + n; b = 0; while ((a = tstbits(bmp, q, n + forward)) != 0) {
q += a; if (n != 1) q = ((q-1)&~(n-1))+n; if (!b) { if (q>>5 != nr>>5) {
b = 1;
q = nr & 0x1f;
}
} elseif (q > nr) break;
} if (!a) {
ret = bs + q; goto rt;
}
nr >>= 5; /*for (i = nr + 1; i != nr; i++, i &= 0x1ff) */
i = nr; do { if (!le32_to_cpu(bmp[i])) goto cont; if (n + forward >= 0x3f && le32_to_cpu(bmp[i]) != 0xffffffff) goto cont;
q = i<<5; if (i > 0) { unsigned k = le32_to_cpu(bmp[i-1]); while (k & 0x80000000) {
q--; k <<= 1;
}
} if (n != 1) q = ((q-1)&~(n-1))+n; while ((a = tstbits(bmp, q, n + forward)) != 0) {
q += a; if (n != 1) q = ((q-1)&~(n-1))+n; if (q>>5 > i) break;
} if (!a) {
ret = bs + q; goto rt;
}
cont:
i++, i &= 0x1ff;
} while (i != nr);
rt: if (ret) { if (hpfs_sb(s)->sb_chk && ((ret >> 14) != (bs >> 14) || (le32_to_cpu(bmp[(ret & 0x3fff) >> 5]) | ~(((1 << n) - 1) << (ret & 0x1f))) != 0xffffffff)) {
hpfs_error(s, "Allocation doesn't work! Wanted %d, allocated at %08x", n, ret);
ret = 0; goto b;
}
bmp[(ret & 0x3fff) >> 5] &= cpu_to_le32(~(((1 << n) - 1) << (ret & 0x1f)));
hpfs_mark_4buffers_dirty(&qbh);
}
b:
hpfs_brelse4(&qbh);
uls: return ret;
}
/* * Allocation strategy: 1) search place near the sector specified * 2) search bitmap where free sectors last found * 3) search all bitmaps * 4) search all bitmaps ignoring number of pre-allocated * sectors
*/
secno hpfs_alloc_sector(struct super_block *s, secno near, unsigned n, int forward)
{
secno sec; int i; unsigned n_bmps; struct hpfs_sb_info *sbi = hpfs_sb(s); int f_p = 0; int near_bmp; if (forward < 0) {
forward = -forward;
f_p = 1;
}
n_bmps = (sbi->sb_fs_size + 0x4000 - 1) >> 14; if (near && near < sbi->sb_fs_size) { if ((sec = alloc_in_bmp(s, near, n, f_p ? forward : forward/4))) goto ret;
near_bmp = near >> 14;
} else near_bmp = n_bmps / 2; /* if (b != -1) { if ((sec = alloc_in_bmp(s, b<<14, n, f_p ? forward : forward/2))) { b &= 0x0fffffff; goto ret; } if (b > 0x10000000) if ((sec = alloc_in_bmp(s, (b&0xfffffff)<<14, n, f_p ? forward : 0))) goto ret;
*/ if (!f_p) if (forward > sbi->sb_max_fwd_alloc) forward = sbi->sb_max_fwd_alloc;
less_fwd: for (i = 0; i < n_bmps; i++) { if (near_bmp+i < n_bmps && ((sec = alloc_in_bmp(s, (near_bmp+i) << 14, n, forward)))) {
sbi->sb_c_bitmap = near_bmp+i; goto ret;
} if (!forward) { if (near_bmp-i-1 >= 0 && ((sec = alloc_in_bmp(s, (near_bmp-i-1) << 14, n, forward)))) {
sbi->sb_c_bitmap = near_bmp-i-1; goto ret;
}
} else { if (near_bmp+i >= n_bmps && ((sec = alloc_in_bmp(s, (near_bmp+i-n_bmps) << 14, n, forward)))) {
sbi->sb_c_bitmap = near_bmp+i-n_bmps; goto ret;
}
} if (i == 1 && sbi->sb_c_bitmap != -1 && ((sec = alloc_in_bmp(s, (sbi->sb_c_bitmap) << 14, n, forward)))) { goto ret;
}
} if (!f_p) { if (forward) {
sbi->sb_max_fwd_alloc = forward * 3 / 4;
forward /= 2; goto less_fwd;
}
}
sec = 0;
ret: if (sec) {
i = 0; do
hpfs_claim_alloc(s, sec + i); while (unlikely(++i < n));
} if (sec && f_p) { for (i = 0; i < forward; i++) { if (!hpfs_alloc_if_possible(s, sec + n + i)) {
hpfs_error(s, "Prealloc doesn't work! Wanted %d, allocated at %08x, can't allocate %d", forward, sec, i);
sec = 0; break;
}
}
} return sec;
}
static secno alloc_in_dirband(struct super_block *s, secno near)
{ unsigned nr = near;
secno sec; struct hpfs_sb_info *sbi = hpfs_sb(s); if (nr < sbi->sb_dirband_start)
nr = sbi->sb_dirband_start; if (nr >= sbi->sb_dirband_start + sbi->sb_dirband_size)
nr = sbi->sb_dirband_start + sbi->sb_dirband_size - 4;
nr -= sbi->sb_dirband_start;
nr >>= 2;
sec = alloc_in_bmp(s, (~0x3fff) | nr, 1, 0); if (!sec) return 0;
hpfs_claim_dirband_alloc(s, sec); return ((sec & 0x3fff) << 2) + sbi->sb_dirband_start;
}
/* * Check if there are at least n free dnodes on the filesystem. * Called before adding to dnode. If we run out of space while * splitting dnodes, it would corrupt dnode tree.
*/
int hpfs_check_free_dnodes(struct super_block *s, int n)
{ int n_bmps = (hpfs_sb(s)->sb_fs_size + 0x4000 - 1) >> 14; int b = hpfs_sb(s)->sb_c_bitmap & 0x0fffffff; int i, j;
__le32 *bmp; struct quad_buffer_head qbh; if ((bmp = hpfs_map_dnode_bitmap(s, &qbh))) { for (j = 0; j < 512; j++) { unsigned k; if (!le32_to_cpu(bmp[j])) continue; for (k = le32_to_cpu(bmp[j]); k; k >>= 1) if (k & 1) if (!--n) {
hpfs_brelse4(&qbh); return 0;
}
}
}
hpfs_brelse4(&qbh);
i = 0; if (hpfs_sb(s)->sb_c_bitmap != -1) {
bmp = hpfs_map_bitmap(s, b, &qbh, "chkdn1"); goto chk_bmp;
}
chk_next: if (i == b) i++; if (i >= n_bmps) return 1;
bmp = hpfs_map_bitmap(s, i, &qbh, "chkdn2");
chk_bmp: if (bmp) { for (j = 0; j < 512; j++) {
u32 k; if (!le32_to_cpu(bmp[j])) continue; for (k = 0xf; k; k <<= 4) if ((le32_to_cpu(bmp[j]) & k) == k) { if (!--n) {
hpfs_brelse4(&qbh); return 0;
}
}
}
hpfs_brelse4(&qbh);
}
i++; goto chk_next;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.