]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/ocfs2/xattr_trusted.c
4c589c447aaf60140bb3dac7401debbae1f86184
[linux-2.6-omap-h63xx.git] / fs / ocfs2 / xattr_trusted.c
1 /* -*- mode: c; c-basic-offset: 8; -*-
2  * vim: noexpandtab sw=8 ts=8 sts=0:
3  *
4  * xattr_trusted.c
5  *
6  * Copyright (C) 2008 Oracle.  All rights reserved.
7  *
8  * CREDITS:
9  * Lots of code in this file is taken from ext3.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this program; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 021110-1307, USA.
25  */
26
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
30
31 #define MLOG_MASK_PREFIX ML_INODE
32 #include <cluster/masklog.h>
33
34 #include "ocfs2.h"
35 #include "alloc.h"
36 #include "dlmglue.h"
37 #include "file.h"
38 #include "ocfs2_fs.h"
39 #include "xattr.h"
40
41 #define XATTR_TRUSTED_PREFIX "trusted."
42
43 static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list,
44                                        size_t list_size, const char *name,
45                                        size_t name_len)
46 {
47         const size_t prefix_len = sizeof(XATTR_TRUSTED_PREFIX) - 1;
48         const size_t total_len = prefix_len + name_len + 1;
49
50         if (list && total_len <= list_size) {
51                 memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
52                 memcpy(list + prefix_len, name, name_len);
53                 list[prefix_len + name_len] = '\0';
54         }
55         return total_len;
56 }
57
58 static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name,
59                                    void *buffer, size_t size)
60 {
61         if (strcmp(name, "") == 0)
62                 return -EINVAL;
63         return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name,
64                                buffer, size);
65 }
66
67 static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name,
68                                    const void *value, size_t size, int flags)
69 {
70         if (strcmp(name, "") == 0)
71                 return -EINVAL;
72
73         return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value,
74                                size, flags);
75 }
76
77 struct xattr_handler ocfs2_xattr_trusted_handler = {
78         .prefix = XATTR_TRUSTED_PREFIX,
79         .list   = ocfs2_xattr_trusted_list,
80         .get    = ocfs2_xattr_trusted_get,
81         .set    = ocfs2_xattr_trusted_set,
82 };