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));