From patchwork Mon Jan 3 19:05:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 449001 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p03J5bh7012684 for ; Mon, 3 Jan 2011 19:05:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754262Ab1ACTFf (ORCPT ); Mon, 3 Jan 2011 14:05:35 -0500 Received: from smtp206.alice.it ([82.57.200.102]:45666 "EHLO smtp206.alice.it" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753782Ab1ACTFe (ORCPT ); Mon, 3 Jan 2011 14:05:34 -0500 Received: from [192.168.7.27] (87.7.209.232) by smtp206.alice.it (8.5.124.08) (authenticated as kreijack@alice.it) id 4C1A268C0E2D87FD; Mon, 3 Jan 2011 20:05:30 +0100 Message-ID: <4D221DFD.60707@libero.it> Date: Mon, 03 Jan 2011 20:05:33 +0100 From: Goffredo Baroncelli Reply-To: kreijack@inwind.it User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20101226 Iceowl/1.0b1 Icedove/3.0.11 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org CC: J G Subject: [PATCH] add a --force option to mkfs.btrf [was Re: Odd mkbtrfs behavior inside of chroot] References: <915110.93115.qm@web112501.mail.gq1.yahoo.com> <4D2106D0.80609@libero.it> In-Reply-To: <4D2106D0.80609@libero.it> X-Enigmail-Version: 1.0.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 03 Jan 2011 19:05:38 +0000 (UTC) diff --git a/man/mkfs.btrfs.8.in b/man/mkfs.btrfs.8.in index 1e14c6c..f51291c 100644 --- a/man/mkfs.btrfs.8.in +++ b/man/mkfs.btrfs.8.in @@ -5,14 +5,14 @@ mkfs.btrfs \- create an btrfs filesystem .B mkfs.btrfs [ \fB\-A\fP\fI alloc-start\fP ] [ \fB\-b\fP\fI byte-count\fP ] -[ \fB \-d\fP\fI data-profile\fP ] -[ \fB \-l\fP\fI leafsize\fP ] -[ \fB \-L\fP\fI label\fP ] -[ \fB \-m\fP\fI metadata profile\fP ] -[ \fB \-n\fP\fI nodesize\fP ] -[ \fB \-s\fP\fI sectorsize\fP ] -[ \fB \-h\fP ] -[ \fB \-V\fP ] \fI device\fP [ \fI device ...\fP ] +[ \fB\-d\fP\fI data-profile\fP ] +[ \fB\-f\fP ] +[ \fB\-l\fP\fI leafsize\fP ] +[ \fB\-L\fP\fI label\fP ] +[ \fB\-m\fP\fI metadata profile\fP ] +[ \fB\-n\fP\fI nodesize\fP ] +[ \fB\-s\fP\fI sectorsize\fP ] +[ \fB\-V\fP ] \fIdevice\fP [ \fIdevice ...\fP ] .SH DESCRIPTION .B mkfs.btrfs is used to create an btrfs filesystem (usually in a disk partition, or an array @@ -34,6 +34,9 @@ mkfs.btrfs uses all the available storage for the filesystem. Specify how the data must be spanned across the devices specified. Valid values are raid0, raid1, raid10 or single. .TP +\fB\-f\fR, \fB\-\-force \fR +Don't check if the device is already mounted. +.TP \fB\-l\fR, \fB\-\-leafsize \fIsize\fR Specify the leaf size, the least data item in which btrfs stores data. The default value is the page size. diff --git a/mkfs.c b/mkfs.c index 2e99b95..21bcc7a 100644 --- a/mkfs.c +++ b/mkfs.c @@ -271,6 +271,7 @@ static void print_usage(void) fprintf(stderr, "\t -A --alloc-start the offset to start the FS\n"); fprintf(stderr, "\t -b --byte-count total number of bytes in the FS\n"); fprintf(stderr, "\t -d --data data profile, raid0, raid1, raid10 or single\n"); + fprintf(stderr, "\t -f --force don't check if a device is already mounted\n"); fprintf(stderr, "\t -l --leafsize size of btree leaves\n"); fprintf(stderr, "\t -L --label set a label\n"); fprintf(stderr, "\t -m --metadata metadata profile, values like data profile\n"); @@ -332,6 +333,7 @@ static struct option long_options[] = { { "sectorsize", 1, NULL, 's' }, { "data", 1, NULL, 'd' }, { "version", 0, NULL, 'V' }, + { "force", 0, NULL, 'f' }, { 0, 0, 0, 0} }; @@ -358,10 +360,11 @@ int main(int ac, char **av) int first_fd; int ret; int i; + int force=0; while(1) { int c; - c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:V", long_options, + c = getopt_long(ac, av, "A:b:l:n:s:m:d:L:Vf", long_options, &option_index); if (c < 0) break; @@ -401,6 +404,9 @@ int main(int ac, char **av) case 'V': print_version(); break; + case 'f': + force=1; + break; default: print_usage(); } @@ -423,13 +429,16 @@ int main(int ac, char **av) file = av[optind++]; ret = check_mounted(file); - if (ret < 0) { - fprintf(stderr, "error checking %s mount status\n", file); - exit(1); - } - if (ret == 1) { - fprintf(stderr, "%s is mounted\n", file); - exit(1); + if(!force){ + if (ret < 0) { + fprintf(stderr, "error checking %s mount status\n", + file); + exit(1); + } + if (ret == 1) { + fprintf(stderr, "%s is mounted\n", file); + exit(1); + } } ac--; fd = open(file, O_RDWR); @@ -479,15 +488,17 @@ int main(int ac, char **av) zero_end = 1; while(ac-- > 0) { file = av[optind++]; - ret = check_mounted(file); - if (ret < 0) { - fprintf(stderr, "error checking %s mount status\n", - file); - exit(1); - } - if (ret == 1) { - fprintf(stderr, "%s is mounted\n", file); - exit(1); + if(!force){ + ret = check_mounted(file); + if (ret < 0) { + fprintf(stderr, "error checking %s" + " mount status\n",file); + exit(1); + } + if (ret == 1) { + fprintf(stderr, "%s is mounted\n", file); + exit(1); + } } fd = open(file, O_RDWR); if (fd < 0) {