From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 B3BCF395250 for ; Mon, 13 Apr 2026 21:06:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776114385; cv=none; b=VSHDaoIfvnNEgroSB5Qsf+WKT0veRn+6FyCiB/2g5LbX2Bz3MlCwDfBbjVlSOwN+z5gFNPAbD7phADFqf1ENOe+OpsuTLFoaJA2gBDwKRWYGgL9MPdad5HSYzRms1eMt6AfgGeZLziP5KM+Tw2VBRlXFKBeqHqDCMtpottF2JC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776114385; c=relaxed/simple; bh=v32LiiFvmmIm2TLfU9CJlRKpWxy/76tGuhfVX78Pjms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OyUUiB7QGmMzjqPY+N6i/p6GMZimR4z+1Zqq+C1UG+QiNny8sESfC4jkIT9bh3bkkPeyGXUo+R2jYiET6fhTIa/5hbq/LtDYf7sezueSKMcc2c125X2Dw33OQxBzyFaul6bELCgsZlSVzrVxOtWSzoA+3lNGtrrR+8yNoCKL8Yo= 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.46 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-f46.google.com with SMTP id 5b1f17b1804b1-488ac04e13dso6180295e9.1 for ; Mon, 13 Apr 2026 14:06:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776114382; x=1776719182; 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=DbD7D+uc0+23/XzD49X5LHz5RWaS8JM3kH9aHiCiWR4=; b=Y1m1T+JvUoeJ+PCr5wER/GQJ96CZXz0YVpWbqX/88UNn4W2U7v+/EfBeJFOCNN4FCT oIFw36fJw8xbBYXhUdY5p8skfQTuJk9PnVO5zVgdlVAmg1LQib3ySfOGty6gRycS/vIJ roilwV87JH9VOLBLWSp9DBVvctynfWH+W9P9csw9sULCefVTrMxNDwAr7yVOtaEsEJzG 8D6ZWxSgo6xGQcJbnaR1Dz1LzVvHlWSUPnJ9387tjOmYf5Z4Jw/aPT2Tf4LQ2xq7ClFk mZTd5e+MozcgXhI0eEFhSffNiHKjFvXnvKllPM0D/uuuqxMA+LafLQ255KMBqkVt1OkB 770g== X-Gm-Message-State: AOJu0YyikR4PewC4FBnni0moOOMfaRISJtybmwVPD3x7qshJDf0sED3E Shdf5bt+oTbhuguBHeInoAd0n0bp1uSp6rQSnufKKTep3YADlg+HavKgxZJcaFm0yMg= X-Gm-Gg: AeBDiesacxTqm3k847GkQHOxgBOWvLrCOWb3Ce3tFojphjSdOy3Su49HErlCV/qZN/b VqPPal/3HdPndxomlSerYPbFAWTlL3kzvdGceAjgRu6qn1UrsQa7oxU4JgpppLG0d7mwDgPrT0y qZELLsbl8wia46mTaw4o4RnqZEswlcpWQnUryn/dtHHM5s1Owf57Ik3mzyq0TEZ3ACCyTjgO/k/ 29t/0inhNUzbq1HbXUWtomLDRCyB3tJa/9OV+B/IaJFCnHIWizUVNAK5r4bIhJID19fCtWuQjSX miX4ozUT36aB0QYQuHwU0Bymyavu9NrENG78s40WmhuH6gxc1D6ihPTjy5pN9umSwoKLetpqR47 yFyM89W3qnFiWZMHtC6to9QzHRBF0HbrZl2xVAxwlTRzWWV/ZlDpFzt9TwvxnXgI5Qy+K+c2iE4 g1YCik4l4D1UJbqbml+GtSNUnfZ/OGElq7wPSzG90VAtOgIYFSJlLFfh6+K6NHLWqVJQfiaf1wJ Do/ X-Received: by 2002:a05:6000:2f84:b0:43d:5584:9077 with SMTP id ffacd0b85a97d-43d64289ccbmr11795787f8f.2.1776114381608; Mon, 13 Apr 2026 14:06:21 -0700 (PDT) Received: from spartian-1.home ([2a01:cb1c:784:2f00:708:2805:7128:7a75]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63e5c98fsm35130020f8f.35.2026.04.13.14.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 14:06:21 -0700 (PDT) From: Aurelien DESBRIERES To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aurelien DESBRIERES , viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, djwong@kernel.org, adilger@dilger.ca, pfalcato@suse.de Subject: [PATCH v2 03/11] ftrfs: add inode operations Date: Tue, 14 Apr 2026 01:05:44 +0200 Message-ID: <20260413230601.525400-4-aurelien@hackers.camp> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260413230601.525400-1-aurelien@hackers.camp> References: <20260413230601.525400-1-aurelien@hackers.camp> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement ftrfs_iget() to read inodes from the on-disk inode table: - Locate inode block from s_inode_table_blk and inode number - Read raw ftrfs_inode via sb_bread() - Verify per-inode CRC32 checksum - Populate VFS inode fields (mode, uid, gid, size, timestamps) - Copy direct/indirect block pointers to ftrfs_inode_info - Assign inode_operations and file_operations based on file type - Use inode_state_read_once() for I_NEW test (kernel 7.0 API) Signed-off-by: Aurelien DESBRIERES --- fs/ftrfs/inode.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 fs/ftrfs/inode.c diff --git a/fs/ftrfs/inode.c b/fs/ftrfs/inode.c new file mode 100644 index 000000000..e1279c796 --- /dev/null +++ b/fs/ftrfs/inode.c @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * FTRFS — Inode operations + * Author: roastercode - Aurelien DESBRIERES + */ + +#include +#include +#include +#include +#include "ftrfs.h" + +/* + * ftrfs_iget — read inode from disk into VFS + * @sb: superblock + * @ino: inode number (1-based) + * + * Inode table starts at s_inode_table_blk. + * Each block holds FTRFS_BLOCK_SIZE / sizeof(ftrfs_inode) inodes. + */ +struct inode *ftrfs_iget(struct super_block *sb, unsigned long ino) +{ + struct ftrfs_sb_info *sbi = FTRFS_SB(sb); + struct ftrfs_inode_info *fi; + struct ftrfs_inode *raw; + struct buffer_head *bh; + struct inode *inode; + unsigned long inodes_per_block; + unsigned long block, offset; + __u32 crc; + + inode = iget_locked(sb, ino); + if (!inode) + return ERR_PTR(-ENOMEM); + + /* Already in cache */ + if (!(inode_state_read_once(inode) & I_NEW)) + return inode; + + inodes_per_block = FTRFS_BLOCK_SIZE / sizeof(struct ftrfs_inode); + block = le64_to_cpu(sbi->s_ftrfs_sb->s_inode_table_blk) + + (ino - 1) / inodes_per_block; + offset = (ino - 1) % inodes_per_block; + + bh = sb_bread(sb, block); + if (!bh) { + pr_err("ftrfs: unable to read inode block %lu\n", block); + iget_failed(inode); + return ERR_PTR(-EIO); + } + + raw = (struct ftrfs_inode *)bh->b_data + offset; + /* Verify inode CRC32 */ + crc = ftrfs_crc32(raw, offsetof(struct ftrfs_inode, i_crc32)); + if (crc != le32_to_cpu(raw->i_crc32)) { + pr_err("ftrfs: inode %lu CRC32 mismatch\n", ino); + brelse(bh); + iget_failed(inode); + return ERR_PTR(-EIO); + } + + fi = FTRFS_I(inode); + + /* Populate VFS inode */ + inode->i_mode = le16_to_cpu(raw->i_mode); + inode->i_uid = make_kuid(sb->s_user_ns, le16_to_cpu(raw->i_uid)); + inode->i_gid = make_kgid(sb->s_user_ns, le16_to_cpu(raw->i_gid)); + set_nlink(inode, le16_to_cpu(raw->i_nlink)); + inode->i_size = le64_to_cpu(raw->i_size); + inode->i_blocks = le32_to_cpu(raw->i_blocks); + + inode_set_atime(inode, + le64_to_cpu(raw->i_atime) / NSEC_PER_SEC, + le64_to_cpu(raw->i_atime) % NSEC_PER_SEC); + inode_set_mtime(inode, + le64_to_cpu(raw->i_mtime) / NSEC_PER_SEC, + le64_to_cpu(raw->i_mtime) % NSEC_PER_SEC); + inode_set_ctime(inode, + le64_to_cpu(raw->i_ctime) / NSEC_PER_SEC, + le64_to_cpu(raw->i_ctime) % NSEC_PER_SEC); + + /* Copy block pointers to in-memory inode */ + memcpy(fi->i_direct, raw->i_direct, sizeof(fi->i_direct)); + fi->i_indirect = raw->i_indirect; + fi->i_dindirect = raw->i_dindirect; + fi->i_flags = le32_to_cpu(raw->i_flags); + + /* Set ops based on file type */ + if (S_ISDIR(inode->i_mode)) { + inode->i_op = &ftrfs_dir_inode_operations; + inode->i_fop = &ftrfs_dir_operations; + } else if (S_ISREG(inode->i_mode)) { + inode->i_op = &ftrfs_file_inode_operations; + inode->i_fop = &ftrfs_file_operations; + } else { + /* Special files: use generic */ + init_special_inode(inode, inode->i_mode, 0); + } + + brelse(bh); + unlock_new_inode(inode); + return inode; +} -- 2.52.0