From patchwork Mon Dec 21 15:50:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Basavanagowda Kanur X-Patchwork-Id: 69137 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id nBLFosWX013487 for ; Mon, 21 Dec 2009 15:50:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756127AbZLUPux (ORCPT ); Mon, 21 Dec 2009 10:50:53 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756124AbZLUPux (ORCPT ); Mon, 21 Dec 2009 10:50:53 -0500 Received: from mail-yw0-f182.google.com ([209.85.211.182]:45523 "EHLO mail-yw0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbZLUPuw (ORCPT ); Mon, 21 Dec 2009 10:50:52 -0500 Received: by ywh12 with SMTP id 12so5733784ywh.21 for ; Mon, 21 Dec 2009 07:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:date:from:to:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=+fN4k14ka34Fy3bJbg78om9HlKqJlDbj5BinM+F6pWY=; b=s8PZ4S8eN6FI6Pjm3Q5E2HPGyc5XXqkuvBBmaNqS0FFfxNrQbEddSp7ByKtrILR6aX cK9QPiVGIMSwBzRQuwb64/yGPtjU4cWrTowxcPAlTfW4ddUDGuVhKgDR0nf3r/yBYgAg Xapvvd2dQhiDe2OWK//HPJmNq0KiTZdNHDTTs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=aMmynSmKzT2hkw6xnRCdZM9zk5OFEROyVC6MOWKvcRVoKPJws76BQrfr84Vtam7Tdi KjAj8kSn5WqUpVj/UTMm9rq3sNY0j8+E6TSE1UkD5mMmjctR/TSP3pkh3BMqFMdfil31 mhnAk1E8bKxf7abqkWYFAO1EpWAFSGU3sw+Bg= Received: by 10.150.46.7 with SMTP id t7mr11485579ybt.118.1261410651748; Mon, 21 Dec 2009 07:50:51 -0800 (PST) Received: from localhost ([122.167.178.150]) by mx.google.com with ESMTPS id 21sm2036331ywh.1.2009.12.21.07.50.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 21 Dec 2009 07:50:50 -0800 (PST) Date: Mon, 21 Dec 2009 21:20:46 +0530 From: Basavanagowda Kanur To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfsctl: scan device and exit without using ioctl Message-ID: <20091221154140.GA26204@shift> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/btrfsctl.c b/btrfsctl.c index 66c4e89..61020de 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -34,6 +34,8 @@ #include "transaction.h" #include "utils.h" #include "version.h" +#include "disk-io.h" +#include "volumes.h" #ifdef __CHECKER__ #define BLKGETSIZE64 0 @@ -88,6 +90,30 @@ static int open_file_or_dir(const char *fname) } return fd; } + +int btrfs_scan_file (const char *path) +{ + int ret = -1; + struct btrfs_fs_devices *fs_devices = NULL; + u64 dev_count = 0; + int fd = -1; + + fd = open (path, O_RDONLY); + if (fd < 0) { + fprintf (stderr, "failed to open %s: %s\n", + path, strerror (errno)); + } else { + + ret = btrfs_scan_one_device (fd, path, &fs_devices, + &dev_count, + BTRFS_SUPER_INFO_OFFSET); + + close (fd); + } + + return ret; +} + int main(int ac, char **av) { char *fname = NULL; @@ -201,12 +227,16 @@ int main(int ac, char **av) fname = av[ac - 1]; if (command == BTRFS_IOC_SCAN_DEV) { - fd = open("/dev/btrfs-control", O_RDWR); - if (fd < 0) { - perror("failed to open /dev/btrfs-control"); - exit(1); - } - name = fname; + ret = btrfs_scan_file (fname); + if (ret < 0) { + fprintf (stdout, "could not find a btrfs volume on " + "%s\n", fname); + } else { + fprintf (stdout, "found a btrfs volume on %s\n", + fname); + } + + exit (1); } else { fd = open_file_or_dir(fname); }