From patchwork Tue Jan 29 13:40:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 1032782 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=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=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="G2lWG49P"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43pnhD641bz9sDX for ; Wed, 30 Jan 2019 00:41:00 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 5ED14C21DA2; Tue, 29 Jan 2019 13:40:32 +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=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 7283CC21E34; Tue, 29 Jan 2019 13:40:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B6267C21E08; Tue, 29 Jan 2019 13:40:23 +0000 (UTC) Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lists.denx.de (Postfix) with ESMTPS id 1F028C21E49 for ; Tue, 29 Jan 2019 13:40:22 +0000 (UTC) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x0TDeIOL123346; Tue, 29 Jan 2019 07:40:18 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1548769218; bh=0ZHhCBxskjHAduHzOuYmGBol3ooH78pNhHYaT4c+BG8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=G2lWG49PM+aYuVaPZUThJwIkb3gKiJxk159Z1qCx8zfs1YGDOFUd7HkTL9bF4+2Ng hSQaVBTJLwF/PRNhjHqFcdnlTqmkhEcQuuh0hskP8U0vraWQ5YA1lLKNELG3TwlfBp eoZEZyKyhch8jIOp0L1lllOcgTDKnr+JCQp7SBf0= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x0TDeIxs099665 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 Jan 2019 07:40:18 -0600 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Tue, 29 Jan 2019 07:40:18 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Tue, 29 Jan 2019 07:40:18 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id x0TDeHjk023736; Tue, 29 Jan 2019 07:40:17 -0600 From: Jean-Jacques Hiblot To: Date: Tue, 29 Jan 2019 14:40:11 +0100 Message-ID: <20190129134011.30407-4-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190129134011.30407-1-jjhiblot@ti.com> References: <20190129134011.30407-1-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: Heinrich Schuchardt , Alexander Graf , u-boot@lists.denx.de, Joe Hershberger Subject: [U-Boot] [PATCH v1 3/3] fs: Add a new command to create symbolic links 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The command line is: ln 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 --- cmd/fs.c | 14 ++++++++++++++ fs/fs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 2 ++ 3 files changed, 60 insertions(+) diff --git a/cmd/fs.c b/cmd/fs.c index 8064a1c84d..ba0e08cd12 100644 --- a/cmd/fs.c +++ b/cmd/fs.c @@ -74,6 +74,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", + " 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 7fd22101ef..953a38dadc 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 #ifdef CONFIG_FS_EXT4 @@ -196,8 +203,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, @@ -221,6 +230,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 @@ -239,6 +249,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 @@ -257,6 +268,7 @@ static struct fstype_info fstypes[] = { .opendir = fs_opendir_unsupported, .unlink = fs_unlink_unsupported, .mkdir = fs_mkdir_unsupported, + .ln = fs_ln_unsupported, }, #endif { @@ -274,6 +286,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) { @@ -838,3 +867,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