Driver core: convert sound core to use struct device
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / jffs2 / security.c
blob52a9894a6364590e004b8839c6a89c9126de6b0e
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2006 NEC Corporation
6 * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
8 * For licensing information, see the file 'LICENCE' in this directory.
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/fs.h>
14 #include <linux/time.h>
15 #include <linux/pagemap.h>
16 #include <linux/highmem.h>
17 #include <linux/crc32.h>
18 #include <linux/jffs2.h>
19 #include <linux/xattr.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/security.h>
22 #include "nodelist.h"
24 /* ---- Initial Security Label Attachment -------------- */
25 int jffs2_init_security(struct inode *inode, struct inode *dir)
27 int rc;
28 size_t len;
29 void *value;
30 char *name;
32 rc = security_inode_init_security(inode, dir, &name, &value, &len);
33 if (rc) {
34 if (rc == -EOPNOTSUPP)
35 return 0;
36 return rc;
38 rc = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, value, len, 0);
40 kfree(name);
41 kfree(value);
42 return rc;
45 /* ---- XATTR Handler for "security.*" ----------------- */
46 static int jffs2_security_getxattr(struct inode *inode, const char *name,
47 void *buffer, size_t size)
49 if (!strcmp(name, ""))
50 return -EINVAL;
52 return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size);
55 static int jffs2_security_setxattr(struct inode *inode, const char *name, const void *buffer,
56 size_t size, int flags)
58 if (!strcmp(name, ""))
59 return -EINVAL;
61 return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size, flags);
64 static size_t jffs2_security_listxattr(struct inode *inode, char *list, size_t list_size,
65 const char *name, size_t name_len)
67 size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1;
69 if (list && retlen <= list_size) {
70 strcpy(list, XATTR_SECURITY_PREFIX);
71 strcpy(list + XATTR_SECURITY_PREFIX_LEN, name);
74 return retlen;
77 struct xattr_handler jffs2_security_xattr_handler = {
78 .prefix = XATTR_SECURITY_PREFIX,
79 .list = jffs2_security_listxattr,
80 .set = jffs2_security_setxattr,
81 .get = jffs2_security_getxattr