From patchwork Tue Jun 28 07:28:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 1649340 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=ihZIXOHg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LXGSh0ngqz9sG2 for ; Tue, 28 Jun 2022 17:29:40 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AAB1684499; Tue, 28 Jun 2022 09:28:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.b="ihZIXOHg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2364C84492; Tue, 28 Jun 2022 09:28:50 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D839A84497 for ; Tue, 28 Jun 2022 09:28:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=wqu@suse.com Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9CFA81FB3C; Tue, 28 Jun 2022 07:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1656401327; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hloSUbimKPIEYh1/9v8Sy8+7YBlPPiZ44GRZGeoZWho=; b=ihZIXOHg+H6I4I3bZfP/iaE7yg6YDMLA15FZqgmRDDLt5XDncNzrEdoQ7kacrl1mnI4QiB xkq95VoSNvFQX7h7MQq7mmaaPEAwRA+iTF7vewnG4e6lgk83eOn9UQKf2Vk27Nfjy1mYql hKr1rEpquRQSqYwUJQXr78zIHLndzpI= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1DC47139E9; Tue, 28 Jun 2022 07:28:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wIevNautumJzFQAAMHmgww (envelope-from ); Tue, 28 Jun 2022 07:28:43 +0000 From: Qu Wenruo To: u-boot@lists.denx.de Cc: marek.behun@nic.cz, linux-btrfs@vger.kernel.org, jnhuang95@gmail.com, linux-erofs@lists.ozlabs.org, trini@konsulko.com, joaomarcos.costa@bootlin.com, thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com, Simon Glass Subject: [PATCH RFC 6/8] fs: sandboxfs: add sandbox_fs_get_blocksize() Date: Tue, 28 Jun 2022 15:28:06 +0800 Message-Id: <9f4b43b84a688b0367a87da2d4e0eb303a36bf32.1656401086.git.wqu@suse.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean This is to make sandboxfs to report blocksize it supports for _fs_read() to handle unaligned read. Unlike all other fses, sandboxfs can handle unaligned read/write without any problem since it's calling read()/write(), which doesn't bother the blocksize at all. This change is mostly to make testing of _fs_read() much easier. Cc: Simon Glass Signed-off-by: Qu Wenruo Reviewed-by: Simon Glass --- arch/sandbox/cpu/os.c | 11 +++++++++++ fs/fs.c | 2 +- fs/sandbox/sandboxfs.c | 14 ++++++++++++++ include/os.h | 8 ++++++++ include/sandboxfs.h | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 5ea54179176c..6c29f29bdd9b 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -46,6 +46,17 @@ ssize_t os_read(int fd, void *buf, size_t count) return read(fd, buf, count); } +ssize_t os_get_blocksize(int fd) +{ + struct stat stat = {0}; + int ret; + + ret = fstat(fd, &stat); + if (ret < 0) + return -errno; + return stat.st_blksize; +} + ssize_t os_write(int fd, const void *buf, size_t count) { return write(fd, buf, count); diff --git a/fs/fs.c b/fs/fs.c index 7e4ead9b790b..337d5711c28c 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -261,7 +261,7 @@ static struct fstype_info fstypes[] = { .exists = sandbox_fs_exists, .size = sandbox_fs_size, .read = fs_read_sandbox, - .get_blocksize = fs_get_blocksize_unsupported, + .get_blocksize = sandbox_fs_get_blocksize, .write = fs_write_sandbox, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c index 4ae41d5b4db1..130fee088621 100644 --- a/fs/sandbox/sandboxfs.c +++ b/fs/sandbox/sandboxfs.c @@ -55,6 +55,20 @@ int sandbox_fs_read_at(const char *filename, loff_t pos, void *buffer, return ret; } +int sandbox_fs_get_blocksize(const char *filename) +{ + int fd; + int ret; + + fd = os_open(filename, OS_O_RDONLY); + if (fd < 0) + return fd; + + ret = os_get_blocksize(fd); + os_close(fd); + return ret; +} + int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer, loff_t towrite, loff_t *actwrite) { diff --git a/include/os.h b/include/os.h index 10e198cf503e..a864d9ca39b2 100644 --- a/include/os.h +++ b/include/os.h @@ -26,6 +26,14 @@ struct sandbox_state; */ ssize_t os_read(int fd, void *buf, size_t count); +/** + * Get the optimial blocksize through stat() call. + * + * @fd: File descriptor as returned by os_open() + * Return: >=0 for the blocksize. <0 for error. + */ +ssize_t os_get_blocksize(int fd); + /** * Access to the OS write() system call * diff --git a/include/sandboxfs.h b/include/sandboxfs.h index 783dd5c88a73..6937068f7b82 100644 --- a/include/sandboxfs.h +++ b/include/sandboxfs.h @@ -32,6 +32,7 @@ void sandbox_fs_close(void); int sandbox_fs_ls(const char *dirname); int sandbox_fs_exists(const char *filename); int sandbox_fs_size(const char *filename, loff_t *size); +int sandbox_fs_get_blocksize(const char *filename); int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); int fs_write_sandbox(const char *filename, void *buf, loff_t offset,