export NFS4_GETFACL_PROG="$(type -P nfs4_getfacl)"
export UBIUPDATEVOL_PROG="$(type -P ubiupdatevol)"
export THIN_CHECK_PROG="$(type -P thin_check)"
-export PYTHON2_PROG="$(type -P python2)"
+export PYTHON3_PROG="$(type -P python3)"
export SQLITE3_PROG="$(type -P sqlite3)"
export TIMEOUT_PROG="$(type -P timeout)"
export SETCAP_PROG="$(type -P setcap)"
# deduce the 4 bytes we need to insert
for c in struct.pack('<L',fwd_crc)[::-1]:
bkd_crc = ((bkd_crc << 8) & 0xffffffff) ^ self.reverse[bkd_crc >> 24]
- bkd_crc ^= ord(c)
+ bkd_crc ^= c
- res = s[:pos] + struct.pack('<L', bkd_crc) + s[pos:]
+ res = bytes(s[:pos], 'ascii') + struct.pack('<L', bkd_crc) + \
+ bytes(s[pos:], 'ascii')
return res
def parse_args(self):
help="number of forged names to create")
return parser.parse_args()
+def has_invalid_chars(result: bytes):
+ for i in result:
+ if i == 0 or i == int.from_bytes(b'/', byteorder="little"):
+ return True
+ return False
+
if __name__=='__main__':
crc = CRC32()
args = crc.parse_args()
dirpath=args.dir
while count < args.count :
- origname = os.urandom (89).encode ("hex")[:-1].strip ("\x00")
+ origname = os.urandom (89).hex()[:-1].strip ("\x00")
forgename = crc.forge(wanted_crc, origname, 4)
- if ("/" not in forgename) and ("\x00" not in forgename):
+ if not has_invalid_chars(forgename):
srcpath=dirpath + '/' + str(count)
- dstpath=dirpath + '/' + forgename
- file (srcpath, 'a').close()
+ # We have to convert all strings to bytes to concatenate the forged
+ # name (bytes).
+ # Thankfully os.rename() can accept bytes directly.
+ dstpath=bytes(dirpath, "ascii") + bytes('/', "ascii") + forgename
+ open(srcpath, mode="a").close()
os.rename(srcpath, dstpath)
os.system('btrfs fi sync %s' % (dirpath))
count+=1;
_supported_fs btrfs
_require_scratch
-_require_command $PYTHON2_PROG python2
+_require_command $PYTHON3_PROG python3
# Currently in btrfs the node/leaf size can not be smaller than the page
# size (but it can be greater than the page size). So use the largest
# ...
#
-$PYTHON2_PROG $here/src/btrfs_crc32c_forged_name.py -d $SCRATCH_MNT -c 310
+$PYTHON3_PROG $here/src/btrfs_crc32c_forged_name.py -d $SCRATCH_MNT -c 310
echo "Silence is golden"
# success, all done