Like any other piece of software (and information generally), this software comes with NO WARRANTY.
While Git might be the most popular SCM in the open source community, it has never been ported to the public domain operating system TempleOS. Until now!
There are a number of pre-requisites to running Git on TempleOS, some of which are quite significant. The biggest issue is that the TempleOS "less is more" philosophy that governs its design places hard limits on the maximum-allowed length of file names in the kernel.
TempleOS supports two file systems: its own native RedSea file system, and a very basic FAT32 implementation. It is important to realize that this FAT32 implementation is not fully-featured and, among other things, limits the length of files to 26 characters.
By comparison, RedSea supports file name lengths up to 38 characters, which must include the '\0' NULL byte commonly found at the end of character strings in C. This limits the maximum-allowed file name length on a RedSea file system to 37 characters.
These limits are established in two places in the kernel. First is the core kernel data structure found in Kernel/KernelA.HH called CDirEntry:
#define CDIR_FILENAME_LEN 38 //Must include terminator zero public class CDirEntry { CDirEntry *next,*parent,*sub; U8 *full_name; I64 user_data,user_data2; U0 start; U16 attr; U8 name[CDIR_FILENAME_LEN]; I64 clus,size; CDate datetime; };
This data structure fixes the maximum length of a "name" value for any directory entry in TempleOS to 37 characters plus a NULL byte. This data structure is used to make the 64-byte directory entries in the RedSea on-disk file system format:
#define CDIR_FILENAME_LEN 38 //Must include terminator zero public class CDirEntry { // "fixed-sized 64-byte directory entries" // means these 64 bytes: U0 start; // 0 bytes U16 attr; // 2 bytes U8 name[CDIR_FILENAME_LEN]; // 38 bytes I64 clus,size; // 16 bytes CDate datetime; // 8 bytes };
Increasing this value by one byte in the kernel would increase the fixed-size entries from 64 bytes to 65 bytes, which breaks the RedSea file system driver.
The TempleOS FAT32 driver has a different limitation. FAT32 introduced "long file names" (LFNs) by integrating additional records into the metadata of the file system in a way that would allow a system to simultaneously have both a "short file name" like "MYLONG~1.DOC" and a "long file name" like "MyLongFileName.doc".
The TempleOS FAT32 driver limits the length of LFNs by capping the number of LFN records to 2. Because the FAT32 specification defines an LFN record to contain up to 13 characters, the maximum length for a file name in a FAT32 file system on TempleOS is 26 characters.
Git writes its objects to disk by naming them after their SHA-1 checksums. Since a SHA-1 checksum is represented as 20 bytes or 40 hexadecimal characters, Git creates a 2-character directory for each object (named after its first byte), and then creates a 38-character file name in that directory (named after the subsequent bytes of the checksum).
Thus to write a Git object to disk one must:
Increase the CDIR_FILENAME_LEN constant by 1 in Kernel/KernelA.HH
Disable the 64-byte CDirEntry assertion in Kernel/BlkDev/FileSysRedSea.HC
Patch the Kernel/BlkDev/FileSysFAT.HC driver's LFN record logic to support reading and writing of one additional record
Recompile the kernel. The easiest way to do this is to run BootHDIns;. This will replace the bootloader.
Optionally, fix the bootloader as needed. Specifics about your choice of bootloader is not covered in this document.
Download the vfat patch
(Optional) A patched FileSysFAT.HC is available if you just want to look at the FAT32 implementation without using it
Copy the patch to your TempleOS system and test it with the patch utility. You can load a Linux live session in a distro of your choice to do this. Run:
patch -p1 --dry-run < /path/to/tos-vfat.patch
The expected output should look like this:
checking file Kernel/BlkDev/FileSysFAT.HC
checking file Kernel/BlkDev/FileSysRedSea.HC
checking file Kernel/KernelA.HH
If there are no conflicts detected, remove the "--dry-run" argument and apply the patch:
patch -p1 < /path/to/tos-vfat.patch
Reboot the system into TempleOS and build a new kernel. The easiest way to do this is to run BootHDIns;. This will replace the bootloader, so if you use a different bootloader like GRUB or syslinux, be sure to reinstall it. You could also run MakeAll; which is called by BootHDIns() and which leaves the bootloader (and current kernel) alone, or compile the kernel yourself with Cmp;, which is what MakeAll; does. Which you should use depends on how you run TempleOS.
If the default TempleOS FAT32 driver is minimal and not strictly within spec, which is the case, then this patch only compounds that problem. It is intended only for experimentation with the TempleOS operating system and should not be used or trusted with important data. Make good backups, on any operating system, and verify that they work before beginning to experiment with file systems.
It's a good idea to make a backup of the Kernel before you make a new one. I call the original Kernel created at install time "Kernel.OLD":
Copy("/Kernel/Kernel.BIN.C","/Kernel/Kernel.OLD");
I make a separate boot entry in my bootloader to load it when needed.
This is version 2024-04-16 of this document.