configfs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * configfs.h - definitions for the device driver filesystem
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public
  17. * License along with this program; if not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 021110-1307, USA.
  20. *
  21. * Based on sysfs:
  22. * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
  23. *
  24. * Based on kobject.h:
  25. * Copyright (c) 2002-2003 Patrick Mochel
  26. * Copyright (c) 2002-2003 Open Source Development Labs
  27. *
  28. * configfs Copyright (C) 2005 Oracle. All rights reserved.
  29. *
  30. * Please read Documentation/filesystems/configfs.txt before using the
  31. * configfs interface, ESPECIALLY the parts about reference counts and
  32. * item destructors.
  33. */
  34. #ifndef _CONFIGFS_H_
  35. #define _CONFIGFS_H_
  36. #ifdef __KERNEL__
  37. #include <linux/types.h>
  38. #include <linux/list.h>
  39. #include <linux/kref.h>
  40. #include <asm/atomic.h>
  41. #include <asm/semaphore.h>
  42. #define CONFIGFS_ITEM_NAME_LEN 20
  43. struct module;
  44. struct configfs_item_operations;
  45. struct configfs_group_operations;
  46. struct configfs_attribute;
  47. struct configfs_subsystem;
  48. struct config_item {
  49. char *ci_name;
  50. char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
  51. struct kref ci_kref;
  52. struct list_head ci_entry;
  53. struct config_item *ci_parent;
  54. struct config_group *ci_group;
  55. struct config_item_type *ci_type;
  56. struct dentry *ci_dentry;
  57. };
  58. extern int config_item_set_name(struct config_item *, const char *, ...);
  59. static inline char *config_item_name(struct config_item * item)
  60. {
  61. return item->ci_name;
  62. }
  63. extern void config_item_init(struct config_item *);
  64. extern void config_item_init_type_name(struct config_item *item,
  65. const char *name,
  66. struct config_item_type *type);
  67. extern void config_item_cleanup(struct config_item *);
  68. extern struct config_item * config_item_get(struct config_item *);
  69. extern void config_item_put(struct config_item *);
  70. struct config_item_type {
  71. struct module *ct_owner;
  72. struct configfs_item_operations *ct_item_ops;
  73. struct configfs_group_operations *ct_group_ops;
  74. struct configfs_attribute **ct_attrs;
  75. };
  76. /**
  77. * group - a group of config_items of a specific type, belonging
  78. * to a specific subsystem.
  79. */
  80. struct config_group {
  81. struct config_item cg_item;
  82. struct list_head cg_children;
  83. struct configfs_subsystem *cg_subsys;
  84. struct config_group **default_groups;
  85. };
  86. extern void config_group_init(struct config_group *group);
  87. extern void config_group_init_type_name(struct config_group *group,
  88. const char *name,
  89. struct config_item_type *type);
  90. static inline struct config_group *to_config_group(struct config_item *item)
  91. {
  92. return item ? container_of(item,struct config_group,cg_item) : NULL;
  93. }
  94. static inline struct config_group *config_group_get(struct config_group *group)
  95. {
  96. return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
  97. }
  98. static inline void config_group_put(struct config_group *group)
  99. {
  100. config_item_put(&group->cg_item);
  101. }
  102. extern struct config_item *config_group_find_obj(struct config_group *, const char *);
  103. struct configfs_attribute {
  104. const char *ca_name;
  105. struct module *ca_owner;
  106. mode_t ca_mode;
  107. };
  108. /*
  109. * If allow_link() exists, the item can symlink(2) out to other
  110. * items. If the item is a group, it may support mkdir(2).
  111. * Groups supply one of make_group() and make_item(). If the
  112. * group supports make_group(), one can create group children. If it
  113. * supports make_item(), one can create config_item children. If it has
  114. * default_groups on group->default_groups, it has automatically created
  115. * group children. default_groups may coexist alongsize make_group() or
  116. * make_item(), but if the group wishes to have only default_groups
  117. * children (disallowing mkdir(2)), it need not provide either function.
  118. * If the group has commit(), it supports pending and commited (active)
  119. * items.
  120. */
  121. struct configfs_item_operations {
  122. void (*release)(struct config_item *);
  123. ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
  124. ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
  125. int (*allow_link)(struct config_item *src, struct config_item *target);
  126. int (*drop_link)(struct config_item *src, struct config_item *target);
  127. };
  128. struct configfs_group_operations {
  129. struct config_item *(*make_item)(struct config_group *group, const char *name);
  130. struct config_group *(*make_group)(struct config_group *group, const char *name);
  131. int (*commit_item)(struct config_item *item);
  132. void (*drop_item)(struct config_group *group, struct config_item *item);
  133. };
  134. struct configfs_subsystem {
  135. struct config_group su_group;
  136. struct semaphore su_sem;
  137. };
  138. static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
  139. {
  140. return group ?
  141. container_of(group, struct configfs_subsystem, su_group) :
  142. NULL;
  143. }
  144. int configfs_register_subsystem(struct configfs_subsystem *subsys);
  145. void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
  146. #endif /* __KERNEL__ */
  147. #endif /* _CONFIGFS_H_ */