From patchwork Wed Jun 11 14:05:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Disseldorp X-Patchwork-Id: 4336451 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B3029F357 for ; Wed, 11 Jun 2014 14:06:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 884AB20218 for ; Wed, 11 Jun 2014 14:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B106B201E4 for ; Wed, 11 Jun 2014 14:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932386AbaFKOGH (ORCPT ); Wed, 11 Jun 2014 10:06:07 -0400 Received: from cantor2.suse.de ([195.135.220.15]:56336 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755587AbaFKOGF (ORCPT ); Wed, 11 Jun 2014 10:06:05 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 76C51AC0B; Wed, 11 Jun 2014 14:06:04 +0000 (UTC) From: David Disseldorp To: fstests@vger.kernel.org Cc: linux-cifs@vger.kernel.org, linux-btrfs@vger.kernel.org, David Disseldorp Subject: [PATCH 1/2] src/cloner: check filesystem type Date: Wed, 11 Jun 2014 16:05:43 +0200 Message-Id: <1402495544-12865-2-git-send-email-ddiss@suse.de> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1402495544-12865-1-git-send-email-ddiss@suse.de> References: <1402495544-12865-1-git-send-email-ddiss@suse.de> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Limit clone requests to Btrfs only for the moment. Signed-off-by: David Disseldorp --- src/cloner.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/cloner.c b/src/cloner.c index ccc2354..6fb40fa 100644 --- a/src/cloner.c +++ b/src/cloner.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #ifdef HAVE_BTRFS_IOCTL_H #include #else @@ -47,6 +49,10 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_clone_range_args) #endif +#ifndef BTRFS_SUPER_MAGIC +#define BTRFS_SUPER_MAGIC 0x9123683E +#endif + static void usage(char *name, const char *msg) { @@ -89,6 +95,41 @@ clone_file_range(int src_fd, int dst_fd, uint64_t src_off, uint64_t dst_off, return ret; } +static int +cloner_check_fs_support(int src_fd, int dest_fd, unsigned int *fs_type) +{ + int ret; + struct statfs sfs; + + ret = fstatfs(src_fd, &sfs); + if (ret != 0) { + printf("failed to stat source FS\n"); + return errno; + } + + if (sfs.f_type != BTRFS_SUPER_MAGIC) { + printf("unsupported source FS 0x%x\n", + (unsigned int)sfs.f_type); + return ENOTSUP; + } + + *fs_type = (unsigned int)sfs.f_type; + + ret = fstatfs(dest_fd, &sfs); + if (ret != 0) { + printf("failed to stat destination FS\n"); + return errno; + } + + if (sfs.f_type != *fs_type) { + printf("dest FS type 0x%x does not match source 0x%x\n", + (unsigned int)sfs.f_type, *fs_type); + return ENOTSUP; + } + + return 0; +} + int main(int argc, char **argv) { @@ -102,6 +143,7 @@ main(int argc, char **argv) int dst_fd; int ret; int opt; + unsigned int fs_type = 0; while ((opt = getopt(argc, argv, "s:d:l:")) != -1) { char *sval_end; @@ -162,6 +204,11 @@ main(int argc, char **argv) goto err_src_close; } + ret = cloner_check_fs_support(src_fd, dst_fd, &fs_type); + if (ret != 0) { + goto err_dst_close; + } + if (full_file) { ret = clone_file(src_fd, dst_fd); } else {