From db8e6c8434f48c67dd57e95e539c72dc838fabe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Wed, 15 Jan 2020 00:01:59 +0100 Subject: [PATCH] Initial commit --- LICENSE | 13 +++++++++++++ README.md | 25 +++++++++++++++++++++++++ mkfs.cursed | 13 +++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 mkfs.cursed diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5c93f45 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a1c9742 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# cursedfs + +Make a disk image formatted with both ext2 and FAT, at once. + +```bash +~/cursedfs% wget 'https://github.com/NieDzejkob/cursedfs/releases/download/v1.0/cursed.img' +~/cursedfs% sudo mount -o loop -t ext2 cursed.img mountpoint/ +~/cursedfs% ls mountpoint/ +mkfs.cursed +~/cursedfs% sudo umount mountpoint/ +~/cursedfs% sudo mount -o loop -t msdos cursed.img mountpoint/ +~/cursedfs% ls mountpoint/ +gudnuse.ogg +``` + +# Why? + +[I got nerd-sniped](https://twitter.com/Foone/status/1217162186130198529?s=20) + +# How? + +It turns out this is surprisingly simple to do: just create a FAT volume with a +lot of reserved sectors and put the ext2 into the reserved sectors. This works +because the filesystems choose different places to put their superblock: FAT +uses the very first sector, while ext2 leaves the first kilobyte unused. diff --git a/mkfs.cursed b/mkfs.cursed new file mode 100755 index 0000000..bc0def7 --- /dev/null +++ b/mkfs.cursed @@ -0,0 +1,13 @@ +#!/bin/sh + +SIZE_EXT2=128 # sectors, max is 65535 + +set -euxo pipefail +EXT2_TMP="$(mktemp)" +trap "rm $EXT2_TMP" EXIT + +truncate -s 4M cursed.img +truncate -s "$((512*$SIZE_EXT2))" $EXT2_TMP +mkfs.ext2 $EXT2_TMP +mkfs.fat -R $SIZE_EXT2 cursed.img +dd if=$EXT2_TMP of=cursed.img bs=512 skip=1 seek=1 conv=notrunc