From patchwork Sun Feb 21 16:40:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 81041 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1LGeQ6R028544 for ; Sun, 21 Feb 2010 16:40:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753007Ab0BUQkZ (ORCPT ); Sun, 21 Feb 2010 11:40:25 -0500 Received: from mail-fx0-f213.google.com ([209.85.220.213]:63100 "EHLO mail-fx0-f213.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752990Ab0BUQkX (ORCPT ); Sun, 21 Feb 2010 11:40:23 -0500 Received: by mail-fx0-f213.google.com with SMTP id 5so1778576fxm.29 for ; Sun, 21 Feb 2010 08:40:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :user-agent:mime-version:content-type:content-transfer-encoding :message-id; bh=iFHS5TlzV8o1r/zfq+tTWqWo4IjZeFNUi2lx3bP1AB0=; b=ED7K0hk5dGv2oteABszXFySHT2wEfn09rllAUjPrUOdhxrxlvHOsGUmpeO2imjYEBV sYTDnDTPYqNGBWHuK3IsaEhEL5S9iiaIBQResZ0agawUCmkPBq1saGOMvXy+NBzl9yaT UqQt6GKI66rKOkWbZnT/FVoLVGXU1iNmgCzBM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:mime-version:content-type :content-transfer-encoding:message-id; b=dut4Paa02iCLH+4QZti47ILOkwWeN96NbprsKZUxzcZEWhLftw4K4CicEwZXta+FUx GuTSO6BCw6jVpChYPBvInR5vxl+XTjye/y8NmlXO3hFiR4DmSgDmCwMDBGIJh6JQ/67Y zTmx6JW2RCfTvvKiiO6XdZwXj0JH6r3kWtV1o= Received: by 10.223.3.135 with SMTP id 7mr9821580fan.21.1266770422938; Sun, 21 Feb 2010 08:40:22 -0800 (PST) Received: from venice.localnet (host94-173-dynamic.11-87-r.retail.telecomitalia.it [87.11.173.94]) by mx.google.com with ESMTPS id 19sm3314425fkr.46.2010.02.21.08.40.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 21 Feb 2010 08:40:22 -0800 (PST) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/3 V3] btrfs, a new tool to manage a btrfs filesystem - commands Date: Sun, 21 Feb 2010 17:40:20 +0100 User-Agent: KMail/1.13.0 (Linux/2.6.32-10-generic; KDE/4.4.0; x86_64; ; ) MIME-Version: 1.0 Message-Id: <201002211740.20954.kreijack@inwind.it> 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 (demeter.kernel.org [140.211.167.41]); Sun, 21 Feb 2010 16:40:26 +0000 (UTC) diff --git a/Makefile b/Makefile index 02f881e..5ebc985 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ bindir = $(prefix)/bin LIBS=-luuid progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck \ - btrfs-map-logical + btrfs-map-logical btrfs # make C=1 to enable sparse ifdef C @@ -36,6 +36,10 @@ all: version $(progs) manpages version: bash version.sh +btrfs: $(objects) btrfs.o btrfs_cmds.o + gcc $(CFLAGS) -o btrfs btrfs.o btrfs_cmds.o \ + $(objects) $(LDFLAGS) $(LIBS) + btrfsctl: $(objects) btrfsctl.o gcc $(CFLAGS) -o btrfsctl btrfsctl.o $(objects) $(LDFLAGS) $(LIBS) diff --git a/btrfs.c b/btrfs.c new file mode 100644 index 0000000..4d263c4 --- /dev/null +++ b/btrfs.c @@ -0,0 +1,333 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + + +#include +#include +#include + +#include "btrfs_cmds.h" +#include "version.h" + +typedef int (*CommandFunction)(int argc, char **argv); + +struct Command { + CommandFunction func; /* function which implements the command */ + int nargs; /* if == 999, any number of arguments + if >= 0, number of arguments, + if < 0, _minimum_ number of arguments */ + char *verb; /* verb */ + char *help; /* help lines; form the 2nd onward they are + indented */ + + /* the following fields are run-time filled by the program */ + char **cmds; /* array of subcommands */ + int ncmds; /* number of subcommand */ +}; + +static struct Command commands[] = { + + /* + avoid short commands different for the case only + */ + { do_clone, 2, + "subvolume snapshot", " [/]\n" + "Create a writable snapshot of the subvolume with\n" + "the name in the directory." + }, + { do_delete_subvolume, 1, + "subvolume delete", "\n" + "Delete the subvolume ." + }, + { do_create_subvol, 1, + "subvolume create", "[/]\n" + "Create a subvolume in (or the current directory if\n" + "not passed)." + }, + { do_defrag, -1, + "filesystem defragment", "| [|...]\n" + "Defragment a file or a directory." + }, + { do_fssync, 1, + "filesystem sync", "\n" + "Force a sync on the filesystem ." + }, + { do_resize, 2, + "filesystem resize", "[+/-][gkm]|max \n" + "Resize the file system. If 'max' is passed, the filesystem\n" + "will occupe all available space on the device." + }, + { do_show_filesystem, 999, + "filesystem show", "[|