From b1f7d55be3ef590521653a184b2f948aacac6d84 Mon Sep 17 00:00:00 2001 From: jdreichmann Date: Sat, 6 Jul 2019 16:30:08 +0200 Subject: [PATCH] add script to create block with random data and script to write file into block and keep track of offset and files --- .gitignore | 2 ++ insert.sh | 18 ++++++++++++++++++ mk_block.sh | 1 + 3 files changed, 21 insertions(+) create mode 100644 .gitignore create mode 100755 insert.sh create mode 100755 mk_block.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0b64e6e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/files/ +/fs/ diff --git a/insert.sh b/insert.sh new file mode 100755 index 0000000..7162a36 --- /dev/null +++ b/insert.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +FILE=$1 + +# Get size of file and current offset +SIZE=$(stat --printf="%s" $FILE) +OFFSET=$(cat ./fs/offset) + +# Write file into block +dd if=$1 of="./fs/0.block" seek=$OFFSET oflag=seek_bytes +RESULT=$? + +if [[ "$RESULT" == "0" ]]; then + # Append index and update offset + echo "$FILE;$OFFSET;$SIZE" >> ./fs/fileIndex + echo $((( $OFFSET + $SIZE ))) > ./fs/offset + echo "file inserted" +fi; diff --git a/mk_block.sh b/mk_block.sh new file mode 100755 index 0000000..3ef403a --- /dev/null +++ b/mk_block.sh @@ -0,0 +1 @@ +dd if=/dev/urandom of=fs/0.block bs=1024k count=64