Blame view

fs/configfs/configfs_internal.h 5.35 KB
7063fbf22   Joel Becker   [PATCH] configfs:...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  /* -*- mode: c; c-basic-offset:8; -*-
   * vim: noexpandtab sw=8 ts=8 sts=0:
   *
   * configfs_internal.h - Internal stuff for configfs
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * General Public License for more details.
   *
   * You should have received a copy of the GNU General Public
   * License along with this program; if not, write to the
   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 021110-1307, USA.
   *
   * Based on sysfs:
   * 	sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
   *
   * configfs Copyright (C) 2005 Oracle.  All rights reserved.
   */
1d88aa441   Fabian Frederick   fs/configfs: use ...
26
27
28
29
30
  #ifdef pr_fmt
  #undef pr_fmt
  #endif
  
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7063fbf22   Joel Becker   [PATCH] configfs:...
31
32
  #include <linux/slab.h>
  #include <linux/list.h>
6f6107640   Louis Rilling   configfs: Introdu...
33
  #include <linux/spinlock.h>
7063fbf22   Joel Becker   [PATCH] configfs:...
34
35
36
  
  struct configfs_dirent {
  	atomic_t		s_count;
631d1feba   Joel Becker   configfs: config ...
37
  	int			s_dependent_count;
7063fbf22   Joel Becker   [PATCH] configfs:...
38
39
40
  	struct list_head	s_sibling;
  	struct list_head	s_children;
  	struct list_head	s_links;
631d1feba   Joel Becker   configfs: config ...
41
  	void			* s_element;
7063fbf22   Joel Becker   [PATCH] configfs:...
42
43
44
  	int			s_type;
  	umode_t			s_mode;
  	struct dentry		* s_dentry;
3d0f89bb1   Joel Becker   configfs: Add per...
45
  	struct iattr		* s_iattr;
e74cc06df   Louis Rilling   configfs: Silence...
46
47
48
  #ifdef CONFIG_LOCKDEP
  	int			s_depth;
  #endif
7063fbf22   Joel Becker   [PATCH] configfs:...
49
50
51
52
  };
  
  #define CONFIGFS_ROOT		0x0001
  #define CONFIGFS_DIR		0x0002
631d1feba   Joel Becker   configfs: config ...
53
  #define CONFIGFS_ITEM_ATTR	0x0004
03607ace8   Pantelis Antoniou   configfs: impleme...
54
  #define CONFIGFS_ITEM_BIN_ATTR	0x0008
631d1feba   Joel Becker   configfs: config ...
55
  #define CONFIGFS_ITEM_LINK	0x0020
7063fbf22   Joel Becker   [PATCH] configfs:...
56
57
58
  #define CONFIGFS_USET_DIR	0x0040
  #define CONFIGFS_USET_DEFAULT	0x0080
  #define CONFIGFS_USET_DROPPING	0x0100
6d8344bae   Louis Rilling   configfs: Fix fai...
59
  #define CONFIGFS_USET_IN_MKDIR	0x0200
2a109f2a4   Louis Rilling   [PATCH] configfs:...
60
  #define CONFIGFS_USET_CREATING	0x0400
03607ace8   Pantelis Antoniou   configfs: impleme...
61
  #define CONFIGFS_NOT_PINNED	(CONFIGFS_ITEM_ATTR | CONFIGFS_ITEM_BIN_ATTR)
7063fbf22   Joel Becker   [PATCH] configfs:...
62

9a73d78cd   Louis Rilling   [PATCH] configfs:...
63
  extern struct mutex configfs_symlink_mutex;
6f6107640   Louis Rilling   configfs: Introdu...
64
  extern spinlock_t configfs_dirent_lock;
e18b890bb   Christoph Lameter   [PATCH] slab: rem...
65
  extern struct kmem_cache *configfs_dir_cachep;
7063fbf22   Joel Becker   [PATCH] configfs:...
66
67
  
  extern int configfs_is_root(struct config_item *item);
b7c177fcd   Al Viro   configfs: kill co...
68
  extern struct inode * configfs_new_inode(umode_t mode, struct configfs_dirent *, struct super_block *);
c88b1e70a   Al Viro   configfs: configf...
69
  extern int configfs_create(struct dentry *, umode_t mode, void (*init)(struct inode *));
7063fbf22   Joel Becker   [PATCH] configfs:...
70
71
  
  extern int configfs_create_file(struct config_item *, const struct configfs_attribute *);
03607ace8   Pantelis Antoniou   configfs: impleme...
72
73
  extern int configfs_create_bin_file(struct config_item *,
  				    const struct configfs_bin_attribute *);
7063fbf22   Joel Becker   [PATCH] configfs:...
74
75
  extern int configfs_make_dirent(struct configfs_dirent *,
  				struct dentry *, void *, umode_t, int);
2a109f2a4   Louis Rilling   [PATCH] configfs:...
76
  extern int configfs_dirent_is_ready(struct configfs_dirent *);
