Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2680550lqo; Tue, 14 May 2024 06:22:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCjqAMCo4ARWTQBWXLlKxzFS1SWTFW/wVz/pI72/ks6pgGS6Vx+k58N+Ivpo7ycI1gaJynZEKornHERdPOQ6QDRJ4TDuSTZPSi9LYsoA== X-Google-Smtp-Source: AGHT+IGe6F6xhZWR2G8H8BDmwF7wzv407+bd3uRAZX0i5cd95wMA9JL4dWyHn0Yid1mV8yV1eO1j X-Received: by 2002:a17:90a:858c:b0:2b2:b1a7:9530 with SMTP id 98e67ed59e1d1-2b6ccef682bmr10558201a91.41.1715692962514; Tue, 14 May 2024 06:22:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715692962; cv=pass; d=google.com; s=arc-20160816; b=j5eoWgdYikc5dd7e80QtsmQWCzGok288YH9qZeGzF56zzmrqJL5eN64tnBhTo+jTAA H1+NBVyi04ls4e91OLsFWsWJJlYLNMUzNAD0uz97d1ZdxuF1SILgHqQSGzFBdn6Pb6T7 UwMhALCdasnIolvo1pf6cQ0Idz3xmE34acg6c0AJLLudWf5HsTSqbrQrEsmTBseMr1Zg kqGIQEeA0iOHgrxUUMAOfQ0ONsEoFUsaTGCzA8tJ7jQmysM1Yne2lLJPcMcN4JZDa/Pv d4UQt5uTMc8UfKz2iCsGIt/ufLcf0xMMBdx7hmDp3LfZAHjAKH/5dk8QGQ9waZMiRsDj X0Fw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UswTy1g0h8WhpaF1uYYHqxzWfUsMnuzmqG3fJ4x5ZR4=; fh=9k0Rnp/Ur4EX9WYMg+l6Wj6vs6hEfZ5kmhPEW0YIRB8=; b=BIn61ostm49RzkQwgA77KBu2kko7ZDNB91dSh1mPoARA+CHmWUAp8C2KNtu96+Rdk3 Fmpf6hgbOaUV1flmj0n8LWfChWjxWu6VUaj5iR1FAaoy0nD1zClohc7XySi4V+64xR7K NPCUGTPVq2tY0HxQGJjH1R7urFnne0sqtSeoH1almPdM7WSXEC978Nej6CY6RzVVzkd1 GZprEYeOpNiT/zgNoLf5yjXwlkxNRuX8yGJ3qrlPDWoWI8twoT2GLFcAOKzb2LCWtwd/ mps0VdBDRMhommEA+4X5mpnVDU/6M0xKcgNeFa3XDr1aMmYC7mpe4sffw+tT1wJyR9zb 5m9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VABahaYF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178722-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178722-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b67116379dsi9715558a91.79.2024.05.14.06.22.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 06:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-178722-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VABahaYF; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-178722-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-178722-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D4663B21D58 for ; Tue, 14 May 2024 13:21:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45AEB154BE3; Tue, 14 May 2024 13:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VABahaYF" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 BC0BE14A601; Tue, 14 May 2024 13:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715692671; cv=none; b=JbGm5htwgFP9ZEmpyNAwG7qmzvo/e7WxQHq9lJXdxlFhc+aaZAE5jbXCP1dUVrqyvqbFiaW7yazeMhaxilnRfTkRUvz8nKsYUP7ahhSNzDme/j4Vt0YAVF7nH9TPILHjyiEJNE6X29z5xbl9bxxqWGTq1IgL+mlNPZhqA7u7EAw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715692671; c=relaxed/simple; bh=h30CdDcKy1aa9nOwMaEOcIznaigfbz3L1bFiMg+w6P0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GSbbB7FZr6VFPY5SUtM46q+dlLDPLg+Y4MTbUv/BV75rB/ltB8iImhEqiNbArust9uzMazuwsepMpZXniiu4pyhJSeyS2ohs3T03T71Ffeqd4pIQjZDZGM2vLLWc0KnVBejo+ioucGkTKFJcwIcp+MLsp2P/9J/w/kvlAQBAR8k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VABahaYF; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1ee5235f5c9so42972365ad.2; Tue, 14 May 2024 06:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715692669; x=1716297469; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UswTy1g0h8WhpaF1uYYHqxzWfUsMnuzmqG3fJ4x5ZR4=; b=VABahaYFQ7nuVgf1tdqMTn/HJ0FPosc+BwUoUk2JrybQVELWa+rPyJI4AePTBR9C1z +cjcyXg3RLlnKHSJSJglPIbeszkN/TXF+EC7EZnHxZVQn0MnPSD6Z1K66uh8dY7uZ7K+ JJiGrM7/vuNfUutpYbj8axRVpiwQ9x6lwRM83KfBT5VOSgur6FXp40Kmfi71zREkOf80 72sfoEvwQYvuXezUJ4a8A3KWrtrjBO7BMsaKNkPMN/aHoGYK3SHEM6ggEEUsUHLGJyAP 2CCpO+m+/wCqIYk4osVkDZRuuqmTrFUe6VleTCFTbsnpUyij+KKz73gyqFZMi4+He1pM a4Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715692669; x=1716297469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UswTy1g0h8WhpaF1uYYHqxzWfUsMnuzmqG3fJ4x5ZR4=; b=dY1ZHF29hZnXIqbn0ULCF8v56QHaIA5acH8RVCbL/APzO6acovXwDSmSCmBD0j5nxS 2dPpVZ/o09d5Ax4TBpl9KkNFjQv1v5vN9uUz73AuvP7AQi3tm50T2xr4chMm2rsuuHvW avxpPziMnuujn0eI2Wf7YCxt/VaYQN1aVmOtlFvQyfHkbzr41DDEzHeUrINhKBZ1lrNr rNQAVb5I6QPfoDgZCoSWcf4G9sl+XLzNR3WORh7rFynaZCIJFoPSuyToF83adcyFrsU7 Xu5qLx5a/uMkB12ffwE0LbnDDxTbiuRn8FjllSoIpS9cjwGnq4ednHqs4D8ASHyq5WxX slPA== X-Forwarded-Encrypted: i=1; AJvYcCUcTIDrQMZzvDQuBmf8fyIlhL02eXpBp/O5I/ztCDnZ6YS31VAo7erdQPD/fjO6eRpms3+m8zIX7D9lrfZnPq0kKjbEG1g9Fe7C65jfTN0tAKL3FoV4HLSCg4/4qROV/beh0l7H/7LUo4hzZcn17l/o0Gv9FPb4iZRdzEUzIgGSEF96TdULK5ljMvqW X-Gm-Message-State: AOJu0Yx2sKkxmJ6mn5/b+JVoTRUqV0mH0ZsojV+IpIfwImcyiSwUrlCV oOqt4PLzTHmnC2nughZE+OCYOqxTrk4rFTZh3Rrfdyy18FZZfvsu X-Received: by 2002:a17:902:bd86:b0:1ea:5aff:c8ce with SMTP id d9443c01a7336-1ef43d2e1cfmr117956635ad.29.1715692669005; Tue, 14 May 2024 06:17:49 -0700 (PDT) Received: from wedsonaf-dev.. ([50.204.89.32]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1ef0b9d18a4sm97277335ad.56.2024.05.14.06.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 06:17:48 -0700 (PDT) From: Wedson Almeida Filho To: Alexander Viro , Christian Brauner , Matthew Wilcox , Dave Chinner Cc: Kent Overstreet , Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Wedson Almeida Filho Subject: [RFC PATCH v2 10/30] rust: fs: add empty file operations Date: Tue, 14 May 2024 10:16:51 -0300 Message-Id: <20240514131711.379322-11-wedsonaf@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240514131711.379322-1-wedsonaf@gmail.com> References: <20240514131711.379322-1-wedsonaf@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Wedson Almeida Filho This is in preparation for allowing modules to implement different file callbacks, which will be introduced in subsequent patches. Signed-off-by: Wedson Almeida Filho --- rust/kernel/fs/file.rs | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index b8386a396251..67dd3ecf7d98 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -14,6 +14,7 @@ types::{ARef, AlwaysRefCounted, Opaque}, }; use core::{marker::PhantomData, ptr}; +use macros::vtable; /// Flags associated with a [`File`]. pub mod flags { @@ -268,3 +269,59 @@ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.pad("EBADF") } } + +/// Operations implemented by files. +#[vtable] +pub trait Operations { + /// File system that these operations are compatible with. + type FileSystem: FileSystem + ?Sized; +} + +/// Represents file operations. +#[allow(dead_code)] +pub struct Ops(pub(crate) *const bindings::file_operations, PhantomData); + +impl Ops { + /// Creates file operations from a type that implements the [`Operations`] trait. + pub const fn new + ?Sized>() -> Self { + struct Table(PhantomData); + impl Table { + const TABLE: bindings::file_operations = bindings::file_operations { + owner: ptr::null_mut(), + llseek: None, + read: None, + write: None, + read_iter: None, + write_iter: None, + iopoll: None, + iterate_shared: None, + poll: None, + unlocked_ioctl: None, + compat_ioctl: None, + mmap: None, + mmap_supported_flags: 0, + open: None, + flush: None, + release: None, + fsync: None, + fasync: None, + lock: None, + get_unmapped_area: None, + check_flags: None, + flock: None, + splice_write: None, + splice_read: None, + splice_eof: None, + setlease: None, + fallocate: None, + show_fdinfo: None, + copy_file_range: None, + remap_file_range: None, + fadvise: None, + uring_cmd: None, + uring_cmd_iopoll: None, + }; + } + Self(&Table::::TABLE, PhantomData) + } +} -- 2.34.1