cleanup
[linux-2.4.git] / fs / jffs / intrep.h
1 /*
2  * JFFS -- Journaling Flash File System, Linux implementation.
3  *
4  * Copyright (C) 1999, 2000  Axis Communications AB.
5  *
6  * Created by Finn Hakansson <finn@axis.com>.
7  *
8  * This is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * $Id: intrep.h,v 1.14 2001/09/23 23:28:37 dwmw2 Exp $
14  *
15  */
16
17 #ifndef __LINUX_JFFS_INTREP_H__
18 #define __LINUX_JFFS_INTREP_H__
19 #include "jffs_fm.h"
20 struct jffs_node *jffs_alloc_node(void);
21 void jffs_free_node(struct jffs_node *n);
22 int jffs_get_node_inuse(void);
23 long jffs_get_file_count(void);
24
25 __u32 jffs_checksum(const void *data, int size);
26
27 void jffs_cleanup_control(struct jffs_control *c);
28 int jffs_build_fs(struct super_block *sb);
29
30 int jffs_insert_node(struct jffs_control *c, struct jffs_file *f,
31                      const struct jffs_raw_inode *raw_inode,
32                      const char *name, struct jffs_node *node);
33 struct jffs_file *jffs_find_file(struct jffs_control *c, __u32 ino);
34 struct jffs_file *jffs_find_child(struct jffs_file *dir, const char *name, int len);
35
36 void jffs_free_node(struct jffs_node *node);
37
38 int jffs_foreach_file(struct jffs_control *c, int (*func)(struct jffs_file *));
39 int jffs_free_node_list(struct jffs_file *f);
40 int jffs_free_file(struct jffs_file *f);
41 int jffs_possibly_delete_file(struct jffs_file *f);
42 int jffs_build_file(struct jffs_file *f);
43 int jffs_insert_file_into_hash(struct jffs_file *f);
44 int jffs_insert_file_into_tree(struct jffs_file *f);
45 int jffs_unlink_file_from_hash(struct jffs_file *f);
46 int jffs_unlink_file_from_tree(struct jffs_file *f);
47 int jffs_remove_redundant_nodes(struct jffs_file *f);
48 int jffs_file_count(struct jffs_file *f);
49
50 int jffs_write_node(struct jffs_control *c, struct jffs_node *node,
51                     struct jffs_raw_inode *raw_inode,
52                     const char *name, const unsigned char *buf,
53                     int recoverable, struct jffs_file *f);
54 int jffs_read_data(struct jffs_file *f, unsigned char *buf, __u32 read_offset, __u32 size);
55
56 /* Garbage collection stuff.  */
57 int jffs_garbage_collect_thread(void *c);
58 void jffs_garbage_collect_trigger(struct jffs_control *c);
59 int jffs_garbage_collect_now(struct jffs_control *c);
60
61 /* Is there enough space on the flash?  */
62 static inline int JFFS_ENOUGH_SPACE(struct jffs_control *c, __u32 space)
63 {
64         struct jffs_fmcontrol *fmc = c->fmc;
65
66         while (1) {
67                 if ((fmc->flash_size - (fmc->used_size + fmc->dirty_size)) 
68                         >= fmc->min_free_size + space) {
69                         return 1;
70                 }
71                 if (fmc->dirty_size < fmc->sector_size)
72                         return 0;
73
74                 if (jffs_garbage_collect_now(c)) {
75                   D1(printk("JFFS_ENOUGH_SPACE: jffs_garbage_collect_now() failed.\n"));
76                   return 0;
77                 }
78         }
79 }
80
81 /* For debugging purposes.  */
82 void jffs_print_node(struct jffs_node *n);
83 void jffs_print_raw_inode(struct jffs_raw_inode *raw_inode);
84 int jffs_print_file(struct jffs_file *f);
85 void jffs_print_hash_table(struct jffs_control *c);
86 void jffs_print_tree(struct jffs_file *first_file, int indent);
87
88 struct buffer_head *jffs_get_write_buffer(kdev_t dev, int block);
89 void jffs_put_write_buffer(struct buffer_head *bh);
90
91 #endif /* __LINUX_JFFS_INTREP_H__  */