diff options
Diffstat (limited to 'include/linux/fs.h')
| -rw-r--r-- | include/linux/fs.h | 46 |
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) \ | ||
| 1677 | static 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 | } \ | ||
| 1682 | static 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 | |||
| 1690 | static 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 | |||
| 1696 | int simple_attr_open(struct inode *inode, struct file *file, | ||
| 1697 | u64 (*get)(void *), void (*set)(void *, u64), | ||
| 1698 | const char *fmt); | ||
| 1699 | int simple_attr_close(struct inode *inode, struct file *file); | ||
| 1700 | ssize_t simple_attr_read(struct file *file, char __user *buf, | ||
| 1701 | size_t len, loff_t *ppos); | ||
| 1702 | ssize_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 |
| 1661 | static inline char *alloc_secdata(void) | 1707 | static inline char *alloc_secdata(void) |
| 1662 | { | 1708 | { |
