From patchwork Tue Sep 11 06:59:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 968451 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Wedq6znK"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 428blG0nkKz9rxp for ; Tue, 11 Sep 2018 17:14:49 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2081BC21EE3; Tue, 11 Sep 2018 07:06:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id EAD8BC21E85; Tue, 11 Sep 2018 07:00:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF09CC21E44; Tue, 11 Sep 2018 07:00:17 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 346FFC21DD9 for ; Tue, 11 Sep 2018 07:00:08 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id x26-v6so11744938pge.12 for ; Tue, 11 Sep 2018 00:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X+AcmSTaCYGaZ32A/XhLqf/ypKyPsh9GyVKF6+XU8d8=; b=Wedq6znKQOLL5UcKLpp6LwYOjoZZEg4SROSAIEPloVo+CorrQvajM88w6cqIaiPOwf h917e8hlA2uzC55JIe3E1+qIgIspPFsbX2HnBYtTsaFAjYOpgZ53e2TDEh9/vbimhqJD d0Muc73JUYBYfcrSsFcKfFJY9Q/aC2E5MhCFQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X+AcmSTaCYGaZ32A/XhLqf/ypKyPsh9GyVKF6+XU8d8=; b=h2ueSVrgkbyFKYiDgUszF29pmwqVpEASBJvxR887JjaOi7cr9thv/DMv7n1WlDNyAE pXYPCL2h+sl1Xjrog6OIVajmoRBYy6NbiYd4dsfu2FtL3mgFtBheNr6dCgPCfS0rPU/o ZMDVB4kG+rzy7n3W/DUywQdt52LzpFnbUvTN4HGgtPJne+JGRniiJqRAURmp+dxVAsWF Z6QjHyyeTlTAgD3Idu+/vsAMx3rZlHNJfzTI5AwpHQthA3fvhjIlvl0tMXqeaC9sC8Ws BREfJA6mBXUcNwi366t5hiB9cag4AQHl3XN2KaKXHMiBeEqHHodBb/pDn+3eXc1a3RFd mybQ== X-Gm-Message-State: APzg51D3rbAOGoWYPtbqk2iin23LeU3UgzVaH0BUFr9qAHE8NIwD2HSQ Jz4adsBgTA98ZMk9XjVtNRLEnQ== X-Google-Smtp-Source: ANB0VdYNOCWU55MJllUDKZyPPonlUZTFXGb0yLubu7crPTaMYOGS2Ktf3ChELLRQMGtVRGbnMewEVg== X-Received: by 2002:a63:f244:: with SMTP id d4-v6mr26181155pgk.2.1536649206768; Tue, 11 Sep 2018 00:00:06 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d66-v6sm26467541pfd.121.2018.09.11.00.00.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 00:00:06 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:13 +0900 Message-Id: <20180911065922.19141-18-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180911065922.19141-1-takahiro.akashi@linaro.org> References: <20180911065922.19141-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 17/26] fs: add unlink interface X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: AKASHI Takahiro "unlink" interface is added to file operations. This is a preparatory change as unlink support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro --- fs/fs.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/fs.h | 12 ++++++++++++ 2 files changed, 52 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 099540f38a10..ba9a65166c70 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -105,6 +105,11 @@ static inline int fs_opendir_unsupported(const char *filename, return -EACCES; } +static inline int fs_unlink_unsupported(const char *filename) +{ + return -1; +} + static inline int fs_mkdir_unsupported(const char *dirname) { return -1; @@ -147,6 +152,7 @@ struct fstype_info { int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp); /* see fs_closedir() */ void (*closedir)(struct fs_dir_stream *dirs); + int (*unlink)(const char *filename); int (*mkdir)(const char *dirname); }; @@ -173,6 +179,7 @@ static struct fstype_info fstypes[] = { .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, + .unlink = fs_unlink_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 @@ -193,6 +200,7 @@ static struct fstype_info fstypes[] = { #endif .uuid = ext4fs_uuid, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -210,6 +218,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_sandbox, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -227,6 +236,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -244,6 +254,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = btrfs_uuid, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, #endif @@ -260,6 +271,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, }, }; @@ -510,6 +522,19 @@ void fs_closedir(struct fs_dir_stream *dirs) fs_close(); } +int fs_unlink(const char *filename) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->unlink(filename); + + fs_type = FS_TYPE_ANY; + fs_close(); + + return ret; +} int fs_mkdir(const char *dirname) { @@ -727,6 +752,21 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } +int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype) +{ + if (argc != 4) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + if (fs_unlink(argv[3])) + return 1; + + return 0; +} + int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype) { diff --git a/include/fs.h b/include/fs.h index fbaee154dd0d..aa3604db8dc4 100644 --- a/include/fs.h +++ b/include/fs.h @@ -155,6 +155,16 @@ struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); */ void fs_closedir(struct fs_dir_stream *dirs); +/* + * fs_unlink - delete a file or directory + * + * If a given name is a directory, it will be deleted only if it's empty + * + * @filename: Name of file or directory to delete + * @return 0 on success, -1 on error conditions + */ +int fs_unlink(const char *filename); + /* * fs_mkdir - Create a directory * @@ -177,6 +187,8 @@ int file_exists(const char *dev_type, const char *dev_part, const char *file, int fstype); int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype); +int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype); int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype);