From patchwork Mon Jan 4 18:59:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 70700 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 o04IxSZk003082 for ; Mon, 4 Jan 2010 18:59:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753782Ab0ADS7Z (ORCPT ); Mon, 4 Jan 2010 13:59:25 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753441Ab0ADS7Y (ORCPT ); Mon, 4 Jan 2010 13:59:24 -0500 Received: from mail-bw0-f227.google.com ([209.85.218.227]:43163 "EHLO mail-bw0-f227.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150Ab0ADS7X (ORCPT ); Mon, 4 Jan 2010 13:59:23 -0500 Received: by bwz27 with SMTP id 27so9476595bwz.21 for ; Mon, 04 Jan 2010 10:59:21 -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:cc:mime-version:content-type:content-transfer-encoding :message-id; bh=oSpS3tMACfNPT+LVm7wAvGwKPctq32K/HTVy+nEE38w=; b=PE+8wVOTEnJgSmndJxSsmosQs2bXXuC6YU4HJK+FfQaQoYSD0SJSSw7S90FXj8Mqqm WUGbu6P2emlCQ+bqpkj/5/aFNgZqF7FjNBl73I0b3b5U6Dsn8prE0JNuTweh+3PfZPDT HUd4mePXXYGcAWdmFDlrNI+agsBMhWVJA+FcQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:mime-version:content-type :content-transfer-encoding:message-id; b=OfvRMcF2xsVfH2bZgKDdIJ/cLQqM+XUDwbhIgwwCd6ptu1//OVcoZtfZ6Bv4XeYa3R Q4FHf6u2yIfg2/Y5X26Y9bY2pq1ZsJuGQgHKpoVeKAuGiG+GEbYHfZo86Ua2DW/yugfY NLd/fYUojtUNHaxCIN3gxyGbMK7kkUrZ4uSLQ= Received: by 10.102.216.24 with SMTP id o24mr935932mug.13.1262631561187; Mon, 04 Jan 2010 10:59:21 -0800 (PST) Received: from venice.localnet (host174-234-dynamic.6-87-r.retail.telecomitalia.it [87.6.234.174]) by mx.google.com with ESMTPS id 25sm12851301mul.50.2010.01.04.10.59.18 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 04 Jan 2010 10:59:19 -0800 (PST) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] [Repost] btrfslabel - kernel space Date: Mon, 4 Jan 2010 19:59:09 +0100 User-Agent: KMail/1.13.0 (Linux/2.6.31-17-generic; KDE/4.3.85; x86_64; ; ) Cc: Morey Roof MIME-Version: 1.0 Message-Id: <201001041959.16910.kreijack@inwind.it> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 645a179..18f3ada 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1301,6 +1301,53 @@ long btrfs_ioctl_trans_end(struct file *file) return 0; } +long btrfs_ioctl_set_label(struct btrfs_root *root, void __user *arg) +{ + struct btrfs_trans_handle *trans; + struct btrfs_ioctl_label_args *label_args; + int ret = 0; + + label_args = kmalloc(sizeof(*label_args), GFP_NOFS); + + if (!label_args) + return -ENOMEM; + + if (copy_from_user(label_args, arg, sizeof(*label_args))) + { + ret = -EFAULT; + } else + { + /* Everything looks good, so lets do a label change */ + label_args->name[BTRFS_LABEL_SIZE] = 0x00; + trans = btrfs_start_transaction(root, 1); + strncpy(root->fs_info->super_copy.label, label_args->name, BTRFS_LABEL_SIZE); + btrfs_commit_transaction(trans, root); + } + + kfree(label_args); + return ret; +} + +long btrfs_ioctl_get_label(struct btrfs_root *root, void __user *arg) +{ + struct btrfs_ioctl_label_args *label_args; + int ret = 0; + + label_args = kmalloc(sizeof(*label_args), GFP_NOFS); + + if (!label_args) + return -ENOMEM; + + strncpy(label_args->name, root->fs_info->super_copy.label, BTRFS_LABEL_SIZE); + if (copy_to_user(arg, label_args, sizeof(*label_args))) + { + ret = -EFAULT; + } + + kfree(label_args); + return ret; +} + long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -1338,6 +1385,10 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_trans_start(file); case BTRFS_IOC_TRANS_END: return btrfs_ioctl_trans_end(file); + case BTRFS_IOC_SET_LABEL: + return btrfs_ioctl_set_label(root, (void __user *)arg); + case BTRFS_IOC_GET_LABEL: + return btrfs_ioctl_get_label(root, (void __user *)arg); case BTRFS_IOC_SYNC: btrfs_sync_fs(file->f_dentry->d_sb, 1); return 0; diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index bc49914..995756d 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -19,6 +19,7 @@ #ifndef __IOCTL_ #define __IOCTL_ #include +#include "ctree.h" #define BTRFS_IOCTL_MAGIC 0x94 #define BTRFS_VOL_NAME_MAX 255 @@ -30,6 +31,10 @@ struct btrfs_ioctl_vol_args { char name[BTRFS_PATH_NAME_MAX + 1]; }; +struct btrfs_ioctl_label_args { + char name[BTRFS_LABEL_SIZE + 1]; +}; + struct btrfs_ioctl_clone_range_args { __s64 src_fd; __u64 src_offset, src_length; @@ -67,4 +72,11 @@ struct btrfs_ioctl_clone_range_args { struct btrfs_ioctl_vol_args) #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ struct btrfs_ioctl_vol_args) + +/* Used to set and get the current volume label */ +#define BTRFS_IOC_SET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 16, \ + struct btrfs_ioctl_label_args) +#define BTRFS_IOC_GET_LABEL _IOW(BTRFS_IOCTL_MAGIC, 17, \ + struct btrfs_ioctl_label_args) + #endif