ext2文件系統源代碼之xattr_trusted.c

我們來看下xattr_trusted.c這個文件的代碼
/*
 * linux/fs/ext2/xattr_trusted.c
 * 信任的擴展屬性處理代碼
 *
 * Copyright (C) 2003 by Andreas Gruenbacher, <[email protected]>
 */


#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,
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章