162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * JFFS2 -- Journalling Flash File System, Version 2.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright © 2006  NEC Corporation
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Created by KaiGai Kohei <kaigai@ak.jp.nec.com>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * For licensing information, see the file 'LICENCE' in this directory.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/kernel.h>
1362306a36Sopenharmony_ci#include <linux/slab.h>
1462306a36Sopenharmony_ci#include <linux/fs.h>
1562306a36Sopenharmony_ci#include <linux/time.h>
1662306a36Sopenharmony_ci#include <linux/pagemap.h>
1762306a36Sopenharmony_ci#include <linux/highmem.h>
1862306a36Sopenharmony_ci#include <linux/crc32.h>
1962306a36Sopenharmony_ci#include <linux/jffs2.h>
2062306a36Sopenharmony_ci#include <linux/xattr.h>
2162306a36Sopenharmony_ci#include <linux/mtd/mtd.h>
2262306a36Sopenharmony_ci#include <linux/security.h>
2362306a36Sopenharmony_ci#include "nodelist.h"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* ---- Initial Security Label(s) Attachment callback --- */
2662306a36Sopenharmony_cistatic int jffs2_initxattrs(struct inode *inode,
2762306a36Sopenharmony_ci			    const struct xattr *xattr_array, void *fs_info)
2862306a36Sopenharmony_ci{
2962306a36Sopenharmony_ci	const struct xattr *xattr;
3062306a36Sopenharmony_ci	int err = 0;
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci	for (xattr = xattr_array; xattr->name != NULL; xattr++) {
3362306a36Sopenharmony_ci		err = do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
3462306a36Sopenharmony_ci					xattr->name, xattr->value,
3562306a36Sopenharmony_ci					xattr->value_len, 0);
3662306a36Sopenharmony_ci		if (err < 0)
3762306a36Sopenharmony_ci			break;
3862306a36Sopenharmony_ci	}
3962306a36Sopenharmony_ci	return err;
4062306a36Sopenharmony_ci}
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* ---- Initial Security Label(s) Attachment ----------- */
4362306a36Sopenharmony_ciint jffs2_init_security(struct inode *inode, struct inode *dir,
4462306a36Sopenharmony_ci			const struct qstr *qstr)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	return security_inode_init_security(inode, dir, qstr,
4762306a36Sopenharmony_ci					    &jffs2_initxattrs, NULL);
4862306a36Sopenharmony_ci}
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* ---- XATTR Handler for "security.*" ----------------- */
5162306a36Sopenharmony_cistatic int jffs2_security_getxattr(const struct xattr_handler *handler,
5262306a36Sopenharmony_ci				   struct dentry *unused, struct inode *inode,
5362306a36Sopenharmony_ci				   const char *name, void *buffer, size_t size)
5462306a36Sopenharmony_ci{
5562306a36Sopenharmony_ci	return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY,
5662306a36Sopenharmony_ci				 name, buffer, size);
5762306a36Sopenharmony_ci}
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cistatic int jffs2_security_setxattr(const struct xattr_handler *handler,
6062306a36Sopenharmony_ci				   struct mnt_idmap *idmap,
6162306a36Sopenharmony_ci				   struct dentry *unused, struct inode *inode,
6262306a36Sopenharmony_ci				   const char *name, const void *buffer,
6362306a36Sopenharmony_ci				   size_t size, int flags)
6462306a36Sopenharmony_ci{
6562306a36Sopenharmony_ci	return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY,
6662306a36Sopenharmony_ci				 name, buffer, size, flags);
6762306a36Sopenharmony_ci}
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciconst struct xattr_handler jffs2_security_xattr_handler = {
7062306a36Sopenharmony_ci	.prefix = XATTR_SECURITY_PREFIX,
7162306a36Sopenharmony_ci	.set = jffs2_security_setxattr,
7262306a36Sopenharmony_ci	.get = jffs2_security_getxattr
7362306a36Sopenharmony_ci};
74