get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/812101/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 812101,
    "url": "http://patchwork.ozlabs.org/api/patches/812101/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170910112149.21358-7-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": "<20170910112149.21358-7-robdclark@gmail.com>",
    "list_archive_url": null,
    "date": "2017-09-10T11:21:23",
    "name": "[U-Boot,v3,3/9] fat/fs: convert to directory iterators",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": false,
    "hash": "8d8840c98888f61230c4c27ca80b38c3292fc4cc",
    "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/20170910112149.21358-7-robdclark@gmail.com/mbox/",
    "series": [
        {
            "id": 2383,
            "url": "http://patchwork.ozlabs.org/api/series/2383/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=2383",
            "date": "2017-09-10T11:21:17",
            "name": "efi_loader: enough UEFI for standard distro boot",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/2383/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/812101/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/812101/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=\"cgAgwt20\"; dkim-atps=neutral"
        ],
        "Received": [
            "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xqpf242Jqz9s8J\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 10 Sep 2017 21:26:02 +1000 (AEST)",
            "by lists.denx.de (Postfix, from userid 105)\n\tid 5042DC21C4C; Sun, 10 Sep 2017 11:23:45 +0000 (UTC)",
            "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id C8A7AC21F1A;\n\tSun, 10 Sep 2017 11:23:08 +0000 (UTC)",
            "by lists.denx.de (Postfix, from userid 105)\n\tid 58FB0C21EDB; Sun, 10 Sep 2017 11:22:29 +0000 (UTC)",
            "from mail-qt0-f194.google.com (mail-qt0-f194.google.com\n\t[209.85.216.194])\n\tby lists.denx.de (Postfix) with ESMTPS id D7BC7C21DEF\n\tfor <u-boot@lists.denx.de>; Sun, 10 Sep 2017 11:22:24 +0000 (UTC)",
            "by mail-qt0-f194.google.com with SMTP id l25so1177091qtf.2\n\tfor <u-boot@lists.denx.de>; Sun, 10 Sep 2017 04:22:24 -0700 (PDT)",
            "from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a])\n\tby smtp.gmail.com with ESMTPSA id\n\ts16sm4348897qks.63.2017.09.10.04.22.22\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 10 Sep 2017 04:22:22 -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\t:mime-version:content-transfer-encoding;\n\tbh=rBXu5viO0nx6ilNLUFtFtvPu5flOKRAP0NAR3BsKh8w=;\n\tb=cgAgwt20AY67gBPkwsGSvJ70itcuf5wQB67zgJgV6KeQ366twZtyi2yKo63Nr+Waxd\n\tTiuZ8SVJvYSMsvevGaJZwg/7tdWcqGRN3IuCeg8pXyfc7YWkox6Q7k7PYn183UDxsduv\n\tIm0FfdWfbHnDoh3iSbuLgClRKO6Ee5JT8HBsKgBA/j8oI6T/Jt3OIGIDppbrlBz3Sld4\n\tdZcHHVUiCQmtGa7pKTTAIAaT2jUSslkPJNQnpdzYAJ8WDdUook5MRue/sWO1n1HwPLEK\n\thjpu0Z3urn37+GEcCiCcaBeQiBeUIzd1R/copDYk58zKxMlFRgEL/FBgjEcOEmHleDvt\n\tBP0w==",
        "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:mime-version:content-transfer-encoding;\n\tbh=rBXu5viO0nx6ilNLUFtFtvPu5flOKRAP0NAR3BsKh8w=;\n\tb=WXmbAiZLH/3i5RJN/or7Up7AignJ+6+PeffschqHS26efbAELU/KS+VYYPwuml4L1U\n\tbTZmRGcK7rh5EAcJXws/Poxh0IZ+AdmBrQkXovc55zqq5ZCAUlCmc0GzgnDZIK039fpQ\n\t2gjZkaXOMKOQCKTJZrhIojOONahoYuz+/X4Fwi9t5VGDKCJtc8PUzRthyMAX5ZMU9mdN\n\tBwHJDmBs7UMjLfMc4F3RzVJQUwlKG2qkXFBso4NEdl7n/7SGypVn6HopChKx35KWm1yD\n\tcizkEOSAhS+CDSKuhOMrkLRyFiIEzB/kLdZAnZhl6TLFzLatrSuRK/tm63Io8GGwz7cZ\n\td/YA==",
        "X-Gm-Message-State": "AHPjjUiQsZjNEpYQq1JSamMjDjYp5rShrcZbOFcvliNA1oKJidMs7Wlf\n\t5Okldjaa1t1J4KkeDf0=",
        "X-Google-Smtp-Source": "AOwi7QASYkmVzixcAXFUqavTp2keWY582i6eOt9BGiQg1g5pvesh1iC6AmK13ZexC2BkfPz1h1sPTw==",
        "X-Received": "by 10.200.14.4 with SMTP id a4mr11324162qti.1.1505042543433;\n\tSun, 10 Sep 2017 04:22:23 -0700 (PDT)",
        "From": "Rob Clark <robdclark@gmail.com>",
        "To": "U-Boot Mailing List <u-boot@lists.denx.de>",
        "Date": "Sun, 10 Sep 2017 07:21:23 -0400",
        "Message-Id": "<20170910112149.21358-7-robdclark@gmail.com>",
        "X-Mailer": "git-send-email 2.13.5",
        "In-Reply-To": "<20170910112149.21358-1-robdclark@gmail.com>",
        "References": "<20170910112149.21358-1-robdclark@gmail.com>",
        "MIME-Version": "1.0",
        "Cc": "Heinrich Schuchardt <xypron.glpk@gmx.de>,\n\tGenevieve Chan <ccheauya@altera.com>, Tien Fong Chee <tfchee@altera.com>",
        "Subject": "[U-Boot] [PATCH v3 3/9] 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>",
        "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>\nReviewed-by: Łukasz Majewski <lukma@denx.de>\n---\n fs/fat/fat.c  | 722 +++++++---------------------------------------------------\n include/fat.h |   6 -\n 2 files changed, 76 insertions(+), 652 deletions(-)",
    "diff": "diff --git a/fs/fat/fat.c b/fs/fat/fat.c\nindex ee2bbe38f1..bbba7947ee 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@@ -573,169 +468,13 @@ static __u8 mkcksum(const char name[8], const char ext[3])\n }\n \n /*\n- * Get the directory entry associated with 'filename' from the directory\n- * starting at 'startsect'\n+ * TODO these should go away once fat_write is reworked to use the\n+ * directory iterator\n  */\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@@ -879,374 +618,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@@ -1595,12 +966,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@@ -1665,31 +1030,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-\treturn do_fat_read(dir, NULL, 0, LS_YES, &size);\n+\tprintf(\"\\n%d file(s), %d dir(s)\\n\\n\", files, dirs);\n+\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 0;\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 21bb6666cf..18d8981c48 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",
        "v3",
        "3/9"
    ]
}