Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1031411imm; Thu, 31 May 2018 13:57:27 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIEh3ZFyIchZwwlysA0RQkJ3lTjMDeeRbmkTKAPkL+yO1YHEaSpSgUSaWTL4R2NTqGHxCTl X-Received: by 2002:a17:902:1aa:: with SMTP id b39-v6mr8429455plb.120.1527800247738; Thu, 31 May 2018 13:57:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527800247; cv=none; d=google.com; s=arc-20160816; b=Cs/oIU68Jeh7+7YG9tzMxueFAdB7TFcFnYVCMAKfgxJUdn79zGClJd1A2tdO8ecDJ1 dQka9dkTSJqrltedPmgjCOwi/A/YfT4ILToK4M3sCdqlBMPF55N7TN31QbYy52e32YnR jkQMY+1VPxgBtlhv+XQvq0K1pxXfAof2HxKwrpTQClaXqFsFw2M6gdeGhax2K6tgM59q 3hCuZknVCAaSizUGqgmW8/kKRPg3eh7I6YWnYdcx/ytlER4Prfk0pBcyGziLNkrn27XX Fyr1HI9Yd7I8HkpPhgc9C3n1ppWSNgy5h9X0OhSCoO86iAvBuzTifa+/x71u1TUgwpXA vZZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:message-id:date :content-transfer-encoding:content-id:mime-version:subject:cc :references:in-reply-to:from:organization:arc-authentication-results; bh=Vk5eW34Xq0EZ/soJDNszvymYXGW/K8zErl1/paVmsbU=; b=qEHjDGq8Y+1JSTUACOtdIM0yzbQPMvU8sPduH9ELaPN/QvgbXpmuRqe2Rf0nEt1TZ9 DVpLAJpvleoKbB4sVOwvmu7oW1gPxmsmr1LEPMvaBg8CkqOb//iMrY4KBpq8kPEzCh/M uA0DgZZ7wCWIkRWgGrpuZ7xxRCrxsHGHGdXzO+TukpKv3U7AfHYg2p6tosGH7uqoQGCl dOvWVWV53RevX+TLb6SzDXqwGGigv8XdT+/ZtMXx+k61XGeZ5EkeiV/BxYyR7IdRvKOm RYb7OKehRnhbch5wmufy2lfYhAK3cA+Buy8BOpraWPiaucVcluUzoWdaD9nnZ4zA9qXc bKpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y5-v6si36438659pfe.134.2018.05.31.13.57.12; Thu, 31 May 2018 13:57:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750756AbeEaU4r convert rfc822-to-8bit (ORCPT + 99 others); Thu, 31 May 2018 16:56:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35708 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750711AbeEaU4q (ORCPT ); Thu, 31 May 2018 16:56:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 762C2401EF17; Thu, 31 May 2018 20:56:45 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-245.rdu2.redhat.com [10.10.121.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB6CA2024CA1; Thu, 31 May 2018 20:56:44 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <152720692470.9073.11301353609129445901.stgit@warthog.procyon.org.uk> References: <152720692470.9073.11301353609129445901.stgit@warthog.procyon.org.uk> <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> Cc: dhowells@redhat.com, viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Test program for move_mount() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32013.1527800204.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Thu, 31 May 2018 21:56:44 +0100 Message-ID: <32014.1527800204@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 31 May 2018 20:56:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 31 May 2018 20:56:45 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org /* move_mount test. * * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #define O_CLONE_MOUNT 040000000 /* Used with O_PATH to clone the mount subtree at path */ #define O_NON_RECURSIVE 0100000000 /* Used with O_CLONE_MOUNT to only clone one mount */ #define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ #define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ #define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ #define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ #define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ #define MOVE_MOUNT__MASK 0x00000077 static inline int move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned int flags) { return syscall(337, from_dfd, from_pathname, to_dfd, to_pathname, flags); } void format(void) { printf("Format: move_mount [-a] [-c] [-r]\n"); exit(2); } int main(int argc, char *argv[]) { bool preopen = false; int ret, fd; int o_flags = O_PATH; if (argc < 3) format(); for (; argc > 3; argc--, argv++) { if (strcmp(argv[1], "-a") == 0) preopen = true; else if (strcmp(argv[1], "-c") == 0) o_flags |= O_CLONE_MOUNT; else if (strcmp(argv[1], "-r") == 0) o_flags |= O_NON_RECURSIVE; else format(); } if (preopen) { fd = open(argv[1], o_flags); if (fd < 0) { fprintf(stderr, "open(%s, O_PATH|...): %m\n", argv[1]); exit(1); } ret = move_mount(fd, "", AT_FDCWD, argv[2], MOVE_MOUNT_F_EMPTY_PATH); if (ret != 0) { fprintf(stderr, "move_mount([%s],%s) = %d: %m\n", argv[1], argv[2], ret); exit(1); } } else { ret = move_mount(AT_FDCWD, argv[1], AT_FDCWD, argv[2], MOVE_MOUNT_F_EMPTY_PATH); if (ret != 0) { fprintf(stderr, "move_mount(%s,%s) = %d: %m\n", argv[1], argv[2], ret); exit(1); } } exit(0); }