From patchwork Fri Jul 20 02:57:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142424 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2443505ljj; Thu, 19 Jul 2018 20:07:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdP6w/hOo7gvsUykMfsYmKdp/6jo+OyEtUA5+2OUQTC0u04saCLekfxGdlsWcklnCHvReA+ X-Received: by 2002:a50:ca83:: with SMTP id x3-v6mr548943edh.287.1532056078589; Thu, 19 Jul 2018 20:07:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532056078; cv=none; d=google.com; s=arc-20160816; b=jjTMbflyF/fIs+ARMtL7OjaoT3p6FXychZk8Un8DwRULKNTh4dzmRq7mJyBRFwdRPn HPEzmYG5MOkcL/WYSTLu0PlqeL4WKORpr3G2gMMkioDfhqixFsQflUaKtndiq0mJD+5H K7EaQ1jzB+KeKCUC3TAWe+L7CG/vSuUMA6XuDXAYYzWx9toMFIVE5xPjRUIoXjSy804m Oz5fvbzAPoidRHR1IjuYc2AGvMKcn8SYxF0wjnXuhrB5mkQzAm1peOrj+etreZYEeBj3 +OGZAx52426XdduRW24v0VdCgww2AoWjbDNRWYV6ou01irwKMATHiz/r13Jf9TUtaHmX 9j6Q== 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:arc-authentication-results; bh=blCpFRpjHqLyNRkrQX8KtuULls/tMnztYzLLtCYGQZ4=; b=QPpdaH9hallRPtKYoIGj2jF93A92GRA+ZeE0ptbxuMutQAtoOvZd97I/n+H1WdFMWK WKshAILqh2D8EJdb6CNMqtoDNUzrfYLnehU+k2v/Q6SSBZU1vhYx+Uig8AEmNc7bnRHx kVMKSpTOMRSToyxGJfuevDkai2FFvZUtxVkP+zarqgQW2U7HuIqYNUeFk+pbY+LipH2+ RhIbL71/Q/CRYmtQvRii3XK0TmXIXxFXbOSaCCfNzrotxQZp5sHLlPgWkhBbdHsNUNG1 Qyp+hUGpQlEcCpcEBf8TEw+zxVLcQdgOAWjtP/QUFtUp/WRbmSBfbek6d+UgU9+HHZhe kr5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fD5YEPIx; 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 y25-v6si928756edl.232.2018.07.19.20.07.58; Thu, 19 Jul 2018 20:07:58 -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=fD5YEPIx; 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 3C277C21E53; Fri, 20 Jul 2018 03:04:04 +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 E1FF5C21DFB; Fri, 20 Jul 2018 03:04:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 80204C21DA6; Fri, 20 Jul 2018 02:58:15 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) by lists.denx.de (Postfix) with ESMTPS id EF65AC21DD9 for ; Fri, 20 Jul 2018 02:58:11 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id 94-v6so4505831ple.12 for ; Thu, 19 Jul 2018 19:58:11 -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=xCHFCNy+zasmae9N7/EQwJqvmGAUCxFk5LejrhkFu70=; b=fD5YEPIxthp1qAMWAiJlzqY3fGZj2bp0KTlrjvwEwbb6eFwj7r/TZ1XpoOqk/HDbGh uq7CR85gIMBaz2XGMOceJrAo9Ksn2LBw3jFq6UzN8mwNBAJqpkV8ud6Gbrep2yc6Yomk rYfTaEBPY7Byw/CcB3whuVyoLS2MfNAl3Tq0s= 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=xCHFCNy+zasmae9N7/EQwJqvmGAUCxFk5LejrhkFu70=; b=BG0py5dhs5qFZYDv5kJ7P66xUBmdafazpB8TpeIBpT3K+R6vRt4LpHXHxOmddHU7OQ axL2aUs3bsnTl2adrOrFduX7vgGx0hbTrbnQeY7mmVydozUpnvIOT+JbuSpzm5G/qlFJ wyEyFOeaZUeNyBHnI9e5Tv7j+RpLzJlBqF54tk5vUSAI7koHt5gsZkU6BVuwumi4QCXt KyQV1GS41+RG56Ya9t2pEKpSv6IIp8R5NEkod2vKrGXgsqv8tkaHdtQ3nyFLEIId5OOJ kmwWPDS+BSeglO5LMwAmdYEMH+4YqTFo7Eo+TajDYREVjtZA8o2Xvok1ap5V5B6F3Otc MWhA== X-Gm-Message-State: AOUpUlGapS3rtiUGtAGGHQOW1U/+ZzWt4TF9ceWCmWM92/51XCCjLbjB 66fAfd92e9usF2h/nQGEY/bg7w== X-Received: by 2002:a17:902:7287:: with SMTP id d7-v6mr320700pll.54.1532055490640; Thu, 19 Jul 2018 19:58:10 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z90-v6sm760840pfk.85.2018.07.19.19.58.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:10 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:17 +0900 Message-Id: <20180720025723.6736-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180720025723.6736-1-takahiro.akashi@linaro.org> References: <20180720025723.6736-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH 11/17] fs: add mkdir 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" "mkdir" interface is added to file operations. This is a preparatory change as mkdir support for FAT file system will be added in next patch. Signed-off-by: AKASHI Takahiro --- fs/fs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/fs.h | 10 ++++++++++ 2 files changed, 55 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 33808d549e..3cb6b21fe9 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_mkdir_unsupported(const char *dirname) +{ + return -1; +} + struct fstype_info { int fstype; char *name; @@ -142,6 +147,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 (*mkdir)(const char *dirname); }; static struct fstype_info fstypes[] = { @@ -165,6 +171,7 @@ static struct fstype_info fstypes[] = { .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 @@ -185,6 +192,7 @@ static struct fstype_info fstypes[] = { #endif .uuid = ext4fs_uuid, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_SANDBOX @@ -201,6 +209,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_sandbox, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_CMD_UBIFS @@ -217,6 +226,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_BTRFS @@ -233,6 +243,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = btrfs_uuid, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, #endif { @@ -248,6 +259,7 @@ static struct fstype_info fstypes[] = { .write = fs_write_unsupported, .uuid = fs_uuid_unsupported, .opendir = fs_opendir_unsupported, + .mkdir = fs_mkdir_unsupported, }, }; @@ -498,6 +510,20 @@ void fs_closedir(struct fs_dir_stream *dirs) } +int fs_mkdir(const char *dirname) +{ + int ret; + + struct fstype_info *info = fs_get_info(fs_type); + + ret = info->mkdir(dirname); + + fs_type = FS_TYPE_ANY; + fs_close(); + + return ret; +} + int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], int fstype) { @@ -700,3 +726,22 @@ int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } +int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], + int fstype) +{ + int ret; + + if (argc != 4) + return CMD_RET_USAGE; + + if (fs_set_blk_dev(argv[1], argv[2], fstype)) + return 1; + + ret = fs_mkdir(argv[3]); + if (ret) { + printf("** Unable to create a directory \"%s\" **\n", argv[3]); + return 1; + } + + return 0; +} diff --git a/include/fs.h b/include/fs.h index 163da103b4..fbaee154dd 100644 --- a/include/fs.h +++ b/include/fs.h @@ -155,6 +155,14 @@ struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs); */ void fs_closedir(struct fs_dir_stream *dirs); +/* + * fs_mkdir - Create a directory + * + * @filename: Name of directory to create + * @return 0 on success, -1 on error conditions + */ +int fs_mkdir(const char *filename); + /* * Common implementation for various filesystem commands, optionally limited * to a specific filesystem type via the fstype parameter. @@ -169,6 +177,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_mkdir(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