7063fbf22   Joel Becker   [PATCH] configfs:...
77

7063fbf22   Joel Becker   [PATCH] configfs:...
78
79
80
81
  extern void configfs_hash_and_remove(struct dentry * dir, const char * name);
  
  extern const unsigned char * configfs_get_name(struct configfs_dirent *sd);
  extern void configfs_drop_dentry(struct configfs_dirent *sd, struct dentry *parent);
3d0f89bb1   Joel Becker   configfs: Add per...
82
  extern int configfs_setattr(struct dentry *dentry, struct iattr *iattr);
7063fbf22   Joel Becker   [PATCH] configfs:...
83

2a152ad3a   Al Viro   make configfs_pin...
84
  extern struct dentry *configfs_pin_fs(void);
7063fbf22   Joel Becker   [PATCH] configfs:...
85
86
87
  extern void configfs_release_fs(void);
  
  extern struct rw_semaphore configfs_rename_sem;
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
88
89
  extern const struct file_operations configfs_dir_operations;
  extern const struct file_operations configfs_file_operations;
03607ace8   Pantelis Antoniou   configfs: impleme...
90
  extern const struct file_operations configfs_bin_file_operations;
754661f14   Arjan van de Ven   [PATCH] mark stru...
91
  extern const struct inode_operations configfs_dir_inode_operations;
81d44ed15   Al Viro   configfs: don't b...
92
  extern const struct inode_operations configfs_root_inode_operations;
754661f14   Arjan van de Ven   [PATCH] mark stru...
93
  extern const struct inode_operations configfs_symlink_inode_operations;
d463a0c4b   Al Viro   switch configfs
94
  extern const struct dentry_operations configfs_dentry_ops;
7063fbf22   Joel Becker   [PATCH] configfs:...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  
  extern int configfs_symlink(struct inode *dir, struct dentry *dentry,
  			    const char *symname);
  extern int configfs_unlink(struct inode *dir, struct dentry *dentry);
  
  struct configfs_symlink {
  	struct list_head sl_list;
  	struct config_item *sl_target;
  };
  
  extern int configfs_create_link(struct configfs_symlink *sl,
  				struct dentry *parent,
  				struct dentry *dentry);
  
  static inline struct config_item * to_item(struct dentry * dentry)
  {
  	struct configfs_dirent * sd = dentry->d_fsdata;
  	return ((struct config_item *) sd->s_element);
  }
  
  static inline struct configfs_attribute * to_attr(struct dentry * dentry)
  {
  	struct configfs_dirent * sd = dentry->d_fsdata;
  	return ((struct configfs_attribute *) sd->s_element);
  }
03607ace8   Pantelis Antoniou   configfs: impleme...
120
121
122
123
124
125
  static inline struct configfs_bin_attribute *to_bin_attr(struct dentry *dentry)
  {
  	struct configfs_attribute *attr = to_attr(dentry);
  
  	return container_of(attr, struct configfs_bin_attribute, cb_attr);
  }
7063fbf22   Joel Becker   [PATCH] configfs:...
126
127
128
  static inline struct config_item *configfs_get_config_item(struct dentry *dentry)
  {
  	struct config_item * item = NULL;
da5029563   Nick Piggin   fs: dcache scale ...
129
  	spin_lock(&dentry->d_lock);
7063fbf22   Joel Becker   [PATCH] configfs:...
130
131
132
133
134
135
136
137
  	if (!d_unhashed(dentry)) {
  		struct configfs_dirent * sd = dentry->d_fsdata;
  		if (sd->s_type & CONFIGFS_ITEM_LINK) {
  			struct configfs_symlink * sl = sd->s_element;
  			item = config_item_get(sl->sl_target);
  		} else
  			item = config_item_get(sd->s_element);
  	}
da5029563   Nick Piggin   fs: dcache scale ...
138
  	spin_unlock(&dentry->d_lock);
7063fbf22   Joel Becker   [PATCH] configfs:...
139
140
141
142
143
144
  
  	return item;
  }
  
  static inline void release_configfs_dirent(struct configfs_dirent * sd)
  {
3d0f89bb1   Joel Becker   configfs: Add per...
145
146
147
148
  	if (!(sd->s_type & CONFIGFS_ROOT)) {
  		kfree(sd->s_iattr);
  		kmem_cache_free(configfs_dir_cachep, sd);
  	}
7063fbf22   Joel Becker   [PATCH] configfs:...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  }
  
  static inline struct configfs_dirent * configfs_get(struct configfs_dirent * sd)
  {
  	if (sd) {
  		WARN_ON(!atomic_read(&sd->s_count));
  		atomic_inc(&sd->s_count);
  	}
  	return sd;
  }
  
  static inline void configfs_put(struct configfs_dirent * sd)
  {
  	WARN_ON(!atomic_read(&sd->s_count));
  	if (atomic_dec_and_test(&sd->s_count))
  		release_configfs_dirent(sd);
  }