您的位置:首页 > 编程语言

ext2文件系统源代码之xattr_trusted.c

2016-03-25 21:03 288 查看
我们来看下xattr_trusted.c这个文件的代码
/*
* linux/fs/ext2/xattr_trusted.c
* 信任的扩展属性处理代码
*
* Copyright (C) 2003 by Andreas Gruenbacher, <a.gruenbacher@computer.org>
*/

#include <linux/module.h>
#include <linux/string.h>
#include <linux/capability.h>
#include <linux/fs.h>
#include <linux/ext2_fs.h>
#include "xattr.h"
/*属性名前缀*/
#define XATTR_TRUSTED_PREFIX "trusted."
/*得到带前缀的属性名称,返回名称长度,list存放全名*/
static size_t
ext2_xattr_trusted_list(struct inode *inode, char *list, size_t list_size,
const char *name, size_t name_len)
{
/*前缀名长度和总长度*/
const int prefix_len = sizeof(XATTR_TRUSTED_PREFIX)-1;
const size_t total_len = prefix_len + name_len + 1;
/*权限*/
if (!capable(CAP_SYS_ADMIN))
return 0;

if (list && total_len <= list_size) {
/*先复制前缀名,再复制后边名字*/
memcpy(list, XATTR_TRUSTED_PREFIX, prefix_len);
memcpy(list+prefix_len, name, name_len);
list[prefix_len + name_len] = '\0';
}
return total_len;
}
/*得到想要的属性*/
static int
ext2_xattr_trusted_get(struct inode *inode, const char *name,
void *buffer, size_t size)
{
/*参数检查*/
if (strcmp(name, "") == 0)
return -EINVAL;
/*调用之前讲过的函数来得到属性*/
return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name,
buffer, size);
}

static int
ext2_xattr_trusted_set(struct inode *inode, const char *name,
const void *value, size_t size, int flags)
{
/*参数检查*/
if (strcmp(name, "") == 0)
return -EINVAL;
/*调用之前讲过的函数来设置属性*/
return ext2_xattr_set(inode, EXT2_XATTR_INDEX_TRUSTED, name,
value, size, flags);
}
/*trusted属性处理函数结构体*/
struct xattr_handler ext2_xattr_trusted_handler = {
.prefix	= XATTR_TRUSTED_PREFIX,
.list	= ext2_xattr_trusted_list,
.get	= ext2_xattr_trusted_get,
.set	= ext2_xattr_trusted_set,
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息