From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0668E3C7E0C for ; Mon, 13 Apr 2026 12:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083065; cv=none; b=UDWIoHp++WY50I+y38/XPFn5WgBjTw7xd5DYF4XTvEvO1tVKMP8RmT8aQ5OTp4IqDWHpNPc8Sr4JqnfhXSAi+ciVSe4QIQ3Q0YKKmV2ruLX1+NY9+H+gOk8mHtpBLFp9EDcap5bj2zGorvPR9O2Qa+VQeXbu0hYIX3EEQfzXwA0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083065; c=relaxed/simple; bh=9MwpuvspxgM9S1xocdqxhpnC1LkHwHjGUtwBjeGYgN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Q8sJL0IutmBWwK6jwrKgX2L4H9olSAftJAz1RgQg59x6WLERURpMxMbdSRbeSKKnAq5DLpJKGMH4tkaKAboV5db7VnZp2bf4zY4W4jeZWvffAHIUyVLRmO550SGjAW+NBaOGU2LdP4+M2e4Uoo1RRHQDh3tIi5CeYMiS5bE+48s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hackers.camp; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hackers.camp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-488a8f97f6bso8168305e9.2 for ; Mon, 13 Apr 2026 05:24:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776083062; x=1776687862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xV2ei1Pjz1ktH8bmxRjBSR/qLLc+Wvu9ssskTBPD/gg=; b=gNLTedqGSw6Rla0HjaGGvBOWHl9pWQA0pBLAcLUO7gwDYY5WwMcrFeU0UyRWtKZ83f 17Sz0MqJHgcXY3NtdU1JzOdjYNrreNeErzIPaZ5HnSh/ZFSJ/Dbl4F+OhnGwT6hdaLpm gxHn6hRbz/8G+HwsNzG4A1/hIbLV2Af8JKb3Cq6Ls5gaCTxd7V6ClmNmwIfJtO1MiL5l ufDrDevk6VveYazm/NWNhXvrEK96dIwO82L8L6i3ZfYuuwqum6OLRl9AU4JBEq0HcUC8 pgTLpFicdo8npySn9ABF5qzhJtpN1teYHfJqX+DAZCSPK2ounQDY/WRjelJAD5eu+JB/ F74Q== X-Gm-Message-State: AOJu0YwmErXZ8MpWt4bonXDDUsEl7BF+z47BoOZfMHj0OVNNCI1TLUsm TXRi7l7eHZNv3oDM4CtJidR27bOgfiuKNG5aaRujO6yOIVXjqvJ2v1aGJsqvirPabtA= X-Gm-Gg: AeBDievm5sPwD1doPPBMXwFl6HERIT2Yxyoiya5ofrbJTONg+X6mf5SDWI4QReiBBJ9 ViKjV0C+qbt5sU+/yldwWN8+lRFrVR17whQRrX8z7xgljOcQNfdeO/qsgRTs3Ge7SecZlp/VQlb JhbYO03ESzkuP8oLZBvzg4hjbzvI4W59RtRV1zZxKOkOfwuBV3neRFfH8t23eupNfddeYDwv+LM vH9piJxpx0sjorJktX1yGG9tyYUbvQyBqhnex2eXS1JMt5ASKcDckNFXId6hqVDJS51vE0esGAT vIr5UHlv/rZ+Fsc10cnJHtmUVgq7zDMD22q8SqTQLSRch0g4zq6cC16ozpdOAfqCnqYKFyIdsja H2+pIlAQuYzVKvebYOnbrZjQQ2JbkN0mEajbYFbAkLKKJ4GgYiTMZ/5ltTEp1Np8huay3e1sKMX OUboi+NfcTqVrlOBi+B9B1QDaoWde7RuFQhqhf1IOTcj43ZmPbI0uA89PTdT+IxmWpfXOqWHyMp f+3 X-Received: by 2002:a05:600c:b85:b0:486:fb8a:fed with SMTP id 5b1f17b1804b1-488d68a0975mr96731605e9.8.1776083062284; Mon, 13 Apr 2026 05:24:22 -0700 (PDT) Received: from spartian-1.home ([2a01:cb1c:784:2f00:708:2805:7128:7a75]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488d532ed4dsm278260915e9.4.2026.04.13.05.24.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 05:24:21 -0700 (PDT) From: Aurelien DESBRIERES To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, aurelien@hackers.camp Subject: [RFC PATCH 08/10] ftrfs: add CRC32 checksumming and Reed-Solomon FEC skeleton Date: Mon, 13 Apr 2026 16:23:54 +0200 Message-ID: <20260413142357.515792-9-aurelien@hackers.camp> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260413142357.515792-1-aurelien@hackers.camp> References: <20260413142357.515792-1-aurelien@hackers.camp> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurélien DESBRIERES Implement data integrity layer: - ftrfs_crc32(): CRC32 wrapper via kernel crc32_le(), used for per-inode and per-superblock checksums - init_gf_tables(): initialize GF(2^8) Galois Field lookup tables (primitive polynomial 0x1d) for Reed-Solomon arithmetic - gf_mul(): GF(2^8) multiplication via log/exp tables - ftrfs_rs_encode(): systematic Reed-Solomon encoder over FTRFS_SUBBLOCK_DATA bytes with FTRFS_RS_PARITY check symbols The RS encoder operates on sub-blocks within each 4096-byte data block. Decoding (error correction) is not yet implemented. Signed-off-by: Aurélien DESBRIERES --- fs/ftrfs/edac.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 fs/ftrfs/edac.c diff --git a/fs/ftrfs/edac.c b/fs/ftrfs/edac.c new file mode 100644 index 000000000..ebe676c98 --- /dev/null +++ b/fs/ftrfs/edac.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * FTRFS — EDAC layer: CRC32 + Reed-Solomon FEC + * Author: roastercode - Aurelien DESBRIERES + */ + +#include +#include +#include +#include "ftrfs.h" + +/* Reed-Solomon FEC context */ +static uint8_t gf_exp[256]; +static uint8_t gf_log[256]; +static bool rs_initialized; + +/* Initialize Galois Field tables */ +static void init_gf_tables(void) +{ + uint8_t x = 1; + + for (int i = 0; i < 255; i++) { + gf_exp[i] = x; + gf_log[x] = i; + x = (x << 1) ^ ((x & 0x80) ? 0x1d : 0); + } + gf_exp[255] = gf_exp[0]; + rs_initialized = true; +} + +/* Galois Field multiplication */ +static uint8_t gf_mul(uint8_t a, uint8_t b) +{ + if (a == 0 || b == 0) + return 0; + return gf_exp[(gf_log[a] + gf_log[b]) % 255]; +} + +/* Reed-Solomon encoding */ +int ftrfs_rs_encode(uint8_t *data, uint8_t *parity) +{ + uint8_t msg[FTRFS_SUBBLOCK_DATA + FTRFS_RS_PARITY]; + + if (!rs_initialized) + init_gf_tables(); + + memset(msg, 0, sizeof(msg)); + memcpy(msg, data, FTRFS_SUBBLOCK_DATA); + + for (int i = 0; i < FTRFS_SUBBLOCK_DATA; i++) { + uint8_t feedback = gf_mul(msg[i], gf_exp[FTRFS_RS_PARITY]); + + if (feedback != 0) { + for (int j = 1; j <= FTRFS_RS_PARITY; j++) + msg[FTRFS_SUBBLOCK_DATA + j - 1] ^= gf_mul(msg[i], gf_exp[j]); + } + } + + memcpy(parity, msg + FTRFS_SUBBLOCK_DATA, FTRFS_RS_PARITY); + return 0; +} + +/* Reed-Solomon decoding (simplified for now) */ +int ftrfs_rs_decode(uint8_t *data, uint8_t *parity) +{ + if (!rs_initialized) + init_gf_tables(); + + /* For now, assume no errors (full decoding to be implemented) */ + return 0; +} + +/* + * ftrfs_crc32 - compute CRC32 checksum + * @buf: data buffer + * @len: length in bytes + * + * Returns CRC32 checksum. Uses kernel's hardware-accelerated CRC32 + * (same as ext4/btrfs). + */ +__u32 ftrfs_crc32(const void *buf, size_t len) +{ + return crc32_le(0xFFFFFFFF, buf, len) ^ 0xFFFFFFFF; +} -- 2.52.0