aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fs.h
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2005-05-18 08:40:59 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-20 18:15:30 -0400
commitacaefc25d21f850e47ecc5098d1e0bc442c526be (patch)
treefbc7aa605c71667507b54d3b3320f9a999458dd4 /include/linux/fs.h
parent4109aca06cb7b042ea791d0f9d3c9615bc3bf5cd (diff)
[PATCH] libfs: add simple attribute files
Based on the discussion about spufs attributes, this is my suggestion for a more generic attribute file support that can be used by both debugfs and spufs. Simple attribute files behave similarly to sequential files from a kernel programmers perspective in that a standard set of file operations is provided and only an open operation needs to be written that registers file specific get() and set() functions. These operations are defined as void foo_set(void *data, u64 val); and u64 foo_get(void *data); where data is the inode->u.generic_ip pointer of the file and the operations just need to make send of that pointer. The infrastructure makes sure this works correctly with concurrent access and partial read calls. A macro named DEFINE_SIMPLE_ATTRIBUTE is provided to further simplify using the attributes. This patch already contains the changes for debugfs to use attributes for its internal file operations. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 0180102dace1..9b8b696d4f15 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1657,6 +1657,52 @@ static inline void simple_transaction_set(struct file *file, size_t n)
1657 ar->size = n; 1657 ar->size = n;
1658} 1658}
1659 1659
1660/*
1661 * simple attribute files
1662 *
1663 * These attributes behave similar to those in sysfs:
1664 *
1665 * Writing to an attribute immediately sets a value, an open file can be
1666 * written to multiple times.
1667 *
1668 * Reading from an attribute creates a buffer from the value that might get
1669 * read with multiple read calls. When the attribute has been read
1670 * completely, no further read calls are possible until the file is opened
1671 * again.
1672 *
1673 * All attributes contain a text representation of a numeric value
1674 * that are accessed with the get() and set() functions.
1675 */
1676#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
1677static int __fops ## _open(struct inode *inode, struct file *file) \
1678{ \
1679 __simple_attr_check_format(__fmt, 0ull); \
1680 return simple_attr_open(inode, file, __get, __set, __fmt); \
1681} \
1682static struct file_operations __fops = { \
1683 .owner = THIS_MODULE, \
1684 .open = __fops ## _open, \
1685 .release = simple_attr_close, \
1686 .read = simple_attr_read, \
1687 .write = simple_attr_write, \
1688};
1689
1690static inline void __attribute__((format(printf, 1, 2)))
1691__simple_attr_check_format(const char *fmt, ...)
1692{
1693 /* don't do anything, just let the compiler check the arguments; */
1694}
1695
1696int simple_attr_open(struct inode *inode, struct file *file,
1697 u64 (*get)(void *), void (*set)(void *, u64),
1698 const char *fmt);
1699int simple_attr_close(struct inode *inode, struct file *file);
1700ssize_t simple_attr_read(struct file *file, char __user *buf,
1701 size_t len, loff_t *ppos);
1702ssize_t simple_attr_write(struct file *file, const char __user *buf,
1703 size_t len, loff_t *ppos);
1704
1705
1660#ifdef CONFIG_SECURITY 1706#ifdef CONFIG_SECURITY
1661static inline char *alloc_secdata(void) 1707static inline char *alloc_secdata(void)
1662{ 1708{