revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / plugin / plugin.h
blob8dc54337b36feb0ea0a40afee472397742016339
1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
3 /* Basic plugin data-types.
4 see fs/reiser4/plugin/plugin.c for details */
6 #if !defined( __FS_REISER4_PLUGIN_TYPES_H__ )
7 #define __FS_REISER4_PLUGIN_TYPES_H__
9 #include "../forward.h"
10 #include "../debug.h"
11 #include "../dformat.h"
12 #include "../key.h"
13 #include "compress/compress.h"
14 #include "crypto/cipher.h"
15 #include "plugin_header.h"
16 #include "item/static_stat.h"
17 #include "item/internal.h"
18 #include "item/sde.h"
19 #include "item/cde.h"
20 #include "item/item.h"
21 #include "node/node.h"
22 #include "node/node40.h"
23 #include "security/perm.h"
24 #include "fibration.h"
26 #include "space/bitmap.h"
27 #include "space/space_allocator.h"
29 #include "disk_format/disk_format40.h"
30 #include "disk_format/disk_format.h"
32 #include <linux/fs.h> /* for struct super_block, address_space */
33 #include <linux/mm.h> /* for struct page */
34 #include <linux/buffer_head.h> /* for struct buffer_head */
35 #include <linux/dcache.h> /* for struct dentry */
36 #include <linux/types.h>
37 #include <linux/crypto.h>
39 typedef struct reiser4_object_on_wire reiser4_object_on_wire;
42 * File plugin. Defines the set of methods that file plugins implement, some
43 * of which are optional.
45 * A file plugin offers to the caller an interface for IO ( writing to and/or
46 * reading from) to what the caller sees as one sequence of bytes. An IO to it
47 * may affect more than one physical sequence of bytes, or no physical sequence
48 * of bytes, it may affect sequences of bytes offered by other file plugins to
49 * the semantic layer, and the file plugin may invoke other plugins and
50 * delegate work to them, but its interface is structured for offering the
51 * caller the ability to read and/or write what the caller sees as being a
52 * single sequence of bytes.
54 * The file plugin must present a sequence of bytes to the caller, but it does
55 * not necessarily have to store a sequence of bytes, it does not necessarily
56 * have to support efficient tree traversal to any offset in the sequence of
57 * bytes (tail and extent items, whose keys contain offsets, do however provide
58 * efficient non-sequential lookup of any offset in the sequence of bytes).
60 * Directory plugins provide methods for selecting file plugins by resolving a
61 * name for them.
63 * The functionality other filesystems call an attribute, and rigidly tie
64 * together, we decompose into orthogonal selectable features of files. Using
65 * the terminology we will define next, an attribute is a perhaps constrained,
66 * perhaps static length, file whose parent has a uni-count-intra-link to it,
67 * which might be grandparent-major-packed, and whose parent has a deletion
68 * method that deletes it.
70 * File plugins can implement constraints.
72 * Files can be of variable length (e.g. regular unix files), or of static
73 * length (e.g. static sized attributes).
75 * An object may have many sequences of bytes, and many file plugins, but, it
76 * has exactly one objectid. It is usually desirable that an object has a
77 * deletion method which deletes every item with that objectid. Items cannot
78 * in general be found by just their objectids. This means that an object must
79 * have either a method built into its deletion plugin method for knowing what
80 * items need to be deleted, or links stored with the object that provide the
81 * plugin with a method for finding those items. Deleting a file within an
82 * object may or may not have the effect of deleting the entire object,
83 * depending on the file plugin's deletion method.
85 * LINK TAXONOMY:
87 * Many objects have a reference count, and when the reference count reaches 0
88 * the object's deletion method is invoked. Some links embody a reference
89 * count increase ("countlinks"), and others do not ("nocountlinks").
91 * Some links are bi-directional links ("bilinks"), and some are
92 * uni-directional("unilinks").
94 * Some links are between parts of the same object ("intralinks"), and some are
95 * between different objects ("interlinks").
97 * PACKING TAXONOMY:
99 * Some items of an object are stored with a major packing locality based on
100 * their object's objectid (e.g. unix directory items in plan A), and these are
101 * called "self-major-packed".
103 * Some items of an object are stored with a major packing locality based on
104 * their semantic parent object's objectid (e.g. unix file bodies in plan A),
105 * and these are called "parent-major-packed".
107 * Some items of an object are stored with a major packing locality based on
108 * their semantic grandparent, and these are called "grandparent-major-packed".
109 * Now carefully notice that we run into trouble with key length if we have to
110 * store a 8 byte major+minor grandparent based packing locality, an 8 byte
111 * parent objectid, an 8 byte attribute objectid, and an 8 byte offset, all in
112 * a 24 byte key. One of these fields must be sacrificed if an item is to be
113 * grandparent-major-packed, and which to sacrifice is left to the item author
114 * choosing to make the item grandparent-major-packed. You cannot make tail
115 * items and extent items grandparent-major-packed, though you could make them
116 * self-major-packed (usually they are parent-major-packed).
118 * In the case of ACLs (which are composed of fixed length ACEs which consist
119 * of {subject-type, subject, and permission bitmask} triples), it makes sense
120 * to not have an offset field in the ACE item key, and to allow duplicate keys
121 * for ACEs. Thus, the set of ACES for a given file is found by looking for a
122 * key consisting of the objectid of the grandparent (thus grouping all ACLs in
123 * a directory together), the minor packing locality of ACE, the objectid of
124 * the file, and 0.
126 * IO involves moving data from one location to another, which means that two
127 * locations must be specified, source and destination.
129 * This source and destination can be in the filesystem, or they can be a
130 * pointer in the user process address space plus a byte count.
132 * If both source and destination are in the filesystem, then at least one of
133 * them must be representable as a pure stream of bytes (which we call a flow,
134 * and define as a struct containing a key, a data pointer, and a length).
135 * This may mean converting one of them into a flow. We provide a generic
136 * cast_into_flow() method, which will work for any plugin supporting
137 * read_flow(), though it is inefficiently implemented in that it temporarily
138 * stores the flow in a buffer (Question: what to do with huge flows that
139 * cannot fit into memory? Answer: we must not convert them all at once. )
141 * Performing a write requires resolving the write request into a flow defining
142 * the source, and a method that performs the write, and a key that defines
143 * where in the tree the write is to go.
145 * Performing a read requires resolving the read request into a flow defining
146 * the target, and a method that performs the read, and a key that defines
147 * where in the tree the read is to come from.
149 * There will exist file plugins which have no pluginid stored on the disk for
150 * them, and which are only invoked by other plugins.
153 /* This should be incremented with each new contributed
154 pair (plugin type, plugin id).
155 NOTE: Make sure there is a release of reiser4progs
156 with the corresponding version number */
157 #define PLUGIN_LIBRARY_VERSION 0
159 /* enumeration of fields within plugin_set */
160 typedef enum {
161 PSET_FILE,
162 PSET_DIR, /* PSET_FILE and PSET_DIR should be first elements:
163 * inode.c:read_inode() depends on this. */
164 PSET_PERM,
165 PSET_FORMATTING,
166 PSET_HASH,
167 PSET_FIBRATION,
168 PSET_SD,
169 PSET_DIR_ITEM,
170 PSET_CIPHER,
171 PSET_DIGEST,
172 PSET_COMPRESSION,
173 PSET_COMPRESSION_MODE,
174 PSET_CLUSTER,
175 PSET_CREATE,
176 PSET_LAST
177 } pset_member;
179 /* builtin file-plugins */
180 typedef enum {
181 /* regular file */
182 UNIX_FILE_PLUGIN_ID,
183 /* directory */
184 DIRECTORY_FILE_PLUGIN_ID,
185 /* symlink */
186 SYMLINK_FILE_PLUGIN_ID,
187 /* for objects completely handled by the VFS: fifos, devices,
188 sockets */
189 SPECIAL_FILE_PLUGIN_ID,
190 /* regular cryptcompress file */
191 CRYPTCOMPRESS_FILE_PLUGIN_ID,
192 /* number of file plugins. Used as size of arrays to hold
193 file plugins. */
194 LAST_FILE_PLUGIN_ID
195 } reiser4_file_id;
197 typedef struct file_plugin {
199 /* generic fields */
200 plugin_header h;
202 struct inode_operations inode_ops;
203 struct file_operations file_ops;
204 struct address_space_operations as_ops;
206 /* save inode cached stat-data onto disk. It was called
207 reiserfs_update_sd() in 3.x */
208 int (*write_sd_by_inode) (struct inode *);
211 * private methods: These are optional. If used they will allow you to
212 * minimize the amount of code needed to implement a deviation from
213 * some other method that also uses them.
217 * Construct flow into @flow according to user-supplied data.
219 * This is used by read/write methods to construct a flow to
220 * write/read. ->flow_by_inode() is plugin method, rather than single
221 * global implementation, because key in a flow used by plugin may
222 * depend on data in a @buf.
224 * NIKITA-FIXME-HANS: please create statistics on what functions are
225 * dereferenced how often for the mongo benchmark. You can supervise
226 * Elena doing this for you if that helps. Email me the list of the
227 * top 10, with their counts, and an estimate of the total number of
228 * CPU cycles spent dereferencing as a percentage of CPU cycles spent
229 * processing (non-idle processing). If the total percent is, say,
230 * less than 1%, it will make our coding discussions much easier, and
231 * keep me from questioning whether functions like the below are too
232 * frequently called to be dereferenced. If the total percent is more
233 * than 1%, perhaps private methods should be listed in a "required"
234 * comment at the top of each plugin (with stern language about how if
235 * the comment is missing it will not be accepted by the maintainer),
236 * and implemented using macros not dereferenced functions. How about
237 * replacing this whole private methods part of the struct with a
238 * thorough documentation of what the standard helper functions are for
239 * use in constructing plugins? I think users have been asking for
240 * that, though not in so many words.
242 int (*flow_by_inode) (struct inode *, const char __user *buf,
243 int user, loff_t size,
244 loff_t off, rw_op op, flow_t *);
247 * Return the key used to retrieve an offset of a file. It is used by
248 * default implementation of ->flow_by_inode() method
249 * (common_build_flow()) and, among other things, to get to the extent
250 * from jnode of unformatted node.
252 int (*key_by_inode) (struct inode *, loff_t off, reiser4_key *);
254 /* NIKITA-FIXME-HANS: this comment is not as clear to others as you think.... */
256 * set the plugin for a file. Called during file creation in creat()
257 * but not reiser4() unless an inode already exists for the file.
259 int (*set_plug_in_inode) (struct inode *inode, struct inode *parent,
260 reiser4_object_create_data *);
262 /* NIKITA-FIXME-HANS: comment and name seem to say different things,
263 * are you setting up the object itself also or just adjusting the
264 * parent?.... */
265 /* set up plugins for new @object created in @parent. @root is root
266 directory. */
267 int (*adjust_to_parent) (struct inode *object, struct inode *parent,
268 struct inode *root);
270 * this does whatever is necessary to do when object is created. For
271 * instance, for unix files stat data is inserted. It is supposed to be
272 * called by create of struct inode_operations.
274 int (*create_object) (struct inode *object, struct inode *parent,
275 reiser4_object_create_data *);
277 /* this does whatever is necessary to do when object is opened */
278 int (*open_object) (struct inode * inode, struct file * file);
280 * this method should check REISER4_NO_SD and set REISER4_NO_SD on
281 * success. Deletion of an object usually includes removal of items
282 * building file body (for directories this is removal of "." and "..")
283 * and removal of stat-data item.
285 int (*delete_object) (struct inode *);
287 /* add link from @parent to @object */
288 int (*add_link) (struct inode *object, struct inode *parent);
290 /* remove link from @parent to @object */
291 int (*rem_link) (struct inode *object, struct inode *parent);
294 * return true if item addressed by @coord belongs to @inode. This is
295 * used by read/write to properly slice flow into items in presence of
296 * multiple key assignment policies, because items of a file are not
297 * necessarily contiguous in a key space, for example, in a plan-b.
299 int (*owns_item) (const struct inode *, const coord_t *);
301 /* checks whether yet another hard links to this object can be
302 added */
303 int (*can_add_link) (const struct inode *);
305 /* checks whether hard links to this object can be removed */
306 int (*can_rem_link) (const struct inode *);
308 /* not empty for DIRECTORY_FILE_PLUGIN_ID only currently. It calls
309 detach of directory plugin to remove ".." */
310 int (*detach) (struct inode * child, struct inode * parent);
312 /* called when @child was just looked up in the @parent. It is not
313 empty for DIRECTORY_FILE_PLUGIN_ID only where it calls attach of
314 directory plugin */
315 int (*bind) (struct inode * child, struct inode * parent);
317 /* process safe-link during mount */
318 int (*safelink) (struct inode * object, reiser4_safe_link_t link,
319 __u64 value);
321 /* The couple of estimate methods for all file operations */
322 struct {
323 reiser4_block_nr(*create) (const struct inode *);
324 reiser4_block_nr(*update) (const struct inode *);
325 reiser4_block_nr(*unlink) (const struct inode *,
326 const struct inode *);
327 } estimate;
330 * reiser4 specific part of inode has a union of structures which are
331 * specific to a plugin. This method is called when inode is read
332 * (read_inode) and when file is created (common_create_child) so that
333 * file plugin could initialize its inode data
335 void (*init_inode_data) (struct inode *, reiser4_object_create_data *,
336 int);
339 * This method performs progressive deletion of items and whole nodes
340 * from right to left.
342 * @tap: the point deletion process begins from,
343 * @from_key: the beginning of the deleted key range,
344 * @to_key: the end of the deleted key range,
345 * @smallest_removed: the smallest removed key,
347 * @return: 0 if success, error code otherwise, -E_REPEAT means that long cut_tree
348 * operation was interrupted for allowing atom commit .
350 int (*cut_tree_worker) (tap_t *, const reiser4_key * from_key,
351 const reiser4_key * to_key,
352 reiser4_key * smallest_removed, struct inode *,
353 int, int *);
355 /* called from ->destroy_inode() */
356 void (*destroy_inode) (struct inode *);
359 * methods to serialize object identify. This is used, for example, by
360 * reiser4_{en,de}code_fh().
362 struct {
363 /* store object's identity at @area */
364 char *(*write) (struct inode * inode, char *area);
365 /* parse object from wire to the @obj */
366 char *(*read) (char *area, reiser4_object_on_wire * obj);
367 /* given object identity in @obj, find or create its dentry */
368 struct dentry *(*get) (struct super_block * s,
369 reiser4_object_on_wire * obj);
370 /* how many bytes ->wire.write() consumes */
371 int (*size) (struct inode * inode);
372 /* finish with object identify */
373 void (*done) (reiser4_object_on_wire * obj);
374 } wire;
375 } file_plugin;
377 extern file_plugin file_plugins[LAST_FILE_PLUGIN_ID];
379 struct reiser4_object_on_wire {
380 file_plugin *plugin;
381 union {
382 struct {
383 obj_key_id key_id;
384 } std;
385 void *generic;
386 } u;
389 /* builtin dir-plugins */
390 typedef enum {
391 HASHED_DIR_PLUGIN_ID,
392 SEEKABLE_HASHED_DIR_PLUGIN_ID,
393 LAST_DIR_ID
394 } reiser4_dir_id;
396 typedef struct dir_plugin {
397 /* generic fields */
398 plugin_header h;
400 struct inode_operations inode_ops;
401 struct file_operations file_ops;
402 struct address_space_operations as_ops;
405 * private methods: These are optional. If used they will allow you to
406 * minimize the amount of code needed to implement a deviation from
407 * some other method that uses them. You could logically argue that
408 * they should be a separate type of plugin.
411 struct dentry *(*get_parent) (struct inode * childdir);
414 * check whether "name" is acceptable name to be inserted into this
415 * object. Optionally implemented by directory-like objects. Can check
416 * for maximal length, reserved symbols etc
418 int (*is_name_acceptable) (const struct inode * inode, const char *name,
419 int len);
421 void (*build_entry_key) (const struct inode * dir /* directory where
422 * entry is (or will
423 * be) in.*/ ,
424 const struct qstr * name /* name of file
425 * referenced by this
426 * entry */ ,
427 reiser4_key * result /* resulting key of
428 * directory entry */ );
429 int (*build_readdir_key) (struct file * dir, reiser4_key * result);
430 int (*add_entry) (struct inode * object, struct dentry * where,
431 reiser4_object_create_data * data,
432 reiser4_dir_entry_desc * entry);
433 int (*rem_entry) (struct inode * object, struct dentry * where,
434 reiser4_dir_entry_desc * entry);
437 * initialize directory structure for newly created object. For normal
438 * unix directories, insert dot and dotdot.
440 int (*init) (struct inode * object, struct inode * parent,
441 reiser4_object_create_data * data);
443 /* destroy directory */
444 int (*done) (struct inode * child);
446 /* called when @subdir was just looked up in the @dir */
447 int (*attach) (struct inode * subdir, struct inode * dir);
448 int (*detach) (struct inode * subdir, struct inode * dir);
450 struct {
451 reiser4_block_nr(*add_entry) (const struct inode *);
452 reiser4_block_nr(*rem_entry) (const struct inode *);
453 reiser4_block_nr(*unlink) (const struct inode *,
454 const struct inode *);
455 } estimate;
456 } dir_plugin;
458 extern dir_plugin dir_plugins[LAST_DIR_ID];
460 typedef struct formatting_plugin {
461 /* generic fields */
462 plugin_header h;
463 /* returns non-zero iff file's tail has to be stored
464 in a direct item. */
465 int (*have_tail) (const struct inode * inode, loff_t size);
466 } formatting_plugin;
468 typedef struct hash_plugin {
469 /* generic fields */
470 plugin_header h;
471 /* computes hash of the given name */
472 __u64(*hash) (const unsigned char *name, int len);
473 } hash_plugin;
475 typedef struct cipher_plugin {
476 /* generic fields */
477 plugin_header h;
478 struct crypto_blkcipher * (*alloc) (void);
479 void (*free) (struct crypto_blkcipher * tfm);
480 /* Offset translator. For each offset this returns (k * offset), where
481 k (k >= 1) is an expansion factor of the cipher algorithm.
482 For all symmetric algorithms k == 1. For asymmetric algorithms (which
483 inflate data) offset translation guarantees that all disk cluster's
484 units will have keys smaller then next cluster's one.
486 loff_t(*scale) (struct inode * inode, size_t blocksize, loff_t src);
487 /* Cipher algorithms can accept data only by chunks of cipher block
488 size. This method is to align any flow up to cipher block size when
489 we pass it to cipher algorithm. To align means to append padding of
490 special format specific to the cipher algorithm */
491 int (*align_stream) (__u8 * tail, int clust_size, int blocksize);
492 /* low-level key manager (check, install, etc..) */
493 int (*setkey) (struct crypto_tfm * tfm, const __u8 * key,
494 unsigned int keylen);
495 /* main text processing procedures */
496 void (*encrypt) (__u32 * expkey, __u8 * dst, const __u8 * src);
497 void (*decrypt) (__u32 * expkey, __u8 * dst, const __u8 * src);
498 } cipher_plugin;
500 typedef struct digest_plugin {
501 /* generic fields */
502 plugin_header h;
503 /* fingerprint size in bytes */
504 int fipsize;
505 struct crypto_hash * (*alloc) (void);
506 void (*free) (struct crypto_hash * tfm);
507 } digest_plugin;
509 typedef struct compression_plugin {
510 /* generic fields */
511 plugin_header h;
512 int (*init) (void);
513 /* the maximum number of bytes the size of the "compressed" data can
514 * exceed the uncompressed data. */
515 int (*overrun) (unsigned src_len);
516 coa_t(*alloc) (tfm_action act);
517 void (*free) (coa_t coa, tfm_action act);
518 /* minimal size of the flow we still try to compress */
519 int (*min_size_deflate) (void);
520 __u32(*checksum) (char *data, __u32 length);
521 /* main transform procedures */
522 void (*compress) (coa_t coa, __u8 * src_first, unsigned src_len,
523 __u8 * dst_first, unsigned *dst_len);
524 void (*decompress) (coa_t coa, __u8 * src_first, unsigned src_len,
525 __u8 * dst_first, unsigned *dst_len);
526 } compression_plugin;
528 typedef struct compression_mode_plugin {
529 /* generic fields */
530 plugin_header h;
531 /* this is called when estimating compressibility
532 of a logical cluster by its content */
533 int (*should_deflate) (struct inode * inode, cloff_t index);
534 /* this is called when results of compression should be saved */
535 int (*accept_hook) (struct inode * inode, cloff_t index);
536 /* this is called when results of compression should be discarded */
537 int (*discard_hook) (struct inode * inode, cloff_t index);
538 } compression_mode_plugin;
540 typedef struct cluster_plugin {
541 /* generic fields */
542 plugin_header h;
543 int shift;
544 } cluster_plugin;
546 typedef struct sd_ext_plugin {
547 /* generic fields */
548 plugin_header h;
549 int (*present) (struct inode * inode, char **area, int *len);
550 int (*absent) (struct inode * inode);
551 int (*save_len) (struct inode * inode);
552 int (*save) (struct inode * inode, char **area);
553 /* alignment requirement for this stat-data part */
554 int alignment;
555 } sd_ext_plugin;
557 /* this plugin contains methods to allocate objectid for newly created files,
558 to deallocate objectid when file gets removed, to report number of used and
559 free objectids */
560 typedef struct oid_allocator_plugin {
561 /* generic fields */
562 plugin_header h;
563 int (*init_oid_allocator) (reiser4_oid_allocator * map, __u64 nr_files,
564 __u64 oids);
565 /* used to report statfs->f_files */
566 __u64(*oids_used) (reiser4_oid_allocator * map);
567 /* get next oid to use */
568 __u64(*next_oid) (reiser4_oid_allocator * map);
569 /* used to report statfs->f_ffree */
570 __u64(*oids_free) (reiser4_oid_allocator * map);
571 /* allocate new objectid */
572 int (*allocate_oid) (reiser4_oid_allocator * map, oid_t *);
573 /* release objectid */
574 int (*release_oid) (reiser4_oid_allocator * map, oid_t);
575 /* how many pages to reserve in transaction for allocation of new
576 objectid */
577 int (*oid_reserve_allocate) (reiser4_oid_allocator * map);
578 /* how many pages to reserve in transaction for freeing of an
579 objectid */
580 int (*oid_reserve_release) (reiser4_oid_allocator * map);
581 void (*print_info) (const char *, reiser4_oid_allocator *);
582 } oid_allocator_plugin;
584 /* disk layout plugin: this specifies super block, journal, bitmap (if there
585 are any) locations, etc */
586 typedef struct disk_format_plugin {
587 /* generic fields */
588 plugin_header h;
589 /* replay journal, initialize super_info_data, etc */
590 int (*init_format) (struct super_block *, void *data);
592 /* key of root directory stat data */
593 const reiser4_key *(*root_dir_key) (const struct super_block *);
595 int (*release) (struct super_block *);
596 jnode *(*log_super) (struct super_block *);
597 int (*check_open) (const struct inode * object);
598 int (*version_update) (struct super_block *);
599 } disk_format_plugin;
601 struct jnode_plugin {
602 /* generic fields */
603 plugin_header h;
604 int (*init) (jnode * node);
605 int (*parse) (jnode * node);
606 struct address_space *(*mapping) (const jnode * node);
607 unsigned long (*index) (const jnode * node);
608 jnode *(*clone) (jnode * node);
611 /* plugin instance. */
612 /* */
613 /* This is "wrapper" union for all types of plugins. Most of the code uses */
614 /* plugins of particular type (file_plugin, dir_plugin, etc.) rather than */
615 /* operates with pointers to reiser4_plugin. This union is only used in */
616 /* some generic code in plugin/plugin.c that operates on all */
617 /* plugins. Technically speaking purpose of this union is to add type */
618 /* safety to said generic code: each plugin type (file_plugin, for */
619 /* example), contains plugin_header as its first memeber. This first member */
620 /* is located at the same place in memory as .h member of */
621 /* reiser4_plugin. Generic code, obtains pointer to reiser4_plugin and */
622 /* looks in the .h which is header of plugin type located in union. This */
623 /* allows to avoid type-casts. */
624 union reiser4_plugin {
625 /* generic fields */
626 plugin_header h;
627 /* file plugin */
628 file_plugin file;
629 /* directory plugin */
630 dir_plugin dir;
631 /* hash plugin, used by directory plugin */
632 hash_plugin hash;
633 /* fibration plugin used by directory plugin */
634 fibration_plugin fibration;
635 /* cipher transform plugin, used by file plugin */
636 cipher_plugin cipher;
637 /* digest transform plugin, used by file plugin */
638 digest_plugin digest;
639 /* compression transform plugin, used by file plugin */
640 compression_plugin compression;
641 /* tail plugin, used by file plugin */
642 formatting_plugin formatting;
643 /* permission plugin */
644 perm_plugin perm;
645 /* node plugin */
646 node_plugin node;
647 /* item plugin */
648 item_plugin item;
649 /* stat-data extension plugin */
650 sd_ext_plugin sd_ext;
651 /* disk layout plugin */
652 disk_format_plugin format;
653 /* object id allocator plugin */
654 oid_allocator_plugin oid_allocator;
655 /* plugin for different jnode types */
656 jnode_plugin jnode;
657 /* compression mode plugin, used by object plugin */
658 compression_mode_plugin compression_mode;
659 /* cluster plugin, used by object plugin */
660 cluster_plugin clust;
661 /* place-holder for new plugin types that can be registered
662 dynamically, and used by other dynamically loaded plugins. */
663 void *generic;
666 struct reiser4_plugin_ops {
667 /* called when plugin is initialized */
668 int (*init) (reiser4_plugin * plugin);
669 /* called when plugin is unloaded */
670 int (*done) (reiser4_plugin * plugin);
671 /* load given plugin from disk */
672 int (*load) (struct inode * inode,
673 reiser4_plugin * plugin, char **area, int *len);
674 /* how many space is required to store this plugin's state
675 in stat-data */
676 int (*save_len) (struct inode * inode, reiser4_plugin * plugin);
677 /* save persistent plugin-data to disk */
678 int (*save) (struct inode * inode, reiser4_plugin * plugin,
679 char **area);
680 /* alignment requirement for on-disk state of this plugin
681 in number of bytes */
682 int alignment;
683 /* install itself into given inode. This can return error
684 (e.g., you cannot change hash of non-empty directory). */
685 int (*change) (struct inode * inode, reiser4_plugin * plugin,
686 pset_member memb);
687 /* install itself into given inode. This can return error
688 (e.g., you cannot change hash of non-empty directory). */
689 int (*inherit) (struct inode * inode, struct inode * parent,
690 reiser4_plugin * plugin);
693 /* functions implemented in fs/reiser4/plugin/plugin.c */
695 /* stores plugin reference in reiser4-specific part of inode */
696 extern int set_object_plugin(struct inode *inode, reiser4_plugin_id id);
697 extern int init_plugins(void);
699 /* builtin plugins */
701 /* builtin hash-plugins */
703 typedef enum {
704 RUPASOV_HASH_ID,
705 R5_HASH_ID,
706 TEA_HASH_ID,
707 FNV1_HASH_ID,
708 DEGENERATE_HASH_ID,
709 LAST_HASH_ID
710 } reiser4_hash_id;
712 /* builtin cipher plugins */
714 typedef enum {
715 NONE_CIPHER_ID,
716 LAST_CIPHER_ID
717 } reiser4_cipher_id;
719 /* builtin digest plugins */
721 typedef enum {
722 SHA256_32_DIGEST_ID,
723 LAST_DIGEST_ID
724 } reiser4_digest_id;
726 /* builtin compression mode plugins */
727 typedef enum {
728 NONE_COMPRESSION_MODE_ID,
729 LATTD_COMPRESSION_MODE_ID,
730 ULTIM_COMPRESSION_MODE_ID,
731 FORCE_COMPRESSION_MODE_ID,
732 CONVX_COMPRESSION_MODE_ID,
733 LAST_COMPRESSION_MODE_ID
734 } reiser4_compression_mode_id;
736 /* builtin cluster plugins */
737 typedef enum {
738 CLUSTER_64K_ID,
739 CLUSTER_32K_ID,
740 CLUSTER_16K_ID,
741 CLUSTER_8K_ID,
742 CLUSTER_4K_ID,
743 LAST_CLUSTER_ID
744 } reiser4_cluster_id;
746 /* builtin tail-plugins */
748 typedef enum {
749 NEVER_TAILS_FORMATTING_ID,
750 ALWAYS_TAILS_FORMATTING_ID,
751 SMALL_FILE_FORMATTING_ID,
752 LAST_TAIL_FORMATTING_ID
753 } reiser4_formatting_id;
755 /* data type used to pack parameters that we pass to vfs object creation
756 function create_object() */
757 struct reiser4_object_create_data {
758 /* plugin to control created object */
759 reiser4_file_id id;
760 /* mode of regular file, directory or special file */
761 /* what happens if some other sort of perm plugin is in use? */
762 int mode;
763 /* rdev of special file */
764 dev_t rdev;
765 /* symlink target */
766 const char *name;
767 /* add here something for non-standard objects you invent, like
768 query for interpolation file etc. */
770 struct reiser4_crypto_info * crypto;
772 struct inode *parent;
773 struct dentry *dentry;
776 /* description of directory entry being created/destroyed/sought for
778 It is passed down to the directory plugin and farther to the
779 directory item plugin methods. Creation of new directory is done in
780 several stages: first we search for an entry with the same name, then
781 create new one. reiser4_dir_entry_desc is used to store some information
782 collected at some stage of this process and required later: key of
783 item that we want to insert/delete and pointer to an object that will
784 be bound by the new directory entry. Probably some more fields will
785 be added there.
788 struct reiser4_dir_entry_desc {
789 /* key of directory entry */
790 reiser4_key key;
791 /* object bound by this entry. */
792 struct inode *obj;
795 #define MAX_PLUGIN_TYPE_LABEL_LEN 32
796 #define MAX_PLUGIN_PLUG_LABEL_LEN 32
798 #define PLUGIN_BY_ID(TYPE,ID,FIELD) \
799 static inline TYPE *TYPE ## _by_id( reiser4_plugin_id id ) \
801 reiser4_plugin *plugin = plugin_by_id ( ID, id ); \
802 return plugin ? & plugin -> FIELD : NULL; \
804 static inline TYPE *TYPE ## _by_disk_id( reiser4_tree *tree, d16 *id ) \
806 reiser4_plugin *plugin = plugin_by_disk_id ( tree, ID, id ); \
807 return plugin ? & plugin -> FIELD : NULL; \
809 static inline TYPE *TYPE ## _by_unsafe_id( reiser4_plugin_id id ) \
811 reiser4_plugin *plugin = plugin_by_unsafe_id ( ID, id ); \
812 return plugin ? & plugin -> FIELD : NULL; \
814 static inline reiser4_plugin* TYPE ## _to_plugin( TYPE* plugin ) \
816 return ( reiser4_plugin * ) plugin; \
818 static inline reiser4_plugin_id TYPE ## _id( TYPE* plugin ) \
820 return TYPE ## _to_plugin (plugin) -> h.id; \
822 typedef struct { int foo; } TYPE ## _plugin_dummy
824 PLUGIN_BY_ID(item_plugin, REISER4_ITEM_PLUGIN_TYPE, item);
825 PLUGIN_BY_ID(file_plugin, REISER4_FILE_PLUGIN_TYPE, file);
826 PLUGIN_BY_ID(dir_plugin, REISER4_DIR_PLUGIN_TYPE, dir);
827 PLUGIN_BY_ID(node_plugin, REISER4_NODE_PLUGIN_TYPE, node);
828 PLUGIN_BY_ID(sd_ext_plugin, REISER4_SD_EXT_PLUGIN_TYPE, sd_ext);
829 PLUGIN_BY_ID(perm_plugin, REISER4_PERM_PLUGIN_TYPE, perm);
830 PLUGIN_BY_ID(hash_plugin, REISER4_HASH_PLUGIN_TYPE, hash);
831 PLUGIN_BY_ID(fibration_plugin, REISER4_FIBRATION_PLUGIN_TYPE, fibration);
832 PLUGIN_BY_ID(cipher_plugin, REISER4_CIPHER_PLUGIN_TYPE, cipher);
833 PLUGIN_BY_ID(digest_plugin, REISER4_DIGEST_PLUGIN_TYPE, digest);
834 PLUGIN_BY_ID(compression_plugin, REISER4_COMPRESSION_PLUGIN_TYPE, compression);
835 PLUGIN_BY_ID(formatting_plugin, REISER4_FORMATTING_PLUGIN_TYPE, formatting);
836 PLUGIN_BY_ID(disk_format_plugin, REISER4_FORMAT_PLUGIN_TYPE, format);
837 PLUGIN_BY_ID(jnode_plugin, REISER4_JNODE_PLUGIN_TYPE, jnode);
838 PLUGIN_BY_ID(compression_mode_plugin, REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
839 compression_mode);
840 PLUGIN_BY_ID(cluster_plugin, REISER4_CLUSTER_PLUGIN_TYPE, clust);
842 extern int save_plugin_id(reiser4_plugin * plugin, d16 * area);
844 extern struct list_head *get_plugin_list(reiser4_plugin_type type_id);
846 #define for_all_plugins(ptype, plugin) \
847 for (plugin = list_entry(get_plugin_list(ptype)->next, reiser4_plugin, h.linkage); \
848 get_plugin_list(ptype) != &plugin->h.linkage; \
849 plugin = list_entry(plugin->h.linkage.next, reiser4_plugin, h.linkage))
852 extern int grab_plugin_pset(struct inode *self, struct inode *ancestor, pset_member memb);
853 extern int force_plugin_pset(struct inode *self, pset_member memb, reiser4_plugin *plug);
854 extern int finish_pset(struct inode *inode);
856 /* defined in fs/reiser4/plugin/object.c */
857 extern file_plugin file_plugins[LAST_FILE_PLUGIN_ID];
858 /* defined in fs/reiser4/plugin/object.c */
859 extern dir_plugin dir_plugins[LAST_DIR_ID];
860 /* defined in fs/reiser4/plugin/item/static_stat.c */
861 extern sd_ext_plugin sd_ext_plugins[LAST_SD_EXTENSION];
862 /* defined in fs/reiser4/plugin/hash.c */
863 extern hash_plugin hash_plugins[LAST_HASH_ID];
864 /* defined in fs/reiser4/plugin/fibration.c */
865 extern fibration_plugin fibration_plugins[LAST_FIBRATION_ID];
866 /* defined in fs/reiser4/plugin/crypt.c */
867 extern cipher_plugin cipher_plugins[LAST_CIPHER_ID];
868 /* defined in fs/reiser4/plugin/digest.c */
869 extern digest_plugin digest_plugins[LAST_DIGEST_ID];
870 /* defined in fs/reiser4/plugin/compress/compress.c */
871 extern compression_plugin compression_plugins[LAST_COMPRESSION_ID];
872 /* defined in fs/reiser4/plugin/compress/compression_mode.c */
873 extern compression_mode_plugin
874 compression_mode_plugins[LAST_COMPRESSION_MODE_ID];
875 /* defined in fs/reiser4/plugin/cluster.c */
876 extern cluster_plugin cluster_plugins[LAST_CLUSTER_ID];
877 /* defined in fs/reiser4/plugin/tail.c */
878 extern formatting_plugin formatting_plugins[LAST_TAIL_FORMATTING_ID];
879 /* defined in fs/reiser4/plugin/security/security.c */
880 extern perm_plugin perm_plugins[LAST_PERM_ID];
881 /* defined in fs/reiser4/plugin/item/item.c */
882 extern item_plugin item_plugins[LAST_ITEM_ID];
883 /* defined in fs/reiser4/plugin/node/node.c */
884 extern node_plugin node_plugins[LAST_NODE_ID];
885 /* defined in fs/reiser4/plugin/disk_format/disk_format.c */
886 extern disk_format_plugin format_plugins[LAST_FORMAT_ID];
888 /* __FS_REISER4_PLUGIN_TYPES_H__ */
889 #endif
891 /* Make Linus happy.
892 Local variables:
893 c-indentation-style: "K&R"
894 mode-name: "LC"
895 c-basic-offset: 8
896 tab-width: 8
897 fill-column: 120
898 End: