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: 146416 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3321481ljw; Tue, 11 Sep 2018 00:12:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZkjOxac0EpU2VN2+eCwxFhXHC+wkKlYZi0J+ko94nLmUo/60XoV42pOTVrEdYRg18gnLt6 X-Received: by 2002:a50:9b5c:: with SMTP id a28-v6mr26774953edj.167.1536649946046; Tue, 11 Sep 2018 00:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649946; cv=none; d=google.com; s=arc-20160816; b=DqQPpB3ZCKwPTVKeXD/8GiMw5BPromE5+pTIQ1yL+qLzswBQJrGnI/O9MCxW4Ehfx6 3EDNXm1FSYY4pkrejwZbOMal/TnQpxSv9G+1A9QQxjQBiws54g7gbNt+Fn2xPG5rU1RH RyEmTStmVfnCr8tVMfueHQWZDF2//RQjFmFpbzJlZAFyX88U2P6mbgjhhKc3C0zHWQ/2 4QEMtVtZUpKw3gCxUTnSLbMkNbU6JCBD3hgofYak71+fDVo6Z5skSOzBxj8FuRFGlsWY 0BauHRBprFiIZImjkqGHhsKH/YbTSZbyQ33ewt1LnFlzM9yjKyyEkgeEFis82tCpGNS2 P79Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature; bh=js2Sg93crJS4pFuBlLMiX7ciQ5A9G2FaiUcP+8DcQlY=; b=XiOhFo93PQUQAOGybrc+rCQINDX4OtJ0SkERJN+Y9zZhRvU/2DTTbwSglp+wOCZ+ae xlHGYdUscUygXW/2h06GmBYkiBOH1mH4A+CibJLL8CIBhbH6N6l7cRh9QwhDBVbo5Jgj tB/h54c5bSUCVuCfTLNOo4fA9lof4drDruK1TqtmQW9NUC+VZUWQG0zEA7js0KCAuuvM nWTSvon3QSNgrubjaapsChituEr3hko8cVwP6xHTcehmV2Mwu63BWjkjXlL82Ap44onD fN1n/K4aPqHrKo7h6TKBBjTdSP+k1jzFdu84pokPzImSFeErPDUGJXhFwaIZeKFVaAch hl5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wedq6znK; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id t15si197606edw.353.2018.09.11.00.12.25; Tue, 11 Sep 2018 00:12:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wedq6znK; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 8E6A3C21ECC; Tue, 11 Sep 2018 07:06:28 +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-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);