From patchwork Wed Oct 14 08:06:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 1381875 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=posteo.net header.i=@posteo.net header.a=rsa-sha256 header.s=2017 header.b=Jx7qFbNX; dkim-atps=neutral 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 (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CB4pM288rz9sVR for ; Wed, 14 Oct 2020 19:10:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 975F182465; Wed, 14 Oct 2020 10:07:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=posteo.net header.i=@posteo.net header.b="Jx7qFbNX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AB8ED82374; Wed, 14 Oct 2020 10:07:13 +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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 50FC5823A5 for ; Wed, 14 Oct 2020 10:07:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=richard.genoud@posteo.net Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id E4F5E2400FE for ; Wed, 14 Oct 2020 10:07:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1602662830; bh=fT/+kDyYpoYIHSE22b4Vk5xJVojsXeGLg2hVSMN+s3o=; h=From:To:Cc:Subject:Date:From; b=Jx7qFbNX1gfM4+1v7AyYvzdUH9mvFd2LgEnErBKZGIibfBo1AfJ5i7BtrWEQFtoYr F0lFNMEdbm2cLOfviYtmTA85qWLy77YhwA7ocqR0Gc21MRoo7aIRRZRwmNlIRKIJLO 0o0sz0HmOzdr5vMIVG+CrCjXHADIEvukZQBEH5z7MHjEkWyjMArEPI6YL86WsqZvR6 Hlone7nRHubz2ZHAgGBd55hwSVxbQRHkZH9vJEeAzHwnQSpSdSZxjwTGMbEO0sbEne snQ+x/bNw1TIF3xDzmuW83cXkfbqztA8liuwPEm9RS5dMpsTO5d2Q8HQGrCGVr7neO /4sGKFveJMfyQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CB4l21vYxz9rxf; Wed, 14 Oct 2020 10:07:10 +0200 (CEST) From: Richard Genoud To: Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal Cc: u-boot@lists.denx.de, Richard Genoud Subject: [PATCH 17/17] fs/squashfs: implement exists() function Date: Wed, 14 Oct 2020 10:06:22 +0200 Message-Id: <20201014080622.14970-18-richard.genoud@posteo.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201014080622.14970-1-richard.genoud@posteo.net> References: <20201014080622.14970-1-richard.genoud@posteo.net> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean This permits to find a file and use the distro_bootcmd Signed-off-by: Richard Genoud --- fs/fs.c | 2 +- fs/squashfs/sqfs.c | 38 ++++++++++++++++++++++++++++++++++++++ include/squashfs.h | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/fs/fs.c b/fs/fs.c index fb27c910d4f..7a4020607a3 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -296,7 +296,7 @@ static struct fstype_info fstypes[] = { .size = sqfs_size, .close = sqfs_close, .closedir = sqfs_closedir, - .exists = fs_exists_unsupported, + .exists = sqfs_exists, .uuid = fs_uuid_unsupported, .write = fs_write_unsupported, .ln = fs_ln_unsupported, diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 82bf1faf25f..6952fc2b53e 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -1627,6 +1627,44 @@ free_strings: return ret; } +int sqfs_exists(const char *filename) +{ + struct fs_dir_stream *dirsp = NULL; + struct squashfs_dir_stream *dirs; + char *dir, *file; + struct fs_dirent *dent; + int ret; + + sqfs_split_path(&file, &dir, filename); + /* + * sqfs_opendir will uncompress inode and directory tables, and will + * return a pointer to the directory that contains the requested file. + */ + ret = sqfs_opendir(dir, &dirsp); + if (ret) { + ret = -EINVAL; + goto free_strings; + } + + dirs = (struct squashfs_dir_stream *)dirsp; + + while (!sqfs_readdir(dirsp, &dent)) { + ret = strcmp(dent->name, file); + if (!ret) + break; + free(dirs->entry); + dirs->entry = NULL; + } + + sqfs_closedir(dirsp); + +free_strings: + free(dir); + free(file); + + return ret == 0; +} + void sqfs_close(void) { free(ctxt.sblk); diff --git a/include/squashfs.h b/include/squashfs.h index 819cf8c2da8..7489eefa1f2 100644 --- a/include/squashfs.h +++ b/include/squashfs.h @@ -19,6 +19,7 @@ int sqfs_probe(struct blk_desc *fs_dev_desc, int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len, loff_t *actread); int sqfs_size(const char *filename, loff_t *size); +int sqfs_exists(const char *filename); void sqfs_close(void); void sqfs_closedir(struct fs_dir_stream *dirs);