From f110f8549801ade98c340d91c718f7240ac5189a Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 20 Nov 2023 00:15:50 +0100 Subject: [PATCH] Simplify partition setup To prepare part1 for grub, part2 for userdata --- Makefile | 2 +- core/main.c | 6 +++--- disk.sfdisk | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 49a3680..e1057de 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ disk.img: disk.sfdisk userspace # Before having filesystem support, just dump the user prog into the first partition strip userspace/user -o userspace/user.strip $(eval file_size:=$(shell du -b userspace/user.strip|awk '{print $$1}' | xargs printf "%016d" )) \ - sed '1s/^/$(file_size)/' userspace/user.strip | dd of=disk.img seek=2048 bs=512 + sed '1s/^/$(file_size)/' userspace/user.strip | dd of=disk.img seek=34816 bs=512 # NASM without preprocessing %.o:%.asm diff --git a/core/main.c b/core/main.c index 7cb2dc9..e52114b 100644 --- a/core/main.c +++ b/core/main.c @@ -45,7 +45,7 @@ void idleThread(void *arg) #define FILE_MAX_SIZE 64 // In nb of sectors void loadUserSpace() { - struct ata_partition *part = ATAGetPartition(0); + struct ata_partition *part = ATAGetPartition(1); if (part == NULL) { printf("No user partition found\n"); @@ -72,8 +72,8 @@ void loadUserSpace() sectorToRead = DIV_ROUND_UP(sizeInt, DISK_SECTOR_SIZE) - 1; } - if (sectorToRead > FILE_MAX_SIZE - 1) { - printf("File too long"); + if (sectorToRead > FILE_MAX_SIZE - 1 || sectorToRead <= 0) { + printf("Invalid file size: %d (sector)\n", sectorToRead); return; } diff --git a/disk.sfdisk b/disk.sfdisk index b1fe753..2004b3d 100644 --- a/disk.sfdisk +++ b/disk.sfdisk @@ -4,6 +4,5 @@ device: disk.img unit: sectors sector-size: 512 -disk.img1 : start= 2048, size= 10240, type=83 -disk.img2 : start= 12288, size= 10240, type=b -disk.img3 : start= 22528, size= 43008, type=e +disk.img1 : start= 2048, size= 32768, type=6, bootable +disk.img2 : start= 34816, size= 30720, type=83