# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/embutils/z-mkswap.patch # Copyright (C) 2024 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- --- embutils-0.19/mkswap.c.vanilla 2024-01-14 14:30:38.427442305 +0100 +++ embutils-0.19/mkswap.c 2024-01-14 14:58:21.016511460 +0100 @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + +void pf(const char*msg) { write(2,msg,strlen(msg)); } +void die(const char*msg) { pf(msg); exit(1); } + +int main(int argc,char *argv[]) { + if (argc <= 1) die("Usage: mkswap swap\n"); + + int fd = open(argv[1], O_RDWR), pagesize = sysconf(_SC_PAGE_SIZE); + if (fd <= 0) die("mkswap: error opening swap\n"); + + off_t len = lseek(fd, 0, SEEK_END); + if (len < 0) die("mkswap: error sizing swap\n"); + + unsigned int pages = (len / pagesize) - 1, swap[129] = {}; + + swap[0] = 1; + swap[1] = pages; + + lseek(fd, 1024, SEEK_SET); + write(fd, swap, 129 * sizeof(unsigned int)); + lseek(fd, pagesize - 10, SEEK_SET); + write(fd, "SWAPSPACE2", 10); + syncfs(fd); + + printf("Swap size: %luk\n", pages * (unsigned long)(pagesize / 1024)); + + return 0; +} --- embutils-0.19/Makefile.vanilla 2024-01-14 14:30:42.583442478 +0100 +++ embutils-0.19/Makefile 2024-01-14 14:30:46.979442661 +0100 @@ -15,7 +15,7 @@ sosrm soscp sosmv sosln soslns sleep2 uniq tr mesg du \ uuencode uudecode nohup nice cmp mktemp truncate test date \ printenv chrootuid renice \ -free losetup switch_root readlink swapon +free losetup switch_root readlink swapon mkswap OS:=$(shell uname) ifeq ($(OS),Linux)