All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akashi, Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 17/26] fs: add unlink interface
Date: Tue, 11 Sep 2018 15:59:13 +0900	[thread overview]
Message-ID: <20180911065922.19141-18-takahiro.akashi@linaro.org> (raw)
In-Reply-To: <20180911065922.19141-1-takahiro.akashi@linaro.org>

From: AKASHI Takahiro <takahiro.akashi@linaro.org>

"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 <takahiro.akashi@linaro.org>
---
 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);
 
-- 
2.18.0

  parent reply	other threads:[~2018-09-11  6:59 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11  6:58 [U-Boot] [PATCH v3 00/26] subject: fs: fat: extend FAT write operations Akashi, Takahiro
2018-09-11  6:58 ` [U-Boot] [PATCH v3 01/26] fs: fat: guard the content of include/fat.h Akashi, Takahiro
2018-09-11 10:12   ` Alexander Graf
2018-09-12  0:53     ` Akashi, Takahiro
2018-09-12  5:41       ` Alexander Graf
2018-09-12  6:55   ` [U-Boot] [PATCH v3.1 " Akashi, Takahiro
2018-09-23 14:42     ` Alexander Graf
2018-09-25  4:54       ` Akashi, Takahiro
2018-09-11  6:58 ` [U-Boot] [PATCH v3 02/26] fs: fat: extend get_fs_info() for write use Akashi, Takahiro
2018-09-11  6:58 ` [U-Boot] [PATCH v3 03/26] fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve() Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 04/26] fs: fat: assure iterator's ->dent belongs to ->clust Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 05/26] Revert "fs: fat: cannot write to subdirectories" Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 06/26] fs: fat: check and normalize file name Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 07/26] fs: fat: write returns error code instead of -1 Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 08/26] fs: fat: support write with sub-directory path Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 09/26] fs: fat: refactor write interface for a file offset Akashi, Takahiro
2019-03-12  8:41   ` [U-Boot] [BUG] cb8af8af5ba0 "fs: fat: support write with non-zero offset" fatwrite followed by fatload and then cmp fails Faiz Abbas
2019-03-13 17:11     ` Rizvi, Mohammad Faiz Abbas
2019-03-13 17:25       ` Tom Rini
2019-03-18  1:42     ` Akashi, Takahiro
2019-03-18  1:44       ` Tom Rini
2019-03-18  1:57         ` Akashi, Takahiro
2019-03-18  1:59           ` Tom Rini
2019-03-21  6:50             ` Faiz Abbas
2019-03-22  9:13               ` Faiz Abbas
2018-09-11  6:59 ` [U-Boot] [PATCH v3 10/26] fs: fat: support write with non-zero offset Akashi, Takahiro
2018-09-11 11:09   ` Alexander Graf
2018-09-12  2:14     ` Akashi, Takahiro
2018-09-12  5:42       ` Alexander Graf
2018-10-15 11:42   ` Jean-Jacques Hiblot
2018-10-31 10:00     ` Clément Péron
2018-10-31 12:22       ` Alexander Graf
2018-10-31 20:54         ` Heinrich Schuchardt
2018-11-01  5:11           ` AKASHI Takahiro
2018-11-05 16:44             ` Clément Péron
2019-02-25 18:20   ` [U-Boot] [BUG] cb8af8af5ba0 "fs: fat: support write with non-zero offset" leads to link error Heinrich Schuchardt
2018-09-11  6:59 ` [U-Boot] [PATCH v3 11/26] cmd: fat: add offset parameter to fatwrite Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 12/26] fs: add mkdir interface Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 13/26] fs: fat: remember the starting cluster number of directory Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 14/26] fs: fat: support mkdir Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 15/26] cmd: fat: add fatmkdir command Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 16/26] efi_loader: file: support creating a directory Akashi, Takahiro
2018-09-11  6:59 ` Akashi, Takahiro [this message]
2018-09-11  6:59 ` [U-Boot] [PATCH v3 18/26] fs: fat: support unlink Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 19/26] cmd: fat: add fatrm command Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 20/26] efi_loader: implement a file delete Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 21/26] fs-test: fix false positive error at Test Case 12 Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 22/26] fs-test: update the test result as of v2018.09 Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 23/26] test/py: convert fs-test.sh to pytest Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 24/26] test/py: fs: add extended write operation test Akashi, Takahiro
2018-09-11  6:59 ` [U-Boot] [PATCH v3 25/26] test/py: fs: add fstest/mkdir test Akashi, Takahiro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180911065922.19141-18-takahiro.akashi@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.