From 3ccd492477811daadef18be55f0a0dd9e864190c Mon Sep 17 00:00:00 2001
From: Noah Peterson <NoahBPeterson1997@gmail.com>
Date: Sat, 8 Feb 2025 16:58:34 -0600
Subject: [PATCH] Add support for GGUF

This adds support for the llama.cpp project's GGUF format

Signed-off-by: Noah Peterson <noahbpeterson1997@gmail.com>
---
 magic/Magdir/gguf | 23 +++++++++++++++++++++++
 magic/Makefile.am |  1 +
 2 files changed, 24 insertions(+)
 create mode 100644 magic/Magdir/gguf

diff --git a/magic/Magdir/gguf b/magic/Magdir/gguf
new file mode 100644
index 00000000..37862e51
--- /dev/null
+++ b/magic/Magdir/gguf
@@ -0,0 +1,23 @@
+
+#------------------------------------------------------------------------------
+# $File: gguf.magic,v 1.1 2025/02/08 16:16:52 noah Exp $
+# 
+#
+# GGUF: magic file for GGUF-models
+# URL:  https://github.com/ggml-org/ggml/
+# From: Noah Peterson <noahbpeterson1997@gmail.com>
+
+0          string      GGUF               GGUF file format
+>4         byte        x                  version %d
+>8         quad        x                  \b, %llu tensors
+>16        quad        >0                 \b, %llu metadata entries
+>&8        search/256  general.architecture    
+>>&12      regex       ([A-Za-z0-9\-]+)   \b, Architecture: %s
+>&8        search/256  general.name    
+>>&12      regex       ([A-Za-z0-9\ \-]+) \b, Name: %s
+>&0        search/512  .block_count
+>>&4       long        x                  \b, Block Count: %u
+>&0        search/512  context_length
+>>&4       long        x                  \b, Context Length: %u
+>&0        search/512  embedding_length
+>>&4       long        x                  \b, Embedding Length: %u
diff --git a/magic/Makefile.am b/magic/Makefile.am
index c28b730c..6758e43c 100644
--- a/magic/Makefile.am
+++ b/magic/Makefile.am
@@ -124,6 +124,7 @@ $(MAGIC_FRAGMENT_DIR)/gconv \
 $(MAGIC_FRAGMENT_DIR)/gentoo \
 $(MAGIC_FRAGMENT_DIR)/geo \
 $(MAGIC_FRAGMENT_DIR)/geos \
+$(MAGIC_FRAGMENT_DIR)/gguf \
 $(MAGIC_FRAGMENT_DIR)/gimp \
 $(MAGIC_FRAGMENT_DIR)/git \
 $(MAGIC_FRAGMENT_DIR)/glibc \
-- 
2.39.5 (Apple Git-154)

