Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/809107/?format=api
{ "id": 809107, "url": "http://patchwork.ozlabs.org/api/patches/809107/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170902163806.27265-4-robdclark@gmail.com/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20170902163806.27265-4-robdclark@gmail.com>", "list_archive_url": null, "date": "2017-09-02T16:37:58", "name": "[U-Boot,v2,3/8] fat/fs: convert to directory iterators", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "4185489f9c59891dd62594c4a0a0aaf662e079e5", "submitter": { "id": 18760, "url": "http://patchwork.ozlabs.org/api/people/18760/?format=api", "name": "Rob Clark", "email": "robdclark@gmail.com" }, "delegate": { "id": 3651, "url": "http://patchwork.ozlabs.org/api/users/3651/?format=api", "username": "trini", "first_name": "Tom", "last_name": "Rini", "email": "trini@ti.com" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20170902163806.27265-4-robdclark@gmail.com/mbox/", "series": [ { "id": 1165, "url": "http://patchwork.ozlabs.org/api/series/1165/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=1165", "date": "2017-09-02T16:37:55", "name": "fs/fat: cleanups + readdir implementation", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/1165/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/809107/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/809107/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"EeKOmQQJ\"; dkim-atps=neutral" ], "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xl20S1s2pz9sRW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 3 Sep 2017 02:40:24 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid EDE04C21F49; Sat, 2 Sep 2017 16:39:25 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id F0B5FC21F95;\n\tSat, 2 Sep 2017 16:38:57 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 2C536C21F96; Sat, 2 Sep 2017 16:38:36 +0000 (UTC)", "from mail-qt0-f196.google.com (mail-qt0-f196.google.com\n\t[209.85.216.196])\n\tby lists.denx.de (Postfix) with ESMTPS id 36FB5C21F84\n\tfor <u-boot@lists.denx.de>; Sat, 2 Sep 2017 16:38:32 +0000 (UTC)", "by mail-qt0-f196.google.com with SMTP id h15so2085179qta.0\n\tfor <u-boot@lists.denx.de>; Sat, 02 Sep 2017 09:38:32 -0700 (PDT)", "from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a])\n\tby smtp.gmail.com with ESMTPSA id\n\tr130sm1076937qke.9.2017.09.02.09.38.29\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSat, 02 Sep 2017 09:38:29 -0700 (PDT)" ], "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=FREEMAIL_FROM,\n\tRCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tT_DKIM_INVALID\n\tautolearn=unavailable autolearn_force=no version=3.4.0", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=tDj+6koHMRbKIgQAN1f4+Gpx3R2S+N1oRktZBy7JWO8=;\n\tb=EeKOmQQJiONGcTTDjpD8a8iWHuYICnLYC2bswDYvERSQ6kUkWvrDQpvDf+V7A+1vFN\n\tgrEeRauE4G3b/gdYRjYc76ra9+GTjMiHNHkSZ6PUHVD8e9XKJVN+6BMc7hDzCiJutoDb\n\tZUDgOBebbOkoEeMfUyh+g7oIZMjPYY/7wMEDX/brGFfBQCLEmgWFzOgzoaKF38mrQyQU\n\t97MnjuGWH1GSIVk2qfiVNtz/ZzBz8F7XN8K8r1Y68vhM0vDYbE8eU42lQFfVCogG53En\n\tABx7xmQx7Ee3NKW2Wg5UGI+B7agGs0NYEX5ND1hbnTpttDj+I7eddxYqNlaGXzuj6QXh\n\tYWdg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=tDj+6koHMRbKIgQAN1f4+Gpx3R2S+N1oRktZBy7JWO8=;\n\tb=D8Bloib7ftI7EGwTaCZNThfA1WWlpAmlTYLb5j8EpssicMcwP73+yxOHEDfcAJeyw4\n\t0nEnqEHY2tt4RnRZQeMm5b+UmfvZKqA4zacZVJFhT+JztvwZxHTbYuLmCmea/RKBK5Dr\n\t1M60bMVkApbjK3BI8s6jLTw0lBODaHJBj1Qr/S7hc0ngGpH9bUmR0NmkBPb0b/69rKSw\n\tkKySr8wDd97/Iw9qYC3hjaNQyRpZ/7l9zxPrMnR2tAFVNPfZmOjLqiOmKT1WYWp9rQ+i\n\tQL9slhiMcNTeJbe2tGx2XXAFzvsMIb8L0RIm3wFoXbJJk7F7f5RmkIoZntlLYPjTVKj3\n\tEcIA==", "X-Gm-Message-State": "AHPjjUhOf/ablZ4MmAyqxWW8tM7dWVs++CNJY7pupSy72ptGxRsrIBFg\n\tvqZRhPxQtilrwjPWKfw=", "X-Google-Smtp-Source": "ADKCNb4/k0Itc+7OOvO/0Z5+uA/UFJ8RPb9VI/KT7rSaUUt2eRNLfwf/3ygFNWK2kB95h5qVNQV4Tw==", "X-Received": "by 10.200.55.100 with SMTP id p33mr7622264qtb.142.1504370310679; \n\tSat, 02 Sep 2017 09:38:30 -0700 (PDT)", "From": "Rob Clark <robdclark@gmail.com>", "To": "U-Boot Mailing List <u-boot@lists.denx.de>", "Date": "Sat, 2 Sep 2017 12:37:58 -0400", "Message-Id": "<20170902163806.27265-4-robdclark@gmail.com>", "X-Mailer": "git-send-email 2.13.5", "In-Reply-To": "<20170902163806.27265-1-robdclark@gmail.com>", "References": "<20170902163806.27265-1-robdclark@gmail.com>", "Cc": "Genevieve Chan <ccheauya@altera.com>, Tien Fong Chee <tfchee@altera.com>", "Subject": "[U-Boot] [PATCH v2 3/8] fat/fs: convert to directory iterators", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.18", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<http://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>" }, "content": "And drop a whole lot of ugly code!\n\nSigned-off-by: Rob Clark <robdclark@gmail.com>\n---\n fs/fat/fat.c | 723 ++++++----------------------------------------------------\n include/fat.h | 6 -\n 2 files changed, 75 insertions(+), 654 deletions(-)", "diff": "diff --git a/fs/fat/fat.c b/fs/fat/fat.c\nindex c72d6ca931..3193290434 100644\n--- a/fs/fat/fat.c\n+++ b/fs/fat/fat.c\n@@ -119,22 +119,6 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no)\n }\n \n /*\n- * Get the first occurence of a directory delimiter ('/' or '\\') in a string.\n- * Return index into string if found, -1 otherwise.\n- */\n-static int dirdelim(char *str)\n-{\n-\tchar *start = str;\n-\n-\twhile (*str != '\\0') {\n-\t\tif (ISDIRDELIM(*str))\n-\t\t\treturn str - start;\n-\t\tstr++;\n-\t}\n-\treturn -1;\n-}\n-\n-/*\n * Extract zero terminated short name from a directory entry.\n */\n static void get_name(dir_entry *dirent, char *s_name)\n@@ -468,95 +452,6 @@ static int slot2str(dir_slot *slotptr, char *l_name, int *idx)\n \treturn 0;\n }\n \n-/*\n- * Extract the full long filename starting at 'retdent' (which is really\n- * a slot) into 'l_name'. If successful also copy the real directory entry\n- * into 'retdent'\n- * Return 0 on success, -1 otherwise.\n- */\n-static int\n-get_vfatname(fsdata *mydata, int curclust, __u8 *cluster,\n-\t dir_entry *retdent, char *l_name)\n-{\n-\tdir_entry *realdent;\n-\tdir_slot *slotptr = (dir_slot *)retdent;\n-\t__u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ?\n-\t\t\t\t\t\t\tPREFETCH_BLOCKS :\n-\t\t\t\t\t\t\tmydata->clust_size);\n-\t__u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;\n-\tint idx = 0;\n-\n-\tif (counter > VFAT_MAXSEQ) {\n-\t\tdebug(\"Error: VFAT name is too long\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\twhile ((__u8 *)slotptr < buflimit) {\n-\t\tif (counter == 0)\n-\t\t\tbreak;\n-\t\tif (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)\n-\t\t\treturn -1;\n-\t\tslotptr++;\n-\t\tcounter--;\n-\t}\n-\n-\tif ((__u8 *)slotptr >= buflimit) {\n-\t\tdir_slot *slotptr2;\n-\n-\t\tif (curclust == 0)\n-\t\t\treturn -1;\n-\t\tcurclust = get_fatent(mydata, curclust);\n-\t\tif (CHECK_CLUST(curclust, mydata->fatsize)) {\n-\t\t\tdebug(\"curclust: 0x%x\\n\", curclust);\n-\t\t\tprintf(\"Invalid FAT entry\\n\");\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tif (get_cluster(mydata, curclust, get_contents_vfatname_block,\n-\t\t\t\tmydata->clust_size * mydata->sect_size) != 0) {\n-\t\t\tdebug(\"Error: reading directory block\\n\");\n-\t\t\treturn -1;\n-\t\t}\n-\n-\t\tslotptr2 = (dir_slot *)get_contents_vfatname_block;\n-\t\twhile (counter > 0) {\n-\t\t\tif (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)\n-\t\t\t & 0xff) != counter)\n-\t\t\t\treturn -1;\n-\t\t\tslotptr2++;\n-\t\t\tcounter--;\n-\t\t}\n-\n-\t\t/* Save the real directory entry */\n-\t\trealdent = (dir_entry *)slotptr2;\n-\t\twhile ((__u8 *)slotptr2 > get_contents_vfatname_block) {\n-\t\t\tslotptr2--;\n-\t\t\tslot2str(slotptr2, l_name, &idx);\n-\t\t}\n-\t} else {\n-\t\t/* Save the real directory entry */\n-\t\trealdent = (dir_entry *)slotptr;\n-\t}\n-\n-\tdo {\n-\t\tslotptr--;\n-\t\tif (slot2str(slotptr, l_name, &idx))\n-\t\t\tbreak;\n-\t} while (!(slotptr->id & LAST_LONG_ENTRY_MASK));\n-\n-\tl_name[idx] = '\\0';\n-\tif (*l_name == DELETED_FLAG)\n-\t\t*l_name = '\\0';\n-\telse if (*l_name == aRING)\n-\t\t*l_name = DELETED_FLAG;\n-\tdowncase(l_name);\n-\n-\t/* Return the real directory entry */\n-\tmemcpy(retdent, realdent, sizeof(dir_entry));\n-\n-\treturn 0;\n-}\n-\n /* Calculate short name checksum */\n static __u8 mkcksum(const char name[8], const char ext[3])\n {\n@@ -572,170 +467,11 @@ static __u8 mkcksum(const char name[8], const char ext[3])\n \treturn ret;\n }\n \n-/*\n- * Get the directory entry associated with 'filename' from the directory\n- * starting at 'startsect'\n- */\n+// These should probably DIAF..\n __u8 get_dentfromdir_block[MAX_CLUSTSIZE]\n \t__aligned(ARCH_DMA_MINALIGN);\n-\n-static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,\n-\t\t\t\t char *filename, dir_entry *retdent,\n-\t\t\t\t int dols)\n-{\n-\t__u16 prevcksum = 0xffff;\n-\t__u32 curclust = START(retdent);\n-\tint files = 0, dirs = 0;\n-\n-\tdebug(\"get_dentfromdir: %s\\n\", filename);\n-\n-\twhile (1) {\n-\t\tdir_entry *dentptr;\n-\n-\t\tint i;\n-\n-\t\tif (get_cluster(mydata, curclust, get_dentfromdir_block,\n-\t\t\t\tmydata->clust_size * mydata->sect_size) != 0) {\n-\t\t\tdebug(\"Error: reading directory block\\n\");\n-\t\t\treturn NULL;\n-\t\t}\n-\n-\t\tdentptr = (dir_entry *)get_dentfromdir_block;\n-\n-\t\tfor (i = 0; i < DIRENTSPERCLUST; i++) {\n-\t\t\tchar s_name[14], l_name[VFAT_MAXLEN_BYTES];\n-\n-\t\t\tl_name[0] = '\\0';\n-\t\t\tif (dentptr->name[0] == DELETED_FLAG) {\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\t\t\tif ((dentptr->attr & ATTR_VOLUME)) {\n-\t\t\t\tif (vfat_enabled &&\n-\t\t\t\t (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&\n-\t\t\t\t (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {\n-\t\t\t\t\tprevcksum = ((dir_slot *)dentptr)->alias_checksum;\n-\t\t\t\t\tget_vfatname(mydata, curclust,\n-\t\t\t\t\t\t get_dentfromdir_block,\n-\t\t\t\t\t\t dentptr, l_name);\n-\t\t\t\t\tif (dols) {\n-\t\t\t\t\t\tint isdir;\n-\t\t\t\t\t\tchar dirc;\n-\t\t\t\t\t\tint doit = 0;\n-\n-\t\t\t\t\t\tisdir = (dentptr->attr & ATTR_DIR);\n-\n-\t\t\t\t\t\tif (isdir) {\n-\t\t\t\t\t\t\tdirs++;\n-\t\t\t\t\t\t\tdirc = '/';\n-\t\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t\t} else {\n-\t\t\t\t\t\t\tdirc = ' ';\n-\t\t\t\t\t\t\tif (l_name[0] != 0) {\n-\t\t\t\t\t\t\t\tfiles++;\n-\t\t\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t}\n-\t\t\t\t\t\tif (doit) {\n-\t\t\t\t\t\t\tif (dirc == ' ') {\n-\t\t\t\t\t\t\t\tprintf(\" %8u %s%c\\n\",\n-\t\t\t\t\t\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t\t\t\t\t\t\tl_name,\n-\t\t\t\t\t\t\t\t\tdirc);\n-\t\t\t\t\t\t\t} else {\n-\t\t\t\t\t\t\t\tprintf(\" %s%c\\n\",\n-\t\t\t\t\t\t\t\t\tl_name,\n-\t\t\t\t\t\t\t\t\tdirc);\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t}\n-\t\t\t\t\t\tdentptr++;\n-\t\t\t\t\t\tcontinue;\n-\t\t\t\t\t}\n-\t\t\t\t\tdebug(\"vfatname: |%s|\\n\", l_name);\n-\t\t\t\t} else {\n-\t\t\t\t\t/* Volume label or VFAT entry */\n-\t\t\t\t\tdentptr++;\n-\t\t\t\t\tcontinue;\n-\t\t\t\t}\n-\t\t\t}\n-\t\t\tif (dentptr->name[0] == 0) {\n-\t\t\t\tif (dols) {\n-\t\t\t\t\tprintf(\"\\n%d file(s), %d dir(s)\\n\\n\",\n-\t\t\t\t\t\tfiles, dirs);\n-\t\t\t\t}\n-\t\t\t\tdebug(\"Dentname == NULL - %d\\n\", i);\n-\t\t\t\treturn NULL;\n-\t\t\t}\n-\t\t\tif (vfat_enabled) {\n-\t\t\t\t__u8 csum = mkcksum(dentptr->name, dentptr->ext);\n-\t\t\t\tif (dols && csum == prevcksum) {\n-\t\t\t\t\tprevcksum = 0xffff;\n-\t\t\t\t\tdentptr++;\n-\t\t\t\t\tcontinue;\n-\t\t\t\t}\n-\t\t\t}\n-\n-\t\t\tget_name(dentptr, s_name);\n-\t\t\tif (dols) {\n-\t\t\t\tint isdir = (dentptr->attr & ATTR_DIR);\n-\t\t\t\tchar dirc;\n-\t\t\t\tint doit = 0;\n-\n-\t\t\t\tif (isdir) {\n-\t\t\t\t\tdirs++;\n-\t\t\t\t\tdirc = '/';\n-\t\t\t\t\tdoit = 1;\n-\t\t\t\t} else {\n-\t\t\t\t\tdirc = ' ';\n-\t\t\t\t\tif (s_name[0] != 0) {\n-\t\t\t\t\t\tfiles++;\n-\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\n-\t\t\t\tif (doit) {\n-\t\t\t\t\tif (dirc == ' ') {\n-\t\t\t\t\t\tprintf(\" %8u %s%c\\n\",\n-\t\t\t\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t\t\t\t\ts_name, dirc);\n-\t\t\t\t\t} else {\n-\t\t\t\t\t\tprintf(\" %s%c\\n\",\n-\t\t\t\t\t\t\ts_name, dirc);\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tif (strcmp(filename, s_name)\n-\t\t\t && strcmp(filename, l_name)) {\n-\t\t\t\tdebug(\"Mismatch: |%s|%s|\\n\", s_name, l_name);\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tmemcpy(retdent, dentptr, sizeof(dir_entry));\n-\n-\t\t\tdebug(\"DentName: %s\", s_name);\n-\t\t\tdebug(\", start: 0x%x\", START(dentptr));\n-\t\t\tdebug(\", size: 0x%x %s\\n\",\n-\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t (dentptr->attr & ATTR_DIR) ? \"(DIR)\" : \"\");\n-\n-\t\t\treturn retdent;\n-\t\t}\n-\n-\t\tcurclust = get_fatent(mydata, curclust);\n-\t\tif (CHECK_CLUST(curclust, mydata->fatsize)) {\n-\t\t\tdebug(\"curclust: 0x%x\\n\", curclust);\n-\t\t\tprintf(\"Invalid FAT entry\\n\");\n-\t\t\treturn NULL;\n-\t\t}\n-\t}\n-\n-\treturn NULL;\n-}\n+__u8 do_fat_read_at_block[MAX_CLUSTSIZE]\n+\t__aligned(ARCH_DMA_MINALIGN);\n \n /*\n * Read boot sector and volume info from a FAT filesystem\n@@ -877,374 +613,6 @@ static int get_fs_info(fsdata *mydata)\n \treturn 0;\n }\n \n-__u8 do_fat_read_at_block[MAX_CLUSTSIZE]\n-\t__aligned(ARCH_DMA_MINALIGN);\n-\n-int do_fat_read_at(const char *filename, loff_t pos, void *buffer,\n-\t\t loff_t maxsize, int dols, int dogetsize, loff_t *size)\n-{\n-\tchar fnamecopy[2048];\n-\tfsdata datablock;\n-\tfsdata *mydata = &datablock;\n-\tdir_entry *dentptr = NULL;\n-\t__u16 prevcksum = 0xffff;\n-\tchar *subname = \"\";\n-\t__u32 cursect;\n-\tint idx, isdir = 0;\n-\tint files = 0, dirs = 0;\n-\tint ret = -1;\n-\tint firsttime;\n-\t__u32 root_cluster = 0;\n-\t__u32 read_blk;\n-\tint rootdir_size = 0;\n-\tint buffer_blk_cnt;\n-\tint do_read;\n-\t__u8 *dir_ptr;\n-\n-\tif (get_fs_info(mydata))\n-\t\treturn -1;\n-\n-\tcursect = mydata->rootdir_sect;\n-\n-\t/* \"cwd\" is always the root... */\n-\twhile (ISDIRDELIM(*filename))\n-\t\tfilename++;\n-\n-\t/* Make a copy of the filename and convert it to lowercase */\n-\tstrcpy(fnamecopy, filename);\n-\tdowncase(fnamecopy);\n-\n-root_reparse:\n-\tif (*fnamecopy == '\\0') {\n-\t\tif (!dols)\n-\t\t\tgoto exit;\n-\n-\t\tdols = LS_ROOT;\n-\t} else if ((idx = dirdelim(fnamecopy)) >= 0) {\n-\t\tisdir = 1;\n-\t\tfnamecopy[idx] = '\\0';\n-\t\tsubname = fnamecopy + idx + 1;\n-\n-\t\t/* Handle multiple delimiters */\n-\t\twhile (ISDIRDELIM(*subname))\n-\t\t\tsubname++;\n-\t} else if (dols) {\n-\t\tisdir = 1;\n-\t}\n-\n-\tbuffer_blk_cnt = 0;\n-\tfirsttime = 1;\n-\twhile (1) {\n-\t\tint i;\n-\n-\t\tif (mydata->fatsize == 32 || firsttime) {\n-\t\t\tdir_ptr = do_fat_read_at_block;\n-\t\t\tfirsttime = 0;\n-\t\t} else {\n-\t\t\t/**\n-\t\t\t * FAT16 sector buffer modification:\n-\t\t\t * Each loop, the second buffered block is moved to\n-\t\t\t * the buffer begin, and two next sectors are read\n-\t\t\t * next to the previously moved one. So the sector\n-\t\t\t * buffer keeps always 3 sectors for fat16.\n-\t\t\t * And the current sector is the buffer second sector\n-\t\t\t * beside the \"firsttime\" read, when it is the first one.\n-\t\t\t *\n-\t\t\t * PREFETCH_BLOCKS is 2 for FAT16 == loop[0:1]\n-\t\t\t * n = computed root dir sector\n-\t\t\t * loop | cursect-1 | cursect | cursect+1 |\n-\t\t\t * 0 | sector n+0 | sector n+1 | none |\n-\t\t\t * 1 | none | sector n+0 | sector n+1 |\n-\t\t\t * 0 | sector n+1 | sector n+2 | sector n+3 |\n-\t\t\t * 1 | sector n+3 | ...\n-\t\t\t*/\n-\t\t\tdir_ptr = (do_fat_read_at_block + mydata->sect_size);\n-\t\t\tmemcpy(do_fat_read_at_block, dir_ptr, mydata->sect_size);\n-\t\t}\n-\n-\t\tdo_read = 1;\n-\n-\t\tif (mydata->fatsize == 32 && buffer_blk_cnt)\n-\t\t\tdo_read = 0;\n-\n-\t\tif (do_read) {\n-\t\t\tread_blk = (mydata->fatsize == 32) ?\n-\t\t\t\t mydata->clust_size : PREFETCH_BLOCKS;\n-\n-\t\t\tdebug(\"FAT read(sect=%d, cnt:%d), clust_size=%d, DIRENTSPERBLOCK=%zd\\n\",\n-\t\t\t\tcursect, read_blk, mydata->clust_size, DIRENTSPERBLOCK);\n-\n-\t\t\tif (disk_read(cursect, read_blk, dir_ptr) < 0) {\n-\t\t\t\tdebug(\"Error: reading rootdir block\\n\");\n-\t\t\t\tgoto exit;\n-\t\t\t}\n-\n-\t\t\tdentptr = (dir_entry *)dir_ptr;\n-\t\t}\n-\n-\t\tfor (i = 0; i < DIRENTSPERBLOCK; i++) {\n-\t\t\tchar s_name[14], l_name[VFAT_MAXLEN_BYTES];\n-\t\t\t__u8 csum;\n-\n-\t\t\tl_name[0] = '\\0';\n-\t\t\tif (dentptr->name[0] == DELETED_FLAG) {\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tif (vfat_enabled)\n-\t\t\t\tcsum = mkcksum(dentptr->name, dentptr->ext);\n-\n-\t\t\tif (dentptr->attr & ATTR_VOLUME) {\n-\t\t\t\tif (vfat_enabled &&\n-\t\t\t\t (dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&\n-\t\t\t\t (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {\n-\t\t\t\t\tprevcksum =\n-\t\t\t\t\t\t((dir_slot *)dentptr)->alias_checksum;\n-\n-\t\t\t\t\tget_vfatname(mydata,\n-\t\t\t\t\t\t root_cluster,\n-\t\t\t\t\t\t dir_ptr,\n-\t\t\t\t\t\t dentptr, l_name);\n-\n-\t\t\t\t\tif (dols == LS_ROOT) {\n-\t\t\t\t\t\tchar dirc;\n-\t\t\t\t\t\tint doit = 0;\n-\t\t\t\t\t\tint isdir =\n-\t\t\t\t\t\t\t(dentptr->attr & ATTR_DIR);\n-\n-\t\t\t\t\t\tif (isdir) {\n-\t\t\t\t\t\t\tdirs++;\n-\t\t\t\t\t\t\tdirc = '/';\n-\t\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t\t} else {\n-\t\t\t\t\t\t\tdirc = ' ';\n-\t\t\t\t\t\t\tif (l_name[0] != 0) {\n-\t\t\t\t\t\t\t\tfiles++;\n-\t\t\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t}\n-\t\t\t\t\t\tif (doit) {\n-\t\t\t\t\t\t\tif (dirc == ' ') {\n-\t\t\t\t\t\t\t\tprintf(\" %8u %s%c\\n\",\n-\t\t\t\t\t\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t\t\t\t\t\t\tl_name,\n-\t\t\t\t\t\t\t\t\tdirc);\n-\t\t\t\t\t\t\t} else {\n-\t\t\t\t\t\t\t\tprintf(\" %s%c\\n\",\n-\t\t\t\t\t\t\t\t\tl_name,\n-\t\t\t\t\t\t\t\t\tdirc);\n-\t\t\t\t\t\t\t}\n-\t\t\t\t\t\t}\n-\t\t\t\t\t\tdentptr++;\n-\t\t\t\t\t\tcontinue;\n-\t\t\t\t\t}\n-\t\t\t\t\tdebug(\"Rootvfatname: |%s|\\n\",\n-\t\t\t\t\t l_name);\n-\t\t\t\t} else {\n-\t\t\t\t\t/* Volume label or VFAT entry */\n-\t\t\t\t\tdentptr++;\n-\t\t\t\t\tcontinue;\n-\t\t\t\t}\n-\t\t\t} else if (dentptr->name[0] == 0) {\n-\t\t\t\tdebug(\"RootDentname == NULL - %d\\n\", i);\n-\t\t\t\tif (dols == LS_ROOT) {\n-\t\t\t\t\tprintf(\"\\n%d file(s), %d dir(s)\\n\\n\",\n-\t\t\t\t\t\tfiles, dirs);\n-\t\t\t\t\tret = 0;\n-\t\t\t\t}\n-\t\t\t\tgoto exit;\n-\t\t\t}\n-\t\t\telse if (vfat_enabled &&\n-\t\t\t\t dols == LS_ROOT && csum == prevcksum) {\n-\t\t\t\tprevcksum = 0xffff;\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tget_name(dentptr, s_name);\n-\n-\t\t\tif (dols == LS_ROOT) {\n-\t\t\t\tint isdir = (dentptr->attr & ATTR_DIR);\n-\t\t\t\tchar dirc;\n-\t\t\t\tint doit = 0;\n-\n-\t\t\t\tif (isdir) {\n-\t\t\t\t\tdirc = '/';\n-\t\t\t\t\tif (s_name[0] != 0) {\n-\t\t\t\t\t\tdirs++;\n-\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t}\n-\t\t\t\t} else {\n-\t\t\t\t\tdirc = ' ';\n-\t\t\t\t\tif (s_name[0] != 0) {\n-\t\t\t\t\t\tfiles++;\n-\t\t\t\t\t\tdoit = 1;\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\t\t\t\tif (doit) {\n-\t\t\t\t\tif (dirc == ' ') {\n-\t\t\t\t\t\tprintf(\" %8u %s%c\\n\",\n-\t\t\t\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t\t\t\t\ts_name, dirc);\n-\t\t\t\t\t} else {\n-\t\t\t\t\t\tprintf(\" %s%c\\n\",\n-\t\t\t\t\t\t\ts_name, dirc);\n-\t\t\t\t\t}\n-\t\t\t\t}\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tif (strcmp(fnamecopy, s_name)\n-\t\t\t && strcmp(fnamecopy, l_name)) {\n-\t\t\t\tdebug(\"RootMismatch: |%s|%s|\\n\", s_name,\n-\t\t\t\t l_name);\n-\t\t\t\tdentptr++;\n-\t\t\t\tcontinue;\n-\t\t\t}\n-\n-\t\t\tif (isdir && !(dentptr->attr & ATTR_DIR))\n-\t\t\t\tgoto exit;\n-\n-\t\t\tdebug(\"RootName: %s\", s_name);\n-\t\t\tdebug(\", start: 0x%x\", START(dentptr));\n-\t\t\tdebug(\", size: 0x%x %s\\n\",\n-\t\t\t FAT2CPU32(dentptr->size),\n-\t\t\t isdir ? \"(DIR)\" : \"\");\n-\n-\t\t\tgoto rootdir_done;\t/* We got a match */\n-\t\t}\n-\t\tdebug(\"END LOOP: buffer_blk_cnt=%d clust_size=%d\\n\", buffer_blk_cnt,\n-\t\t mydata->clust_size);\n-\n-\t\t/*\n-\t\t * On FAT32 we must fetch the FAT entries for the next\n-\t\t * root directory clusters when a cluster has been\n-\t\t * completely processed.\n-\t\t */\n-\t\t++buffer_blk_cnt;\n-\t\tint rootdir_end = 0;\n-\t\tif (mydata->fatsize == 32) {\n-\t\t\tif (buffer_blk_cnt == mydata->clust_size) {\n-\t\t\t\tint nxtsect = 0;\n-\t\t\t\tint nxt_clust = 0;\n-\n-\t\t\t\tnxt_clust = get_fatent(mydata, root_cluster);\n-\t\t\t\trootdir_end = CHECK_CLUST(nxt_clust, 32);\n-\n-\t\t\t\tnxtsect = mydata->data_begin +\n-\t\t\t\t\t(nxt_clust * mydata->clust_size);\n-\n-\t\t\t\troot_cluster = nxt_clust;\n-\n-\t\t\t\tcursect = nxtsect;\n-\t\t\t\tbuffer_blk_cnt = 0;\n-\t\t\t}\n-\t\t} else {\n-\t\t\tif (buffer_blk_cnt == PREFETCH_BLOCKS)\n-\t\t\t\tbuffer_blk_cnt = 0;\n-\n-\t\t\trootdir_end = (++cursect - mydata->rootdir_sect >=\n-\t\t\t\t rootdir_size);\n-\t\t}\n-\n-\t\t/* If end of rootdir reached */\n-\t\tif (rootdir_end) {\n-\t\t\tif (dols == LS_ROOT) {\n-\t\t\t\tprintf(\"\\n%d file(s), %d dir(s)\\n\\n\",\n-\t\t\t\t files, dirs);\n-\t\t\t\t*size = 0;\n-\t\t\t}\n-\t\t\tgoto exit;\n-\t\t}\n-\t}\n-rootdir_done:\n-\n-\tfirsttime = 1;\n-\n-\twhile (isdir) {\n-\t\tint startsect = mydata->data_begin\n-\t\t\t+ START(dentptr) * mydata->clust_size;\n-\t\tdir_entry dent;\n-\t\tchar *nextname = NULL;\n-\n-\t\tdent = *dentptr;\n-\t\tdentptr = &dent;\n-\n-\t\tidx = dirdelim(subname);\n-\n-\t\tif (idx >= 0) {\n-\t\t\tsubname[idx] = '\\0';\n-\t\t\tnextname = subname + idx + 1;\n-\t\t\t/* Handle multiple delimiters */\n-\t\t\twhile (ISDIRDELIM(*nextname))\n-\t\t\t\tnextname++;\n-\t\t\tif (dols && *nextname == '\\0')\n-\t\t\t\tfirsttime = 0;\n-\t\t} else {\n-\t\t\tif (dols && firsttime) {\n-\t\t\t\tfirsttime = 0;\n-\t\t\t} else {\n-\t\t\t\tisdir = 0;\n-\t\t\t}\n-\t\t}\n-\n-\t\tif (get_dentfromdir(mydata, startsect, subname, dentptr,\n-\t\t\t\t isdir ? 0 : dols) == NULL) {\n-\t\t\tif (dols && !isdir)\n-\t\t\t\t*size = 0;\n-\t\t\tgoto exit;\n-\t\t}\n-\n-\t\tif (isdir && !(dentptr->attr & ATTR_DIR))\n-\t\t\tgoto exit;\n-\n-\t\t/*\n-\t\t * If we are looking for a directory, and found a directory\n-\t\t * type entry, and the entry is for the root directory (as\n-\t\t * denoted by a cluster number of 0), jump back to the start\n-\t\t * of the function, since at least on FAT12/16, the root dir\n-\t\t * lives in a hard-coded location and needs special handling\n-\t\t * to parse, rather than simply following the cluster linked\n-\t\t * list in the FAT, like other directories.\n-\t\t */\n-\t\tif (isdir && (dentptr->attr & ATTR_DIR) && !START(dentptr)) {\n-\t\t\t/*\n-\t\t\t * Modify the filename to remove the prefix that gets\n-\t\t\t * back to the root directory, so the initial root dir\n-\t\t\t * parsing code can continue from where we are without\n-\t\t\t * confusion.\n-\t\t\t */\n-\t\t\tstrcpy(fnamecopy, nextname ?: \"\");\n-\t\t\t/*\n-\t\t\t * Set up state the same way as the function does when\n-\t\t\t * first started. This is required for the root dir\n-\t\t\t * parsing code operates in its expected environment.\n-\t\t\t */\n-\t\t\tsubname = \"\";\n-\t\t\tcursect = mydata->rootdir_sect;\n-\t\t\tisdir = 0;\n-\t\t\tgoto root_reparse;\n-\t\t}\n-\n-\t\tif (idx >= 0)\n-\t\t\tsubname = nextname;\n-\t}\n-\n-\tif (dogetsize) {\n-\t\t*size = FAT2CPU32(dentptr->size);\n-\t\tret = 0;\n-\t} else {\n-\t\tret = get_contents(mydata, dentptr, pos, buffer, maxsize, size);\n-\t}\n-\tdebug(\"Size: %u, got: %llu\\n\", FAT2CPU32(dentptr->size), *size);\n-\n-exit:\n-\tfree(mydata->fatbuf);\n-\treturn ret;\n-}\n-\n \n /*\n * Directory iterator, to simplify filesystem traversal\n@@ -1571,12 +939,6 @@ static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)\n \treturn -ENOENT;\n }\n \n-int do_fat_read(const char *filename, void *buffer, loff_t maxsize, int dols,\n-\t\tloff_t *actread)\n-{\n-\treturn do_fat_read_at(filename, 0, buffer, maxsize, dols, 0, actread);\n-}\n-\n int file_fat_detectfs(void)\n {\n \tboot_sector bs;\n@@ -1641,31 +1003,96 @@ int file_fat_detectfs(void)\n \n int file_fat_ls(const char *dir)\n {\n-\tloff_t size;\n+\tfsdata fsdata;\n+\tfat_itr itrblock, *itr = &itrblock;\n+\tint files = 0, dirs = 0;\n+\tint ret;\n+\n+\tret = fat_itr_root(itr, &fsdata);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = fat_itr_resolve(itr, dir, TYPE_DIR);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\twhile (fat_itr_next(itr)) {\n+\t\tif (fat_itr_isdir(itr)) {\n+\t\t\tprintf(\" %s/\\n\", itr->name);\n+\t\t\tdirs++;\n+\t\t} else {\n+\t\t\tprintf(\" %8u %s\\n\",\n+\t\t\t FAT2CPU32(itr->dent->size),\n+\t\t\t itr->name);\n+\t\t\tfiles++;\n+\t\t}\n+\t}\n+\n+\tprintf(\"\\n%d file(s), %d dir(s)\\n\\n\", files, dirs);\n \n-\treturn do_fat_read(dir, NULL, 0, LS_YES, &size);\n+\treturn 0;\n }\n \n int fat_exists(const char *filename)\n {\n+\tfsdata fsdata;\n+\tfat_itr itrblock, *itr = &itrblock;\n \tint ret;\n-\tloff_t size;\n \n-\tret = do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, &size);\n+\tret = fat_itr_root(itr, &fsdata);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = fat_itr_resolve(itr, filename, TYPE_ANY);\n \treturn ret == 0;\n }\n \n int fat_size(const char *filename, loff_t *size)\n {\n-\treturn do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1, size);\n+\tfsdata fsdata;\n+\tfat_itr itrblock, *itr = &itrblock;\n+\tint ret;\n+\n+\tret = fat_itr_root(itr, &fsdata);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = fat_itr_resolve(itr, filename, TYPE_FILE);\n+\tif (ret) {\n+\t\t/*\n+\t\t * Directories don't have size, but fs_size() is not\n+\t\t * expected to fail if passed a directory path:\n+\t\t */\n+\t\tfat_itr_root(itr, &fsdata);\n+\t\tif (!fat_itr_resolve(itr, filename, TYPE_DIR)) {\n+\t\t\t*size = 0;\n+\t\t\treturn 0;\n+\t\t}\n+\t\treturn ret;\n+\t}\n+\n+\t*size = FAT2CPU32(itr->dent->size);\n+\n+\treturn 0;\n }\n \n int file_fat_read_at(const char *filename, loff_t pos, void *buffer,\n \t\t loff_t maxsize, loff_t *actread)\n {\n+\tfsdata fsdata;\n+\tfat_itr itrblock, *itr = &itrblock;\n+\tint ret;\n+\n+\tret = fat_itr_root(itr, &fsdata);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tret = fat_itr_resolve(itr, filename, TYPE_FILE);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tprintf(\"reading %s\\n\", filename);\n-\treturn do_fat_read_at(filename, pos, buffer, maxsize, LS_NO, 0,\n-\t\t\t actread);\n+\treturn get_contents(&fsdata, itr->dent, pos, buffer, maxsize, actread);\n }\n \n int file_fat_read(const char *filename, void *buffer, int maxsize)\ndiff --git a/include/fat.h b/include/fat.h\nindex 6d3fc8e4a6..3e7ab9ea8d 100644\n--- a/include/fat.h\n+++ b/include/fat.h\n@@ -58,12 +58,6 @@\n */\n #define LAST_LONG_ENTRY_MASK\t0x40\n \n-/* Flags telling whether we should read a file or list a directory */\n-#define LS_NO\t\t0\n-#define LS_YES\t\t1\n-#define LS_DIR\t\t1\n-#define LS_ROOT\t\t2\n-\n #define ISDIRDELIM(c)\t((c) == '/' || (c) == '\\\\')\n \n #define FSTYPE_NONE\t(-1)\n", "prefixes": [ "U-Boot", "v2", "3/8" ] }