Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/809106/?format=api
{ "id": 809106, "url": "http://patchwork.ozlabs.org/api/patches/809106/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20170902163806.27265-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": "<20170902163806.27265-3-robdclark@gmail.com>", "list_archive_url": null, "date": "2017-09-02T16:37:57", "name": "[U-Boot,v2,2/8] fs/fat: introduce new director iterators", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "fc201bc4ec3ee6a73ad17f33c036ca163c62cfbe", "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-3-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/809106/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/809106/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=\"RD4AbdkE\"; dkim-atps=neutral" ], "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xl20S3rbYz9t16\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 3474AC21E9B; Sat, 2 Sep 2017 16:39:00 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id D69C8C21F40;\n\tSat, 2 Sep 2017 16:38:56 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 98036C21F95; Sat, 2 Sep 2017 16:38:27 +0000 (UTC)", "from mail-qt0-f195.google.com (mail-qt0-f195.google.com\n\t[209.85.216.195])\n\tby lists.denx.de (Postfix) with ESMTPS id 38162C21E2F\n\tfor <u-boot@lists.denx.de>; Sat, 2 Sep 2017 16:38:26 +0000 (UTC)", "by mail-qt0-f195.google.com with SMTP id d15so2067576qta.5\n\tfor <u-boot@lists.denx.de>; Sat, 02 Sep 2017 09:38:26 -0700 (PDT)", "from localhost ([2601:184:4780:aac0:25f8:dd96:a084:785a])\n\tby smtp.gmail.com with ESMTPSA id\n\tb27sm302794qtc.24.2017.09.02.09.38.23\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSat, 02 Sep 2017 09:38:23 -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=cVM2R9RV3bSW69uD7NwvUe/vw63bY7ygfC7fi1RXjJU=;\n\tb=RD4AbdkEUiLPGGehRtaoS4rGOPO8KTxEkgmvxmOTGz+2tX+gH/7y/w55mGIx+4+0P+\n\ts68ZoZ26kyQkxLWIU28YkFTsV3RhJuvtHlbR89NQz0NULESYOvB+658/7Y0r5INLZ8jj\n\tZwcIEYoXrP8RKkxuWK0CSp052NtJFV5gm66WuZDw8f1WOVh7LoMKi5TYA7LtXN3c9gDJ\n\tAIVBgc0F7QJHZKKCQxS7twcIO1CtkomGb1k2t7m3VThe8ZyCrkDuZV2uTxvRNx/H1VLY\n\t4RxkydayhBRd2bBZxReC1YqZoqXRSXo/cN3jKa6vN1UFDAs8R16SlTrkEOrRdkXhiJvA\n\t/vuA==", "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=cVM2R9RV3bSW69uD7NwvUe/vw63bY7ygfC7fi1RXjJU=;\n\tb=kQ0/J9m5Yx+tBt0BE/bcTcwlWTzdtSrE8yxYJztIgmPBZWo/sjRz7X+o9Kh0lANyNR\n\tnuIsWL4YAkNJyTNp1Ekd4CkSgc0rRs/yDJH9RJUtSPCJooY344zYKFHhVpPi7vBg1Qxc\n\tWep8aICVbvcojtVx3yb8jyushNzCNgECYMull0TzhDRlEKsF+LnSbsjSy3yBoPBap4tz\n\tKHFz9vl7nK2J6KHQNH7XThNmrNxtkt/5CY9DUl3U36fNcCiMQCs1f7z4A6rdqq1Ia+/4\n\tGWhq8yu48w9d70yeKigeZGltGd+StCT4jgORlUtvB2rEb1BdrMJJNQDjZvxyiU9wMpVD\n\t967Q==", "X-Gm-Message-State": "AHPjjUj02JcK8cYN/kmlsQtMcyO0wWCwKcodEErlcn1I0bvhhOmQrLeL\n\tej30tvTovrIUHwItQgM=", "X-Google-Smtp-Source": "ADKCNb4chboZ9KwuFLCgWQNmTgXgSSYYXRvBJVDDpuI1YHJj2/r8P7Q6YszcPhim5Yd7+HqcVVZtrQ==", "X-Received": "by 10.237.38.164 with SMTP id q33mr7802718qtd.238.1504370304837; \n\tSat, 02 Sep 2017 09:38:24 -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:57 -0400", "Message-Id": "<20170902163806.27265-3-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>", "Subject": "[U-Boot] [PATCH v2 2/8] 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>", "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": "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>\n---\n fs/fat/fat.c | 326 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 326 insertions(+)", "diff": "diff --git a/fs/fat/fat.c b/fs/fat/fat.c\nindex e1c0a15dc7..c72d6ca931 100644\n--- a/fs/fat/fat.c\n+++ b/fs/fat/fat.c\n@@ -1245,6 +1245,332 @@ exit:\n \treturn ret;\n }\n \n+\n+/*\n+ * Directory iterator, to simplify filesystem traversal\n+ */\n+\n+typedef struct {\n+\tfsdata *fsdata;\n+\tunsigned cursect;\n+\tdir_entry *dent;\n+\tint remaining; /* remaining dent's in current cluster */\n+\tint last_cluster;\n+\tint is_root;\n+\n+\t/* current iterator position values: */\n+\tchar l_name[VFAT_MAXLEN_BYTES];\n+\tchar s_name[14];\n+\tchar *name; /* l_name if there is one, else s_name */\n+\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->cursect = fsdata->rootdir_sect;\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->cursect = itr->fsdata->data_begin +\n+\t\t\t(clustnum * itr->fsdata->clust_size);\n+\t} else {\n+\t\titr->cursect = parent->fsdata->rootdir_sect;\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+\n+\t/* have we reached the end? */\n+\tif (itr->last_cluster)\n+\t\treturn NULL;\n+\n+\tdebug(\"FAT read(sect=%d), clust_size=%d, DIRENTSPERBLOCK=%zd\\n\",\n+\t itr->cursect, 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(itr->cursect, 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->cursect++;\n+\t\tif (itr->cursect - itr->fsdata->rootdir_sect >=\n+\t\t itr->fsdata->rootdir_size) {\n+\t\t\tdebug(\"cursect: 0x%x\\n\", itr->cursect);\n+\t\t\titr->last_cluster = 1;\n+\t\t}\n+\t} else {\n+\t\titr->cursect = get_fatent(itr->fsdata, itr->cursect);\n+\t\tif (CHECK_CLUST(itr->cursect, itr->fsdata->fatsize)) {\n+\t\t\tdebug(\"cursect: 0x%x\\n\", itr->cursect);\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+\n+\t\t/* have we reached the last cluster? */\n+\t\tif (!dent)\n+\t\t\treturn NULL;\n+\n+\t\titr->remaining = itr->fsdata->sect_size / 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+\n+\t\t/* check both long and short name: */\n+\t\tif (!strncasecmp(path, itr->name, next - path))\n+\t\t\tmatch = 1;\n+\t\telse if (itr->name != itr->s_name &&\n+\t\t\t !strncasecmp(path, itr->s_name, (next - path)))\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 {\n", "prefixes": [ "U-Boot", "v2", "2/8" ] }