From patchwork Mon Apr 16 14:11:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 898641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oCC9Lil2"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B5NXexcM"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Pr1c05H3z9s1l for ; Tue, 17 Apr 2018 00:12:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=iZUsMJQ4js1Nf/TKSZ4xUSpj2fpKj9IuTLjcHEdfMw4=; b=oCC9Lil2aIhC77 2jGq2mu5lLcWXW0521sX7jKb5M2nR7/YOA7Gn5HmcwwVrIB6XHh8GZaDqpZ+0xszDqjBX0F7DI8Pr 0r6vHO1StMAoAk1AUwqKQ44bjBaWXLlaRNCd9c/37VQ9M/oiaDly2m04OXoyeOulof4Rk56RiR+ev hgZP5mw/UKn4kYoLslLM5NBJ+yLhpFyai6ZUMsN7aIDx9z2NGicLiI38zXHMI4YvYieGHaedfgXI0 mGHHV/nlKZLSA9SrkMsajt2Dr8etz3Z1JSW42gM2mEuVzTw1YT8/b2ZhlV4hTpxKJAmasp7dwZELp OwKb/sPYyczBMpjBFzsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f84rt-000163-Tu; Mon, 16 Apr 2018 14:12:29 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f84rq-000155-8N for lede-dev@lists.infradead.org; Mon, 16 Apr 2018 14:12:27 +0000 Received: by mail-lf0-x244.google.com with SMTP id r125-v6so5577222lfe.2 for ; Mon, 16 Apr 2018 07:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xn4xDYyPqxYhrstZ8lMZmD0u9XsPa5pnmBOSAQBZr+0=; b=B5NXexcMd3rOvDlai0hsGWVSiMaiTi7yUjkXkrJDGYXT0BVYmhMr4zJOdT0vn2tnR9 P8Bg0KMiioe1aflnSYc6vRd+6EZUfzYuhBnngILrxkbhwDbv8W8ugCyHZLCXTDstmBpD 5L8ybo6zY6A7R0SSw/7m3hCVNF8Uff6zN+wnL3PTjUAPhlywSzI5V14bZhA2yWYKB/Pl nfa13raLTM3ucDwOmzMEhc3VRXiOlpJyArsWNuNigtIarKE2vQtx7rH+tebDRwQoBvZk iO/pHJH/48VzYIuVIjWVoc1cRVzRkT2kBBP+tmPC/AmeqcB98QXzu2ZybGaDiXfFdTv8 fQgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xn4xDYyPqxYhrstZ8lMZmD0u9XsPa5pnmBOSAQBZr+0=; b=p2CCzDwvrSW/iRuHQgq+UHSZSzpffbfDMXNS01TLq33Mq5RN3IsmEuXdduOqWj4Ig2 IAuqa/vuFR9WhktB1MTppkDgiNNVdQFK+gMDOseB7T1MZNfp8bQjiPN9WfSuCWdHa3Iz ZQ7ynp8FF/cOuWXAX3XsCROyhLo4VvJcYJI2taa7CopclLBh/oYY8B6TugiCVQOPox0g IUjED6VoK2Hdi0ZbgpZS5GI841JBWSbRoArwWl0tjL4WJ2v75q2+Bdbb9yk8MquDs3r6 m/szMsEhlBpkjSSyEb2zfuJi9A3VTnV9Ek3ujbC18+2w8O40zacYdkMvc0CXvvQrNxH0 gaMw== X-Gm-Message-State: ALQs6tAMPG1OdEfSB9ei31RzUhbwOhQMqLcR/ISS31ib0tXNUuNG/xHL p9DsGTDlaeu+aigsfe+xv1Y= X-Google-Smtp-Source: AIpwx4+JnrY2jyzo+sOth6h9CUGQ+3zreyAU/oOyi5tdPQ/Yk1iSiITPIOzjXJiKD4o3ujMHecljSA== X-Received: by 10.46.137.13 with SMTP id d13mr9292950lji.27.1523887933264; Mon, 16 Apr 2018 07:12:13 -0700 (PDT) Received: from linux-795u.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id z189-v6sm2879296lfa.18.2018.04.16.07.12.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 07:12:12 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: John Crispin , lede-dev@lists.infradead.org Date: Mon, 16 Apr 2018 16:11:47 +0200 Message-Id: <20180416141147.20658-1-zajec5@gmail.com> X-Mailer: git-send-email 2.12.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180416_071226_338762_0D1FBAD2 X-CRM114-Status: GOOD ( 14.91 ) X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4010:c07:0:0:0:244 listed in] [list.dnswl.org] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (zajec5[at]gmail.com) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zajec5[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [LEDE-DEV] [PATCH fstools] libfstools: move mount points when switching to JFFS2 X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rafał Miłecki Switching from "tmpfs" to "jffs2" happens after JFFS2 formatting is done. During that time user can use filesystem (thanks to RAM) and the role of switch2jffs() is to copy all changes to the JFFS2 overlay partition. What wasn't handled so far was moving mount points. User can create custom mounts, cp command won't copy them and umounting "tmpfs" will cause these mounts to go away. To preserve them switch2jffs() has to find all custom mount points and move them to the new filesystem. Signed-off-by: Rafał Miłecki Acked-by: John Crispin --- libfstools/overlay.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libfstools/overlay.c b/libfstools/overlay.c index a41364c..ebc43f7 100644 --- a/libfstools/overlay.c +++ b/libfstools/overlay.c @@ -112,6 +112,24 @@ foreachdir(const char *dir, int (*cb)(const char*)) cb(dir); } +static void foreach_mount(int (*cb)(const char *, const char *)) +{ + FILE *fp = fopen("/proc/mounts", "r"); + static char line[256]; + + if (!fp) + return; + + while (fgets(line, sizeof(line), fp)) { + char device[32], mount_point[32]; + + if (sscanf(line, "%31s %31s %*s %*s %*u %*u", device, mount_point) == 2) + cb(device, mount_point); + } + + fclose(fp); +} + void overlay_delete(const char *dir, bool _keep_sysupgrade) { @@ -135,6 +153,19 @@ overlay_mount(struct volume *v, char *fs) return 0; } +/** + * move_mount - move mount point to the new root + */ +static int move_mount(const char *device, const char *mount_point) +{ + static const char *prefix = "/tmp/root/"; + + if (strncmp(mount_point, prefix, strlen(prefix))) + return 0; + + return mount_move(prefix, "/", mount_point + strlen(prefix)); +} + static int switch2jffs(struct volume *v) { @@ -174,7 +205,20 @@ switch2jffs(struct volume *v) return -1; } - return fopivot("/overlay", "/rom"); + ret = fopivot("/overlay", "/rom"); + + /* + * Besides copying overlay data from "tmpfs" to "jffs2" we should also + * move mount points that user could create during JFFS2 formatting. + * This has to happen after fopivot call because: + * 1) It's trivial to find mount points to move then (/tmp/root/...). + * 2) We can't do that earlier using /rom/overlay/upper/ as overlay(fs) + * doesn't support mounts. Mounting to upper dir don't make overlay + * /propagate/ files to the target dir. + */ + foreach_mount(move_mount); + + return ret; } int