From patchwork Thu Mar 15 08:13:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10284025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81392602C2 for ; Thu, 15 Mar 2018 08:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7133E26D08 for ; Thu, 15 Mar 2018 08:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64557288EF; Thu, 15 Mar 2018 08:14:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF4EE26D08 for ; Thu, 15 Mar 2018 08:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751408AbeCOIOC (ORCPT ); Thu, 15 Mar 2018 04:14:02 -0400 Received: from mgwym01.jp.fujitsu.com ([211.128.242.40]:37405 "EHLO mgwym01.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750722AbeCOIOB (ORCPT ); Thu, 15 Mar 2018 04:14:01 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym01.jp.fujitsu.com with smtp id 3aee_6288_9ef10f0a_eeea_445f_85b1_4d775bd6bd66; Thu, 15 Mar 2018 17:13:57 +0900 Received: from g01jpfmpwyt01.exch.g01.fujitsu.local (g01jpfmpwyt01.exch.g01.fujitsu.local [10.128.193.38]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id E1894AC0173 for ; Thu, 15 Mar 2018 17:13:56 +0900 (JST) Received: from G01JPEXCHYT17.g01.fujitsu.local (G01JPEXCHYT17.g01.fujitsu.local [10.128.194.56]) by g01jpfmpwyt01.exch.g01.fujitsu.local (Postfix) with ESMTP id 251936D64CD for ; Thu, 15 Mar 2018 17:13:56 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 77eae27e0e1d4e599d7f9dd4e76545ee Subject: [RFC PATCH v2 3/8] btrfs-progs: sub list: Add helper function which checks the permission for tree search ioctl From: "Misono, Tomohiro" To: linux-btrfs References: <226b6805-c5aa-c40d-4ea6-f81dc1b7de20@jp.fujitsu.com> Message-ID: Date: Thu, 15 Mar 2018 17:13:53 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <226b6805-c5aa-c40d-4ea6-f81dc1b7de20@jp.fujitsu.com> Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preparetion work to allow normal user to call "subvolume list/show". Signed-off-by: Tomohiro Misono --- btrfs-list.c | 33 +++++++++++++++++++++++++++++++++ btrfs-list.h | 1 + 2 files changed, 34 insertions(+) diff --git a/btrfs-list.c b/btrfs-list.c index 50e5ce5f..88689a9d 100644 --- a/btrfs-list.c +++ b/btrfs-list.c @@ -958,6 +958,39 @@ out: return 0; } +/* + * Check the permission for tree search ioctl by searching a key + * which alwasys exists + */ +int check_perm_for_tree_search(int fd) +{ + struct btrfs_ioctl_search_args args; + struct btrfs_ioctl_search_key *sk = &args.key; + int ret; + + memset(&args, 0, sizeof(args)); + sk->tree_id = BTRFS_ROOT_TREE_OBJECTID; + sk->min_objectid = BTRFS_EXTENT_TREE_OBJECTID; + sk->max_objectid = BTRFS_EXTENT_TREE_OBJECTID; + sk->min_type = BTRFS_ROOT_ITEM_KEY; + sk->max_type = BTRFS_ROOT_ITEM_KEY; + sk->min_offset = 0; + sk->max_offset = (u64)-1; + sk->min_transid = 0; + sk->max_transid = (u64)-1; + sk->nr_items = 1; + ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args); + + if (!ret) + ret = 1; + else if (ret < 0 && errno == EPERM) + ret = 0; + else + ret = -errno; + + return ret; +} + static int list_subvol_search(int fd, struct root_lookup *root_lookup) { int ret; diff --git a/btrfs-list.h b/btrfs-list.h index 6e5fc778..6225311d 100644 --- a/btrfs-list.h +++ b/btrfs-list.h @@ -176,5 +176,6 @@ char *btrfs_list_path_for_root(int fd, u64 root); int btrfs_list_get_path_rootid(int fd, u64 *treeid); int btrfs_get_subvol(int fd, struct root_info *the_ri); int btrfs_get_toplevel_subvol(int fd, struct root_info *the_ri); +int check_perm_for_tree_search(int fd); #endif