From patchwork Fri Dec 11 21:12:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 66750 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBBLCFsE010775 for ; Fri, 11 Dec 2009 21:12:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759240AbZLKVMH (ORCPT ); Fri, 11 Dec 2009 16:12:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758959AbZLKVMG (ORCPT ); Fri, 11 Dec 2009 16:12:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42719 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758903AbZLKVMF (ORCPT ); Fri, 11 Dec 2009 16:12:05 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBBLC9PP005803 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 11 Dec 2009 16:12:09 -0500 Received: from localhost.localdomain (vpn-9-96.rdu.redhat.com [10.11.9.96]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBBLC7GK002506; Fri, 11 Dec 2009 16:12:08 -0500 Date: Fri, 11 Dec 2009 16:12:07 -0500 From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: chris.mason@oracle.com Subject: [PATCH] Btrfs-progs: add command to set default subvol Message-ID: <20091211211207.GR2191@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 064c0d0..81d2a30 100644 --- a/btrfsctl.c +++ b/btrfsctl.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "kerncompat.h" #include "ctree.h" #include "transaction.h" @@ -58,6 +59,8 @@ static void print_usage(void) printf("\t-c: forces a single FS sync\n"); printf("\t-D: delete snapshot\n"); printf("\t-l file: listing snapshot/subvolume under a subvolume\n"); + printf("\t-m [tree id] directory: set the default mounted subvolume" + " to the [tree id] or the directory\n"); printf("%s\n", BTRFS_BUILD_VERSION); exit(1); } @@ -266,6 +269,7 @@ int main(int ac, char **av) unsigned long command = 0; int len; char *fullpath; + u64 objectid = 0; if (ac == 2 && strcmp(av[1], "-a") == 0) { fprintf(stderr, "Scanning for Btrfs filesystems\n"); @@ -380,6 +384,16 @@ int main(int ac, char **av) exit(1); } command = BTRFS_IOC_SNAP_LISTING; + } else if (strcmp(av[i], "-m") == 0) { + command = BTRFS_IOC_DEFAULT_SUBVOL; + if (i == ac - 3) { + objectid = (unsigned long long) + strtoll(av[i + 1], NULL, 0); + if (errno == ERANGE) { + fprintf(stderr, "invalid tree id\n"); + exit(1); + } + } } } if (command == 0) { @@ -410,6 +424,9 @@ int main(int ac, char **av) ret = ioctl(snap_fd, command, &args); } else if (command == BTRFS_IOC_SNAP_LISTING) { ret = btrfs_list_subvolumes(snap_fd, command); + } else if (command == BTRFS_IOC_DEFAULT_SUBVOL) { + printf("objectid is %llu\n", objectid); + ret = ioctl(fd, command, &objectid); } else ret = ioctl(fd, command, &args); if (ret < 0) { diff --git a/ioctl.h b/ioctl.h index 19020cb..70fc15d 100644 --- a/ioctl.h +++ b/ioctl.h @@ -91,4 +91,6 @@ struct btrfs_ioctl_subvol_leaf { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SNAP_LISTING _IOWR(BTRFS_IOCTL_MAGIC, 16, \ struct btrfs_ioctl_subvol_args) +#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 17, u64) + #endif