From patchwork Fri Jul 20 02:57:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142408 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2435574ljj; Thu, 19 Jul 2018 19:57:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeB79EL/8OhUtZizmjvuAkXpFh+XmFD0z61QnK0uJ2XdOf+j2SGPx6slLNxEKNdMTmmvLcc X-Received: by 2002:aa7:c68b:: with SMTP id n11-v6mr538406edq.122.1532055434280; Thu, 19 Jul 2018 19:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055434; cv=none; d=google.com; s=arc-20160816; b=uucwuATWPRnd4Jjt/Erp+qZ6CM7NRVHxVoFhtiu1f4w3T/VNh2M9ihYjznApWPRIiu DYsceiS/jgBP5d1Q9BC6bFXoK3oUuI5C0rfQJ95vOucBngZuSml2NChEAAATEecbBc3U Ti/OwJnlO4Hf5P8gZOAveevy+JlCwOOSXRjavOE8CkDfp/PeHDbDkiw3wpKce6nQ+B5O bkUt69/FCV8xkJYab+8inTfzqi1x/f6gpc08fMuZSht6IAaF9rUaWOTGpH73w+vfzAm8 HB/yyGdzxIrJFcfpUbHIjMWeBu/24LCIw3z7XYUK+/6oScBk3RnUYs8P44sORanLHoOr G8Mg== 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=5a3QemxdnCn+932RjlTubbMVKUitHDRdXaeMl7cnQWA=; b=RLEDnRCv7qcC6vE1uPGvT0njuNX0AdGvaG1qFozs+Z8wkwtblhu8DzQWBVkvexnsv3 mPKWOjZJimuPnepI7GLZbZJZAG/lZzvuwbopBehXc09zHnaJx5UrI9l4Jyi5ISDAt1Sk cVMifgQMvdUhfkLCn6ymvVESOPlFPBZiWuK8LghMnIQ8/cK/Wqrw+R/yEYxTlAFeU45g Dd0dlAfu2rBXcll9zgdc4oSUZ+3ppz9p/rUznnNu+bR8Z5Kh9Vh7v7ux7kOZUKSTXsea UddIkx5iIaSIgtpiJNZ/9t35hsIlR+fzs0+4x75mIHgUkPPWChkDXfLCTTjGhymujT3s ZAeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cTLNZoUf; 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 z29-v6si783061edb.410.2018.07.19.19.57.14; Thu, 19 Jul 2018 19:57:14 -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=cTLNZoUf; 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 C3D49C21D8E; Fri, 20 Jul 2018 02:56:55 +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 0C769C21D9A; Fri, 20 Jul 2018 02:56:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 893C2C21D8E; Fri, 20 Jul 2018 02:56:41 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id 720B7C21E12 for ; Fri, 20 Jul 2018 02:56:40 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id r1-v6so5502651pgp.11 for ; Thu, 19 Jul 2018 19:56:40 -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=lrMaNz7y2TRbSj/lDOe3R42pAyczy7hESeQ3YgYYdNI=; b=cTLNZoUfTwBE40XwQgMVFHD4U0ai4SVP9kSCe7x93TIUTnEmPzDgiNr53v7xRan5LZ I0UY6OjmO90lr6DOPlg75FKUuNW1+Z48umPVjR3fXt8a/hsPEgEvU8rG4ZNXiy5KUN/P jS0+Vp2h5cutFwpO6oN/Dody+jab2MHqlY3Ec= 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=lrMaNz7y2TRbSj/lDOe3R42pAyczy7hESeQ3YgYYdNI=; b=V6Avbnc8ID+kNgJC759SVJwRN8FTTmBDC9ejOGwf+P1IBoUf8MZNCshkFxftvTjCuU JFtVUvPSb/RDDDAuOZSLmd1q+hQPimz0fX5YOdHWaK3RB7M2LbBnC9NYYmhl3g+a5ePv lb8WyUI+n433XfmJ9yYB+tg9UJLV2WyOlDe0JEywP/L+wzgRBpR90wy8ifo0a3pSv+rr 0U72cfos9XpXv9X4uFvHEOobZ9zPjRqgM5/UJEkD20PsX9dmAd1xsHJ8+JXG5RRFz+QM J7KvT1eMwo80TLvuJeLNGNR058USFnKaCvvVCT4p096OHOHcrkI1obaPill8Dis7M6Sz CjrQ== X-Gm-Message-State: AOUpUlEGUnBv2xNmGVF+bAiayTISjFkUS2vx/pOrNpAd/3WbAVNILAXw NZX3HzN+bYxnoKUkuLPiKbttaw== X-Received: by 2002:a62:bd4:: with SMTP id 81-v6mr294151pfl.67.1532055398994; Thu, 19 Jul 2018 19:56:38 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x25-v6sm477133pgv.63.2018.07.19.19.56.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:56:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:07 +0900 Message-Id: <20180720025723.6736-2-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 01/17] fs: fat: extend get_fs_info() for write use 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" get_fs_info() was introduced in major re-work of read operation by Rob. We want to reuse this function in write operation by extending it with additional members in fsdata structure. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 3 +++ include/fat.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 4efe8a3eda..b48f48a751 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -556,6 +556,9 @@ static int get_fs_info(fsdata *mydata) return ret; } + mydata->bs_total_sect = bs.total_sect; + mydata->bs_fats = bs.fats; + if (mydata->fatsize == 32) { mydata->fatlength = bs.fat32_length; } else { diff --git a/include/fat.h b/include/fat.h index 09e1423685..0c88b59a4a 100644 --- a/include/fat.h +++ b/include/fat.h @@ -173,6 +173,8 @@ typedef struct { int fatbufnum; /* Used by get_fatent, init to -1 */ int rootdir_size; /* Size of root dir for non-FAT32 */ __u32 root_cluster; /* First cluster of root dir for FAT32 */ + __u32 bs_total_sect; /* Boot sector's number of sectors */ + __u8 bs_fats; /* Boot sector's number of FATs */ } fsdata; static inline u32 clust_to_sect(fsdata *fsdata, u32 clust) From patchwork Fri Jul 20 02:57: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: 142409 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2435992ljj; Thu, 19 Jul 2018 19:57:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLdOZ5YnzW/EMaNCBRXDcf8N++56iyZp3xGFkZCuvMEUNaMEEX744QIoAviC2pggqj1eLT X-Received: by 2002:a50:8561:: with SMTP id 88-v6mr521830edr.181.1532055468711; Thu, 19 Jul 2018 19:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055468; cv=none; d=google.com; s=arc-20160816; b=DGAHZe+1heFJc7uEhZgGOf06esYZEfLPPQjy4MNfx7BnuEHUhM4zSZi0B9jKg2qvp+ H1W/ofchKCIj5B+f3SqtYlSMJMB7YU4X10g5zuJxOYM+i35KU5lExpv8VK3crkPpkQCb RbL0f0HHVHg2y3/zAAmaTO1nca+aVA4kXZzNkypUIByxdmU0GB2lIypVzKYjx55nd5JD EqFTrvGdfNJHguQMda6dUdskkDqZtSqqwZGk764HppOevlGIirJ0J7MbDdpevGf6fspr r8f0o6P54R44u06l25dgPf4uP+HRXExYX9tOBzPim/njEYnlCZYTlioT2VJ/YJdlnJfx e68g== 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=piN0fj8t1rzjmbinSFk+f7toRy/sjm1tZpDbc8nih+k=; b=NigvIkw1r45n6j9Q7xdAOf35umZSiDv/e7DsHltihAt05OpGfYEpi5VttOzD0cp156 6zpGwr1VZnEPx3M3KYOOQgumMSJPSDDa02zMSDCpmWE+j1xz/EiJ03TM55ZurXai23+b 0BPQ/qeHph8WVkqJaLfPTPowvf2esdFr1O+5Y/83KtpzJ32C6M0cKeiwXoPveI/pemhn 6ZZvpxd5uveLZZDe4piuLGr8Q4LXBlPcRX3/f5HPGkzf8SdthOwxXIX4lmICVWuVrjvi CSzwL2U4CxH/8yb6L2150UWp9/FddwXhReVygS6GdTHzqgpc2WcRg2XVXnG+JW21GTMg gxIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=M11GzLof; 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 w25-v6si1339421edl.174.2018.07.19.19.57.48; Thu, 19 Jul 2018 19:57:48 -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=M11GzLof; 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 5A5EDC21D4A; Fri, 20 Jul 2018 02:57:12 +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_H2, 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 6BE30C21E26; Fri, 20 Jul 2018 02:56:55 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 26127C21E07; Fri, 20 Jul 2018 02:56:53 +0000 (UTC) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by lists.denx.de (Postfix) with ESMTPS id 80415C21E02 for ; Fri, 20 Jul 2018 02:56:52 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id r1-v6so5503059pgp.11 for ; Thu, 19 Jul 2018 19:56:52 -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=08IvreLHSrgS9LZ/K9Zw3LEmGXjsS+QfeRN8njFFcg4=; b=M11GzLofH23W8kHcBM4yE/38ndQS9V97fgl72cOG6eII30ONubZ51/XgLxkduB4bnP xbJx7KFso2qSbqaJMkbL8pYmDLAFLv0Oek4geu+UyZVSTo0iEs6nIqHCACAkjsjPQh5d wU+5NK3rDXrsbcxStylzCHnt99D2dq5hVIs+w= 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=08IvreLHSrgS9LZ/K9Zw3LEmGXjsS+QfeRN8njFFcg4=; b=aHl6RY6OmNvESt2A6j5hXXV9ARyrpUnEPd59nhSt+hg5sdLTfDV+qoPtJX37xMFEs3 GgHMMT29zdajOGIyeQBDz1S/phikpcGG13NkveP9ieu36HNAbMxQCvTd9ZoX0B46P44T 2aQHrNZbwQVZ3VAQ0qLdPtKa/PIDeZgHgE0wq1BTGYet/Nr/a2THtOl2qtIcg1ujHwyw X4L65Q0+blhHY74KxrWjqwZw8z9dZ7aWi/Fcbq1wLmwtKbCu8YiMKhZ9D8ROlg1zQ0Pg l34bcsbI3jZqHDWvquFSeUZQmBFUKWFTcM52dSUPndRdxCgAUNMxzeCpzDl4Lx/b5S+x bjKA== X-Gm-Message-State: AOUpUlGd71uvkU3h+FqHEet6t8GjOIBqxD5ERl1XKTooupg5SEjcca4e XH4NfOI+No6zMRRF9M9FO6/REw== X-Received: by 2002:a63:1b5c:: with SMTP id b28-v6mr308489pgm.204.1532055411247; Thu, 19 Jul 2018 19:56:51 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d132-v6sm616819pgc.93.2018.07.19.19.56.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:56:50 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:08 +0900 Message-Id: <20180720025723.6736-3-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 02/17] fs: fat: handle "." and ".." of root dir correctly with fat_itr_resolve() 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" FAT's root directory does not have "." nor ".." So care must be taken when scanning root directory with fat_itr_resolve(). Without this patch, any file path starting with "." or ".." will not be resolved at all. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index b48f48a751..fd6523c66b 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -927,6 +927,27 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) while (next[0] && !ISDIRDELIM(next[0])) next++; + if (itr->is_root) { + /* root dir doesn't have "." nor ".." */ + if ((((next - path) == 1) && !strncmp(path, ".", 1)) || + (((next - path) == 2) && !strncmp(path, "..", 2))) { + /* point back to itself */ + itr->clust = itr->fsdata->root_cluster; + itr->dent = NULL; + itr->remaining = 0; + itr->last_cluster = 0; + + if (next[0] == 0) { + if (type & TYPE_DIR) + return 0; + else + return -ENOENT; + } + + return fat_itr_resolve(itr, next, type); + } + } + while (fat_itr_next(itr)) { int match = 0; unsigned n = max(strlen(itr->name), (size_t)(next - path)); From patchwork Fri Jul 20 02:57:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142411 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2436731ljj; Thu, 19 Jul 2018 19:59:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfQeJIV8wvuZ7QVWd54/RXKLN1kZ4F724idmw6ePsvEsbcztUPqS4+lozuZFVx24kwP82su X-Received: by 2002:a50:b56e:: with SMTP id z43-v6mr518700edd.223.1532055544193; Thu, 19 Jul 2018 19:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055544; cv=none; d=google.com; s=arc-20160816; b=ohuvBIqoaz2menBCxV/0aY6FL/LvFTaiuo0blCzl3+WrC5Xx0GTlM519rhg7jd/PEC 8AK4jIf5/B1iuERHwOedHPQaKeFUeuEH+ym5UQTKM1DLXex/SeglZLeFcyFPm1iwiIUe 2cH7o3zCPUS7lOHrjfy9IF9DZyEZ/9NoIu4yHbtawoDcHkDifnpRw8tGD4TEAJ3lvRP9 xRRzViNcw18YYmC124VuPvDWKptTAYNpUENlXdxWcTS1nMl6KlJrSB/7AYoWSGFZTPMi O2PTOab9bzcS577tM+ddHRtzRHDA2vGN1dllHrd1wMlzg9WYwvRQC/FhvXaRd93e6Hmw 6n3g== 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=fyjEkyvREvHbEwNvchgmf7/h3ctDwjQX1OIORAinxbI=; b=YJLOfReA6C8WUMtTHS1K7qQ7t1BE0AcNS535JMx5sRong9Zj1DTe8m7QBQna4lKg7B 7vC3mcgvkIUnouEmZ35pt1SEkCFOQM5zZIxhGW94zQtuD8T/xIpcLUvyKmv5euKjR7GZ am4236VYv1sbh0uJbFR0Qk98HhYFI/FnubtJZu8Pk86bqc6B9+4MUU3Pm6wFdWVuX81j Mi53EdbNY/ZO+xu4SN8c+xHbD2cV9KcmBLdfBcUMgh9Hs7B37sb97W+Fsj7EwWGSZtlP zR3vGR56L/NLsvZQb+VYZeG+WBjj1DnzHpezd/A/2acy3rScXJm4Kvf8/UUNTKA5rq2t YLQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jAIeaLLZ; 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 x21-v6si505885edq.436.2018.07.19.19.59.03; Thu, 19 Jul 2018 19:59: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=jAIeaLLZ; 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 AF434C21E26; Fri, 20 Jul 2018 02:57:55 +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 54E17C21C57; Fri, 20 Jul 2018 02:57:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B4B53C21E2B; Fri, 20 Jul 2018 02:57:05 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by lists.denx.de (Postfix) with ESMTPS id 6907FC21E0F for ; Fri, 20 Jul 2018 02:57:01 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id p23-v6so5494674pgv.13 for ; Thu, 19 Jul 2018 19:57: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=oUvVfjwHXvS7E/oO9zmpCgL7lpT0efc4OCPjCK2fdg0=; b=jAIeaLLZNuvpDEOTJfailVXBAttUjGvRuuPmYBjL7GrNN9nT6E1Nz5yS2nibvZw20r 1PgNjcX+g/3ErcXCYlVWLnzQtp0LsANhQDd2fAK6Jaf25av7HSnAWep/6H9P7/eMajWG YnH9LCKm01/j8NjkBaVfaXPbKVjcAXV+gG7tY= 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=oUvVfjwHXvS7E/oO9zmpCgL7lpT0efc4OCPjCK2fdg0=; b=b3ofei8JR/C8FUtiBQdEt2Qlk3C1llHguEF3CzV5HDrU2q6pQc0AI9iky9UycBtCEG e6v5k1XghYGHNbYsnWDINICp/qE/cvhiakLJA0gEldYNX5RwmCqlS/hhVqxFLjve9+mH StiEWyMZF+j8VHJQl7FdSokaaswywUTES5Dz+w0L6W/twKr0OODeetTYY0Bga0c2cYxS 2GW3pr36OqEMzIAzd7E3dq8thFrGt3kP34JQ7eEqXsbt3148aPoGsYNhK0nkAiXyoFl+ nckj9Y5TLrzOBcUBbEe8z2OiXW39X4esWJTKZ0gxdny9C6dxJaq+AwyqLxGHp5UH97yo hlNQ== X-Gm-Message-State: AOUpUlGA0eqtnmpJu2FY1VE+QvOEgxgvgVjyRanyPFOPuO+OAJOYHCD2 ciC5Mja2j1ZNN0ik+k5dNu7TTA== X-Received: by 2002:a62:3f44:: with SMTP id m65-v6mr327067pfa.98.1532055420061; Thu, 19 Jul 2018 19:57:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id a20-v6sm588421pfi.124.2018.07.19.19.56.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:56:59 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:09 +0900 Message-Id: <20180720025723.6736-4-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 03/17] fs: fat: make directory iterator global for write use 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" Directory iterator was introduced in major re-work of read operation by Rob. We want to use it for write operation extensively as well. This patch makes relevant functions, as well as iterator defition, visible outside of fat.c. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 39 ++++++--------------------------------- include/fat.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index fd6523c66b..0f82cbe1bd 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -634,25 +634,6 @@ static int get_fs_info(fsdata *mydata) * For more complete example, see fat_itr_resolve() */ -typedef struct { - fsdata *fsdata; /* filesystem parameters */ - unsigned clust; /* current cluster */ - int last_cluster; /* set once we've read last cluster */ - int is_root; /* is iterator at root directory */ - int remaining; /* remaining dent's in current cluster */ - - /* current iterator position values: */ - dir_entry *dent; /* current directory entry */ - char l_name[VFAT_MAXLEN_BYTES]; /* long (vfat) name */ - char s_name[14]; /* short 8.3 name */ - char *name; /* l_name if there is one, else s_name */ - - /* storage for current cluster in memory: */ - u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); -} fat_itr; - -static int fat_itr_isdir(fat_itr *itr); - /** * fat_itr_root() - initialize an iterator to start at the root * directory @@ -661,7 +642,7 @@ static int fat_itr_isdir(fat_itr *itr); * @fsdata: filesystem data for the partition * @return 0 on success, else -errno */ -static int fat_itr_root(fat_itr *itr, fsdata *fsdata) +int fat_itr_root(fat_itr *itr, fsdata *fsdata) { if (get_fs_info(fsdata)) return -ENXIO; @@ -693,7 +674,7 @@ static int fat_itr_root(fat_itr *itr, fsdata *fsdata) * @parent: the iterator pointing at a directory entry in the * parent directory of the directory to iterate */ -static void fat_itr_child(fat_itr *itr, fat_itr *parent) +void fat_itr_child(fat_itr *itr, fat_itr *parent) { fsdata *mydata = parent->fsdata; /* for silly macros */ unsigned clustnum = START(parent->dent); @@ -713,7 +694,7 @@ static void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->last_cluster = 0; } -static void *next_cluster(fat_itr *itr) +void *next_cluster(fat_itr *itr) { fsdata *mydata = itr->fsdata; /* for silly macros */ int ret; @@ -834,7 +815,7 @@ static dir_entry *extract_vfat_name(fat_itr *itr) * @return boolean, 1 if success or 0 if no more entries in the * current directory */ -static int fat_itr_next(fat_itr *itr) +int fat_itr_next(fat_itr *itr) { dir_entry *dent; @@ -879,19 +860,11 @@ static int fat_itr_next(fat_itr *itr) * @itr: the iterator * @return true if cursor is at a directory */ -static int fat_itr_isdir(fat_itr *itr) +int fat_itr_isdir(fat_itr *itr) { return !!(itr->dent->attr & ATTR_DIR); } -/* - * Helpers: - */ - -#define TYPE_FILE 0x1 -#define TYPE_DIR 0x2 -#define TYPE_ANY (TYPE_FILE | TYPE_DIR) - /** * fat_itr_resolve() - traverse directory structure to resolve the * requested path. @@ -907,7 +880,7 @@ static int fat_itr_isdir(fat_itr *itr) * @type: bitmask of allowable file types * @return 0 on success or -errno */ -static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) { const char *next; diff --git a/include/fat.h b/include/fat.h index 0c88b59a4a..577e6b4592 100644 --- a/include/fat.h +++ b/include/fat.h @@ -187,6 +187,38 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) return (sect - fsdata->data_begin) / fsdata->clust_size; } +/* + * Directory iterator + */ + +#define TYPE_FILE 0x1 +#define TYPE_DIR 0x2 +#define TYPE_ANY (TYPE_FILE | TYPE_DIR) + +typedef struct { + fsdata *fsdata; /* filesystem parameters */ + unsigned clust; /* current cluster */ + int last_cluster; /* set once we've read last cluster */ + int is_root; /* is iterator at root directory */ + int remaining; /* remaining dent's in current cluster */ + + /* current iterator position values: */ + dir_entry *dent; /* current directory entry */ + char l_name[VFAT_MAXLEN_BYTES]; /* long (vfat) name */ + char s_name[14]; /* short 8.3 name */ + char *name; /* l_name if there is one, else s_name */ + + /* storage for current cluster in memory: */ + u8 block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); +} fat_itr; + +int fat_itr_root(fat_itr *itr, fsdata *fsdata); +void fat_itr_child(fat_itr *itr, fat_itr *parent); +void *next_cluster(fat_itr *itr); +int fat_itr_next(fat_itr *itr); +int fat_itr_isdir(fat_itr *itr); +int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type); + int file_fat_detectfs(void); int fat_exists(const char *filename); int fat_size(const char *filename, loff_t *size); From patchwork Fri Jul 20 02:57:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142410 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2436330ljj; Thu, 19 Jul 2018 19:58:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcEBgEQRqerd2GyjHp61e5WDvP1eXR9XPhCqFPineukOFugNkOZA+zPv34wT0rPxQ8QVjNi X-Received: by 2002:a50:8be8:: with SMTP id n37-v6mr490247edn.216.1532055504502; Thu, 19 Jul 2018 19:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055504; cv=none; d=google.com; s=arc-20160816; b=hMu2csohC+FLMVB4TtwcOU4dkCuXFpQMlgw6a/dhBMRUqFnn0sq72Vaw6osXrcjD+Z uJ76HcS+yjCtTYQHMblf4UfG/6tAefQLtMuxKXTOQO/JBMaJWDXt0dJVk2Ohif4Twd/y KkuFsAHB1/zy10P5U3f4LRWgr+IBfUOA7vaF8UfbuW8bm9wMS994+Dg0ZdM+yitwqZEQ roWcmO7MEJVJtZeCqvXkmV5GeotuFSTz5ClTFZCz1PZkvCK799B7q5rsuZVRErRzE5VZ 3tDcE0QQ4UfZxTcO/kymTy6+AP2cQWlg8Ha3Ozkx30MwpCc7Nhhv/o8rSl+Q4yrC2cKA 4udw== 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=+UzCazrtQoPHZ+PrwynK67nMR48wW209EPlVe1A1eLA=; b=W6AXOX3DzleCnQmq5a2yqKFnwIRsoH13ckshY1HvDFHwDjMxLUmKTma76wRGMXOyh4 eMmbwC1qAb3WFUFGjBAaJXZdpb7L1F8QRLVkdjO2qAKeSgdAWjZCHZQxZZf5NYmHVCGL xrjgXxy20qnSTL1qYvg3PuZPOf5ybDlVdOL88owJRf3XJZNaM8jhXm1Jd9OyoBMA1cOG xeuJjqInraYyFRNKwYM3Q9Ws+So392bCtn3TW4CAN4rBmnGg7qUWogiOufi8qHL/483/ Hz/HdBOP7llYmk/UNCGqDUarnAbLDaleuQoYj45wJ7vwT4tevDNf+qrw55ItAAETjj/4 Npkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=XmK6hHGq; 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 n14-v6si694528edq.198.2018.07.19.19.58.24; Thu, 19 Jul 2018 19:58:24 -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=XmK6hHGq; 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 F150EC21C4A; Fri, 20 Jul 2018 02:57:30 +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 5C477C21DED; Fri, 20 Jul 2018 02:57:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6528DC21D74; Fri, 20 Jul 2018 02:57:12 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lists.denx.de (Postfix) with ESMTPS id 90AB2C21E1B for ; Fri, 20 Jul 2018 02:57:08 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id y4-v6so5500032pgp.9 for ; Thu, 19 Jul 2018 19:57:08 -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=AflR2hL6TKDn+EZgEb8Y89lODSYrzM80W2mn/VncO7I=; b=XmK6hHGqFmgsLkxWc5YEWyWRYWiRioslD4ZZs1VpukeC5Dj6ue/tUleVtNa6n8lJyY QPrB0xtX/qhrO72Kfg4FUjACUsf4V+qeaE6VJaelxhQuHVzwUOq/yyCtBAyhZNKLz2RR LdVDSHww7kTMfhSF2Afc8mWan1Y7e/58reIA4= 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=AflR2hL6TKDn+EZgEb8Y89lODSYrzM80W2mn/VncO7I=; b=Cx902so2Nr3bteg5KGxcfu2kzeP92u3HObuoXcBpElK33EfAV6UEQ3SfWgq6fhQNj0 bEw02OFtPPJG9vgcf2Ekcc8VU74qPwYYsecQ59UPGSq42ou9nlF3x3siXje+cHSwoEq6 4nZjzoqYhIHYS+NkhCUV4K28ZvUp5AnZWJoRMkj128EOf6aEy4AnBlQ2YW/ZlQBCZOtJ SuG2Y6LDWkLagkIxsQZXpE/HWg+ypzrKd92i1/BMZZ0MCLxpGC7YM4NPeopSqf+9e2h/ DFYv6gGvDBIcL4VOwXm8wAB0ZnmLr8iJBgo0nef8d+PH22FzLMILsUiGLOC5uDrPW5H/ emzw== X-Gm-Message-State: AOUpUlEwgVjHIZtBzDxjJ3butUdAdwSjnqPIRxWvYPhaM0I/9s+hy26T aX8D+ddhsWvH/ONmJqWQYOEiFQ== X-Received: by 2002:aa7:8591:: with SMTP id w17-v6mr297241pfn.77.1532055427242; Thu, 19 Jul 2018 19:57:07 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j191-v6sm695153pfc.136.2018.07.19.19.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:06 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:10 +0900 Message-Id: <20180720025723.6736-5-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 04/17] fs: fat: assure iterator's ->dent belongs to ->clust 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" In my attempt to re-work write operation, it was revealed that iterator's "clust" does not always point to a cluster to which a current directory entry ("dent") belongs. This patch assures that it is always true by adding "next_clust" which is used solely for dereferencing a cluster chain. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 24 ++++++++++++++++-------- include/fat.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 0f82cbe1bd..d9bfb08d97 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -649,6 +649,7 @@ int fat_itr_root(fat_itr *itr, fsdata *fsdata) itr->fsdata = fsdata; itr->clust = fsdata->root_cluster; + itr->next_clust = fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; @@ -684,9 +685,11 @@ void fat_itr_child(fat_itr *itr, fat_itr *parent) itr->fsdata = parent->fsdata; if (clustnum > 0) { itr->clust = clustnum; + itr->next_clust = clustnum; itr->is_root = 0; } else { itr->clust = parent->fsdata->root_cluster; + itr->next_clust = parent->fsdata->root_cluster; itr->is_root = 1; } itr->dent = NULL; @@ -704,7 +707,7 @@ void *next_cluster(fat_itr *itr) if (itr->last_cluster) return NULL; - sect = clust_to_sect(itr->fsdata, itr->clust); + sect = clust_to_sect(itr->fsdata, itr->next_clust); debug("FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\n", sect, itr->fsdata->clust_size, DIRENTSPERBLOCK); @@ -725,18 +728,19 @@ void *next_cluster(fat_itr *itr) return NULL; } + itr->clust = itr->next_clust; if (itr->is_root && itr->fsdata->fatsize != 32) { - itr->clust++; - sect = clust_to_sect(itr->fsdata, itr->clust); + itr->next_clust++; + sect = clust_to_sect(itr->fsdata, itr->next_clust); if (sect - itr->fsdata->rootdir_sect >= itr->fsdata->rootdir_size) { - debug("cursect: 0x%x\n", itr->clust); + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } else { - itr->clust = get_fatent(itr->fsdata, itr->clust); - if (CHECK_CLUST(itr->clust, itr->fsdata->fatsize)) { - debug("cursect: 0x%x\n", itr->clust); + itr->next_clust = get_fatent(itr->fsdata, itr->next_clust); + if (CHECK_CLUST(itr->next_clust, itr->fsdata->fatsize)) { + debug("nextclust: 0x%x\n", itr->next_clust); itr->last_cluster = 1; } } @@ -752,8 +756,11 @@ static dir_entry *next_dent(fat_itr *itr) itr->fsdata->clust_size; /* have we reached the last cluster? */ - if (!dent) + if (!dent) { + /* a sign for no more entries left */ + itr->dent = NULL; return NULL; + } itr->remaining = nbytes / sizeof(dir_entry) - 1; itr->dent = dent; @@ -906,6 +913,7 @@ int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type) (((next - path) == 2) && !strncmp(path, "..", 2))) { /* point back to itself */ itr->clust = itr->fsdata->root_cluster; + itr->next_clust = itr->fsdata->root_cluster; itr->dent = NULL; itr->remaining = 0; itr->last_cluster = 0; diff --git a/include/fat.h b/include/fat.h index 577e6b4592..bc0f77abb5 100644 --- a/include/fat.h +++ b/include/fat.h @@ -198,6 +198,7 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) typedef struct { fsdata *fsdata; /* filesystem parameters */ unsigned clust; /* current cluster */ + unsigned next_clust; /* next cluster if remaining == 0 */ int last_cluster; /* set once we've read last cluster */ int is_root; /* is iterator at root directory */ int remaining; /* remaining dent's in current cluster */ From patchwork Fri Jul 20 02:57:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142415 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2439126ljj; Thu, 19 Jul 2018 20:02:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdLmK93kAeWuVQ0Vbdr+rb5NOTw++dnzZT70FLgF97KCGEXGxqKrZJq4YcUdnriTMOTfwnk X-Received: by 2002:a50:b962:: with SMTP id m89-v6mr538523ede.20.1532055725323; Thu, 19 Jul 2018 20:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055725; cv=none; d=google.com; s=arc-20160816; b=sOTM8u/2sEGId7oI+ScXVh/R+druax2jLvXfMLMybZtxJ+evg1FDl/Frd+uKYBbrlv Pk+j4UIUVym5A/ANrviacG7PSEjiy1wzsZSpW+Oa+tTI72Ym2FaZ8UY8JMuamsmaHkYp VyBFhKxBIlTVlioJG5yu8qv+R1FCSP89TRoKkDr82SEX7SogpAj9vLi9edMBjdqOrL83 2myTVYs9gHtcK80FMTzMgLzumg48DoYpz/7tmT2N6sdg/+E7TCNL8DU1iz9JP20Vrr4Z gbCWyn3lJQr+d7kxlLmwCoVn56CI3ezJ1SimScUxI0AIFnE6VuRTVJi28Q67J7a/vd+2 fwyQ== 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=fmFz9foq8nezX+OP2dYAuPzW3mnsS7sCQH+fr6eK+tE=; b=gThfnnATnIcGky5fR5RW1ncC9Rk0vCxyT+enzoeZHKOQrgR2+D/TlXEE0G+lB9ECpv MzFB26RlTL2XxIcyp3URQ1LwVI0+/h08AmMyJRwA3oDGALisbg2ncy8TUhhETWZX7cd2 VHGjRiUEbNzBRwpRk59Inl0xlozlHJsff9U+1gTRbczIilGzOE9awpN+XBEpavUE0n4B FvqM+ciPUs0D7WlyQt5M6ekTyovrsL+/+BrS7CCNoXrxjevmMkQ5QMNGOpTzf3JkFAFh fjx9Tl1tMHFiW4KxK+AhkeGhh6BCvYnW1Qlbctb9wD+30EJ21r9G+VLAB6YkS6dcPYgz rjQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=gpgG+0Xi; 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 e2-v6si980241edc.442.2018.07.19.20.02.05; Thu, 19 Jul 2018 20:02:05 -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=gpgG+0Xi; 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 EBB5BC21E1D; Fri, 20 Jul 2018 02:58: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 323C3C21C4A; Fri, 20 Jul 2018 02:58:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EE521C21DC1; Fri, 20 Jul 2018 02:57:23 +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 4BE55C21DED for ; Fri, 20 Jul 2018 02:57:19 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id t17-v6so1955144ply.13 for ; Thu, 19 Jul 2018 19:57:19 -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=gdSLz1Ry8iefhwZaQbECAt0igIjvg9SBGP9hyNj9E8Q=; b=gpgG+0Xi8D9CIAJe4XKorNd0IXHzcawGy+S/GWXrmbmOC3jI6t741FUfNl4BlWngGd NKokgcQ2zPlrMhyS9oCpFBHbUMWUQOGpaF6+QRTPXkX1Pi3uDtFoEEJJwYlTEoH+t7z/ 4H1Jb8Uyd2xTEaQnxU7WYEJMtUQQEYt/9is7Q= 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=gdSLz1Ry8iefhwZaQbECAt0igIjvg9SBGP9hyNj9E8Q=; b=pxQ+mN61QOj/jUlYt8Rm0aTQP1FsbBfZpGMgTIW1v+G1fsGk9/s7xGFKphGphXV1UW eGQkm7kHOVMuIxeSxehDt4pfVJLZui0dTHx/4lMaE3AuazXdejdd3LjSXIDXLBDXE8In +tJvEnF/NojA8Y/1XMgCKS7fYzvDlJSiGDHlcIEUC5K2aTW2CZNwugf4ml5BMLVfgTEQ FOB1RnWud0xT+P3xNLHCoWW4+SXv7BEtxBBm1RwM+w4TZ+wsHY15M46hPbd5qPGikmCI Ckd5v4qoob5hK2puLhtdIj1pU6M/9ajmT2LU/YYzRvR8/LJ+ruD59sCSG7O2/mjIx1Qq 7VSg== X-Gm-Message-State: AOUpUlH33nnyz4lP6Ul7+Kww+kxv/FBhlvhMxTfb+3WATgbaa++jiNGP oWGU/rIBzWcAFqR6R5DOOP/zsA== X-Received: by 2002:a17:902:864b:: with SMTP id y11-v6mr262262plt.335.1532055437964; Thu, 19 Jul 2018 19:57:17 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id c19-v6sm570869pfn.182.2018.07.19.19.57.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:17 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:11 +0900 Message-Id: <20180720025723.6736-6-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 05/17] fs: fat: check and normailze file name 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" FAT file system's long file name support is a bit complicated and has some restrictions on its naming. We should be careful about it especially for write as it may easily end up with wrong file system. normalize_longname() check for the rules and normalize a file name if necessary. Please note, however, that this function is yet to be extended to fully comply with the standard. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 52 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 3b77557b3e..6c715a70f4 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -899,6 +899,44 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect, return NULL; } +static int normalize_longname(char *l_filename, const char *filename) +{ + const char *p, legal[] = "!#$%&\'()-.@^`_{}~"; + char c; + int name_len; + + /* Check that the filename is valid */ + for (p = filename; p < filename + strlen(filename); p++) { + c = *p; + + if (('0' <= c) && (c <= '9')) + continue; + if (('A' <= c) && (c <= 'Z')) + continue; + if (('a' <= c) && (c <= 'z')) + continue; + if (strchr(legal, c)) + continue; + /* extended code */ + if ((0x80 <= c) && (c <= 0xff)) + continue; + + return -1; + } + + /* Normalize it */ + name_len = strlen(filename); + if (name_len >= VFAT_MAXLEN_BYTES) + /* should return an error? */ + name_len = VFAT_MAXLEN_BYTES - 1; + + memcpy(l_filename, filename, name_len); + l_filename[name_len] = 0; /* terminate the string */ + downcase(l_filename, INT_MAX); + + return 0; +} + static int do_fat_write(const char *filename, void *buffer, loff_t size, loff_t *actwrite) { @@ -910,7 +948,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, fsdata datablock; fsdata *mydata = &datablock; int cursect; - int ret = -1, name_len; + int ret = -1; char l_filename[VFAT_MAXLEN_BYTES]; *actwrite = size; @@ -971,13 +1009,11 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } dentptr = (dir_entry *) do_fat_read_at_block; - name_len = strlen(filename); - if (name_len >= VFAT_MAXLEN_BYTES) - name_len = VFAT_MAXLEN_BYTES - 1; - - memcpy(l_filename, filename, name_len); - l_filename[name_len] = 0; /* terminate the string */ - downcase(l_filename, INT_MAX); + if (normalize_longname(l_filename, filename)) { + printf("FAT: illegal filename (%s)\n", filename); + ret = -EINVAL; + goto exit; + } startsect = mydata->rootdir_sect; retdent = find_directory_entry(mydata, startsect, From patchwork Fri Jul 20 02:57:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142414 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2437715ljj; Thu, 19 Jul 2018 20:00:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIZbtS4gusKgrJeN/qQAzihcl1OPuAUbI80JzIHJJUADRvdhDASL2VZmoPlxDm69w8gtRN X-Received: by 2002:a50:a166:: with SMTP id 93-v6mr505489edj.184.1532055629323; Thu, 19 Jul 2018 20:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055629; cv=none; d=google.com; s=arc-20160816; b=iaVMRjzXM0mLy0AKDEVlGmkqEFLAQ9acLQQQ8KemCuGaYhjzEzFfAnw9DLfGggszSG s+qTr2c9e02zuh87eFjg4Q4MoXParO7B9UXQwW1TFjjHsfafNIO2JYxJv6NTCKKIfH8b vQDwKltQKJdmJ7OCLZAcMpfmPIO2jSdnBECW3ZZherfbT+nk1X2WqaXJMWoKY9Oc9gAT 8/Md1ZX2AVPlhBmcJXoDZdztxcJ8G4mCcbNprOqfrDOkd91R3wVdiNtAf+6RUpqv0I88 6gO4JV6fRIuKw4POpH3UXSaHjeZ+rwQN2w0lVBkt08i+nj25abak/g2q4h1l2AkXgRt3 IoJA== 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=1CbOol4MFyVpBNHxgVl6bLVe5OldMpH4Tu6KXJL2VZ0=; b=D1wEBk4iY9FvO1+rTFUEFSbB5E1KMvpqFe7R7q38O+bDSF4oSet+pWt9VMbwQxbHO0 63MxeKflDUMhziWx6NWtZTjyqs2VKfFbEHvWiHAbMrPH3KqM1A3FcKLD0Rw1ZogIK8Ak FTKU9n8TG3QtQKvIOUf3XtKa3R8RgeRm3Lv0iyxjGSTJR/j/FzVtBjN+xmlf0+GiruBx 14Of0zTKkix9X5MMSp72GtF6pbPUgsKo86bq1IV0r8JSs3GLIgmHfs38URLwG2xvuiu7 bLdlgy2pwlKazPkzk6OgynXXquDVmkls3nkY/U0AnS9ZEDhMQYZ+WC6cAqeinNDnB5OG 1qDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZOrsr3XY; 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 i57-v6si279267eda.238.2018.07.19.20.00.28; Thu, 19 Jul 2018 20:00:29 -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=ZOrsr3XY; 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 C6F22C21DB3; Fri, 20 Jul 2018 02:58:14 +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 D3A45C21DC1; Fri, 20 Jul 2018 02:58:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6A703C21D9A; Fri, 20 Jul 2018 02:57:33 +0000 (UTC) Received: from mail-pl0-f43.google.com (mail-pl0-f43.google.com [209.85.160.43]) by lists.denx.de (Postfix) with ESMTPS id BDFB7C21DF8 for ; Fri, 20 Jul 2018 02:57:29 +0000 (UTC) Received: by mail-pl0-f43.google.com with SMTP id 6-v6so4515478plb.0 for ; Thu, 19 Jul 2018 19:57:29 -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=BPzUpR5wLH8HCOOwmOCTlkYJK0x+jfG+XHxAqPa3gt0=; b=ZOrsr3XYIOlee8/B0uvub9qmxY9oFM3hX+Gi64TDE0zyD4qYiN5c2KtgId222+7NXb Vr1AuAVF6ijvOR2KU19BRnH71fH31GuPrZ8cDkcntt+SPA8W53GpU3bhUHl9j/tR1JDs 61j/k/lKfLPY8uLFAgYAIxvMgO+04X8LEDhR4= 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=BPzUpR5wLH8HCOOwmOCTlkYJK0x+jfG+XHxAqPa3gt0=; b=IbF8HZZe8CgbahoE/BYge3Bh2OvUyQqtwEC+60Z70Y5HJ5Lxqg4bNT/LBSfnQSs8pL KvEO1oP8bd8lCCFuXfCCiDGpEpsq+2G7ZA/McApvUamjwnHSYWS341CBvuq5lFySBNHU tiiHUft9DINsyO50j2S7PDrJtJv6j3HLmjDYGbgIxnnnp5Q2Xvu+Brfzlzx+p5kPHH36 r0igazlVYxfRXnNc3RcqgFH18rX3VUr94rJ1387HUQdqyie821ZuX1qPgbJ5sbSz00N7 Ku6Ixp2+GtNwuf7QlWQoB8XvYhKnie00dYo9hW64NPmOI2reBBm3sFY6Vfws6CXXJ4Vb R5nA== X-Gm-Message-State: AOUpUlFCuWrHQbsAMtq8u/jVy0eyn2934kg9mZPm6Av+1iWJQlIOl8iv 01MT4+NeaS732+nF7NvL3q+4oQ== X-Received: by 2002:a17:902:7c8b:: with SMTP id y11-v6mr290591pll.222.1532055448429; Thu, 19 Jul 2018 19:57:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id p3-v6sm614085pfo.130.2018.07.19.19.57.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:27 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:12 +0900 Message-Id: <20180720025723.6736-7-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 06/17] fs: fat: write returns error code instead of -1 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" It would be good that FAT write function return error code instead of just returning -1 as fat_read_file() does. This patch attempts to address this issue although it is 'best effort (or estimate)' for now. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 6c715a70f4..1e4f5af910 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -956,7 +956,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { debug("error: reading boot sector\n"); - return -1; + return -EIO; } total_sector = bs.total_sect; @@ -997,7 +997,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); if (mydata->fatbuf == NULL) { debug("Error: allocating memory\n"); - return -1; + return -ENOMEM; } if (disk_read(cursect, @@ -1005,6 +1005,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, (mydata->clust_size) : PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { debug("Error: reading rootdir block\n"); + ret = -EIO; goto exit; } dentptr = (dir_entry *) do_fat_read_at_block; @@ -1029,6 +1030,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } @@ -1036,6 +1038,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = clear_fatent(mydata, start_cluster); if (ret) { printf("Error: clearing FAT entries\n"); + ret = -EIO; goto exit; } @@ -1045,12 +1048,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } @@ -1065,12 +1070,14 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = start_cluster = find_empty_cluster(mydata); if (ret < 0) { printf("Error: finding empty cluster\n"); + ret = -ENOSPC; goto exit; } ret = check_overflow(mydata, start_cluster, size); if (ret) { printf("Error: %llu overflow\n", size); + ret = -ENOSPC; goto exit; } } else { @@ -1087,6 +1094,7 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = set_contents(mydata, retdent, buffer, size, actwrite); if (ret < 0) { printf("Error: writing contents\n"); + ret = -EIO; goto exit; } debug("attempt to write 0x%llx bytes\n", *actwrite); @@ -1095,14 +1103,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, ret = flush_dirty_fat_buffer(mydata); if (ret) { printf("Error: flush fat buffer\n"); + ret = -EIO; goto exit; } /* Write directory table to device */ ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, mydata->clust_size * mydata->sect_size); - if (ret) + if (ret) { printf("Error: writing directory entry\n"); + ret = -EIO; + } exit: free(mydata->fatbuf); @@ -1114,7 +1125,7 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, { if (offset != 0) { printf("Error: non zero offset is currently not supported.\n"); - return -1; + return -EINVAL; } printf("writing %s\n", filename); From patchwork Fri Jul 20 02:57:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142412 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2437097ljj; Thu, 19 Jul 2018 19:59:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdONor45vuO8DRDFuow/FMEjZZ91/GBcbR9YU9H1Rh72lB36RKXCFTsxGgHJhv6f1+eERs9 X-Received: by 2002:a50:baae:: with SMTP id x43-v6mr517378ede.65.1532055582798; Thu, 19 Jul 2018 19:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055582; cv=none; d=google.com; s=arc-20160816; b=GVBDKL3WHr373ntGyCkc7YecSC29mGZo+L4k59V3z4z4YNKlSqXjzXa0J4kI/w8EvW hencxViqqrNstTbBmc/F3HOUMnfN7ZRFIsHisUFPwUyX8VizSJFdGnG3gi+OxSZoJugk z2vLqmluG+lfxCLweEFfgeAdEss5g0O3bkK6RzVnkp2l9Md+P1fySspnjkZzYDm2NT3t /0iT0diYw49h4oael4NusufP/2mpWaPTmcekPmsTSQimAinrZJsJ3MrBZnteF6hAtKef iQNrVK9PLEQm8Z2kmGIJZyvMYpvHFV7iEjoawUHLnWvz9bxdHc/5PMGHMAr0qcJCx3A1 Faag== 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=iFYB6c+Yjd3nNKUqLep5wfbUbuX21zJ/OKrV5/00ngo=; b=H2YlTWpujqs1rINJAa7aGCF7Em/PZHcFOG6YxmLtSo9p+ixKzCqQWjjWtPMe3Dn8cA QsKuFETrn2oXF8aG9pQTS5ayIl/yxKBjha6Yq026Sc0xoJN1iYbSsLQgAft3cX7enOQT cUmTslRcpj+oMUPHjzYn+Nus0SWQMp9MsgIM0RbhhJxDnOyOPuEh/eV4nWfnigDo7r6L 8UnSLXB2WAYKKuxtk9LWIHFnD2UGUAgYYh9X7AfnovFp7mkSVBF+kaYfIFl7KiigdTt3 Ou0XGpI8iULIcbyESXX6AvMAGGWqhFGL9WNSYkuM2YkZ95HrlegxlsRch7GAWT8fqJmE Y7jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="P/7lx/OG"; 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 f24-v6si1102448edb.1.2018.07.19.19.59.42; Thu, 19 Jul 2018 19:59:42 -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="P/7lx/OG"; 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 5B3A3C21DA6; Fri, 20 Jul 2018 02:59:30 +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 AFAB3C21E29; Fri, 20 Jul 2018 02:59:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CDF8DC21C27; Fri, 20 Jul 2018 02:57:42 +0000 (UTC) Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by lists.denx.de (Postfix) with ESMTPS id C6C64C21DFF for ; Fri, 20 Jul 2018 02:57:37 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id g2-v6so5509946pgs.6 for ; Thu, 19 Jul 2018 19:57:37 -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=4j68ggPICZIdcDeKzUtmc0m64fpVROYY+kkQWmCxZjw=; b=P/7lx/OGOB41OphE6NHKTeBi5BsB2zGHerMw7jIMLy433hGlCMCXLtBT+JO/n1oUbe tN4Hhj2IZ37lzM05LsUXtFgqRGsXBXesbXQvZo70NWexUJAzHCBWAC7dPoTIRnkCQ1RU iKMh0zfAdXl6RiiFvGTCT4k2uJAWHAgPvQUbQ= 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=4j68ggPICZIdcDeKzUtmc0m64fpVROYY+kkQWmCxZjw=; b=VfSo9pPz6ooAh1VMKxfarLq5XFTNGbD1Ce0mBJxM+lX00r3IPnqoiU/x4NwGV+4tnm nG/N2q4xDXQ6+bhbDuJ8SVf5Kk63rnr8D3LA6T2NqaoI3h5QotYR/2yRdJM/vNMU+WQ1 6JCIySPrCcMgZwk92wBpuLc21VXnn/krP8GNmoQzhm9KVzEjlh8vTOZR0yvGGU6vGtR9 sS504aGBARN3m59SRk36D1Hsif87B2YupVlx82rY2OxWeiiOAtIFDRViIGfeoq0dBVOz N1iYkNWxBHUQV5D6lxpda2XR5CIO/izIivZG4Cd7OP1UOUExBMmMFIIni8/FSq6HA5z2 0vuQ== X-Gm-Message-State: AOUpUlH2hhzYKYY1WXG0ldEzD6eEVX1Vwc+ll02wdMxInTWCoaFFXgCR SLGSnX7dKuwecb9xS+2+5XOQ5A== X-Received: by 2002:a62:5984:: with SMTP id k4-v6mr322505pfj.116.1532055456219; Thu, 19 Jul 2018 19:57:36 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b12-v6sm611471pfe.148.2018.07.19.19.57.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:35 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:13 +0900 Message-Id: <20180720025723.6736-8-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 07/17] fs: fat: support write with sub-directory path 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" In this patch, write implementation is overhauled and rewritten by making full use of directory iterator. The ovbious bonus is that we are now able to write to a file with a directory path, like /A/B/C/FILE. Please note that, as there is no notion of "current directory" on u-boot, a file name specified must contain an absolute directory path. Otherwise, "/" (root directory) is assumed. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 9 - fs/fat/fat_write.c | 469 +++++++++++++++------------------------------ 2 files changed, 157 insertions(+), 321 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index d9bfb08d97..9bafc3a40c 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -464,15 +464,6 @@ static __u8 mkcksum(const char name[8], const char ext[3]) return ret; } -/* - * TODO these should go away once fat_write is reworked to use the - * directory iterator - */ -__u8 get_dentfromdir_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); -__u8 do_fat_read_at_block[MAX_CLUSTSIZE] - __aligned(ARCH_DMA_MINALIGN); - /* * Read boot sector and volume info from a FAT filesystem */ diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 1e4f5af910..96edb6674c 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -99,7 +99,6 @@ static void set_name(dir_entry *dirent, const char *filename) debug("ext : %s\n", dirent->ext); } -static __u8 num_of_fats; /* * Write fat buffer into block device */ @@ -128,7 +127,7 @@ static int flush_dirty_fat_buffer(fsdata *mydata) return -1; } - if (num_of_fats == 2) { + if (mydata->bs_fats == 2) { /* Update corresponding second FAT blocks */ startblock += mydata->fatlength; if (disk_write(startblock, getsize, bufptr) < 0) { @@ -210,15 +209,14 @@ name11_12: return 1; } -static int is_next_clust(fsdata *mydata, dir_entry *dentptr); -static void flush_dir_table(fsdata *mydata, dir_entry **dentptr); +static int flush_dir_table(fat_itr *itr); /* * Fill dir_slot entries with appropriate name, id, and attr - * The real directory entry is returned by 'dentptr' + * 'itr' will point to a next entry */ -static void -fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) +static int +fill_dir_slot(fat_itr *itr, const char *l_name) { __u8 temp_dir_slot_buffer[MAX_LFN_SLOT * sizeof(dir_slot)]; dir_slot *slotptr = (dir_slot *)temp_dir_slot_buffer; @@ -226,7 +224,7 @@ fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) int idx = 0, ret; /* Get short file name checksum value */ - checksum = mkcksum((*dentptr)->name, (*dentptr)->ext); + checksum = mkcksum(itr->dent->name, itr->dent->ext); do { memset(slotptr, 0x00, sizeof(dir_slot)); @@ -241,120 +239,21 @@ fill_dir_slot(fsdata *mydata, dir_entry **dentptr, const char *l_name) slotptr->id |= LAST_LONG_ENTRY_MASK; while (counter >= 1) { - if (is_next_clust(mydata, *dentptr)) { - /* A new cluster is allocated for directory table */ - flush_dir_table(mydata, dentptr); - } - memcpy(*dentptr, slotptr, sizeof(dir_slot)); - (*dentptr)++; + memcpy(itr->dent, slotptr, sizeof(dir_slot)); slotptr--; counter--; - } - - if (is_next_clust(mydata, *dentptr)) { - /* A new cluster is allocated for directory table */ - flush_dir_table(mydata, dentptr); - } -} - -static __u32 dir_curclust; - -/* - * Extract the full long filename starting at 'retdent' (which is really - * a slot) into 'l_name'. If successful also copy the real directory entry - * into 'retdent' - * If additional adjacent cluster for directory entries is read into memory, - * then 'get_contents_vfatname_block' is copied into 'get_dentfromdir_block' and - * the location of the real directory entry is returned by 'retdent' - * Return 0 on success, -1 otherwise. - */ -static int -get_long_file_name(fsdata *mydata, int curclust, __u8 *cluster, - dir_entry **retdent, char *l_name) -{ - dir_entry *realdent; - dir_slot *slotptr = (dir_slot *)(*retdent); - dir_slot *slotptr2 = NULL; - __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ? - PREFETCH_BLOCKS : - mydata->clust_size); - __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff; - int idx = 0, cur_position = 0; - - if (counter > VFAT_MAXSEQ) { - debug("Error: VFAT name is too long\n"); - return -1; - } - - while ((__u8 *)slotptr < buflimit) { - if (counter == 0) - break; - if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter) - return -1; - slotptr++; - counter--; - } - - if ((__u8 *)slotptr >= buflimit) { - if (curclust == 0) - return -1; - curclust = get_fatent(mydata, dir_curclust); - if (CHECK_CLUST(curclust, mydata->fatsize)) { - debug("curclust: 0x%x\n", curclust); - printf("Invalid FAT entry\n"); - return -1; - } - - dir_curclust = curclust; - - if (get_cluster(mydata, curclust, get_contents_vfatname_block, - mydata->clust_size * mydata->sect_size) != 0) { - debug("Error: reading directory block\n"); - return -1; - } - - slotptr2 = (dir_slot *)get_contents_vfatname_block; - while (counter > 0) { - if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK) - & 0xff) != counter) + if (!fat_itr_next(itr)) + if (!itr->dent && !itr->is_root && flush_dir_table(itr)) return -1; - slotptr2++; - counter--; - } - - /* Save the real directory entry */ - realdent = (dir_entry *)slotptr2; - while ((__u8 *)slotptr2 > get_contents_vfatname_block) { - slotptr2--; - slot2str(slotptr2, l_name, &idx); - } - } else { - /* Save the real directory entry */ - realdent = (dir_entry *)slotptr; } - do { - slotptr--; - if (slot2str(slotptr, l_name, &idx)) - break; - } while (!(slotptr->id & LAST_LONG_ENTRY_MASK)); - - l_name[idx] = '\0'; - if (*l_name == DELETED_FLAG) - *l_name = '\0'; - else if (*l_name == aRING) - *l_name = DELETED_FLAG; - downcase(l_name, INT_MAX); - - /* Return the real directory entry */ - *retdent = realdent; - - if (slotptr2) { - memcpy(get_dentfromdir_block, get_contents_vfatname_block, - mydata->clust_size * mydata->sect_size); - cur_position = (__u8 *)realdent - get_contents_vfatname_block; - *retdent = (dir_entry *) &get_dentfromdir_block[cur_position]; - } + if (!itr->dent && !itr->is_root) + /* + * don't care return value here because we have already + * finished completing an entry with name, only ending up + * no more entry left + */ + flush_dir_table(itr); return 0; } @@ -569,20 +468,20 @@ static int find_empty_cluster(fsdata *mydata) } /* - * Write directory entries in 'get_dentfromdir_block' to block device + * Write directory entries in itr's buffer to block device */ -static void flush_dir_table(fsdata *mydata, dir_entry **dentptr) +static int flush_dir_table(fat_itr *itr) { + fsdata *mydata = itr->fsdata; int dir_newclust = 0; + unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; - if (set_cluster(mydata, dir_curclust, - get_dentfromdir_block, - mydata->clust_size * mydata->sect_size) != 0) { - printf("error: wrinting directory entry\n"); - return; + if (set_cluster(mydata, itr->clust, itr->block, bytesperclust) != 0) { + printf("error: writing directory entry\n"); + return -1; } dir_newclust = find_empty_cluster(mydata); - set_fatent_value(mydata, dir_curclust, dir_newclust); + set_fatent_value(mydata, itr->clust, dir_newclust); if (mydata->fatsize == 32) set_fatent_value(mydata, dir_newclust, 0xffffff8); else if (mydata->fatsize == 16) @@ -590,15 +489,19 @@ static void flush_dir_table(fsdata *mydata, dir_entry **dentptr) else if (mydata->fatsize == 12) set_fatent_value(mydata, dir_newclust, 0xff8); - dir_curclust = dir_newclust; + itr->clust = dir_newclust; + itr->next_clust = dir_newclust; if (flush_dirty_fat_buffer(mydata) < 0) - return; + return -1; + + memset(itr->block, 0x00, bytesperclust); - memset(get_dentfromdir_block, 0x00, - mydata->clust_size * mydata->sect_size); + itr->dent = (dir_entry *)itr->block; + itr->last_cluster = 1; + itr->remaining = bytesperclust / sizeof(dir_entry) - 1; - *dentptr = (dir_entry *) get_dentfromdir_block; + return 0; } /* @@ -764,139 +667,83 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) return 0; } -/* - * Check if adding several entries exceed one cluster boundary - */ -static int is_next_clust(fsdata *mydata, dir_entry *dentptr) -{ - int cur_position; - - cur_position = (__u8 *)dentptr - get_dentfromdir_block; - - if (cur_position >= mydata->clust_size * mydata->sect_size) - return 1; - else - return 0; -} - -static dir_entry *empty_dentptr; /* * Find a directory entry based on filename or start cluster number * If the directory entry is not found, * the new position for writing a directory entry will be returned */ -static dir_entry *find_directory_entry(fsdata *mydata, int startsect, - char *filename, dir_entry *retdent, __u32 start) +static dir_entry *find_directory_entry(fat_itr *itr, char *filename) { - __u32 curclust = sect_to_clust(mydata, startsect); - - debug("get_dentfromdir: %s\n", filename); + int match = 0; - while (1) { - dir_entry *dentptr; + while (fat_itr_next(itr)) { + /* check both long and short name: */ + if (!strcasecmp(filename, itr->name)) + match = 1; + else if (itr->name != itr->s_name && + !strcasecmp(filename, itr->s_name)) + match = 1; - int i; + if (!match) + continue; - if (get_cluster(mydata, curclust, get_dentfromdir_block, - mydata->clust_size * mydata->sect_size) != 0) { - printf("Error: reading directory block\n"); + if (itr->dent->name[0] == '\0') return NULL; - } - - dentptr = (dir_entry *)get_dentfromdir_block; - - dir_curclust = curclust; - - for (i = 0; i < DIRENTSPERCLUST; i++) { - char s_name[14], l_name[VFAT_MAXLEN_BYTES]; - - l_name[0] = '\0'; - if (dentptr->name[0] == DELETED_FLAG) { - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } - if ((dentptr->attr & ATTR_VOLUME)) { - if ((dentptr->attr & ATTR_VFAT) && - (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) { - get_long_file_name(mydata, curclust, - get_dentfromdir_block, - &dentptr, l_name); - debug("vfatname: |%s|\n", l_name); - } else { - /* Volume label or VFAT entry */ - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } - } - if (dentptr->name[0] == 0) { - debug("Dentname == NULL - %d\n", i); - empty_dentptr = dentptr; - return NULL; - } - - get_name(dentptr, s_name); - - if (strncasecmp(filename, s_name, sizeof(s_name)) && - strncasecmp(filename, l_name, sizeof(l_name))) { - debug("Mismatch: |%s|%s|\n", - s_name, l_name); - dentptr++; - if (is_next_clust(mydata, dentptr)) - break; - continue; - } + else + return itr->dent; + } - memcpy(retdent, dentptr, sizeof(dir_entry)); + if (!itr->dent && !itr->is_root && flush_dir_table(itr)) + /* indicate that allocating dent failed */ + itr->dent = NULL; - debug("DentName: %s", s_name); - debug(", start: 0x%x", START(dentptr)); - debug(", size: 0x%x %s\n", - FAT2CPU32(dentptr->size), - (dentptr->attr & ATTR_DIR) ? - "(DIR)" : ""); + return NULL; +} - return dentptr; +static int split_filename(char *filename, char **dirname, char **basename) +{ + char *p, *last_slash, *last_slash_cont; + +again: + p = filename; + last_slash = NULL; + last_slash_cont = NULL; + while (*p) { + if (ISDIRDELIM(*p)) { + last_slash = p; + last_slash_cont = p; + /* continuous slashes */ + while (ISDIRDELIM(*p)) + last_slash_cont = p++; + if (!*p) + break; } + p++; + } - /* - * In FAT16/12, the root dir is locate before data area, shows - * in following: - * ------------------------------------------------------------- - * | Boot | FAT1 & 2 | Root dir | Data (start from cluster #2) | - * ------------------------------------------------------------- - * - * As a result if curclust is in Root dir, it is a negative - * number or 0, 1. - * - */ - if (mydata->fatsize != 32 && (int)curclust <= 1) { - /* Current clust is in root dir, set to next clust */ - curclust++; - if ((int)curclust <= 1) - continue; /* continue to find */ - - /* Reach the end of root dir */ - empty_dentptr = dentptr; - return NULL; + if (last_slash) { + if (last_slash_cont == (filename + strlen(filename) - 1)) { + /* remove trailing slashes */ + *last_slash = '\0'; + goto again; } - curclust = get_fatent(mydata, dir_curclust); - if (IS_LAST_CLUST(curclust, mydata->fatsize)) { - empty_dentptr = dentptr; - return NULL; - } - if (CHECK_CLUST(curclust, mydata->fatsize)) { - debug("curclust: 0x%x\n", curclust); - debug("Invalid FAT entry\n"); - return NULL; + if (last_slash == filename) { + /* avoid ""(null) directory */ + *dirname = "/"; + } else { + *last_slash = '\0'; + *dirname = filename; } + + *last_slash_cont = '\0'; + *basename = last_slash_cont + 1; + } else { + *dirname = "/"; /* root by default */ + *basename = filename; } - return NULL; + return 0; } static int normalize_longname(char *l_filename, const char *filename) @@ -940,86 +787,60 @@ static int normalize_longname(char *l_filename, const char *filename) static int do_fat_write(const char *filename, void *buffer, loff_t size, loff_t *actwrite) { - dir_entry *dentptr, *retdent; - __u32 startsect; + dir_entry *retdent; __u32 start_cluster; - boot_sector bs; - volume_info volinfo; - fsdata datablock; + fsdata datablock = { .fatbuf = NULL, }; fsdata *mydata = &datablock; - int cursect; + fat_itr *itr = NULL; int ret = -1; + char *filename_copy, *parent, *basename; char l_filename[VFAT_MAXLEN_BYTES]; - *actwrite = size; - dir_curclust = 0; + filename_copy = strdup(filename); + if (!filename_copy) + return -ENOMEM; - if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { - debug("error: reading boot sector\n"); - return -EIO; + split_filename(filename_copy, &parent, &basename); + if (!strlen(basename)) { + ret = -EINVAL; + goto exit; } - total_sector = bs.total_sect; - if (total_sector == 0) - total_sector = (int)cur_part_info.size; /* cast of lbaint_t */ - - if (mydata->fatsize == 32) - mydata->fatlength = bs.fat32_length; - else - mydata->fatlength = bs.fat_length; - - mydata->fat_sect = bs.reserved; - - cursect = mydata->rootdir_sect - = mydata->fat_sect + mydata->fatlength * bs.fats; - num_of_fats = bs.fats; - - mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0]; - mydata->clust_size = bs.cluster_size; - - if (mydata->fatsize == 32) { - mydata->data_begin = mydata->rootdir_sect - - (mydata->clust_size * 2); - } else { - int rootdir_size; - - rootdir_size = ((bs.dir_entries[1] * (int)256 + - bs.dir_entries[0]) * - sizeof(dir_entry)) / - mydata->sect_size; - mydata->data_begin = mydata->rootdir_sect + - rootdir_size - - (mydata->clust_size * 2); + filename = basename; + if (normalize_longname(l_filename, filename)) { + printf("FAT: illegal filename (%s)\n", filename); + ret = -EINVAL; + goto exit; } - mydata->fatbufnum = -1; - mydata->fat_dirty = 0; - mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); - if (mydata->fatbuf == NULL) { - debug("Error: allocating memory\n"); - return -ENOMEM; + itr = malloc_cache_aligned(sizeof(fat_itr)); + if (!itr) { + ret = -ENOMEM; + goto exit; } - if (disk_read(cursect, - (mydata->fatsize == 32) ? - (mydata->clust_size) : - PREFETCH_BLOCKS, do_fat_read_at_block) < 0) { - debug("Error: reading rootdir block\n"); - ret = -EIO; + ret = fat_itr_root(itr, &datablock); + if (ret) goto exit; - } - dentptr = (dir_entry *) do_fat_read_at_block; - if (normalize_longname(l_filename, filename)) { - printf("FAT: illegal filename (%s)\n", filename); - ret = -EINVAL; + total_sector = datablock.bs_total_sect; + if (total_sector == 0) + total_sector = (int)cur_part_info.size; /* cast of lbaint_t */ + + ret = fat_itr_resolve(itr, parent, TYPE_DIR); + if (ret) { + printf("%s: doesn't exist (%d)\n", parent, ret); goto exit; } - startsect = mydata->rootdir_sect; - retdent = find_directory_entry(mydata, startsect, - l_filename, dentptr, 0); + retdent = find_directory_entry(itr, l_filename); + if (retdent) { + if (fat_itr_isdir(itr)) { + ret = -EISDIR; + goto exit; + } + /* Update file size and start_cluster in a directory entry */ retdent->size = cpu_to_le32(size); start_cluster = START(retdent); @@ -1062,9 +883,31 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, set_start_cluster(mydata, retdent, start_cluster); } } else { + /* Create a new file */ + + if (itr->is_root) { + /* root dir cannot have "." or ".." */ + if (!strcmp(l_filename, ".") || + !strcmp(l_filename, "..")) { + ret = -EINVAL; + goto exit; + } + } + + if (!itr->dent) { + printf("Error: allocating new dir entry\n"); + ret = -EIO; + goto exit; + } + + memset(itr->dent, 0, sizeof(*itr->dent)); + /* Set short name to set alias checksum field in dir_slot */ - set_name(empty_dentptr, filename); - fill_dir_slot(mydata, &empty_dentptr, filename); + set_name(itr->dent, filename); + if (fill_dir_slot(itr, filename)) { + ret = -EIO; + goto exit; + } if (size) { ret = start_cluster = find_empty_cluster(mydata); @@ -1085,10 +928,10 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } /* Set attribute as archieve for regular file */ - fill_dentry(mydata, empty_dentptr, filename, - start_cluster, size, 0x20); + fill_dentry(itr->fsdata, itr->dent, filename, + start_cluster, size, 0x20); - retdent = empty_dentptr; + retdent = itr->dent; } ret = set_contents(mydata, retdent, buffer, size, actwrite); @@ -1108,15 +951,17 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, } /* Write directory table to device */ - ret = set_cluster(mydata, dir_curclust, get_dentfromdir_block, - mydata->clust_size * mydata->sect_size); + ret = set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); if (ret) { printf("Error: writing directory entry\n"); ret = -EIO; } exit: + free(filename_copy); free(mydata->fatbuf); + free(itr); return ret; } From patchwork Fri Jul 20 02:57:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142413 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2437511ljj; Thu, 19 Jul 2018 20:00:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcLluYycHSLKw40F0/mNy1ZEbgHQiINDvSTJ1wjL53ljrdHjuVNCN3sbyYkZx47B9FmiQiP X-Received: by 2002:a50:9e2f:: with SMTP id z44-v6mr486613ede.303.1532055616066; Thu, 19 Jul 2018 20:00:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055616; cv=none; d=google.com; s=arc-20160816; b=W+6BSV4IDTPB4LnG89WagTzlV6sDH/rWLxk78JwurGJFR9/SrzRgksde5X/Pj2izVL 0DjqJhYmlIvArxbzYt4GzSLAFIxQLNEwFHwMdYl6ZIRNK1aSrnRj5MOL0rpucXkN0ql7 BLVPWI0ovEFuynznFsPeM04k4V8h+aC4Nl21zIbeOQ8HWQwNscoOvegma41M4mdZIFBq dNLj4cTMQwmYF1iSVuj4bLmro7gknwgsMNM8KhE2PlbFIl1ps59YnLj7BLIEBYBSvRpD blYhBZi+QdXquP4WMGX+Sk2Zt3Lfqm4raR4KI/Y1nd0TyGzVTqrv0m765GBAonVHaLrB DmkA== 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=fpi4ToqGD0aFjD9ckT30Nxd1FfznniqeSJROeB8zCJU=; b=lVSUCNxnvW/fUDvKO1rzQN6P0NRb8iCI7+pgh9L7g1ChC2DpD1MnJK21Ej97LQyiB0 dRGUK01gfyxtNfY3rZq0GQm+YRQSwGbt82PXkVU/SUh1sG9tObJa8S6iXEevJJ3tBPPO fuds71lJP5Rw2BphWG1tIjHeFg8el93yssAaGprFmyWaoPcVjNaZJMX9/WkoxqB8EDVw zqBndBYc+d0P9YmAC58NsrboFPF6Vm2KXnopXbuOJDhWqOwPBawvA52+oC1hlq0GrQnm juTpUseGWY9rIhZijdQxd9dRt8bbMAzn+Dzc4wenUfMKKCqQqemEA0g24jEwoT6l+nnu 9tBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Or+ibdTw; 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 j7-v6si863121edj.92.2018.07.19.20.00.15; Thu, 19 Jul 2018 20:00:16 -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=Or+ibdTw; 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 A6A10C21E1B; Fri, 20 Jul 2018 02:59:05 +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 2C616C21E0D; Fri, 20 Jul 2018 02:59:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 540D6C21D9A; Fri, 20 Jul 2018 02:57:46 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 24A4AC21D8E for ; Fri, 20 Jul 2018 02:57:45 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id g2-v6so5510211pgs.6 for ; Thu, 19 Jul 2018 19:57:45 -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=mZ0VFtsJ299qPD9pw0oWcdMdEsjf1I013YEVr4EGJB8=; b=Or+ibdTwHoKTLNXar7vJC8BUncOhKURQTphi31DantEw5x9vHiZkcgIy5RuyanxzQe KprubHcaRKivX5pglSqvd1z953iiD0DX3WhZj9ASP7qL7nYdAfuh7ny9Nfa7B/JTCDeM pdoUvJ3z5edCFJgkTwPYX5+2KAI9KtQmkTUTw= 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=mZ0VFtsJ299qPD9pw0oWcdMdEsjf1I013YEVr4EGJB8=; b=Ai/dxVl+k4KJ2wiYzoXq/rbNJdKkHCPBAzMwMtjwl2DdB3GZmI9jRj84PKz4FEt3Ry 6AYAFJse7r9v91+9VHR0w8M1EkkdRT+siFnJj2lsS0ffjmeM2jtuQvTMywR9qK/WPcUS uNyx28DJr73SdAVTKpXWuNt2DILMMVow0dd7IzLRiMKbz9Rgc1M69kUixge4XHLAkbIB 9Dj4eVhu6av1dlagbDsFgDfdcheOkpA7BC2Riwd3qPmKnUwR5D9mOEy4yQOE3HN+Khxq HaOSwTdE5lxSEj8piv46GiGln6YK3rGmDsKI87/qXONze8907Xp0vlEA3jIamWY2HTss TvPg== X-Gm-Message-State: AOUpUlH7Qpn9C1oHFMKg43E/km7+4oLvJGSq9Ac4KdvKliPxAsR9rT8W 5JEq5HsVvgObtsdbaqzGtKAS2w== X-Received: by 2002:a63:6441:: with SMTP id y62-v6mr299743pgb.240.1532055463735; Thu, 19 Jul 2018 19:57:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v22-v6sm810236pfi.60.2018.07.19.19.57.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:43 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:14 +0900 Message-Id: <20180720025723.6736-9-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 08/17] fs: fat: refactor write interface for a file offset 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" The current write implementation is quite simple: remove existing clusters and then allocating new ones and filling them with data. This, inevitably, enforces always writing from the beginning of a file. As the first step to lift this restriction, fat_file_write() and set_contents() are modified to accept an additional parameter, file offset and further re-factored so that, in the next patch, all the necessary code will be put into set_contents(). Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 178 +++++++++++++++++---------------------------- 1 file changed, 65 insertions(+), 113 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 96edb6674c..3a9c53e253 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -528,6 +528,43 @@ static int clear_fatent(fsdata *mydata, __u32 entry) return 0; } +/* + * Set start cluster in directory entry + */ +static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, + __u32 start_cluster) +{ + if (mydata->fatsize == 32) + dentptr->starthi = + cpu_to_le16((start_cluster & 0xffff0000) >> 16); + dentptr->start = cpu_to_le16(start_cluster & 0xffff); +} + +/* + * Check whether adding a file makes the file system to + * exceed the size of the block device + * Return -1 when overflow occurs, otherwise return 0 + */ +static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) +{ + __u32 startsect, sect_num, offset; + + if (clustnum > 0) { + startsect = clust_to_sect(mydata, clustnum); + } else { + startsect = mydata->rootdir_sect; + } + + sect_num = div_u64_rem(size, mydata->sect_size, &offset); + + if (offset != 0) + sect_num++; + + if (startsect + sect_num > total_sector) + return -1; + return 0; +} + /* * Write at most 'maxsize' bytes from 'buffer' into * the file associated with 'dentptr' @@ -535,29 +572,36 @@ static int clear_fatent(fsdata *mydata, __u32 entry) * or return -1 on fatal errors. */ static int -set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, +set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, loff_t maxsize, loff_t *gotsize) { - loff_t filesize = FAT2CPU32(dentptr->size); + loff_t filesize; unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; __u32 curclust = START(dentptr); __u32 endclust = 0, newclust = 0; loff_t actsize; *gotsize = 0; - debug("Filesize: %llu bytes\n", filesize); - - if (maxsize > 0 && filesize > maxsize) - filesize = maxsize; + filesize = maxsize; debug("%llu bytes\n", filesize); - if (!curclust) { - if (filesize) { - debug("error: nonempty clusterless file!\n"); + if (curclust) { + /* + * release already-allocated clusters anyway + */ + if (clear_fatent(mydata, curclust)) { + printf("Error: clearing FAT entries\n"); return -1; } - return 0; + } + + curclust = find_empty_cluster(mydata); + set_start_cluster(mydata, dentptr, curclust); + + if (check_overflow(mydata, curclust, filesize)) { + printf("Error: no space left: %llu\n", filesize); + return -1; } actsize = bytesperclust; @@ -568,6 +612,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, newclust = determine_fatent(mydata, endclust); if ((newclust - 1) != endclust) + /* write to */ goto getit; if (CHECK_CLUST(newclust, mydata->fatsize)) { @@ -614,18 +659,8 @@ getit: actsize = bytesperclust; curclust = endclust = newclust; } while (1); -} -/* - * Set start cluster in directory entry - */ -static void set_start_cluster(const fsdata *mydata, dir_entry *dentptr, - __u32 start_cluster) -{ - if (mydata->fatsize == 32) - dentptr->starthi = - cpu_to_le16((start_cluster & 0xffff0000) >> 16); - dentptr->start = cpu_to_le16(start_cluster & 0xffff); + return 0; } /* @@ -642,31 +677,6 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr, set_name(dentptr, filename); } -/* - * Check whether adding a file makes the file system to - * exceed the size of the block device - * Return -1 when overflow occurs, otherwise return 0 - */ -static int check_overflow(fsdata *mydata, __u32 clustnum, loff_t size) -{ - __u32 startsect, sect_num, offset; - - if (clustnum > 0) { - startsect = clust_to_sect(mydata, clustnum); - } else { - startsect = mydata->rootdir_sect; - } - - sect_num = div_u64_rem(size, mydata->sect_size, &offset); - - if (offset != 0) - sect_num++; - - if (startsect + sect_num > total_sector) - return -1; - return 0; -} - /* * Find a directory entry based on filename or start cluster number * If the directory entry is not found, @@ -784,11 +794,10 @@ static int normalize_longname(char *l_filename, const char *filename) return 0; } -static int do_fat_write(const char *filename, void *buffer, loff_t size, - loff_t *actwrite) +int file_fat_write_at(const char *filename, loff_t pos, void *buffer, + loff_t size, loff_t *actwrite) { dir_entry *retdent; - __u32 start_cluster; fsdata datablock = { .fatbuf = NULL, }; fsdata *mydata = &datablock; fat_itr *itr = NULL; @@ -796,6 +805,8 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, char *filename_copy, *parent, *basename; char l_filename[VFAT_MAXLEN_BYTES]; + debug("writing %s\n", filename); + filename_copy = strdup(filename); if (!filename_copy) return -ENOMEM; @@ -841,47 +852,8 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, goto exit; } - /* Update file size and start_cluster in a directory entry */ - retdent->size = cpu_to_le32(size); - start_cluster = START(retdent); - - if (start_cluster) { - if (size) { - ret = check_overflow(mydata, start_cluster, - size); - if (ret) { - printf("Error: %llu overflow\n", size); - ret = -ENOSPC; - goto exit; - } - } - - ret = clear_fatent(mydata, start_cluster); - if (ret) { - printf("Error: clearing FAT entries\n"); - ret = -EIO; - goto exit; - } - - if (!size) - set_start_cluster(mydata, retdent, 0); - } else if (size) { - ret = start_cluster = find_empty_cluster(mydata); - if (ret < 0) { - printf("Error: finding empty cluster\n"); - ret = -ENOSPC; - goto exit; - } - - ret = check_overflow(mydata, start_cluster, size); - if (ret) { - printf("Error: %llu overflow\n", size); - ret = -ENOSPC; - goto exit; - } - - set_start_cluster(mydata, retdent, start_cluster); - } + /* Update file size in a directory entry */ + retdent->size = cpu_to_le32(pos + size); } else { /* Create a new file */ @@ -909,32 +881,13 @@ static int do_fat_write(const char *filename, void *buffer, loff_t size, goto exit; } - if (size) { - ret = start_cluster = find_empty_cluster(mydata); - if (ret < 0) { - printf("Error: finding empty cluster\n"); - ret = -ENOSPC; - goto exit; - } - - ret = check_overflow(mydata, start_cluster, size); - if (ret) { - printf("Error: %llu overflow\n", size); - ret = -ENOSPC; - goto exit; - } - } else { - start_cluster = 0; - } - /* Set attribute as archieve for regular file */ - fill_dentry(itr->fsdata, itr->dent, filename, - start_cluster, size, 0x20); + fill_dentry(itr->fsdata, itr->dent, filename, 0, size, 0x20); retdent = itr->dent; } - ret = set_contents(mydata, retdent, buffer, size, actwrite); + ret = set_contents(mydata, retdent, pos, buffer, size, actwrite); if (ret < 0) { printf("Error: writing contents\n"); ret = -EIO; @@ -973,6 +926,5 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, return -EINVAL; } - printf("writing %s\n", filename); - return do_fat_write(filename, buffer, maxsize, actwrite); + return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } From patchwork Fri Jul 20 02:57:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142418 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2440675ljj; Thu, 19 Jul 2018 20:04:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcnf/6fYYN17VvPUTsSSk1/q9hp7ymgVIEu4BSzS5mim27L4xexQ9eJy2zKVmwixd+DGEKx X-Received: by 2002:a50:a584:: with SMTP id a4-v6mr553086edc.289.1532055853334; Thu, 19 Jul 2018 20:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055853; cv=none; d=google.com; s=arc-20160816; b=QZ5/aFasBHZTDnsagf3STtyHAmeq033+b97cYm3WJq8HztLkJj5renGPqwdH0H9u5m vyVB7+L5Bt8eWLAHrLq2hbiIvDq+bh8+seOdBac7Gsb/QZmcstsWku9uOV8AQgyjV0MF 9Hz2yiG2S2m4g9U3WQg/w26VFYastA83NZ1oOmglxTl0TPYTPQfa34DhfT5r9TE1YipF G8nEqLZinclozf2Ps7xWXhQerszy1JDASBKhpzfkV67xYL+u7ScGHq+te46pjX4LxPNi 4isEug2Ek2x9z9neCYD5KJuqr+8XjsnVVs93xj3KZ/0kVQlyQsxlh8BgalHwQnYBquJR mQHg== 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=2EY2NFdgtBgUhkWqkDMGw0GymsLVUaQxXeN8PRAESN4=; b=ic4pnMTuW9bffLC+OiT5NryBcAfQqh9G7oNig2bWihBZKoJrJ6P2I59LWnVado6wiH ALvpQD3Ie2fS5NIghzVwqyx8YW8TMtaH/LTfS9bxV6HwhLOCl8hVNm7BL/U4cU/Wg3MU lEBd80pFvgYVCtpPHTsJY9a9vRD2QqqJMIYg46S03ZwlnVE8YmFC6nHrukK4xSr7XCeM HZq0LpZLqzdcs9bYLq/L/A9vzDrcJK9k3jIyf6iH36hRZev9G8S4KzUpXIk+U7G5i5zX 8amScMWb0/WXZPaxfdgSgliZktWcBkLuxXsHwUWgluDScgv2Vo548KMS2UOF9/sc6+4q 7uog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZWtCBWZz; 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 y67-v6si205195ede.433.2018.07.19.20.04.13; Thu, 19 Jul 2018 20:04:13 -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=ZWtCBWZz; 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 BDF65C21DA2; Fri, 20 Jul 2018 03:01:03 +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 76A33C21E36; Fri, 20 Jul 2018 03:00:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B2962C21E36; Fri, 20 Jul 2018 02:57:57 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by lists.denx.de (Postfix) with ESMTPS id 9BBEFC21DFB for ; Fri, 20 Jul 2018 02:57:53 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id z7-v6so2735465plo.9 for ; Thu, 19 Jul 2018 19:57:53 -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=uTLOBoWrhW6WAFoX6WJPZT9BhXSiyH8UiiiGDYgVgkQ=; b=ZWtCBWZzor4Yr2VDvL72p9iU9KgN8Qd0KxJphX+mFUIdSHcwLlyQ4UJogZS7cjLoIu OxFAxhnMZp8BchhXu6r1w0qvi+2koWyo+/ayExyxBzU+aiShqcZCQ+/lRWef8PWT37TT GbjKOjBNATbnWr1lbq5P8hgOyEJtYQxFeH2y8= 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=uTLOBoWrhW6WAFoX6WJPZT9BhXSiyH8UiiiGDYgVgkQ=; b=p8MFwPl2wzTwI6qpD/FEZNZSgSCMNlgALCkyleVTbumrkxAQLIos+D9htyvZIahML7 cpv5p9Fh+Vr++wV6mDrSZIX/nQ8LuY1U+gqhf7nAPQH7YxygRgxHnDXZnjKu9kkl169s WKCEAv8p2msNGzYbfxtcZeD4oBz3em0D41ZNOUWCu//utnNzlZ3dGo3OV7cMFxi7fbRh E+YpotC9FoUMOpKsUfqUl99Zbd++aa3OEOo4YY0EHHTE977Aclq3t7oyNuHzveXfcxXO apJuv8jNZoyjDKpATkli1W4Eo2E5AphIfdHLa/mpb+7Nu1XYw7PNZOrkXgpXAQp8oCzZ 0JwA== X-Gm-Message-State: AOUpUlHbACV56T4KU33NqggUBz5G00ohgH+PzHP2LtRjEBu1ji7E40DW U2h4OAslMDfkVmK3HElzKar1SQ== X-Received: by 2002:a17:902:d70d:: with SMTP id w13-v6mr325252ply.40.1532055472238; Thu, 19 Jul 2018 19:57:52 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l3-v6sm638786pff.8.2018.07.19.19.57.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:51 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:15 +0900 Message-Id: <20180720025723.6736-10-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 09/17] fs: fat: support write with non-zero offset 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" In this patch, all the necessary code for allowing for a file offset at write is implemented. What plays a major roll here is get_set_cluster(), which, in contrast to its counterpart, set_cluster(), only operates on already-allocated clusters, overwriting with data. So, with a file offset specified, set_contents() seeks and writes data with set_get_cluster() until the end of a file, and, once it reaches there, continues writing with set_cluster() for the rest. Please note that a file will be trimmed as a result of write operation if write ends before reaching file's end. This is an intended behavior in order to maitain compatibility with the current interface. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 287 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 272 insertions(+), 15 deletions(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index 3a9c53e253..cc45a33876 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -450,6 +450,120 @@ set_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, return 0; } +static __u8 tmpbuf_cluster[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN); + +/* + * Read and modify data on existing and consecutive cluster blocks + */ +static int +get_set_cluster(fsdata *mydata, __u32 clustnum, loff_t pos, __u8 *buffer, + loff_t size, loff_t *gotsize) +{ + unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; + __u32 startsect; + loff_t wsize; + int clustcount, i, ret; + + *gotsize = 0; + if (!size) + return 0; + + assert(pos < bytesperclust); + startsect = clust_to_sect(mydata, clustnum); + + debug("clustnum: %d, startsect: %d, pos: %lld\n", clustnum, startsect, + pos); + + /* partial write at beginning */ + if (pos) { + wsize = min(bytesperclust - pos, size); + ret = disk_read(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error reading data (got %d)\n", ret); + return -1; + } + + memcpy(tmpbuf_cluster + pos, buffer, wsize); + ret = disk_write(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + + startsect += mydata->clust_size; + + if (!size) + return 0; + } + + /* full-cluster write */ + if (size >= bytesperclust) { + clustcount = lldiv(size, bytesperclust); + + if (!((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1))) { + wsize = clustcount * bytesperclust; + ret = disk_write(startsect, + clustcount * mydata->clust_size, + buffer); + if (ret != clustcount * mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + + startsect += clustcount * mydata->clust_size; + } else { + for (i = 0; i < clustcount; i++) { + memcpy(tmpbuf_cluster, buffer, bytesperclust); + ret = disk_write(startsect, mydata->clust_size, + tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", + ret); + return -1; + } + + size -= bytesperclust; + buffer += bytesperclust; + *gotsize += bytesperclust; + + startsect += mydata->clust_size; + } + } + } + + /* partial write at end */ + if (size) { + wsize = size; + ret = disk_read(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error reading data (got %d)\n", ret); + return -1; + } + memcpy(tmpbuf_cluster, buffer, wsize); + ret = disk_write(startsect, mydata->clust_size, tmpbuf_cluster); + if (ret != mydata->clust_size) { + debug("Error writing data (got %d)\n", ret); + return -1; + } + + size -= wsize; + buffer += wsize; + *gotsize += wsize; + } + + assert(!size); + + return 0; +} + /* * Find the first empty cluster */ @@ -579,26 +693,158 @@ set_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, __u8 *buffer, unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; __u32 curclust = START(dentptr); __u32 endclust = 0, newclust = 0; - loff_t actsize; + loff_t cur_pos, offset, actsize, wsize; *gotsize = 0; - filesize = maxsize; + filesize = pos + maxsize; debug("%llu bytes\n", filesize); - if (curclust) { - /* - * release already-allocated clusters anyway - */ - if (clear_fatent(mydata, curclust)) { - printf("Error: clearing FAT entries\n"); + if (!filesize) { + if (!curclust) + return 0; + if (!CHECK_CLUST(curclust, mydata->fatsize) || + IS_LAST_CLUST(curclust, mydata->fatsize)) { + clear_fatent(mydata, curclust); + set_start_cluster(mydata, dentptr, 0); + return 0; + } + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); + return -1; + } + + if (!curclust) { + assert(pos == 0); + goto set_clusters; + } + + /* go to cluster at pos */ + cur_pos = bytesperclust; + while (1) { + if (pos <= cur_pos) + break; + if (IS_LAST_CLUST(curclust, mydata->fatsize)) + break; + + newclust = get_fatent(mydata, curclust); + if (!IS_LAST_CLUST(newclust, mydata->fatsize) && + CHECK_CLUST(newclust, mydata->fatsize)) { + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); return -1; } + + cur_pos += bytesperclust; + curclust = newclust; + } + if (IS_LAST_CLUST(curclust, mydata->fatsize)) { + assert(pos == cur_pos); + goto set_clusters; } - curclust = find_empty_cluster(mydata); - set_start_cluster(mydata, dentptr, curclust); + assert(pos < cur_pos); + cur_pos -= bytesperclust; + /* overwrite */ + assert(IS_LAST_CLUST(curclust, mydata->fatsize) || + !CHECK_CLUST(curclust, mydata->fatsize)); + + while (1) { + /* search for allocated consecutive clusters */ + actsize = bytesperclust; + endclust = curclust; + while (1) { + if (filesize <= (cur_pos + actsize)) + break; + + newclust = get_fatent(mydata, endclust); + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) + break; + if (CHECK_CLUST(newclust, mydata->fatsize)) { + debug("curclust: 0x%x\n", curclust); + debug("Invalid FAT entry\n"); + return -1; + } + + actsize += bytesperclust; + endclust = newclust; + } + + /* overwrite to */ + if (pos < cur_pos) + offset = 0; + else + offset = pos - cur_pos; + wsize = min(cur_pos + actsize, filesize) - pos; + if (get_set_cluster(mydata, curclust, offset, buffer, wsize, + &actsize)) { + printf("Error get-and-setting cluster\n"); + return -1; + } + buffer += wsize; + *gotsize += wsize; + cur_pos += offset + wsize; + + if (filesize <= cur_pos) + break; + + /* CHECK: newclust = get_fatent(mydata, endclust); */ + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) + /* no more clusters */ + break; + + curclust = newclust; + } + + if (filesize <= cur_pos) { + /* no more write */ + newclust = get_fatent(mydata, endclust); + if (!IS_LAST_CLUST(newclust, mydata->fatsize)) { + /* truncate the rest */ + clear_fatent(mydata, newclust); + + /* Mark end of file in FAT */ + if (mydata->fatsize == 12) + newclust = 0xfff; + else if (mydata->fatsize == 16) + newclust = 0xffff; + else if (mydata->fatsize == 32) + newclust = 0xfffffff; + set_fatent_value(mydata, endclust, newclust); + } + + return 0; + } + + curclust = endclust; + filesize -= cur_pos; + assert(!(cur_pos % bytesperclust)); + +set_clusters: + /* allocate and write */ + assert(!pos); + + /* Assure that curclust is valid */ + if (!curclust) { + curclust = find_empty_cluster(mydata); + set_start_cluster(mydata, dentptr, curclust); + } else { + newclust = get_fatent(mydata, curclust); + + if (IS_LAST_CLUST(newclust, mydata->fatsize)) { + newclust = determine_fatent(mydata, curclust); + set_fatent_value(mydata, curclust, newclust); + curclust = newclust; + } else { + debug("error: something wrong\n"); + return -1; + } + } + + /* TODO: already partially written */ if (check_overflow(mydata, curclust, filesize)) { printf("Error: no space left: %llu\n", filesize); return -1; @@ -852,6 +1098,16 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } + /* A file exists */ + if (pos == -1) + /* Append to the end */ + pos = FAT2CPU32(retdent->size); + if (pos > retdent->size) { + /* No hole allowed */ + ret = -EINVAL; + goto exit; + } + /* Update file size in a directory entry */ retdent->size = cpu_to_le32(pos + size); } else { @@ -872,6 +1128,12 @@ int file_fat_write_at(const char *filename, loff_t pos, void *buffer, goto exit; } + if (pos) { + /* No hole allowed */ + ret = -EINVAL; + goto exit; + } + memset(itr->dent, 0, sizeof(*itr->dent)); /* Set short name to set alias checksum field in dir_slot */ @@ -921,10 +1183,5 @@ exit: int file_fat_write(const char *filename, void *buffer, loff_t offset, loff_t maxsize, loff_t *actwrite) { - if (offset != 0) { - printf("Error: non zero offset is currently not supported.\n"); - return -EINVAL; - } - return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } From patchwork Fri Jul 20 02:57:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142416 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2440003ljj; Thu, 19 Jul 2018 20:03:12 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeM6N0WE+KoFM/xr8s81dmnOsnvKkeZCSRXPfY5Pq4UKP7TY95K90fU64L9k+UxQDFmahfu X-Received: by 2002:a50:ef09:: with SMTP id m9-v6mr548743eds.136.1532055792338; Thu, 19 Jul 2018 20:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055792; cv=none; d=google.com; s=arc-20160816; b=jcS0YPhOotY+1mpiBtujJ0FdDeurhwlRcGB+zEjrKPKa6NuJXIUcv+CsSs0e0Lt1CV 1/okEM4fA9XF8uAXXhB52p4vuFwHHl8kQULXYZJGiZaQGtx//nFn96gxrEn9hQ5Chw4Z MIUfjPW/ZswDYpkPpYseNplOXTfz8DTzRe6AMxy6hhEYC/ptbkGD5dXyIbOkIVOJcQl2 TDSyb5qMxqBMLzinD8fbPP95WcwjqBUzWQ4npI5hgmPOLAz8KovgwtOb9bA+r9MXuJIC oVEcvFLHAet/sHx7BWqwZ7V1O5L7Gh0KT50rc3nXOHv7NZxuHa2oHVOlI0J2IpeXCCPP S73g== 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=ILXvt34x+ZvwfLNsc+pgR5qXUhPsVE/0shkL0otQONM=; b=HZ79awIDZjNcd0JNvluc8OihE+V8bat04OhumRez1lCAxk5Wy3kq+SqMjTBy9H8KM0 EEwzPtuGQoIj7jJfs5zcUAQBxKnW4bm13ILoZlnc/p9/8/BEqx98FF76Kgqe4Tj+m44+ 2j7hvMPAy/iZOkgjPGSYuCemSnjJInlZONYKslkPQICoD7mXTatcuXQzAsdZ+BZ0xRLG 3pR22i0zhsNAevXUcTXCEmgGh2TXmWhatH4+U0cLGC+lhQMFnGRrexxKxCTzrxkj0J7Y exO0MGPAhd1fJiJOhx+LVlx4vVH6a0wOtFXffWg66bSTkbKFzCka/GoME7xGWwyZXGZO 3iiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=f09E9Qec; 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 k1-v6si41017edc.350.2018.07.19.20.03.12; Thu, 19 Jul 2018 20:03:12 -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=f09E9Qec; 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 CAA31C21D74; Fri, 20 Jul 2018 03:02:07 +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 C4B71C21DA6; Fri, 20 Jul 2018 03:02:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 114A9C21CB1; Fri, 20 Jul 2018 02:58:05 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by lists.denx.de (Postfix) with ESMTPS id F1195C21DD9 for ; Fri, 20 Jul 2018 02:58:00 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id 31-v6so4517136plc.4 for ; Thu, 19 Jul 2018 19:58:00 -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=tQ1O2ymDUIanSLWNCcPprVYYR9mDSdAB3vbYd58Nw7c=; b=f09E9QecUoFbXjm1EzOlqDpvcB+GvHbzho2Ept1JZgiHvQ3tA1bweAnozUjvFQSkuH R9tbcaZv6gSjXnE0IJvlHxMlAyyaQXAGgFtcFXxLNCBK2JrQjAswVJyaTBS7e3ms/wpe 3wJkVX+Dtc/AdeMVLXPELiFcXohylCtMYduDI= 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=tQ1O2ymDUIanSLWNCcPprVYYR9mDSdAB3vbYd58Nw7c=; b=diuPxCbTqCcMu5j1orq4ZYg50W/vil03NK+Kw1vSswo/Aq6zOI7tsufXt8TcoynQaj apigf++XtrmkruoUuipoaQ/W/82adWoEpEBsZAo9hbGKTUxjBZgS4NqNYexSvwI5K73Q 4csdqeupHAupWLnhwywKh0aQmVtjOq9UygRzbk6V6MZKZ5QCt80ZG+djwaZz3QiAcj7d BKBBVoJ6tqqAwKKyQC5C4nLDFtWVJgx10jxtBL8aSHvo/7JMqKze4EcRV26vaSL/WMJZ /JJOPA466BQu3MiAS8k7EPGXiAAObIZX7rmCop6ZoofinPlq7UyLhXYYBN51FTciHKCg M+vA== X-Gm-Message-State: AOUpUlErdASJR4ETVgL2ueQKxO+f5zICTR9Q/GUhA++vRPSzNuriGN7F X8rB8YN2H+OiIOkNAP63NQhfjA== X-Received: by 2002:a17:902:292b:: with SMTP id g40-v6mr265768plb.273.1532055479696; Thu, 19 Jul 2018 19:57:59 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id s1-v6sm908756pfj.53.2018.07.19.19.57.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:57:59 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:16 +0900 Message-Id: <20180720025723.6736-11-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 10/17] cmd: fat: add offset parameter to fatwrite 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" In this patch, fatwrite command is extended so as to accept an additional parameter of file offset. Signed-off-by: AKASHI Takahiro --- cmd/fat.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/fat.c b/cmd/fat.c index 03de5d11af..2a5f7bfc26 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -104,6 +104,7 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, int ret; unsigned long addr; unsigned long count; + long offset; struct blk_desc *dev_desc = NULL; disk_partition_t info; int dev = 0; @@ -126,9 +127,11 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, } addr = simple_strtoul(argv[3], NULL, 16); count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16); + /* offset should be a hex, but "-1" is allowed */ + offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16); buf = map_sysmem(addr, count); - ret = file_fat_write(argv[4], buf, 0, count, &size); + ret = file_fat_write(argv[4], buf, offset, count, &size); unmap_sysmem(buf); if (ret < 0) { printf("\n** Unable to write \"%s\" from %s %d:%d **\n", @@ -142,9 +145,9 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, } U_BOOT_CMD( - fatwrite, 6, 0, do_fat_fswrite, + fatwrite, 7, 0, do_fat_fswrite, "write file into a dos filesystem", - " []\n" + " [ []]\n" " - write file 'filename' from the address 'addr' in RAM\n" " to 'dev' on 'interface'" ); 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 From patchwork Fri Jul 20 02:57:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142420 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2441011ljj; Thu, 19 Jul 2018 20:04:40 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfJFMCtSq83LXUsD1U+QX9X2Mrz7b9xcjt96xr7aVPLa3mxL7odTTc92KHCYPO4L8QV49xv X-Received: by 2002:aa7:da9a:: with SMTP id q26-v6mr519621eds.115.1532055880041; Thu, 19 Jul 2018 20:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055880; cv=none; d=google.com; s=arc-20160816; b=na8ocRWoankHUsou9Ul6TzQdL+A3eUP9FpwV0yp/nbHVg18GA8L5ERTfSvP8A+POZw ILkdbhRsZzkRWIJpeCX1XEooSjJ8OUWRnhhvkq7Rg0HSUSy35Zdj5XklztzpdzYDhFU0 4s46Yg8iZEIphcY5dr9JLZHBd7kTwoZ84OHDiG/yduOr/4AZqy9RP4lpJi4DOeag4TTJ p8r8VBG4A1sY9CKkaCXmWItM3CSJ8NU/cF2s90BDrddRdNuLIttf1S2mVYXttx1AhTqe iNW9fDDnkuy5XPcdyyE4NmHd1i+owFPru+Jc1HMRMwBpzW0Txm1tCmHASYILhHOHPEQ1 TBLA== 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=SIjZ4USAzgStL03M9j3QS/1hGoxX7uNmyZ31MUfvHRE=; b=OhouFXvs+3fewzF2Eu3+j4DnXkPvee6+vEXtUFqpVygHJww8T+k0NcL2IrdlWvDoOA 6bcREJJ3YMeb29EBV1AbQ0RdrgDBNUpoMXg69QOqC2Tc6X0ArYNZC9Y9MLxsR+UxFsnJ vtaKabVu8bJtvNfEEwmlKvV4W8Mznz3c37eYW0HMMgeiftPrNp376bnYnHLDKVMre+Om vdYLlKNmuy6CrlCNk58Uxr6XLUlIAsDgWYrpi+UgUtIITccidAsNO6nRT/QGN9MI++uu SRtYt6gOU73BMShc2s5qcWtPZ3+cVJdKcD2dLWd1BZZ/zcVDbk0Fys0tj03eSSXHMX2L Iqkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Dyyi6WXE; 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 v6-v6si899309edc.281.2018.07.19.20.04.39; Thu, 19 Jul 2018 20:04:40 -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=Dyyi6WXE; 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 A9DDFC21E50; Fri, 20 Jul 2018 03:02:44 +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 264BDC21E39; Fri, 20 Jul 2018 03:02:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 873FDC21DA2; Fri, 20 Jul 2018 02:58:23 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by lists.denx.de (Postfix) with ESMTPS id D2CC1C21D9A for ; Fri, 20 Jul 2018 02:58:19 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id o7-v6so4506710plk.10 for ; Thu, 19 Jul 2018 19:58:19 -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=PQZD4N1m/ve8xtW5V/Osp4UGVuLos6JSaLBGkr3LNLo=; b=Dyyi6WXEs9W7tIPQCTb3V1orVJS8Pi8je5+Wn91xaR2fMJXzV4K2v92/c6cLauegbL WtimOmI4LzAih6XZHiIGQeZFrZyf+go+TOrHHKttMYKwZj1Eg9CBY6IlXZWWpOr312u2 qPHYDNTMsUqcJFaj3+TSgopl49LuT4xKC2TvY= 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=PQZD4N1m/ve8xtW5V/Osp4UGVuLos6JSaLBGkr3LNLo=; b=rxCFqVswS5MiZoZgpmmfy70f6f/ExyBfSKfSnhQzHJoj4kBG/6ZayzrHkT/nPUZUdO Uu6jKSde/IpyxBRZ3PSvbd3Ld7EUuFaeSA8W76FjVqM3O43ZlTaNjF57f6ap2fIBEuLR hojCloaQTdfsKQfek19v+VX82cn73k5us7uUtqocVrGS6tz+ulAx/WWEpvU2aXmzLMnS aqZuv19u4FYM7/wL3n1AtBFGD8KNrjp0yu+2fakMLGDaiGoxf2FYe2KWaoJbWcKdp4DR KTcr5VPNHkIcogLm7DYWQu5D3h7s/YVPJxTzpufB5lXv+d/sPzMBvHrzZ7OA9AZDP1kU nTCg== X-Gm-Message-State: AOUpUlGQx0m7TLVwLvHSGJNjH3mwQV46ztPuu4ikh9iiAlPMzIdbM3mQ /Z9bv0KETGguLO6+UKuLwD4ayw== X-Received: by 2002:a17:902:8a4:: with SMTP id 33-v6mr256141pll.343.1532055498568; Thu, 19 Jul 2018 19:58:18 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l190-v6sm509987pgl.75.2018.07.19.19.58.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:17 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:18 +0900 Message-Id: <20180720025723.6736-13-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 12/17] fs: fat: remember the starting cluster number of directory 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" The starting cluster number of directory is needed to initialize ".." (parent directory) entry when creating a new directory. Signed-off-by: AKASHI Takahiro --- fs/fat/fat.c | 2 ++ include/fat.h | 1 + 2 files changed, 3 insertions(+) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 9bafc3a40c..ade5264551 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -639,6 +639,7 @@ int fat_itr_root(fat_itr *itr, fsdata *fsdata) return -ENXIO; itr->fsdata = fsdata; + itr->start_clust = 0; itr->clust = fsdata->root_cluster; itr->next_clust = fsdata->root_cluster; itr->dent = NULL; @@ -674,6 +675,7 @@ void fat_itr_child(fat_itr *itr, fat_itr *parent) assert(fat_itr_isdir(parent)); itr->fsdata = parent->fsdata; + itr->start_clust = clustnum; if (clustnum > 0) { itr->clust = clustnum; itr->next_clust = clustnum; diff --git a/include/fat.h b/include/fat.h index bc0f77abb5..295da0f243 100644 --- a/include/fat.h +++ b/include/fat.h @@ -197,6 +197,7 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect) typedef struct { fsdata *fsdata; /* filesystem parameters */ + unsigned start_clust; /* first cluster */ unsigned clust; /* current cluster */ unsigned next_clust; /* next cluster if remaining == 0 */ int last_cluster; /* set once we've read last cluster */ From patchwork Fri Jul 20 02:57:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142423 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2442036ljj; Thu, 19 Jul 2018 20:05:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdkM3szVAiGbTZsNmb4GWUnG4gt6nyFY2hk/fXR0+682L4GpNKxfJIMewvj0FKhYczG2ZZn X-Received: by 2002:a50:b5e6:: with SMTP id a93-v6mr525100ede.94.1532055959755; Thu, 19 Jul 2018 20:05:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055959; cv=none; d=google.com; s=arc-20160816; b=D5t6D9td4L2MxEVIzOQD6/ueoQVz4lprSV8cnWhsJOb0DQZNReRzh+xia3a9Pd7g6W 24TMmgsqCQMhUMnV3pkxrdzts0OlpWNIYp1F/Q+NtH+xy45MkFfFjdt3oDdrHM+h1qtI xaRlRDxNQys1U7INfhBXzU9d7ONYCtI/8mFximHmcdsmdEj5hjPyVPFix+lVKq2BdVFO mdovS3onfI6vhaFuSVvkkiM5cgUf0oCwhSKJY853iepIi8+OmWi47U/RcgCqjA7UPVIz yCRt8Km50JZsfMh8NmYkYS8dQEpzlvhmFD2GHoC3HetvWOkAQrTu+fPlG5MHaX1WyBKz /5EA== 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=STxayVKeXQmEO/Mq6xtOm2ibwlpyEYRp2gnN7HX0C+o=; b=RIUTexywLkZES2p2AV4/wT4/csRPIbRo7Iol+seRGja7uqtA1cStVVIASygArSQ2Gw Egy9IHZrICeVzlaSEnn2+m4HHwPwilc7zX/BCJiiDqGabTL38whG1xRig3ezjprBhvtW pJM7DEj123jjnn+nmEP8ph0FjioQEkPT0X8f/+YSiWmY2sccutztQA3109eKjDT/xm0T KVufISDwHlJo9lclXTH190tuWS1nXRLoFGHhqZroETj9jTLwleVezbVm85ZqdNsdFPYH 02draCdqzkmWKxG/WanxmT29uqOzkA6TqLXJz++3NEiSajJA1QldJHZeOb/T6wwP27P1 m5+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OFecIrcp; 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-v6si925510edl.232.2018.07.19.20.05.59; Thu, 19 Jul 2018 20:05:59 -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=OFecIrcp; 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 64FFFC21E53; Fri, 20 Jul 2018 03:02:26 +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 E32B6C21C4A; Fri, 20 Jul 2018 03:02:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B1465C21E1D; Fri, 20 Jul 2018 02:58:29 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id 0F60EC21D9A for ; Fri, 20 Jul 2018 02:58:29 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id v13-v6so5508831pgr.10 for ; Thu, 19 Jul 2018 19:58:28 -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=dip1A6GwtL4I4c5LfupKMoK0g2B5ytXLslfNbqfARDo=; b=OFecIrcpCiC3TCXs70ZF3QlZlCWAyzuaC2NdubgYzLqZrNICZkL2kcitfc9uEAA25E 0JadKF+y0EqUeYJKZLV3Pp8XT/7632JskuBhgnFPksE/TB9r9p6Pa+kgbqY/kECnk8ZJ mBft2QUrJ+s7cOxp3AKK/D7VZ7gp/nsvVCjxc= 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=dip1A6GwtL4I4c5LfupKMoK0g2B5ytXLslfNbqfARDo=; b=AVq11LyLM099Jjajrzqm2QzTRoDaX+h0rcYUlabFQbZJsaSzsXGUX8/apzJwVwYcoU LkIwn+w3AWVFas0m2kfdbZ9xkPuqOJXjWsk+fYPeUMc4R4Vt0B0RI/g6ohNFg+cJk9qV iQgvYVKBoodt4gpoOu/JloR5kDTCNAkQb4jxHzvPym1ZQ8jzVmwvH8HF+noCX5gZYx41 r2Sh2sEheFXpjTl/xk2oA3qNxfKqXdd5Dvwq9DJ1AmHLNEJJwyjq82mFRhTT91owhNRA 16o16mIcuQLnyfjDJJgBFL+F57JvaQ4NRFErZLVbkryRUt6DGCI1s3b6N3kYq724ssaJ QK/Q== X-Gm-Message-State: AOUpUlE9VO98BU5hd3t08LkCWL3GKMPOF3VJUvABrFn5OCn35z7B7F4r RzOOdLwsVLvFcPQWBfV7dHovj9Vvi6s= X-Received: by 2002:a62:245d:: with SMTP id r90-v6mr326047pfj.108.1532055507649; Thu, 19 Jul 2018 19:58:27 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l71-v6sm524968pgd.70.2018.07.19.19.58.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:27 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:19 +0900 Message-Id: <20180720025723.6736-14-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 13/17] fs: fat: support mkdir 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" In this patch, mkdir support is added to FAT file system. A newly created directory contains only "." and ".." entries. Signed-off-by: AKASHI Takahiro --- fs/fat/fat_write.c | 138 +++++++++++++++++++++++++++++++++++++++++++++ fs/fs.c | 3 +- include/fat.h | 1 + 3 files changed, 141 insertions(+), 1 deletion(-) diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c index cc45a33876..781883c9f4 100644 --- a/fs/fat/fat_write.c +++ b/fs/fat/fat_write.c @@ -1185,3 +1185,141 @@ int file_fat_write(const char *filename, void *buffer, loff_t offset, { return file_fat_write_at(filename, offset, buffer, maxsize, actwrite); } + +int fat_mkdir(const char *new_dirname) +{ + dir_entry *retdent; + fsdata datablock = { .fatbuf = NULL, }; + fsdata *mydata = &datablock; + fat_itr *itr = NULL; + char *dirname_copy, *parent, *dirname; + char l_dirname[VFAT_MAXLEN_BYTES]; + int ret = -1; + loff_t actwrite; + unsigned int bytesperclust; + dir_entry *dotdent = NULL; + + dirname_copy = strdup(new_dirname); + if (!dirname_copy) + goto exit; + + split_filename(dirname_copy, &parent, &dirname); + if (!strlen(dirname)) { + ret = -EINVAL; + goto exit; + } + + if (normalize_longname(l_dirname, dirname)) { + printf("FAT: illegal filename (%s)\n", dirname); + ret = -EINVAL; + goto exit; + } + + itr = malloc_cache_aligned(sizeof(fat_itr)); + if (!itr) { + ret = -ENOMEM; + goto exit; + } + + ret = fat_itr_root(itr, &datablock); + if (ret) + goto exit; + + total_sector = datablock.bs_total_sect; + if (total_sector == 0) + total_sector = (int)cur_part_info.size; /* cast of lbaint_t */ + + ret = fat_itr_resolve(itr, parent, TYPE_DIR); + if (ret) { + printf("%s: doesn't exist (%d)\n", parent, ret); + goto exit; + } + + retdent = find_directory_entry(itr, l_dirname); + + if (retdent) { + printf("%s: already exists\n", l_dirname); + ret = -EEXIST; + goto exit; + } else { + if (itr->is_root) { + /* root dir cannot have "." or ".." */ + if (!strcmp(l_dirname, ".") || + !strcmp(l_dirname, "..")) { + ret = -EINVAL; + goto exit; + } + } + + if (!itr->dent) { + printf("Error: allocating new dir entry\n"); + ret = -EIO; + goto exit; + } + + memset(itr->dent, 0, sizeof(*itr->dent)); + + /* Set short name to set alias checksum field in dir_slot */ + set_name(itr->dent, dirname); + fill_dir_slot(itr, dirname); + + /* Set attribute as archieve for regular file */ + fill_dentry(itr->fsdata, itr->dent, dirname, 0, 0, + ATTR_DIR | ATTR_ARCH); + + retdent = itr->dent; + } + + /* Default entries */ + bytesperclust = mydata->clust_size * mydata->sect_size; + dotdent = malloc_cache_aligned(bytesperclust); + if (!dotdent) { + ret = -ENOMEM; + goto exit; + } + memset(dotdent, 0, bytesperclust); + + memcpy(dotdent[0].name, ". ", 8); + memcpy(dotdent[0].ext, " ", 3); + dotdent[0].attr = ATTR_DIR | ATTR_ARCH; + + memcpy(dotdent[1].name, ".. ", 8); + memcpy(dotdent[1].ext, " ", 3); + dotdent[1].attr = ATTR_DIR | ATTR_ARCH; + set_start_cluster(mydata, &dotdent[1], itr->start_clust); + + ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, bytesperclust, + &actwrite); + if (ret < 0) { + printf("Error: writing contents\n"); + goto exit; + } + /* Write twice for "." */ + set_start_cluster(mydata, &dotdent[0], START(retdent)); + ret = set_contents(mydata, retdent, 0, (__u8 *)dotdent, bytesperclust, + &actwrite); + if (ret < 0) { + printf("Error: writing contents\n"); + goto exit; + } + + /* Flush fat buffer */ + ret = flush_dirty_fat_buffer(mydata); + if (ret) { + printf("Error: flush fat buffer\n"); + goto exit; + } + + /* Write directory table to device */ + ret = set_cluster(mydata, itr->clust, itr->block, + mydata->clust_size * mydata->sect_size); + if (ret) + printf("Error: writing directory entry\n"); + +exit: + free(dirname_copy); + free(mydata->fatbuf); + free(itr); + free(dotdent); + return ret; +} diff --git a/fs/fs.c b/fs/fs.c index 3cb6b21fe9..a92e060296 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -164,14 +164,15 @@ static struct fstype_info fstypes[] = { .read = fat_read_file, #ifdef CONFIG_FAT_WRITE .write = file_fat_write, + .mkdir = fat_mkdir, #else .write = fs_write_unsupported, + .mkdir = fs_mkdir_unsupported, #endif .uuid = fs_uuid_unsupported, .opendir = fat_opendir, .readdir = fat_readdir, .closedir = fat_closedir, - .mkdir = fs_mkdir_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 diff --git a/include/fat.h b/include/fat.h index 295da0f243..039b6e03de 100644 --- a/include/fat.h +++ b/include/fat.h @@ -237,5 +237,6 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len, int fat_opendir(const char *filename, struct fs_dir_stream **dirsp); int fat_readdir(struct fs_dir_stream *dirs, struct fs_dirent **dentp); void fat_closedir(struct fs_dir_stream *dirs); +int fat_mkdir(const char *dirname); void fat_close(void); #endif /* _FAT_H_ */ From patchwork Fri Jul 20 02:57:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142417 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2440218ljj; Thu, 19 Jul 2018 20:03:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf40mxkIFXzSlbrDb8qq/l6DuKV7ny4Wng0XDpCjwLjP27w+9YkyvlUtx+riH24VK4q31gf X-Received: by 2002:a50:b764:: with SMTP id g91-v6mr559384ede.187.1532055812279; Thu, 19 Jul 2018 20:03:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055812; cv=none; d=google.com; s=arc-20160816; b=0TBDyXDW2bK1yJqcUGhwTIqhU1PJIUN8JJngeqqWVv0dlUcL8w0oBN6DORNa1pEK7n hcnJPfik4q4Cp85W1dfjqCYQ7bctsGlkUFu/zW0qgsvMYRdns9fIGDCmRx/AhkMbFqbR tSrDb7CoX94hs0JYnRkxCEH1flfGFnGhf6KVpW4pOxsILWcWybX+nJZZT/oK6Kp5YMLi yQcogahVexhEJ+jtuXG9fHt94BQdaeVPUJFZAA4R7AdnJLWWPuQU9nRNXLu4UTNcgC6A L8gCzHVQa4vam7ouy5Q/DGB5PowQ7yCZ6A5KTm9o3C92ygc+oyIP+WZKq/84Bam58dLQ l4Jg== 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=1GTdiWm2kQiOswA3xvE1eUV+zspiaH7aIltciaNTPH8=; b=pg60M3BQ+aKv1ROfqCzeqkUIiveyMzu4J9T+NcqTNNaBf2gD4D4gMm6lr+k8CW57o+ WLqrEw/Bje5IrM54PRO4B5YTmlTEeal7zQQ8bZ6HHeysj/5V3P0q87ytaxUtaaEJVJ56 R6h295gjzk8IT4E5KWIaposlgdIgPCY6EzwfwSv62htxAIOhMTCBn7ZWT40nRnTc08eY vE44Brj1zvy9m8+Rr2rToNewmfS6Uqz2WodA/obR1u/xTJJHUaBZg4REzsOgycPWJSFi jygqYoFhTYGPMR54eanIHzeePCOuoWg9BZK3iiDTLIuyKwZdjouu8wQWIyKjf4mS0utJ W+dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=NGqniW0u; 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 n17-v6si852821edf.15.2018.07.19.20.03.32; Thu, 19 Jul 2018 20:03:32 -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=NGqniW0u; 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 DA029C21DF9; Fri, 20 Jul 2018 03:01:40 +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 93143C21CB1; Fri, 20 Jul 2018 03:01:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9BCD1C21C57; Fri, 20 Jul 2018 02:58:37 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id 006AFC21DC1 for ; Fri, 20 Jul 2018 02:58:36 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id n7-v6so5510382pgq.4 for ; Thu, 19 Jul 2018 19:58:36 -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=UVflIeyMl5xttb3jczQKDbH55jd7rVdkbcdw3w30Df8=; b=NGqniW0uP1f0lMvPjvTo0RdA10pn1rjL48X6lV/QZy8q1cl6GM4fn/94dmIGK353uq njtRlmWsEk+1PsR7OLptdtJNqzyQwl7pXBJqPEnyR9/ALXEPccUBD6tiw11gRSP9HcdI ofe8K9jTzO53xgZVvlTtttAJ5O+87/m8IpQ+A= 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=UVflIeyMl5xttb3jczQKDbH55jd7rVdkbcdw3w30Df8=; b=UKo7Vgh0o337H1RZwiwdy3HoBhOdnAk0+QhKDFnxs1keK2Qbb8jZf7IqRQhHba/3oZ x5gsj8oDCaMtVf0arP835AgtnenFbtiRa3911QmVSlwnrdOqGCnRuj05wEHzPc+rOwgp DTcP+eGLXidM6c3OhFHuK9WbLpok8KlWDgXF15urkaNtJO+dFB7GrMAHpIzpJa47tCFL F/Slg4mFudBtwTVphA8s2ncnW9wqBya39Itz3Oei41RTlUi57notnLJxzqHNQNPZfapx rvAf18dVW6uKMyBb2/P6fqJ1ykxzz1d/9lM4qYnZNkZ2D918tOyHx0oToa1F0FPGNmK8 f8ag== X-Gm-Message-State: AOUpUlH1JQtXJ4BecyjhzPqbF/MHMVCQ3Vh/1qbLbXmCNtdqKlgTthBj Rl4wLqb9RpYWK9ku+AfmD/1z0Q== X-Received: by 2002:a63:ce12:: with SMTP id y18-v6mr311911pgf.144.1532055515724; Thu, 19 Jul 2018 19:58:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id t63-v6sm510186pgt.57.2018.07.19.19.58.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:35 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:20 +0900 Message-Id: <20180720025723.6736-15-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 14/17] cmd: fat: add fatmkdir command 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" In this patch, a new command, fatmkdir, is added. Please note that, as there is no notion of "current directory" on u-boot, a directory name specified must contains an absolute directory path as a parent directory. Otherwise, "/" (root directory) is assumed. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/fat.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/fat.c b/cmd/fat.c index 2a5f7bfc26..136a5114c6 100644 --- a/cmd/fat.c +++ b/cmd/fat.c @@ -151,4 +151,17 @@ U_BOOT_CMD( " - write file 'filename' from the address 'addr' in RAM\n" " to 'dev' on 'interface'" ); + +static int do_fat_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT); +} + +U_BOOT_CMD( + fatmkdir, 4, 1, do_fat_mkdir, + "create a directory", + " [] \n" + " - create a directory in 'dev' on 'interface'" +); #endif From patchwork Fri Jul 20 02:57:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142419 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2440811ljj; Thu, 19 Jul 2018 20:04:24 -0700 (PDT) X-Google-Smtp-Source: AAOMgpddImH8VdcjJFROrTL9W3nTM7K665mK537kkEEN/FxNKQwJ0BkbuWHtOjkhy44JNLaZUVBZ X-Received: by 2002:a50:db03:: with SMTP id o3-v6mr528556edk.76.1532055863970; Thu, 19 Jul 2018 20:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055863; cv=none; d=google.com; s=arc-20160816; b=lt4poBcL7TZv0AzwuzDJDRaJztl9apUyfEz4FeSA5j6RrM7N1A1rfnXCE3ElbODd6o hcPo3wzQxhk7WzZ/mC3z8B8ytNzCpNRQZzsV5Pg8ubrIrXD4bs5oYw2Xi7ay2wnWSRc3 28kmGeKlZWG2+1y9BKdX/xyg0aZ36g70B7UeguZ19e7PGtAO4saOu3n5bxKS2FBYKXbw 2BLg003vnlE/njslwpeF9I+ICJALsOrnY6E5eK1iYcpmzgdK40gx44GHzCDDTb05SLwy qZohYHJ3oeGVLRsTn+IlWgizWWJskTn9HHywZvxCiO0r2sXDD1btoTSVee0XLp/Noi1h gcsg== 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=miO1LB8uRIK/opUJk9iGPja81xlTJkmIQ9FE4JPhASI=; b=oMuH05l2cemQDJ2rfWfjluAr9V0mQlr5CsaEZo08b0l8WCpnq4tk8tUZ572PMjcgvi y2wsHsiqLw17lIdz3qPKMA9Cd8OX2bw1aGcD7vIsijSNyDTwVpwqvocqhyLciDY4caa+ vw+/gcMMfYkdUAz9jneMcye9/vhtr+gUPO/BzNIJ2bBmzbrrlXDpMrVH8+ZNMIkY36VU YwXJZLDnSkfpHyBVLg5BcwG2frY3yazY4EPB7W/e/WT1Uuf75dbXocDwoFIAVsc/Q0FV PN1DyYFQgaTweFkxWu/omI18FPUus99DV6p5Nrh+pIPwasPjuNy4tHvKX2UZOJ/gy+W6 Ok4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=WVlHw0tF; 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 w11-v6si577971edq.75.2018.07.19.20.04.23; Thu, 19 Jul 2018 20:04:23 -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=WVlHw0tF; 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 9AA94C21E50; Fri, 20 Jul 2018 03:00:11 +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 42B0AC21D4A; Fri, 20 Jul 2018 02:59:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AE462C21D74; Fri, 20 Jul 2018 02:58:49 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by lists.denx.de (Postfix) with ESMTPS id EBB76C21D74 for ; Fri, 20 Jul 2018 02:58:45 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id r1-v6so5506790pgp.11 for ; Thu, 19 Jul 2018 19:58:45 -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=2Io2oeoR/DFJb2qJUSf9S9jujfFCbN3bLZmhiLBVUmw=; b=WVlHw0tF3Hs/6fPef3f4hVnwT/zF0CwnZAKVdbidG7BXV9HKnwfwIhNSgz5tjIr2oB lEbJAp4Kw9XZnJHnU3euCSgt2cNa2x3OtFbxWTmsRA+SJAzePI0YS/1e34tCKKUAtbuL hUqFzLRRV9xefyLx+v6Z7DtZsFDO2JW7wtneM= 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=2Io2oeoR/DFJb2qJUSf9S9jujfFCbN3bLZmhiLBVUmw=; b=YALJvJ9p/KhtL5O40Y2OIllwA6paFlRZNckwKyb9yuFUI4eC2LqG45b9YViXrY26G6 NyL7NkK8U+50/5zC7lL9myNmC0sWDjGL6XcorHfRbgUetqS+sykEIwQJ7lhpqWaXq7b2 EQfzwflB6uFbvU9hh6DuqWDZA2Jnli85r/VN6Bh4MTSxNYOEnNPq82KFgXCXYOtmLhO8 qXQlZyKB0H+6SvtuEYhL4zZrtl5oz27qM/c1QJYCX3YLbo4pXIzCiUjLWIdFyM3hLcnz 5XcSf2Zgmaxd4YcbrB86nSuJegupYMMtFfipoYGYsuGkzMIvQupLvQyAixEn/2DVkcHc aRig== X-Gm-Message-State: AOUpUlHG/CLVRv5xZneUGP44WfcwJP0iQJeof66zg6HKhwmIYlb5Iz1J 1pcN8tLgJZCn0kaN1mSIPDC2Ig== X-Received: by 2002:a65:49c7:: with SMTP id t7-v6mr290254pgs.23.1532055524650; Thu, 19 Jul 2018 19:58:44 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id x5-v6sm599923pfh.67.2018.07.19.19.58.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:44 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:21 +0900 Message-Id: <20180720025723.6736-16-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 15/17] efi_loader: file: support creating a directory 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" In efi world, there is no obvious "mkdir" interface, instead, Open() with EFI_FILE_MODE_CREATE in mode parameter and EFI_FILE_DIRECTORY in attributes parameter creates a directory. In this patch, efi_file_open() is extended so as to accept such a combination of parameters and call u-boot's mkdir interface for expected action. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index e6a15bcb52..6ec98c8022 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -130,7 +130,8 @@ static int sanitize_path(char *path) * With windoze style backlashes, ofc. */ static struct efi_file_handle *file_open(struct file_system *fs, - struct file_handle *parent, s16 *file_name, u64 mode) + struct file_handle *parent, s16 *file_name, u64 mode, + u64 attributes) { struct file_handle *fh; char f0[MAX_UTF8_PER_UTF16] = {0}; @@ -173,7 +174,12 @@ static struct efi_file_handle *file_open(struct file_system *fs, if (set_blk_dev(fh)) goto error; - if (!((mode & EFI_FILE_MODE_CREATE) || fs_exists(fh->path))) + if ((mode & EFI_FILE_MODE_CREATE) && + (attributes & EFI_FILE_DIRECTORY)) { + if (fs_mkdir(fh->path)) + goto error; + } else if (!((mode & EFI_FILE_MODE_CREATE) || + fs_exists(fh->path))) goto error; /* figure out if file is a directory: */ @@ -199,7 +205,7 @@ static efi_status_t EFIAPI efi_file_open(struct efi_file_handle *file, EFI_ENTRY("%p, %p, \"%ls\", %llx, %llu", file, new_handle, file_name, open_mode, attributes); - *new_handle = file_open(fh->fs, fh, file_name, open_mode); + *new_handle = file_open(fh->fs, fh, file_name, open_mode, attributes); if (!*new_handle) return EFI_EXIT(EFI_NOT_FOUND); @@ -598,7 +604,7 @@ efi_open_volume(struct efi_simple_file_system_protocol *this, EFI_ENTRY("%p, %p", this, root); - *root = file_open(fs, NULL, NULL, 0); + *root = file_open(fs, NULL, NULL, 0, 0); return EFI_EXIT(EFI_SUCCESS); } From patchwork Fri Jul 20 02:57:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142421 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2441242ljj; Thu, 19 Jul 2018 20:04:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeGFGkQgR2gV/in2azlp/x0/JKXzou/wFsTWd37+idjOziug5lJ8+DL+eWHTJZ3NtNLXdMg X-Received: by 2002:a50:c986:: with SMTP id w6-v6mr540089edh.222.1532055897806; Thu, 19 Jul 2018 20:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055897; cv=none; d=google.com; s=arc-20160816; b=D+j7CgbbxrzEoGVE/sHJhp9UGx+Ww4rO3fZ+VL/P/ABAnW+4mm7KUpc3LIh6ar8vfS dOKyyQ06fGY5LXlcS8n6DAHPayWiTPI4IPVsyKpomHspkKzNuOYIBz+RPmevZfLbQLI/ cd6kewjgeF0lgVG9TaTFB2qp86T04CZci8/lK1HZnTB4PywCmZzHAW3qdoPSVxlq0RjD Jqv81Xd+pQGAB+ShYnGKwSIeO4fKjMKib43bj+iRF3bwx6Iq2D3SdWrPoiZjrBosT7N9 hbfFVxr81XbH++NTSFOiGhVxzBmx2GxTS3IUmJbZveFEREuoz0oYUt+HtwcnM2kryEYx fR9w== 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=oxcHy6QraQTKgzYvVM3T6pVoFz+NhPQ3itSmbgfwPL4=; b=XVrHHJfXs3sAOlzS+lz+QOLumLxs8YdKPH6gUUxivMpqpiOmb45pMqhAT5B4xVHL4e s0UEwGsnJSnE1kX3cu/En+4Nd2im+P2PYkTe0KkxHB9NOu9xHgd/BwVSrA9neAJV0E1d cys8jeKAgatoIhOkUF4sbDESLwit2awgmiVJvXEHmkC8aO65Yftd0yBSl6126C1d/n7K 3a7aztgxE4S4+jYdpacfVL03HemKlLRAl1FzC0tuDb3qKppDZNfAgA8Aos6O+ZXAiSye 1TiFyyCEijicY3qGXqCyui+6ZrdG5qBNn5yM1BzdrzQ8VUCLOl8huPjJWe6nq5C7lwTk 47TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fU8TRYD4; 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 q6-v6si714055edr.390.2018.07.19.20.04.57; Thu, 19 Jul 2018 20:04:57 -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=fU8TRYD4; 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 559F5C21C27; Fri, 20 Jul 2018 03:03:11 +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 AAE4AC21DF9; Fri, 20 Jul 2018 03:03:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A07B7C21E2B; Fri, 20 Jul 2018 02:58:56 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) by lists.denx.de (Postfix) with ESMTPS id A37BFC21D74 for ; Fri, 20 Jul 2018 02:58:54 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id w8-v6so4506005ply.8 for ; Thu, 19 Jul 2018 19:58:54 -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=6DI0QLAmKvJ06ZXTLO5lgRPP1xRoOV1Fk5r5+9K5ktE=; b=fU8TRYD4hsP4d1xyNJ5dDWplumFLO3lKKTrupioPkOdH4nGclKIQhbaspdfBxxZRr8 nZXWTWZaVSqTy/ZIpzrQKV+1hNwyfb5zDWk0CfmYRlUFx7zUhyYnlJcD2OQYDK83/cRb mGKX6tdMhdsS/96e7D03Wd4B4dvSo5BL2JKDQ= 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=6DI0QLAmKvJ06ZXTLO5lgRPP1xRoOV1Fk5r5+9K5ktE=; b=hdFZI4FR6gbfgbNeux7XTLn8yzKoaxR427SlBuYixREr14Mv8jxA9lG1R7RBqUknKs 4omzjNxSY3OBmaCmD3WUwJN2euV7qVINMeXnpzmP0thxGiGkUypjfv5oS0EeaEJ3yP5r JOCjWetLLyC3YSj19ssbS4wEZI80LUpoYh0EVisSSQQNJI8v1Ro1bM4iGRE1jjMqoR8W GHohHxSdqJpB4jZINfwYEOnogfuzPI4iE16u2AwNk0mWKo618Oa0JrpFxkHsrWLeYI4C H/YESY+2B1uJERD7U8xKptzlMiMLkkyUE2k8KxeymqyxKQzPQY5TxeLxg4m7QeR9o7nV nNSQ== X-Gm-Message-State: AOUpUlHyqOTak1bxZfb2Y4XLfD5CoZpkCKBSmY1pICO8KH5aBGC90stf rrqD7DIx/UQkbFNbIa3eN+dW0g== X-Received: by 2002:a17:902:22e:: with SMTP id 43-v6mr323996plc.82.1532055533368; Thu, 19 Jul 2018 19:58:53 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r81-v6sm845411pfa.18.2018.07.19.19.58.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:58:52 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:22 +0900 Message-Id: <20180720025723.6736-17-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 16/17] efi_loader: implement a pseudo "file delete" 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" This patch is necessary to run SCT.efi (UEFI Self-Certification Test). Returning EFI_SUCCESS can cheat SCT execution. Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_file.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 6ec98c8022..12044a0c71 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -226,12 +226,20 @@ static efi_status_t EFIAPI efi_file_close(struct efi_file_handle *file) return EFI_EXIT(file_close(fh)); } +static efi_status_t EFIAPI efi_file_write(struct efi_file_handle *file, + efi_uintn_t *buffer_size, + void *buffer); + static efi_status_t EFIAPI efi_file_delete(struct efi_file_handle *file) { struct file_handle *fh = to_fh(file); + efi_uintn_t size = 0; EFI_ENTRY("%p", file); + + /* TODO: implement real 'delete' */ + efi_file_write(file, &size, NULL); file_close(fh); - return EFI_EXIT(EFI_WARN_DELETE_FAILURE); + return EFI_SUCCESS; } static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size, From patchwork Fri Jul 20 02:57:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 142422 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2441532ljj; Thu, 19 Jul 2018 20:05:18 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcx/5zWxdKwvn0H7uTEAMdNzAbXWbu9JXLrX82PwyTSmr0YsBdd9U1qf4O7JQd/7OPooQ5Y X-Received: by 2002:a50:f78a:: with SMTP id h10-v6mr516738edn.37.1532055918334; Thu, 19 Jul 2018 20:05:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532055918; cv=none; d=google.com; s=arc-20160816; b=qsugW3qdWjtKMq66nN8GZCMJORR35KibpzKopZ1kOq79GbKiVYgL2psC5905V7QVBB oAgYhnykfSK7wPjW6OSHG4trAPtNqY7pGZVWsFRwvxeSQ8CwNEwYDAK9YR8hG1++fEVl mCuG6xpmycIhas9k7CkXWkBnM23rzLc0qbouePpWcLHvu/nZ/qAJPt4ucJfNUhWflNJ6 W35XVy/MQbh1ykeU7ucStVSJEGBRLe5AloT45pQPgIxfds/DKWYl8yOwZ/4AA/5+xkqf DM96W0IhEcAg1TjyB7I0ABF1uXBg/nkvpQKcbMpXWwtUoPJQqsS5Iil65VVl/CWx0YZb vkjg== 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=g4A3elZ4/shPD6LNCG52oFtfDWEEhR0BMgD+vOFan80=; b=V3H3gOyykTlWOTzMw+6uwHXdD07Kaix4NIrWjF1Ma4PbSH4Ygpr29fHpwqTCdsfIbv u/jZ8pQPUKZ8YUpNHwdgVW3bEyMPZJKiK98ii+O2ykt9p950orwo4/Dk5mChywsUjBGt ubdIvju43C+ATxlUTSM5DOn4TNVam+edRTnKAdkhNzN8sd/v/k2ffOx9XZP4cnio8RCG aWuN6eOra2Lvn0A9t0pBDWOX6cb4jzO/2c0NM6kZ05mO5rZbopb3PHjn4HXp14hHsmmC yibe8MiM+mz4vdHeEjDfhp618WdEYIfpagPbyI35itsFnSTkQ0cHU6gurT15fv5xFK0K QuCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Gu9juOb/"; 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 w12-v6si744137edh.154.2018.07.19.20.05.18; Thu, 19 Jul 2018 20:05:18 -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="Gu9juOb/"; 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 D92C3C21E2B; Fri, 20 Jul 2018 03:00:42 +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 75636C21E1B; Fri, 20 Jul 2018 03:00:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0DB47C21E68; Fri, 20 Jul 2018 02:59:06 +0000 (UTC) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by lists.denx.de (Postfix) with ESMTPS id EE76BC21E1A for ; Fri, 20 Jul 2018 02:59:01 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id k3-v6so5510877pgq.5 for ; Thu, 19 Jul 2018 19:59: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=w0QoagawiMmP3KF9nft71v8ELQ70x1+HF5/6amiJQvk=; b=Gu9juOb/opbM1yEwrSQGTbWBL0ABIylCzdOrKY6YL/2i/1v01pzeUrEJV5BQ7UKaNl lib3B6IleVZsnj7GLxHEwaCaPPkCBSXRH06mSc/yJAmvuycnd4zur/mT6HlxubohhKGk cBmVzWXWhAU1AhcRMs96AIDK7Z9h2t0XaNkfE= 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=w0QoagawiMmP3KF9nft71v8ELQ70x1+HF5/6amiJQvk=; b=JArWOEBnWR4Cyy9YSHAIdyWub3V8902uY8HzNWQJVWL2CNvdQL0qFGJeIoA0kX127w QhP8ZZzR6cViLiAgJ6toMB/NxcmrdS0lSoqbrq+XBOwV+JOUBVrK/KtfEl5u1dMPfYzF hbnL1Vg8ptRxmL9jolXz3qXRlW3UOMEvli/7UyShoeQ97cNFjYiXxCqdZpoeZt/+XdEh T0u63QGLJQcW9kwnPInSsUAzUfzOMYzFKAl6TF2n0ZaEVUaDA4TwS3dCdP9qKXkx1YO8 /7nzo9tgR7lL+hUdH8yeK/Oqfr5u/gGgWpVyhNYS7Es8bH0pH/aJY4B/2cAPFK3MjYLe Puxg== X-Gm-Message-State: AOUpUlFL2l/B7SWdcwcGvIXq+PE3L5jaRMwr7ks843bXhbvFbPpzP9Mh CmF2lWpw/wDaZpQygsrR8veEig== X-Received: by 2002:a63:f45:: with SMTP id 5-v6mr262487pgp.447.1532055540703; Thu, 19 Jul 2018 19:59:00 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id o21-v6sm717764pfa.54.2018.07.19.19.58.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 19:59:00 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com Date: Fri, 20 Jul 2018 11:57:23 +0900 Message-Id: <20180720025723.6736-18-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 17/17] fs-test: fix false positive error at Test Case 12 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" The error message to be matched is wrong. Fix it. Signed-off-by: AKASHI Takahiro --- test/fs/fs-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fs/fs-test.sh b/test/fs/fs-test.sh index 2e8d5ee4df..7b0c5ea56f 100755 --- a/test/fs/fs-test.sh +++ b/test/fs/fs-test.sh @@ -522,7 +522,7 @@ function check_results() { "TC11: 1MB write to $3.w - content verified" # Check lookup of 'dot' directory - grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write file' + grep -A4 "Test Case 12 " "$1" | grep -q 'Unable to write' pass_fail "TC12: 1MB write to . - write denied" # Check directory traversal