From patchwork Tue Sep 4 07:49:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 145866 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3370413ljw; Tue, 4 Sep 2018 01:00:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZHsFJN15574vo/W/RdS7yxTvv5ekuZu5WV0iXGjbmmY5U47qBmm/XO4fqTqe70lL2JFVGk X-Received: by 2002:aa7:c314:: with SMTP id l20-v6mr34781168edq.53.1536048046874; Tue, 04 Sep 2018 01:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536048046; cv=none; d=google.com; s=arc-20160816; b=yeWlULl02yx4Q/gt4Uuz9D35pqTDrVV19QWEV7BzAARG5SpV0vdlK7VCK8Riag9xwj 47WVQIXjVEyQ3jOpCCqnec0qBPbkGY68Q5EwdbEnK8KBeRMtdSMEXfiTyEZm8pKMQsEV VlvbJtzK9WMoC4xEMoRi2YcMaYzVM/cJpLGH/utgGzRBDFR1O1JGbp14JExTmdLDEy0E i+YOQ/SkiCXOJwf+e5CBQIw+8MMVpb4vbMvUBrOVvTprPFX4+FFFK17iYJk2rQvEI61/ frjzO0ddexNyk3Oac9l8vV6th+ieN6aaFp/3cFIwLUd670nt5ulFGEz/oSYpCpQBCO2I C0oA== 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=+R6YZ3duVwlbHQsXGjFxi6nrRVyslT3IBlT1EvdBb2I=; b=DSs5fGKjq/vvoO2RxfXfjW/a62/iSqKuZF8mUtN/l7DtlhR+/dVj1KCkiQ0rK5eYdf DlXaA2K7hI817QpTjcCtGEPlum4fBRettjLrkDP4h1yCa6TH8u0uOORrqX9NmuyOkv+c T7tymzG+DB6dnb8lvCxySYp6V8PyXH+D9o1EeyEXw5LqHv5p3QlShnSf6ThzY4cAi+gn gcC/SWZia0qBSFnLDqKaymsENvny+7H8Mv3Kl+R+UFi4KzgJqWl8fCmk5nSFu2XpvxpH yFKRJE9nJve/vCvCRMYQTMVmI7dZJ6lTMzriYJ533tP5XoSHHnQwL4l1fuILIXLimAxD pj7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JP3YyDuF; 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 k4-v6si717851edr.290.2018.09.04.01.00.46; Tue, 04 Sep 2018 01:00:46 -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=JP3YyDuF; 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 78C14C21E49; Tue, 4 Sep 2018 07:52:41 +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 5D37DC21F2F; Tue, 4 Sep 2018 07:52:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 46CC2C21F24; Tue, 4 Sep 2018 07:52:05 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by lists.denx.de (Postfix) with ESMTPS id 0CDF5C21F05 for ; Tue, 4 Sep 2018 07:52:02 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b11-v6so1289794pfo.3 for ; Tue, 04 Sep 2018 00:52:01 -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=KUbEBLLEiOGSfLLeu3DRSDyelWRj+eLD4n+pf52SbgA=; b=JP3YyDuFnVG5v6YVczvXPg1djkmEnjHi00g8TFmURbSd+XnZxzrsHUSWRp92fT+YXi JjATAgZl1E5YxSAw9LG3XaBC6g4kAYRXf10rTkR3nUJvvypOo4TkHqQOMu3Y963MWubg Grvu7PZwb6wWHlReTwya5wcXEZhX+vomlEX9Q= 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=KUbEBLLEiOGSfLLeu3DRSDyelWRj+eLD4n+pf52SbgA=; b=oBFQ4VWfk8uQyK2EOu9i99OCPB0N/+nFzWxKspGXrGRGxeS4bxEwkKHoyiZTqsqLIL cBKIp2toWYF9Ved5GcpkuR7i++59UXdXcG0Vpu51gwaPo4CgqFP6dhUZV9VFd5IZNyQ/ xXDMyeVc7l4h+L49ZKJWHDAReViJmd05O/uGNPZNl0NC72DEXv7vMSh1F025KE0dHjVF A72EoA0Jzx34HJj5tTemjeKbCaSbvdcCf04RG1ZXPR6O3QFyfB34Wc3mBFr7GJMmd1/z /fPAllFMk9ggUFdg+KRKM7uIg4Xs1sySeaPvtFrqv7z638GLi1WR6kY6Z8xY9xwcJ1Uu yEzQ== X-Gm-Message-State: APzg51Cjso/XOcDRhgv9U2fEOsQfWDnPp7Tlv1s/StwGWbygWi4k0qZj Mkd632sI4A2KYr619AdIQg225Q== X-Received: by 2002:a63:f26:: with SMTP id e38-v6mr29312557pgl.354.1536047520634; Tue, 04 Sep 2018 00:52:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t17-v6sm41515487pfm.138.2018.09.04.00.51.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Sep 2018 00:52:00 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Tue, 4 Sep 2018 16:49:38 +0900 Message-Id: <20180904074948.18146-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180904074948.18146-1-takahiro.akashi@linaro.org> References: <20180904074948.18146-1-takahiro.akashi@linaro.org> Cc: xypron.glpk@gmx.de, agraf@suse.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 13/23] 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 cb68e81cd309..62165d5c5701 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 163da103b472..fbaee154dd0d 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