From patchwork Tue Sep 11 06:59:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 146404 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3314449ljw; Tue, 11 Sep 2018 00:04:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYNYms4n7SIdSn1rWirO6VNrReS28WekudICtlExCwtOaV4yK2vnJU0Ab16c+piGhmrInuu X-Received: by 2002:a50:af03:: with SMTP id g3-v6mr27893923edd.220.1536649444621; Tue, 11 Sep 2018 00:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536649444; cv=none; d=google.com; s=arc-20160816; b=iGUcSo8IGMIUB4r2vDLW8dOUx6pB9DFe4YogZ6wJvUfs85wmCm0Fl+UKyi5HEEmarQ KF78nqxU6Lm/kBxS2sEVZyXNUrFVvQIohV9jTgm/irjL0Dv9Ne07TeFos1uDFWIFEXoT uyCoz/81djpimKELoWFTp2HqjE92gpumwYwZKUZf5JX+V7tRfa3lTEksBC+mofgrBpv9 JQZNOW2nk9S9gjEBeVyJw97T0E3V3SHDgdmgYjTpY0E9eNBe01kx6pPgR/M08ZTmQlAm mAG4S0ua0imLbh0Yh1AOBZlLUCUN+oIJ2tEvRxuqSaa0kXxdJhsGF3VE9E8ZROFw7r3u agSg== 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; bh=/81ZOFY9U7yFQ3Cdf0+/xzBa0GR8zUwPHibd0ViQhpw=; b=MtjDTFgqQEPfttW3VyeJ/Ht419VOmHSTAecNLjS9bndLsTpepC5O+cmm0QP5MFiZKs uDJe3cxW18z589HtvDZebqcdZH9swZg/mFipBdB23/jCzmNOiPgZqw4Oa9b/JwkPSeoU UfX0wm+OF3oRQAlxULsLaEZXce3RVGjRJ4l46A6y5O128WpRs0rqQ+c4Y5LxOn/bv53z +SsUG8QQhuRBas5qbAXcPU83XqnCxX49lieG6X6aPUFw5ULT/J+O5ofv02A6JaL48lG8 E3OEWSRH5KF/uwCJ1zaCnp8m42p2FlLWZThy3jtlcQkyOZVE2h0p72r+Ht28xk+EblNV NeHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=h81WQ6fQ; 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 l8-v6si1726864edb.116.2018.09.11.00.04.04; Tue, 11 Sep 2018 00:04:04 -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=h81WQ6fQ; 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 CE54CC21E62; Tue, 11 Sep 2018 07:02:22 +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 35454C21E7F; Tue, 11 Sep 2018 06:59:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D45CCC21E1A; Tue, 11 Sep 2018 06:59:55 +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 84467C21E89 for ; Tue, 11 Sep 2018 06:59:49 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j8-v6so11740745pff.6 for ; Mon, 10 Sep 2018 23:59:49 -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=AqztbRLDhZ6l8EEhvFlCJvPn1sueBHj4bIuWqsVulIU=; b=h81WQ6fQZKVJtr29NpvuqmDNqzSgJt09h0AAJRkS2A070SLHuUDYedK9TE1C+UrqQh hEl7zSVYsxWm85RkYHMsrH8X0t/WHIIWWFSnmkFMqvldseeIGtN/Uy6altpo/vHWww3W EYBMoj7awwBZ5oYa87ne5s28aaDnSne/ceQic= 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=AqztbRLDhZ6l8EEhvFlCJvPn1sueBHj4bIuWqsVulIU=; b=qHxv6PQ8IUOiysWa2hOMd2oQzauZsc/+WesNvls+H8dpHWiLs+WozJ1bNXJX3Zykxt FvPsM/W2+nUqirV1oeAYGLl1Nmvx0N/DpYEKHYHq49/OpoGXddIRamtmM06gsOq/2/+m k6CuxyY+i4bZIVWzDUfrLMuVX/LyB4cnh3s6BP+/m4072T27CvxfSwqwrXf7LuULG7/d lVqnPmuwqinMjdCm2U+m4/De2gkdZslznIiK3cmy8PHYzUq/i1GA+Dgj1d/CjwL5lgp7 mquJXbVLQU8W5u0mpPi76qf/zT2s26U2qtUxg1TVsCBHvZ2bLGPTIvJaDQ7+63F5p1KH DMFA== X-Gm-Message-State: APzg51BNhwSYdof1i6Zk+HG16j7/lt7he+sV8bGCbUnb1ytumzwrk23K GDqOU9APtAUeVmZ0jnJsc/r+ig== X-Received: by 2002:a63:f111:: with SMTP id f17-v6mr25935109pgi.87.1536649188076; Mon, 10 Sep 2018 23:59:48 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 9-v6sm30006855pfc.20.2018.09.10.23.59.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 23:59:46 -0700 (PDT) From: "Akashi, Takahiro" To: trini@konsulko.com Date: Tue, 11 Sep 2018 15:59:08 +0900 Message-Id: <20180911065922.19141-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180911065922.19141-1-takahiro.akashi@linaro.org> References: <20180911065922.19141-1-takahiro.akashi@linaro.org> Cc: u-boot@lists.denx.de, xypron.glpk@gmx.de, agraf@suse.de Subject: [U-Boot] [PATCH v3 12/26] 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" From: AKASHI Takahiro "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