summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2019-02-13 12:15:26 +0100
committerTom Rini <trini@konsulko.com>2019-04-09 20:04:03 -0400
commitaaa12157c7d22132688ae97dcb35fc37f9ae88d5 (patch)
tree47db5d6ec45fe2ea156277afd48bf2f7b0c5e9b4
parent5efc0686eebc0c0daabfbfc2c403f8251b468526 (diff)
downloadu-boot-aaa12157c7d22132688ae97dcb35fc37f9ae88d5.tar.gz
fs: Add a new command to create symbolic links
The command line is: ln <interface> <dev[:part]> target linkname Currently symbolic links are supported only in ext4 and only if the option CMD_EXT4_WRITE is enabled. Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Tom Rini <trini@konsulko.com>
-rw-r--r--cmd/fs.c14
-rw-r--r--fs/fs.c44
-rw-r--r--include/fs.h2
3 files changed, 60 insertions, 0 deletions
diff --git a/cmd/fs.c b/cmd/fs.c
index 94467671be..aaafbf9b52 100644
--- a/cmd/fs.c
+++ b/cmd/fs.c
@@ -76,6 +76,20 @@ U_BOOT_CMD(
" device type 'interface' instance 'dev'."
)
+static int do_ln_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
+ char * const argv[])
+{
+ return do_ln(cmdtp, flag, argc, argv, FS_TYPE_ANY);
+}
+
+U_BOOT_CMD(
+ ln, 5, 1, do_ln_wrapper,
+ "Create a symbolic link",
+ "<interface> <dev[:part]> target linkname\n"
+ " - create a symbolic link to 'target' with the name 'linkname' on\n"
+ " device type 'interface' instance 'dev'."
+)
+
static int do_fstype_wrapper(cmd_tbl_t *cmdtp, int flag, int argc,
char * const argv[])
{
diff --git a/fs/fs.c b/fs/fs.c
index c5c35ebf5f..736ebef4a9 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -90,6 +90,11 @@ static inline int fs_write_unsupported(const char *filename, void *buf,
return -1;
}
+static inline int fs_ln_unsupported(const char *filename, const char *target)
+{
+ return -1;
+}
+
static inline void fs_close_unsupported(void)
{
}
@@ -154,6 +159,7 @@ struct fstype_info {
void (*closedir)(struct fs_dir_stream *dirs);
int (*unlink)(const char *filename);
int (*mkdir)(const char *dirname);
+ int (*ln)(const char *filename, const char *target);
};
static struct fstype_info fstypes[] = {
@@ -181,6 +187,7 @@ static struct fstype_info fstypes[] = {
.opendir = fat_opendir,
.readdir = fat_readdir,
.closedir = fat_closedir,
+ .ln = fs_ln_unsupported,
},
#endif
@@ -197,8 +204,10 @@ static struct fstype_info fstypes[] = {
.read = ext4_read_file,
#ifdef CONFIG_CMD_EXT4_WRITE
.write = ext4_write_file,
+ .ln = ext4fs_create_link,
#else
.write = fs_write_unsupported,
+ .ln = fs_ln_unsupported,
#endif
.uuid = ext4fs_uuid,
.opendir = fs_opendir_unsupported,
@@ -222,6 +231,7 @@ static struct fstype_info fstypes[] = {
.opendir = fs_opendir_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .ln = fs_ln_unsupported,
},
#endif
#ifdef CONFIG_CMD_UBIFS
@@ -240,6 +250,7 @@ static struct fstype_info fstypes[] = {
.opendir = fs_opendir_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .ln = fs_ln_unsupported,
},
#endif
#ifdef CONFIG_FS_BTRFS
@@ -258,6 +269,7 @@ static struct fstype_info fstypes[] = {
.opendir = fs_opendir_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .ln = fs_ln_unsupported,
},
#endif
{
@@ -275,6 +287,7 @@ static struct fstype_info fstypes[] = {
.opendir = fs_opendir_unsupported,
.unlink = fs_unlink_unsupported,
.mkdir = fs_mkdir_unsupported,
+ .ln = fs_ln_unsupported,
},
};
@@ -602,6 +615,22 @@ int fs_mkdir(const char *dirname)
return ret;
}
+int fs_ln(const char *fname, const char *target)
+{
+ struct fstype_info *info = fs_get_info(fs_type);
+ int ret;
+
+ ret = info->ln(fname, target);
+
+ if (ret < 0) {
+ printf("** Unable to create link %s -> %s **\n", fname, target);
+ ret = -1;
+ }
+ fs_close();
+
+ return ret;
+}
+
int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
int fstype)
{
@@ -840,3 +869,18 @@ int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
return 0;
}
+
+int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+ int fstype)
+{
+ if (argc != 5)
+ return CMD_RET_USAGE;
+
+ if (fs_set_blk_dev(argv[1], argv[2], fstype))
+ return 1;
+
+ if (fs_ln(argv[3], argv[4]))
+ return 1;
+
+ return 0;
+}
diff --git a/include/fs.h b/include/fs.h
index aa3604db8d..6854597700 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -191,6 +191,8 @@ 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);
+int do_ln(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+ int fstype);
/*
* Determine the UUID of the specified filesystem and print it. Optionally it is