Show a patch.

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

{
    "id": 8771,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/8771/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/8771/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20200714090936.9562-1-laurent.pinchart@ideasonboard.com>",
    "date": "2020-07-14T09:09:33",
    "name": "[libcamera-devel,v2,1/4] libcamera: file: Add read/write support",
    "commit_ref": "25288281d1e72c8e6c264525926a200511407ac7",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "37180e69b057badc56d3cc8fbbae8f8f583a683b",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/8771/mbox/",
    "series": [
        {
            "id": 1103,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1103/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1103",
            "date": "2020-07-14T09:09:33",
            "name": "[libcamera-devel,v2,1/4] libcamera: file: Add read/write support",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1103/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/8771/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/8771/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 02C8ABD790\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 14 Jul 2020 09:09:49 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6D34C607BD;\n\tTue, 14 Jul 2020 11:09:48 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F8BF60483\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jul 2020 11:09:47 +0200 (CEST)",
            "from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AD788564\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 14 Jul 2020 11:09:46 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ieu+jSUb\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1594717786;\n\tbh=/QsgrHKm13Gr5qOL7fK0z3kLpCEXUBZJipLsV/Rpo6E=;\n\th=From:To:Subject:Date:From;\n\tb=ieu+jSUblAbujoE7Xi4WtivR5KMUFEEWOj8Pi1UjQBTZWek+OliQFrrAJPg/ZtigK\n\tjUGSghQ/I76ngp8p/la4+LpZRvIb/Dd5Ax501tAztl4f0CyggWYUDgVqRlRR56Na28\n\tYfKNUIebSw8edd/Sha2RVo7OqFZnjKwUnAVA99LE=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 14 Jul 2020 12:09:33 +0300",
        "Message-Id": "<20200714090936.9562-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 1/4] libcamera: file: Add read/write\n\tsupport",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add basic support to read and write data from/to a file, along with\nretrieving and setting the current read/write position.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v1:\n\n- Don't cache pos(), use lseek()\n---\n include/libcamera/internal/file.h |   6 ++\n src/libcamera/file.cpp            | 109 ++++++++++++++++++++++++++++++\n 2 files changed, 115 insertions(+)",
    "diff": "diff --git a/include/libcamera/internal/file.h b/include/libcamera/internal/file.h\nindex e3e72132e336..9b6d011f5e9d 100644\n--- a/include/libcamera/internal/file.h\n+++ b/include/libcamera/internal/file.h\n@@ -49,6 +49,12 @@ public:\n \tint error() const { return error_; }\n \tssize_t size() const;\n \n+\toff_t pos() const;\n+\toff_t seek(off_t pos);\n+\n+\tssize_t read(const Span<uint8_t> &data);\n+\tssize_t write(const Span<const uint8_t> &data);\n+\n \tSpan<uint8_t> map(off_t offset = 0, ssize_t size = -1,\n \t\t\t  MapFlag flags = MapNoOption);\n \tbool unmap(uint8_t *addr);\ndiff --git a/src/libcamera/file.cpp b/src/libcamera/file.cpp\nindex c471bde3fc68..d99a1806e1c8 100644\n--- a/src/libcamera/file.cpp\n+++ b/src/libcamera/file.cpp\n@@ -237,6 +237,115 @@ ssize_t File::size() const\n \treturn st.st_size;\n }\n \n+/**\n+ * \\brief Return current read or write position\n+ *\n+ * If the file is closed, this function returns 0.\n+ *\n+ * \\return The current read or write position\n+ */\n+off_t File::pos() const\n+{\n+\tif (!isOpen())\n+\t\treturn 0;\n+\n+\treturn lseek(fd_, 0, SEEK_CUR);\n+}\n+\n+/**\n+ * \\brief Set the read or write position\n+ * \\param[in] pos The desired position\n+ * \\return The resulting offset from the beginning of the file on success, or a\n+ * negative error code otherwise\n+ */\n+off_t File::seek(off_t pos)\n+{\n+\tif (!isOpen())\n+\t\treturn -EINVAL;\n+\n+\toff_t ret = lseek(fd_, pos, SEEK_SET);\n+\tif (ret < 0)\n+\t\treturn -errno;\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * \\brief Read data from the file\n+ * \\param[in] data Memory to read data into\n+ *\n+ * Read at most \\a data.size() bytes from the file into \\a data.data(), and\n+ * return the number of bytes read. If less data than requested is available,\n+ * the returned byte count may be smaller than the requested size. If no more\n+ * data is available, 0 is returned.\n+ *\n+ * The position of the file as returned by pos() is advanced by the number of\n+ * bytes read. If an error occurs, the position isn't modified.\n+ *\n+ * \\return The number of bytes read on success, or a negative error code\n+ * otherwise\n+ */\n+ssize_t File::read(const Span<uint8_t> &data)\n+{\n+\tif (!isOpen())\n+\t\treturn -EINVAL;\n+\n+\tsize_t readBytes = 0;\n+\tssize_t ret = 0;\n+\n+\t/* Retry in case of interrupted system calls. */\n+\twhile (readBytes < data.size()) {\n+\t\tret = ::read(fd_, data.data() + readBytes,\n+\t\t\t     data.size() - readBytes);\n+\t\tif (ret <= 0)\n+\t\t\tbreak;\n+\n+\t\treadBytes += ret;\n+\t}\n+\n+\tif (ret < 0 && !readBytes)\n+\t\treturn -errno;\n+\n+\treturn readBytes;\n+}\n+\n+/**\n+ * \\brief Write data to the file\n+ * \\param[in] data Memory containing data to be written\n+ *\n+ * Write at most \\a data.size() bytes from \\a data.data() to the file, and\n+ * return the number of bytes written. If the file system doesn't have enough\n+ * space for the data, the returned byte count may be less than requested.\n+ *\n+ * The position of the file as returned by pos() is advanced by the number of\n+ * bytes written. If an error occurs, the position isn't modified.\n+ *\n+ * \\return The number of bytes written on success, or a negative error code\n+ * otherwise\n+ */\n+ssize_t File::write(const Span<const uint8_t> &data)\n+{\n+\tif (!isOpen())\n+\t\treturn -EINVAL;\n+\n+\tsize_t writtenBytes = 0;\n+\n+\t/* Retry in case of interrupted system calls. */\n+\twhile (writtenBytes < data.size()) {\n+\t\tssize_t ret = ::write(fd_, data.data() + writtenBytes,\n+\t\t\t\t      data.size() - writtenBytes);\n+\t\tif (ret <= 0)\n+\t\t\tbreak;\n+\n+\t\twrittenBytes += ret;\n+\t}\n+\n+\tif (data.size() && !writtenBytes)\n+\t\treturn -errno;\n+\n+\treturn writtenBytes;\n+}\n+\n /**\n  * \\brief Map a region of the file in the process memory\n  * \\param[in] offset The region offset within the file\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "1/4"
    ]
}