get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 811973,
    "url": "http://patchwork.ozlabs.org/api/patches/811973/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170909171606.20029-3-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": "<20170909171606.20029-3-robdclark@gmail.com>",
    "list_archive_url": null,
    "date": "2017-09-09T17:15:53",
    "name": "[U-Boot,v3,2/9] fs/fat: introduce new director iterators",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "589cdc854f33a13c0f91ae11c60249273389a410",
    "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/20170909171606.20029-3-robdclark@gmail.com/mbox/",
    "series": [
        {
            "id": 2355,
            "url": "http://patchwork.ozlabs.org/api/series/2355/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=2355",
            "date": "2017-09-09T17:15:51",
            "name": "fs/fat: cleanups + readdir implementation",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/2355/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/811973/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/811973/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=\"k7e1O3sX\"; dkim-atps=neutral"
        ],
        "Received": [
            "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xqLYJ6VNFz9t16\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSun, 10 Sep 2017 03:20:20 +1000 (AEST)",
            "by lists.denx.de (Postfix, from userid 105)\n\tid 9456EC21F03; Sat,  9 Sep 2017 17:18:45 +0000 (UTC)",
            "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 3BFF8C21EB1;\n\tSat,  9 Sep 2017 17:17:42 +0000 (UTC)",
            "by lists.denx.de (Postfix, from userid 105)\n\tid 49CD2C21E92; Sat,  9 Sep 2017 17:16:30 +0000 (UTC)",
            "from mail-qk0-f195.google.com (mail-qk0-f195.google.com\n\t[209.85.220.195])\n\tby lists.denx.de (Postfix) with ESMTPS id A73A8C21EDC\n\tfor <u-boot@lists.denx.de>; Sat,  9 Sep 2017 17:16:28 +0000 (UTC)",
            "by mail-qk0-f195.google.com with SMTP id g128so3247223qke.0\n\tfor <u-boot@lists.denx.de>; Sat, 09 Sep 2017 10:16:28 -0700 (PDT)",
            "from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a])\n\tby smtp.gmail.com with ESMTPSA id\n\tt26sm3276058qkt.89.2017.09.09.10.16.25\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSat, 09 Sep 2017 10:16:25 -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=olLHt/LWSXBdsV2nZv8WrqeymB/JReM33i5ffkISCXc=;\n\tb=k7e1O3sXbFtCZ8DKJRQqJjIxZeKPBgLUxo3TyfRX6FXW4W0s4HGNB7nA8cmYROgof0\n\tiQ1CM4WLpCkPGAgl5dpcLzn38XcX/r+a1MdorED0tgmmWtYI7wfU9dPDfF6w6If/B4Id\n\teV6owJSwEaB4jDhIqAdDAiF9sL9nx38HHJPfe4uVCFa+GMMZ5UQPl92v1fg+kf0+J23A\n\tkJP3/Vmdi92iY73jK0iiXVEoAsJYVH2y9SRCzXVHKKMpSEbbD9//R/bJTe951TeW9qCb\n\t+uRPGHRLx0BQVslnxnwodV3ziuew3xt+0nN7ejovHzDPPVHbiqONjIzL1KdiuFZpSVUL\n\t8ujA==",
        "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=olLHt/LWSXBdsV2nZv8WrqeymB/JReM33i5ffkISCXc=;\n\tb=WY5gahQ5kkGXmGObTAHC2GuhIQAYvgiJAZuHlQemLYGSDzkPO5r3xSir33gkk5MYsv\n\t3mJg2C7fbNR5xRr0UuY3pe7Ab7beOEr7nBGq1sr3Qcbu99of1kuy51U8HLhTdGUePOSs\n\tKI9bOzBZpi7+txp7BFH1uwZ2qg9aTbZCAjdq0ONalOTWZSb0KBS9N6iYx97tFZiAwCgj\n\tkqiMm8X1c4Qk2Ov2uvRekxYZdDj0lAc9o/bF/A3/0exv4QfT00OK5/JGQFe8DHyw1ty4\n\tFjYp8SM5XrN5+qa+gF+BwB2T2XxQ5U7SM5nbMQ+bwH7Oc9Kz++568Z7KZwzM3qk61V++\n\t10rA==",
        "X-Gm-Message-State": "AHPjjUi00BrBfpQCgzGK2kngascPTgGzehWtKn30+SaYW6YFzBrteNH5\n\tzjFvn+BiOHAu14PheCA=",
        "X-Google-Smtp-Source": "AOwi7QAhqp/3/meoqE0Y/FCeL9ngSxRZBRn5v4HCJkvPoG93E7Apl4ZHtPMtz35RQYk6Hz2mEPg6yA==",
        "X-Received": "by 10.55.20.210 with SMTP id 79mr8578216qku.194.1504977386941;\n\tSat, 09 Sep 2017 10:16:26 -0700 (PDT)",
        "From": "Rob Clark <robdclark@gmail.com>",
        "To": "U-Boot Mailing List <u-boot@lists.denx.de>",
        "Date": "Sat,  9 Sep 2017 13:15:53 -0400",
        "Message-Id": "<20170909171606.20029-3-robdclark@gmail.com>",
        "X-Mailer": "git-send-email 2.13.5",
        "In-Reply-To": "<20170909171606.20029-1-robdclark@gmail.com>",
        "References": "<20170909171606.20029-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 2/9] fs/fat: introduce new director 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": "Untangle directory traversal into a simple iterator, to replace the\nexisting multi-purpose do_fat_read_at() + get_dentfromdir().\n\nSigned-off-by: Rob Clark <robdclark@gmail.com>\nReviewed-by: Łukasz Majewski <lukma@denx.de>\n---\n fs/fat/fat.c  | 356 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n include/fat.h |   7 ++\n 2 files changed, 360 insertions(+), 3 deletions(-)",
    "diff": "diff --git a/fs/fat/fat.c b/fs/fat/fat.c\nindex e1c0a15dc7..ee2bbe38f1 100644\n--- a/fs/fat/fat.c\n+++ b/fs/fat/fat.c\n@@ -812,7 +812,6 @@ static int get_fs_info(fsdata *mydata)\n {\n \tboot_sector bs;\n \tvolume_info volinfo;\n-\t__u32 root_cluster = 0;\n \tint ret;\n \n \tret = read_bootsectandvi(&bs, &volinfo, &mydata->fatsize);\n@@ -822,7 +821,6 @@ static int get_fs_info(fsdata *mydata)\n \t}\n \n \tif (mydata->fatsize == 32) {\n-\t\troot_cluster = bs.root_cluster;\n \t\tmydata->fatlength = bs.fat32_length;\n \t} else {\n \t\tmydata->fatlength = bs.fat_length;\n@@ -843,6 +841,7 @@ static int get_fs_info(fsdata *mydata)\n \tif (mydata->fatsize == 32) {\n \t\tmydata->data_begin = mydata->rootdir_sect -\n \t\t\t\t\t(mydata->clust_size * 2);\n+\t\tmydata->root_cluster = bs.root_cluster;\n \t} else {\n \t\tmydata->rootdir_size = ((bs.dir_entries[1]  * (int)256 +\n \t\t\t\t\t bs.dir_entries[0]) *\n@@ -851,6 +850,9 @@ static int get_fs_info(fsdata *mydata)\n \t\tmydata->data_begin = mydata->rootdir_sect +\n \t\t\t\t\tmydata->rootdir_size -\n \t\t\t\t\t(mydata->clust_size * 2);\n+\t\tmydata->root_cluster = (mydata->rootdir_sect -\n+\t\t\t\t\tmydata->data_begin) /\n+\t\t\t\t\tmydata->clust_size;\n \t}\n \n \tmydata->fatbufnum = -1;\n@@ -868,7 +870,7 @@ static int get_fs_info(fsdata *mydata)\n \t       mydata->fatsize, mydata->fat_sect, mydata->fatlength);\n \tdebug(\"Rootdir begins at cluster: %d, sector: %d, offset: %x\\n\"\n \t       \"Data begins at: %d\\n\",\n-\t       root_cluster,\n+\t       mydata->root_cluster,\n \t       mydata->rootdir_sect,\n \t       mydata->rootdir_sect * mydata->sect_size, mydata->data_begin);\n \tdebug(\"Sector size: %d, cluster size: %d\\n\", mydata->sect_size,\n@@ -1245,6 +1247,354 @@ exit:\n \treturn ret;\n }\n \n+\n+/*\n+ * Directory iterator, to simplify filesystem traversal\n+ *\n+ * Implements an iterator pattern to traverse directory tables,\n+ * transparently handling directory tables split across multiple\n+ * clusters, and the difference between FAT12/FAT16 root directory\n+ * (contiguous) and subdirectories + FAT32 root (chained).\n+ *\n+ * Rough usage:\n+ *\n+ *   for (fat_itr_root(&itr, fsdata); fat_itr_next(&itr); ) {\n+ *      // to traverse down to a subdirectory pointed to by\n+ *      // current iterator position:\n+ *      fat_itr_child(&itr, &itr);\n+ *   }\n+ *\n+ * For more complete example, see fat_itr_resolve()\n+ */\n+\n+typedef struct {\n+\tfsdata    *fsdata;        /* filesystem parameters */\n+\tunsigned   clust;         /* current cluster */\n+\tint        last_cluster;  /* set once we've read last cluster */\n+\tint        is_root;       /* is iterator at root directory */\n+\tint        remaining;     /* remaining dent's in current cluster */\n+\n+\t/* current iterator position values: */\n+\tdir_entry *dent;          /* current directory entry */\n+\tchar       l_name[VFAT_MAXLEN_BYTES];    /* long (vfat) name */\n+\tchar       s_name[14];    /* short 8.3 name */\n+\tchar      *name;          /* l_name if there is one, else s_name */\n+\n+\t/* storage for current cluster in memory: */\n+\tu8         block[MAX_CLUSTSIZE] __aligned(ARCH_DMA_MINALIGN);\n+} fat_itr;\n+\n+static int fat_itr_isdir(fat_itr *itr);\n+\n+/**\n+ * fat_itr_root() - initialize an iterator to start at the root\n+ * directory\n+ *\n+ * @itr: iterator to initialize\n+ * @fsdata: filesystem data for the partition\n+ * @return 0 on success, else -errno\n+ */\n+static int fat_itr_root(fat_itr *itr, fsdata *fsdata)\n+{\n+\tif (get_fs_info(fsdata))\n+\t\treturn -ENXIO;\n+\n+\titr->fsdata = fsdata;\n+\titr->clust = fsdata->root_cluster;\n+\titr->dent = NULL;\n+\titr->remaining = 0;\n+\titr->last_cluster = 0;\n+\titr->is_root = 1;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * fat_itr_child() - initialize an iterator to descend into a sub-\n+ * directory\n+ *\n+ * Initializes 'itr' to iterate the contents of the directory at\n+ * the current cursor position of 'parent'.  It is an error to\n+ * call this if the current cursor of 'parent' is pointing at a\n+ * regular file.\n+ *\n+ * Note that 'itr' and 'parent' can be the same pointer if you do\n+ * not need to preserve 'parent' after this call, which is useful\n+ * for traversing directory structure to resolve a file/directory.\n+ *\n+ * @itr: iterator to initialize\n+ * @parent: the iterator pointing at a directory entry in the\n+ *    parent directory of the directory to iterate\n+ */\n+static void fat_itr_child(fat_itr *itr, fat_itr *parent)\n+{\n+\tfsdata *mydata = parent->fsdata;  /* for silly macros */\n+\tunsigned clustnum = START(parent->dent);\n+\n+\tassert(fat_itr_isdir(parent));\n+\n+\titr->fsdata = parent->fsdata;\n+\tif (clustnum > 0) {\n+\t\titr->clust = clustnum;\n+\t} else {\n+\t\titr->clust = parent->fsdata->root_cluster;\n+\t}\n+\titr->dent = NULL;\n+\titr->remaining = 0;\n+\titr->last_cluster = 0;\n+\titr->is_root = 0;\n+}\n+\n+static void *next_cluster(fat_itr *itr)\n+{\n+\tfsdata *mydata = itr->fsdata;  /* for silly macros */\n+\tint ret;\n+\tu32 sect;\n+\n+\t/* have we reached the end? */\n+\tif (itr->last_cluster)\n+\t\treturn NULL;\n+\n+\tsect = clust_to_sect(itr->fsdata, itr->clust);\n+\n+\tdebug(\"FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\\n\",\n+\t      sect, itr->fsdata->clust_size, DIRENTSPERBLOCK);\n+\n+\t/*\n+\t * NOTE: do_fat_read_at() had complicated logic to deal w/\n+\t * vfat names that span multiple clusters in the fat16 case,\n+\t * which get_dentfromdir() probably also needed (and was\n+\t * missing).  And not entirely sure what fat32 didn't have\n+\t * the same issue..  We solve that by only caring about one\n+\t * dent at a time and iteratively constructing the vfat long\n+\t * name.\n+\t */\n+\tret = disk_read(sect, itr->fsdata->clust_size,\n+\t\t\titr->block);\n+\tif (ret < 0) {\n+\t\tdebug(\"Error: reading block\\n\");\n+\t\treturn NULL;\n+\t}\n+\n+\tif (itr->is_root && itr->fsdata->fatsize != 32) {\n+\t\titr->clust++;\n+\t\tsect = clust_to_sect(itr->fsdata, itr->clust);\n+\t\tif (sect - itr->fsdata->rootdir_sect >=\n+\t\t    itr->fsdata->rootdir_size) {\n+\t\t\tdebug(\"cursect: 0x%x\\n\", itr->clust);\n+\t\t\titr->last_cluster = 1;\n+\t\t}\n+\t} else {\n+\t\titr->clust = get_fatent(itr->fsdata, itr->clust);\n+\t\tif (CHECK_CLUST(itr->clust, itr->fsdata->fatsize)) {\n+\t\t\tdebug(\"cursect: 0x%x\\n\", itr->clust);\n+\t\t\titr->last_cluster = 1;\n+\t\t}\n+\t}\n+\n+\treturn itr->block;\n+}\n+\n+static dir_entry *next_dent(fat_itr *itr)\n+{\n+\tif (itr->remaining == 0) {\n+\t\tstruct dir_entry *dent = next_cluster(itr);\n+\t\tunsigned nbytes = itr->fsdata->sect_size *\n+\t\t\titr->fsdata->clust_size;\n+\n+\t\t/* have we reached the last cluster? */\n+\t\tif (!dent)\n+\t\t\treturn NULL;\n+\n+\t\titr->remaining = nbytes / sizeof(dir_entry) - 1;\n+\t\titr->dent = dent;\n+\t} else {\n+\t\titr->remaining--;\n+\t\titr->dent++;\n+\t}\n+\n+\t/* have we reached the last valid entry? */\n+\tif (itr->dent->name[0] == 0)\n+\t\treturn NULL;\n+\n+\treturn itr->dent;\n+}\n+\n+static dir_entry *extract_vfat_name(fat_itr *itr)\n+{\n+\tstruct dir_entry *dent = itr->dent;\n+\tint seqn = itr->dent->name[0] & ~LAST_LONG_ENTRY_MASK;\n+\tu8 chksum, alias_checksum = ((dir_slot *)dent)->alias_checksum;\n+\tint n = 0;\n+\n+\twhile (seqn--) {\n+\t\tchar buf[13];\n+\t\tint idx = 0;\n+\n+\t\tslot2str((dir_slot *)dent, buf, &idx);\n+\n+\t\t/* shift accumulated long-name up and copy new part in: */\n+\t\tmemmove(itr->l_name + idx, itr->l_name, n);\n+\t\tmemcpy(itr->l_name, buf, idx);\n+\t\tn += idx;\n+\n+\t\tdent = next_dent(itr);\n+\t\tif (!dent)\n+\t\t\treturn NULL;\n+\t}\n+\n+\titr->l_name[n] = '\\0';\n+\n+\tchksum = mkcksum(dent->name, dent->ext);\n+\n+\t/* checksum mismatch could mean deleted file, etc.. skip it: */\n+\tif (chksum != alias_checksum) {\n+\t\tdebug(\"** chksum=%x, alias_checksum=%x, l_name=%s, s_name=%8s.%3s\\n\",\n+\t\t      chksum, alias_checksum, itr->l_name, dent->name, dent->ext);\n+\t\treturn NULL;\n+\t}\n+\n+\treturn dent;\n+}\n+\n+/**\n+ * fat_itr_next() - step to the next entry in a directory\n+ *\n+ * Must be called once on a new iterator before the cursor is valid.\n+ *\n+ * @itr: the iterator to iterate\n+ * @return boolean, 1 if success or 0 if no more entries in the\n+ *    current directory\n+ */\n+static int fat_itr_next(fat_itr *itr)\n+{\n+\tdir_entry *dent;\n+\n+\titr->name = NULL;\n+\n+\twhile (1) {\n+\t\tdent = next_dent(itr);\n+\t\tif (!dent)\n+\t\t\treturn 0;\n+\n+\t\tif (dent->name[0] == DELETED_FLAG ||\n+\t\t    dent->name[0] == aRING)\n+\t\t\tcontinue;\n+\n+\t\tif (dent->attr & ATTR_VOLUME) {\n+\t\t\tif (vfat_enabled &&\n+\t\t\t    (dent->attr & ATTR_VFAT) == ATTR_VFAT &&\n+\t\t\t    (dent->name[0] & LAST_LONG_ENTRY_MASK)) {\n+\t\t\t\tdent = extract_vfat_name(itr);\n+\t\t\t\tif (!dent)\n+\t\t\t\t\tcontinue;\n+\t\t\t\titr->name = itr->l_name;\n+\t\t\t\tbreak;\n+\t\t\t} else {\n+\t\t\t\t/* Volume label or VFAT entry, skip */\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t}\n+\n+\t\tbreak;\n+\t}\n+\n+\tget_name(dent, itr->s_name);\n+\tif (!itr->name)\n+\t\titr->name = itr->s_name;\n+\n+\treturn 1;\n+}\n+\n+/**\n+ * fat_itr_isdir() - is current cursor position pointing to a directory\n+ *\n+ * @itr: the iterator\n+ * @return true if cursor is at a directory\n+ */\n+static int fat_itr_isdir(fat_itr *itr)\n+{\n+\treturn !!(itr->dent->attr & ATTR_DIR);\n+}\n+\n+/*\n+ * Helpers:\n+ */\n+\n+#define TYPE_FILE 0x1\n+#define TYPE_DIR  0x2\n+#define TYPE_ANY  (TYPE_FILE | TYPE_DIR)\n+\n+/**\n+ * fat_itr_resolve() - traverse directory structure to resolve the\n+ * requested path.\n+ *\n+ * Traverse directory structure to the requested path.  If the specified\n+ * path is to a directory, this will descend into the directory and\n+ * leave it iterator at the start of the directory.  If the path is to a\n+ * file, it will leave the iterator in the parent directory with current\n+ * cursor at file's entry in the directory.\n+ *\n+ * @itr: iterator initialized to root\n+ * @path: the requested path\n+ * @type: bitmask of allowable file types\n+ * @return 0 on success or -errno\n+ */\n+static int fat_itr_resolve(fat_itr *itr, const char *path, unsigned type)\n+{\n+\tconst char *next;\n+\n+\t/* chomp any extra leading slashes: */\n+\twhile (path[0] && ISDIRDELIM(path[0]))\n+\t\tpath++;\n+\n+\t/* are we at the end? */\n+\tif (strlen(path) == 0) {\n+\t\tif (!(type & TYPE_DIR))\n+\t\t\treturn -ENOENT;\n+\t\treturn 0;\n+\t}\n+\n+\t/* find length of next path entry: */\n+\tnext = path;\n+\twhile (next[0] && !ISDIRDELIM(next[0]))\n+\t\tnext++;\n+\n+\twhile (fat_itr_next(itr)) {\n+\t\tint match = 0;\n+\t\tunsigned n = max(strlen(itr->name), (size_t)(next - path));\n+\n+\t\t/* check both long and short name: */\n+\t\tif (!strncasecmp(path, itr->name, n))\n+\t\t\tmatch = 1;\n+\t\telse if (itr->name != itr->s_name &&\n+\t\t\t !strncasecmp(path, itr->s_name, n))\n+\t\t\tmatch = 1;\n+\n+\t\tif (!match)\n+\t\t\tcontinue;\n+\n+\t\tif (fat_itr_isdir(itr)) {\n+\t\t\t/* recurse into directory: */\n+\t\t\tfat_itr_child(itr, itr);\n+\t\t\treturn fat_itr_resolve(itr, next, type);\n+\t\t} else if (next[0]) {\n+\t\t\t/*\n+\t\t\t * If next is not empty then we have a case\n+\t\t\t * like: /path/to/realfile/nonsense\n+\t\t\t */\n+\t\t\tdebug(\"bad trailing path: %s\\n\", next);\n+\t\t\treturn -ENOENT;\n+\t\t} else if (!(type & TYPE_FILE)) {\n+\t\t\treturn -ENOTDIR;\n+\t\t} else {\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\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 {\ndiff --git a/include/fat.h b/include/fat.h\nindex b671ee8f81..21bb6666cf 100644\n--- a/include/fat.h\n+++ b/include/fat.h\n@@ -175,8 +175,15 @@ typedef struct {\n \tint\tdata_begin;\t/* The sector of the first cluster, can be negative */\n \tint\tfatbufnum;\t/* Used by get_fatent, init to -1 */\n \tint\trootdir_size;\t/* Size of root dir for non-FAT32 */\n+\t__u32\troot_cluster;\t/* First cluster of root dir for FAT32 */\n } fsdata;\n \n+/* TODO clean up places that are open-coding this: */\n+static inline u32 clust_to_sect(fsdata *fsdata, u32 clust)\n+{\n+\treturn fsdata->data_begin + clust * fsdata->clust_size;\n+}\n+\n typedef int\t(file_detectfs_func)(void);\n typedef int\t(file_ls_func)(const char *dir);\n typedef int\t(file_read_func)(const char *filename, void *buffer,\n",
    "prefixes": [
        "U-Boot",
        "v3",
        "2/9"
    ]
}