From 73f01d3e8119358cc1fe6a34db9f86542e9549d4 Mon Sep 17 00:00:00 2001 From: Elliot Nunn Date: Mon, 8 Oct 2018 08:20:03 +0800 Subject: [PATCH] neaten up newlines --- machfs/bitmanip.py | 2 ++ machfs/btree.py | 35 ++++++++++++++++++++--------------- machfs/directory.py | 1 - machfs/main.py | 1 + 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/machfs/bitmanip.py b/machfs/bitmanip.py index 5bf683c..3a87ec4 100644 --- a/machfs/bitmanip.py +++ b/machfs/bitmanip.py @@ -3,6 +3,7 @@ def pad_up(size, factor): x = size + factor - 1 return x - (x % factor) + def bits(ntotal, nset): """Return a buffer of ntotal bits with the first nset set to 1""" assert ntotal % 8 == 0 @@ -25,6 +26,7 @@ def bits(ntotal, nset): return bytes(accum) + def chunkify(b, blksize): for i in range(0, len(b), blksize): ab = b[i:i+blksize] diff --git a/machfs/btree.py b/machfs/btree.py index 799dabc..164c311 100644 --- a/machfs/btree.py +++ b/machfs/btree.py @@ -51,6 +51,7 @@ def unpack_extent_record(record): if f: l.append((e, f)) return l + def _unpack_btree_node(buf, start): """Slice a btree node into records, including the 14-byte node descriptor""" ndFLink, ndBLink, ndType, ndNHeight, ndNRecs = struct.unpack_from('>LLBBH', buf, start) @@ -60,6 +61,25 @@ def _unpack_btree_node(buf, start): records = [bytes(buf[start+i_start:start+i_stop]) for (i_start, i_stop) in zip(starts, stops)] return ndFLink, ndBLink, ndType, ndNHeight, records + +def _pack_leaf_record(key, value): + """Pack a key-value pair to go into a leaf node as a record""" + if len(value) & 1: value += b'\x00' + b = bytes([len(key)+1, 0, *key]) + if len(b) & 1: b += bytes(1) + b += value + return b + + +def _make_index_record(rec, pointer): + """Convert a key-value to a special key-pointer record""" + rec = rec[:1+rec[0]] + rec = b'\x25' + rec[1:] + rec += bytes(rec[0]+1-len(rec)) + rec += struct.pack('>L', pointer) + return rec + + def dump_btree(buf): """Walk an HFS B*-tree, returning an iterator of (key, value) tuples.""" @@ -82,21 +102,6 @@ def dump_btree(buf): break this_leaf = ndFLink -def _pack_leaf_record(key, value): - """Pack a key-value pair to go into a leaf node as a record""" - if len(value) & 1: value += b'\x00' - b = bytes([len(key)+1, 0, *key]) - if len(b) & 1: b += bytes(1) - b += value - return b - -def _make_index_record(rec, pointer): - """Convert a key-value to a special key-pointer record""" - rec = rec[:1+rec[0]] - rec = b'\x25' + rec[1:] - rec += bytes(rec[0]+1-len(rec)) - rec += struct.pack('>L', pointer) - return rec def make_btree(records, bthKeyLen): nodelist = [] # append to this as we go diff --git a/machfs/directory.py b/machfs/directory.py index 9e08f46..be12f06 100644 --- a/machfs/directory.py +++ b/machfs/directory.py @@ -4,7 +4,6 @@ import collections _CASE = list(range(256)) # cheating, fix this! - def _to_lower(orig): return bytes(_CASE[x] for x in orig) diff --git a/machfs/main.py b/machfs/main.py index ae672e8..ec16109 100644 --- a/machfs/main.py +++ b/machfs/main.py @@ -50,6 +50,7 @@ def _catalog_rec_sort(b): return b[:4] + bytes(order[ch] for ch in b[5:]) + def _suggest_allocblk_size(volsize, minalign): min_nonalloc_blks = 6 # just for this estimation retval = minalign