blob: f4e7f796bd1effad8d2816ec9066865c557f41ca [file] [log] [blame]
William Juulc051bbe2007-11-15 11:13:05 +01001/*
Wolfgang Denk74e0dde2008-08-14 14:41:06 +02002 * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
William Juulc051bbe2007-11-15 11:13:05 +01003 *
Charles Manning3796e1f2012-05-09 16:55:17 +00004 * Copyright (C) 2002-2011 Aleph One Ltd.
William Juulc051bbe2007-11-15 11:13:05 +01005 * for Toby Churchill Ltd and Brightstar Engineering
6 *
7 * Created by Charles Manning <charles@aleph1.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License version 2.1 as
11 * published by the Free Software Foundation.
12 *
13 * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14 */
15
16#ifndef __YAFFS_GUTS_H__
17#define __YAFFS_GUTS_H__
18
William Juulc051bbe2007-11-15 11:13:05 +010019#include "yportenv.h"
20
21#define YAFFS_OK 1
22#define YAFFS_FAIL 0
23
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020024/* Give us a Y=0x59,
25 * Give us an A=0x41,
Charles Manning3796e1f2012-05-09 16:55:17 +000026 * Give us an FF=0xff
William Juulc051bbe2007-11-15 11:13:05 +010027 * Give us an S=0x53
Wolfgang Denk74e0dde2008-08-14 14:41:06 +020028 * And what have we got...
William Juulc051bbe2007-11-15 11:13:05 +010029 */
Charles Manning3796e1f2012-05-09 16:55:17 +000030#define YAFFS_MAGIC 0x5941ff53
William Juulc051bbe2007-11-15 11:13:05 +010031
Charles Manning3796e1f2012-05-09 16:55:17 +000032/*
33 * Tnodes form a tree with the tnodes in "levels"
34 * Levels greater than 0 hold 8 slots which point to other tnodes.
35 * Those at level 0 hold 16 slots which point to chunks in NAND.
36 *
37 * A maximum level of 8 thust supports files of size up to:
38 *
39 * 2^(3*MAX_LEVEL+4)
40 *
41 * Thus a max level of 8 supports files with up to 2^^28 chunks which gives
42 * a maximum file size of arounf 51Gbytees with 2k chunks.
43 */
44#define YAFFS_NTNODES_LEVEL0 16
William Juulc051bbe2007-11-15 11:13:05 +010045#define YAFFS_TNODES_LEVEL0_BITS 4
46#define YAFFS_TNODES_LEVEL0_MASK 0xf
47
Charles Manning3796e1f2012-05-09 16:55:17 +000048#define YAFFS_NTNODES_INTERNAL (YAFFS_NTNODES_LEVEL0 / 2)
49#define YAFFS_TNODES_INTERNAL_BITS (YAFFS_TNODES_LEVEL0_BITS - 1)
William Juulc051bbe2007-11-15 11:13:05 +010050#define YAFFS_TNODES_INTERNAL_MASK 0x7
Charles Manning3796e1f2012-05-09 16:55:17 +000051#define YAFFS_TNODES_MAX_LEVEL 8
52#define YAFFS_TNODES_MAX_BITS (YAFFS_TNODES_LEVEL0_BITS + \
53 YAFFS_TNODES_INTERNAL_BITS * \
54 YAFFS_TNODES_MAX_LEVEL)
55#define YAFFS_MAX_CHUNK_ID ((1 << YAFFS_TNODES_MAX_BITS) - 1)
William Juulc051bbe2007-11-15 11:13:05 +010056
Charles Manning3796e1f2012-05-09 16:55:17 +000057/* Constants for YAFFS1 mode */
William Juulc051bbe2007-11-15 11:13:05 +010058#define YAFFS_BYTES_PER_SPARE 16
59#define YAFFS_BYTES_PER_CHUNK 512
60#define YAFFS_CHUNK_SIZE_SHIFT 9
61#define YAFFS_CHUNKS_PER_BLOCK 32
Charles Manning3796e1f2012-05-09 16:55:17 +000062#define YAFFS_BYTES_PER_BLOCK (YAFFS_CHUNKS_PER_BLOCK*YAFFS_BYTES_PER_CHUNK)
William Juulc051bbe2007-11-15 11:13:05 +010063
Charles Manning3796e1f2012-05-09 16:55:17 +000064#define YAFFS_MIN_YAFFS2_CHUNK_SIZE 1024
William Juulc051bbe2007-11-15 11:13:05 +010065#define YAFFS_MIN_YAFFS2_SPARE_SIZE 32
66
William Juulc051bbe2007-11-15 11:13:05 +010067#define YAFFS_ALLOCATION_NOBJECTS 100
68#define YAFFS_ALLOCATION_NTNODES 100
69#define YAFFS_ALLOCATION_NLINKS 100
70
71#define YAFFS_NOBJECT_BUCKETS 256
72
William Juulc051bbe2007-11-15 11:13:05 +010073#define YAFFS_OBJECT_SPACE 0x40000
Charles Manning3796e1f2012-05-09 16:55:17 +000074#define YAFFS_MAX_OBJECT_ID (YAFFS_OBJECT_SPACE - 1)
William Juulc051bbe2007-11-15 11:13:05 +010075
Charles Manning3796e1f2012-05-09 16:55:17 +000076/* Binary data version stamps */
77#define YAFFS_SUMMARY_VERSION 1
78#define YAFFS_CHECKPOINT_VERSION 6
William Juulc051bbe2007-11-15 11:13:05 +010079
80#ifdef CONFIG_YAFFS_UNICODE
81#define YAFFS_MAX_NAME_LENGTH 127
82#define YAFFS_MAX_ALIAS_LENGTH 79
83#else
84#define YAFFS_MAX_NAME_LENGTH 255
85#define YAFFS_MAX_ALIAS_LENGTH 159
86#endif
87
88#define YAFFS_SHORT_NAME_LENGTH 15
89
90/* Some special object ids for pseudo objects */
91#define YAFFS_OBJECTID_ROOT 1
92#define YAFFS_OBJECTID_LOSTNFOUND 2
93#define YAFFS_OBJECTID_UNLINKED 3
94#define YAFFS_OBJECTID_DELETED 4
95
Charles Manning3796e1f2012-05-09 16:55:17 +000096/* Fake object Id for summary data */
97#define YAFFS_OBJECTID_SUMMARY 0x10
William Juulc051bbe2007-11-15 11:13:05 +010098
Charles Manning3796e1f2012-05-09 16:55:17 +000099/* Pseudo object ids for checkpointing */
100#define YAFFS_OBJECTID_CHECKPOINT_DATA 0x20
101#define YAFFS_SEQUENCE_CHECKPOINT_DATA 0x21
William Juulc051bbe2007-11-15 11:13:05 +0100102
103#define YAFFS_MAX_SHORT_OP_CACHES 20
104
Charles Manning3796e1f2012-05-09 16:55:17 +0000105#define YAFFS_N_TEMP_BUFFERS 6
William Juulc051bbe2007-11-15 11:13:05 +0100106
107/* We limit the number attempts at sucessfully saving a chunk of data.
108 * Small-page devices have 32 pages per block; large-page devices have 64.
109 * Default to something in the order of 5 to 10 blocks worth of chunks.
110 */
111#define YAFFS_WR_ATTEMPTS (5*64)
112
113/* Sequence numbers are used in YAFFS2 to determine block allocation order.
114 * The range is limited slightly to help distinguish bad numbers from good.
115 * This also allows us to perhaps in the future use special numbers for
116 * special purposes.
Charles Manning3796e1f2012-05-09 16:55:17 +0000117 * EFFFFF00 allows the allocation of 8 blocks/second (~1Mbytes) for 15 years,
William Juulc051bbe2007-11-15 11:13:05 +0100118 * and is a larger number than the lifetime of a 2GB device.
119 */
120#define YAFFS_LOWEST_SEQUENCE_NUMBER 0x00001000
Charles Manning3796e1f2012-05-09 16:55:17 +0000121#define YAFFS_HIGHEST_SEQUENCE_NUMBER 0xefffff00
122
123/* Special sequence number for bad block that failed to be marked bad */
124#define YAFFS_SEQUENCE_BAD_BLOCK 0xffff0000
William Juulc051bbe2007-11-15 11:13:05 +0100125
126/* ChunkCache is used for short read/write operations.*/
Charles Manning3796e1f2012-05-09 16:55:17 +0000127struct yaffs_cache {
128 struct yaffs_obj *object;
129 int chunk_id;
130 int last_use;
William Juulc051bbe2007-11-15 11:13:05 +0100131 int dirty;
Charles Manning3796e1f2012-05-09 16:55:17 +0000132 int n_bytes; /* Only valid if the cache is dirty */
William Juulc051bbe2007-11-15 11:13:05 +0100133 int locked; /* Can't push out or flush while locked. */
Charles Manning3796e1f2012-05-09 16:55:17 +0000134 u8 *data;
135};
William Juulc051bbe2007-11-15 11:13:05 +0100136
Charles Manning3796e1f2012-05-09 16:55:17 +0000137/* yaffs1 tags structures in RAM
138 * NB This uses bitfield. Bitfields should not straddle a u32 boundary
139 * otherwise the structure size will get blown out.
William Juulc051bbe2007-11-15 11:13:05 +0100140 */
141
Charles Manning3796e1f2012-05-09 16:55:17 +0000142struct yaffs_tags {
143 unsigned chunk_id:20;
144 unsigned serial_number:2;
145 unsigned n_bytes_lsb:10;
146 unsigned obj_id:18;
William Juulc051bbe2007-11-15 11:13:05 +0100147 unsigned ecc:12;
Charles Manning3796e1f2012-05-09 16:55:17 +0000148 unsigned n_bytes_msb:2;
149};
William Juulc051bbe2007-11-15 11:13:05 +0100150
Charles Manning3796e1f2012-05-09 16:55:17 +0000151union yaffs_tags_union {
152 struct yaffs_tags as_tags;
153 u8 as_bytes[8];
154};
William Juulc051bbe2007-11-15 11:13:05 +0100155
William Juulc051bbe2007-11-15 11:13:05 +0100156/* Stuff used for extended tags in YAFFS2 */
157
Charles Manning3796e1f2012-05-09 16:55:17 +0000158enum yaffs_ecc_result {
William Juulc051bbe2007-11-15 11:13:05 +0100159 YAFFS_ECC_RESULT_UNKNOWN,
160 YAFFS_ECC_RESULT_NO_ERROR,
161 YAFFS_ECC_RESULT_FIXED,
162 YAFFS_ECC_RESULT_UNFIXED
Charles Manning3796e1f2012-05-09 16:55:17 +0000163};
William Juulc051bbe2007-11-15 11:13:05 +0100164
Charles Manning3796e1f2012-05-09 16:55:17 +0000165enum yaffs_obj_type {
William Juulc051bbe2007-11-15 11:13:05 +0100166 YAFFS_OBJECT_TYPE_UNKNOWN,
167 YAFFS_OBJECT_TYPE_FILE,
168 YAFFS_OBJECT_TYPE_SYMLINK,
169 YAFFS_OBJECT_TYPE_DIRECTORY,
170 YAFFS_OBJECT_TYPE_HARDLINK,
171 YAFFS_OBJECT_TYPE_SPECIAL
Charles Manning3796e1f2012-05-09 16:55:17 +0000172};
William Juulc051bbe2007-11-15 11:13:05 +0100173
174#define YAFFS_OBJECT_TYPE_MAX YAFFS_OBJECT_TYPE_SPECIAL
175
Charles Manning3796e1f2012-05-09 16:55:17 +0000176struct yaffs_ext_tags {
177 unsigned chunk_used; /* Status of the chunk: used or unused */
178 unsigned obj_id; /* If 0 this is not used */
179 unsigned chunk_id; /* If 0 this is a header, else a data chunk */
180 unsigned n_bytes; /* Only valid for data chunks */
William Juulc051bbe2007-11-15 11:13:05 +0100181
182 /* The following stuff only has meaning when we read */
Charles Manning3796e1f2012-05-09 16:55:17 +0000183 enum yaffs_ecc_result ecc_result;
184 unsigned block_bad;
William Juulc051bbe2007-11-15 11:13:05 +0100185
186 /* YAFFS 1 stuff */
Charles Manning3796e1f2012-05-09 16:55:17 +0000187 unsigned is_deleted; /* The chunk is marked deleted */
188 unsigned serial_number; /* Yaffs1 2-bit serial number */
William Juulc051bbe2007-11-15 11:13:05 +0100189
190 /* YAFFS2 stuff */
Charles Manning3796e1f2012-05-09 16:55:17 +0000191 unsigned seq_number; /* The sequence number of this block */
William Juulc051bbe2007-11-15 11:13:05 +0100192
193 /* Extra info if this is an object header (YAFFS2 only) */
194
Charles Manning3796e1f2012-05-09 16:55:17 +0000195 unsigned extra_available; /* Extra info available if not zero */
196 unsigned extra_parent_id; /* The parent object */
197 unsigned extra_is_shrink; /* Is it a shrink header? */
198 unsigned extra_shadows; /* Does this shadow another object? */
William Juulc051bbe2007-11-15 11:13:05 +0100199
Charles Manning3796e1f2012-05-09 16:55:17 +0000200 enum yaffs_obj_type extra_obj_type; /* What object type? */
William Juulc051bbe2007-11-15 11:13:05 +0100201
Charles Manning3796e1f2012-05-09 16:55:17 +0000202 loff_t extra_file_size; /* Length if it is a file */
203 unsigned extra_equiv_id; /* Equivalent object for a hard link */
204};
William Juulc051bbe2007-11-15 11:13:05 +0100205
206/* Spare structure for YAFFS1 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000207struct yaffs_spare {
208 u8 tb0;
209 u8 tb1;
210 u8 tb2;
211 u8 tb3;
212 u8 page_status; /* set to 0 to delete the chunk */
213 u8 block_status;
214 u8 tb4;
215 u8 tb5;
216 u8 ecc1[3];
217 u8 tb6;
218 u8 tb7;
219 u8 ecc2[3];
220};
William Juulc051bbe2007-11-15 11:13:05 +0100221
222/*Special structure for passing through to mtd */
Charles Manning3796e1f2012-05-09 16:55:17 +0000223struct yaffs_nand_spare {
224 struct yaffs_spare spare;
William Juulc051bbe2007-11-15 11:13:05 +0100225 int eccres1;
226 int eccres2;
227};
228
229/* Block data in RAM */
230
Charles Manning3796e1f2012-05-09 16:55:17 +0000231enum yaffs_block_state {
William Juulc051bbe2007-11-15 11:13:05 +0100232 YAFFS_BLOCK_STATE_UNKNOWN = 0,
233
234 YAFFS_BLOCK_STATE_SCANNING,
Charles Manning3796e1f2012-05-09 16:55:17 +0000235 /* Being scanned */
236
237 YAFFS_BLOCK_STATE_NEEDS_SCAN,
238 /* The block might have something on it (ie it is allocating or full,
239 * perhaps empty) but it needs to be scanned to determine its true
240 * state.
241 * This state is only valid during scanning.
242 * NB We tolerate empty because the pre-scanner might be incapable of
243 * deciding
244 * However, if this state is returned on a YAFFS2 device,
245 * then we expect a sequence number
William Juulc051bbe2007-11-15 11:13:05 +0100246 */
247
248 YAFFS_BLOCK_STATE_EMPTY,
249 /* This block is empty */
250
251 YAFFS_BLOCK_STATE_ALLOCATING,
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200252 /* This block is partially allocated.
William Juulc051bbe2007-11-15 11:13:05 +0100253 * At least one page holds valid data.
254 * This is the one currently being used for page
Charles Manning3796e1f2012-05-09 16:55:17 +0000255 * allocation. Should never be more than one of these.
256 * If a block is only partially allocated at mount it is treated as
257 * full.
William Juulc051bbe2007-11-15 11:13:05 +0100258 */
259
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200260 YAFFS_BLOCK_STATE_FULL,
William Juulc051bbe2007-11-15 11:13:05 +0100261 /* All the pages in this block have been allocated.
Charles Manning3796e1f2012-05-09 16:55:17 +0000262 * If a block was only partially allocated when mounted we treat
263 * it as fully allocated.
William Juulc051bbe2007-11-15 11:13:05 +0100264 */
265
266 YAFFS_BLOCK_STATE_DIRTY,
Charles Manning3796e1f2012-05-09 16:55:17 +0000267 /* The block was full and now all chunks have been deleted.
William Juulc051bbe2007-11-15 11:13:05 +0100268 * Erase me, reuse me.
269 */
270
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200271 YAFFS_BLOCK_STATE_CHECKPOINT,
Charles Manning3796e1f2012-05-09 16:55:17 +0000272 /* This block is assigned to holding checkpoint data. */
William Juulc051bbe2007-11-15 11:13:05 +0100273
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200274 YAFFS_BLOCK_STATE_COLLECTING,
William Juulc051bbe2007-11-15 11:13:05 +0100275 /* This block is being garbage collected */
276
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200277 YAFFS_BLOCK_STATE_DEAD
Charles Manning3796e1f2012-05-09 16:55:17 +0000278 /* This block has failed and is not in use */
279};
William Juulc051bbe2007-11-15 11:13:05 +0100280
281#define YAFFS_NUMBER_OF_BLOCK_STATES (YAFFS_BLOCK_STATE_DEAD + 1)
282
Charles Manning3796e1f2012-05-09 16:55:17 +0000283struct yaffs_block_info {
William Juulc051bbe2007-11-15 11:13:05 +0100284
Charles Manning3796e1f2012-05-09 16:55:17 +0000285 int soft_del_pages:10; /* number of soft deleted pages */
286 int pages_in_use:10; /* number of pages in use */
287 unsigned block_state:4; /* One of the above block states. */
288 /* NB use unsigned because enum is sometimes
289 * an int */
290 u32 needs_retiring:1; /* Data has failed on this block, */
291 /*need to get valid data off and retire*/
292 u32 skip_erased_check:1;/* Skip the erased check on this block */
293 u32 gc_prioritise:1; /* An ECC check or blank check has failed.
294 Block should be prioritised for GC */
295 u32 chunk_error_strikes:3; /* How many times we've had ecc etc
296 failures on this block and tried to reuse it */
297 u32 has_summary:1; /* The block has a summary */
William Juulc051bbe2007-11-15 11:13:05 +0100298
Charles Manning3796e1f2012-05-09 16:55:17 +0000299 u32 has_shrink_hdr:1; /* This block has at least one shrink header */
300 u32 seq_number; /* block sequence number for yaffs2 */
William Juulc051bbe2007-11-15 11:13:05 +0100301
Charles Manning3796e1f2012-05-09 16:55:17 +0000302};
William Juulc051bbe2007-11-15 11:13:05 +0100303
304/* -------------------------- Object structure -------------------------------*/
305/* This is the object structure as stored on NAND */
306
Charles Manning3796e1f2012-05-09 16:55:17 +0000307struct yaffs_obj_hdr {
308 enum yaffs_obj_type type;
William Juulc051bbe2007-11-15 11:13:05 +0100309
310 /* Apply to everything */
Charles Manning3796e1f2012-05-09 16:55:17 +0000311 int parent_obj_id;
312 u16 sum_no_longer_used; /* checksum of name. No longer used */
William Juulc051bbe2007-11-15 11:13:05 +0100313 YCHAR name[YAFFS_MAX_NAME_LENGTH + 1];
314
Charles Manning3796e1f2012-05-09 16:55:17 +0000315 /* The following apply to all object types except for hard links */
316 u32 yst_mode; /* protection */
William Juulc051bbe2007-11-15 11:13:05 +0100317
Charles Manning3796e1f2012-05-09 16:55:17 +0000318 u32 yst_uid;
319 u32 yst_gid;
320 u32 yst_atime;
321 u32 yst_mtime;
322 u32 yst_ctime;
William Juulc051bbe2007-11-15 11:13:05 +0100323
324 /* File size applies to files only */
Charles Manning3796e1f2012-05-09 16:55:17 +0000325 u32 file_size_low;
William Juulc051bbe2007-11-15 11:13:05 +0100326
327 /* Equivalent object id applies to hard links only. */
Charles Manning3796e1f2012-05-09 16:55:17 +0000328 int equiv_id;
William Juulc051bbe2007-11-15 11:13:05 +0100329
330 /* Alias is for symlinks only. */
331 YCHAR alias[YAFFS_MAX_ALIAS_LENGTH + 1];
332
Charles Manning3796e1f2012-05-09 16:55:17 +0000333 u32 yst_rdev; /* stuff for block and char devices (major/min) */
William Juulc051bbe2007-11-15 11:13:05 +0100334
Charles Manning3796e1f2012-05-09 16:55:17 +0000335 u32 win_ctime[2];
336 u32 win_atime[2];
337 u32 win_mtime[2];
William Juulc051bbe2007-11-15 11:13:05 +0100338
Charles Manning3796e1f2012-05-09 16:55:17 +0000339 u32 inband_shadowed_obj_id;
340 u32 inband_is_shrink;
William Juulc051bbe2007-11-15 11:13:05 +0100341
Charles Manning3796e1f2012-05-09 16:55:17 +0000342 u32 file_size_high;
343 u32 reserved[1];
344 int shadows_obj; /* This object header shadows the
345 specified object if > 0 */
William Juulc051bbe2007-11-15 11:13:05 +0100346
Charles Manning3796e1f2012-05-09 16:55:17 +0000347 /* is_shrink applies to object headers written when wemake a hole. */
348 u32 is_shrink;
William Juulc051bbe2007-11-15 11:13:05 +0100349
350};
351
Charles Manning3796e1f2012-05-09 16:55:17 +0000352/*--------------------------- Tnode -------------------------- */
William Juulc051bbe2007-11-15 11:13:05 +0100353
Charles Manning3796e1f2012-05-09 16:55:17 +0000354struct yaffs_tnode {
355 struct yaffs_tnode *internal[YAFFS_NTNODES_INTERNAL];
William Juulc051bbe2007-11-15 11:13:05 +0100356};
357
William Juulc051bbe2007-11-15 11:13:05 +0100358/*------------------------ Object -----------------------------*/
359/* An object can be one of:
360 * - a directory (no data, has children links
361 * - a regular file (data.... not prunes :->).
362 * - a symlink [symbolic link] (the alias).
363 * - a hard link
364 */
365
Charles Manning3796e1f2012-05-09 16:55:17 +0000366struct yaffs_file_var {
367 loff_t file_size;
368 loff_t scanned_size;
369 loff_t shrink_size;
370 int top_level;
371 struct yaffs_tnode *top;
372};
William Juulc051bbe2007-11-15 11:13:05 +0100373
Charles Manning3796e1f2012-05-09 16:55:17 +0000374struct yaffs_dir_var {
William Juulc051bbe2007-11-15 11:13:05 +0100375 struct list_head children; /* list of child links */
Charles Manning3796e1f2012-05-09 16:55:17 +0000376 struct list_head dirty; /* Entry for list of dirty directories */
377};
William Juulc051bbe2007-11-15 11:13:05 +0100378
Charles Manning3796e1f2012-05-09 16:55:17 +0000379struct yaffs_symlink_var {
William Juulc051bbe2007-11-15 11:13:05 +0100380 YCHAR *alias;
Charles Manning3796e1f2012-05-09 16:55:17 +0000381};
William Juulc051bbe2007-11-15 11:13:05 +0100382
Charles Manning3796e1f2012-05-09 16:55:17 +0000383struct yaffs_hardlink_var {
384 struct yaffs_obj *equiv_obj;
385 u32 equiv_id;
386};
William Juulc051bbe2007-11-15 11:13:05 +0100387
Charles Manning3796e1f2012-05-09 16:55:17 +0000388union yaffs_obj_var {
389 struct yaffs_file_var file_variant;
390 struct yaffs_dir_var dir_variant;
391 struct yaffs_symlink_var symlink_variant;
392 struct yaffs_hardlink_var hardlink_variant;
393};
William Juulc051bbe2007-11-15 11:13:05 +0100394
Charles Manning3796e1f2012-05-09 16:55:17 +0000395struct yaffs_obj {
396 u8 deleted:1; /* This should only apply to unlinked files. */
397 u8 soft_del:1; /* it has also been soft deleted */
398 u8 unlinked:1; /* An unlinked file.*/
399 u8 fake:1; /* A fake object has no presence on NAND. */
400 u8 rename_allowed:1; /* Some objects cannot be renamed. */
401 u8 unlink_allowed:1;
402 u8 dirty:1; /* the object needs to be written to flash */
403 u8 valid:1; /* When the file system is being loaded up, this
William Juulc051bbe2007-11-15 11:13:05 +0100404 * object might be created before the data
Charles Manning3796e1f2012-05-09 16:55:17 +0000405 * is available
406 * ie. file data chunks encountered before
407 * the header.
William Juulc051bbe2007-11-15 11:13:05 +0100408 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000409 u8 lazy_loaded:1; /* This object has been lazy loaded and
410 * is missing some detail */
William Juulc051bbe2007-11-15 11:13:05 +0100411
Charles Manning3796e1f2012-05-09 16:55:17 +0000412 u8 defered_free:1; /* Object is removed from NAND, but is
413 * still in the inode cache.
414 * Free of object is defered.
William Juulc051bbe2007-11-15 11:13:05 +0100415 * until the inode is released.
416 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000417 u8 being_created:1; /* This object is still being created
418 * so skip some verification checks. */
419 u8 is_shadowed:1; /* This object is shadowed on the way
420 * to being renamed. */
William Juulc051bbe2007-11-15 11:13:05 +0100421
Charles Manning3796e1f2012-05-09 16:55:17 +0000422 u8 xattr_known:1; /* We know if this has object has xattribs
423 * or not. */
424 u8 has_xattr:1; /* This object has xattribs.
425 * Only valid if xattr_known. */
William Juulc051bbe2007-11-15 11:13:05 +0100426
Charles Manning3796e1f2012-05-09 16:55:17 +0000427 u8 serial; /* serial number of chunk in NAND.*/
428 u16 sum; /* sum of the name to speed searching */
William Juulc051bbe2007-11-15 11:13:05 +0100429
Charles Manning3796e1f2012-05-09 16:55:17 +0000430 struct yaffs_dev *my_dev; /* The device I'm on */
William Juulc051bbe2007-11-15 11:13:05 +0100431
Charles Manning3796e1f2012-05-09 16:55:17 +0000432 struct list_head hash_link; /* list of objects in hash bucket */
433
434 struct list_head hard_links; /* hard linked object chain*/
William Juulc051bbe2007-11-15 11:13:05 +0100435
436 /* directory structure stuff */
437 /* also used for linking up the free list */
Charles Manning3796e1f2012-05-09 16:55:17 +0000438 struct yaffs_obj *parent;
William Juulc051bbe2007-11-15 11:13:05 +0100439 struct list_head siblings;
440
441 /* Where's my object header in NAND? */
Charles Manning3796e1f2012-05-09 16:55:17 +0000442 int hdr_chunk;
William Juulc051bbe2007-11-15 11:13:05 +0100443
Charles Manning3796e1f2012-05-09 16:55:17 +0000444 int n_data_chunks; /* Number of data chunks for this file. */
William Juulc051bbe2007-11-15 11:13:05 +0100445
Charles Manning3796e1f2012-05-09 16:55:17 +0000446 u32 obj_id; /* the object id value */
William Juulc051bbe2007-11-15 11:13:05 +0100447
Charles Manning3796e1f2012-05-09 16:55:17 +0000448 u32 yst_mode;
William Juulc051bbe2007-11-15 11:13:05 +0100449
Charles Manning3796e1f2012-05-09 16:55:17 +0000450 YCHAR short_name[YAFFS_SHORT_NAME_LENGTH + 1];
William Juulc051bbe2007-11-15 11:13:05 +0100451
452#ifdef CONFIG_YAFFS_WINCE
Charles Manning3796e1f2012-05-09 16:55:17 +0000453 u32 win_ctime[2];
454 u32 win_mtime[2];
455 u32 win_atime[2];
William Juulc051bbe2007-11-15 11:13:05 +0100456#else
Charles Manning3796e1f2012-05-09 16:55:17 +0000457 u32 yst_uid;
458 u32 yst_gid;
459 u32 yst_atime;
460 u32 yst_mtime;
461 u32 yst_ctime;
William Juulc051bbe2007-11-15 11:13:05 +0100462#endif
463
Charles Manning3796e1f2012-05-09 16:55:17 +0000464 u32 yst_rdev;
William Juulc051bbe2007-11-15 11:13:05 +0100465
Charles Manning3796e1f2012-05-09 16:55:17 +0000466 void *my_inode;
William Juulc051bbe2007-11-15 11:13:05 +0100467
Charles Manning3796e1f2012-05-09 16:55:17 +0000468 enum yaffs_obj_type variant_type;
William Juulc051bbe2007-11-15 11:13:05 +0100469
Charles Manning3796e1f2012-05-09 16:55:17 +0000470 union yaffs_obj_var variant;
William Juulc051bbe2007-11-15 11:13:05 +0100471
472};
473
Charles Manning3796e1f2012-05-09 16:55:17 +0000474struct yaffs_obj_bucket {
William Juulc051bbe2007-11-15 11:13:05 +0100475 struct list_head list;
476 int count;
Charles Manning3796e1f2012-05-09 16:55:17 +0000477};
William Juulc051bbe2007-11-15 11:13:05 +0100478
Charles Manning3796e1f2012-05-09 16:55:17 +0000479/* yaffs_checkpt_obj holds the definition of an object as dumped
William Juulc051bbe2007-11-15 11:13:05 +0100480 * by checkpointing.
481 */
482
Charles Manning3796e1f2012-05-09 16:55:17 +0000483struct yaffs_checkpt_obj {
484 int struct_type;
485 u32 obj_id;
486 u32 parent_id;
487 int hdr_chunk;
488 enum yaffs_obj_type variant_type:3;
489 u8 deleted:1;
490 u8 soft_del:1;
491 u8 unlinked:1;
492 u8 fake:1;
493 u8 rename_allowed:1;
494 u8 unlink_allowed:1;
495 u8 serial;
496 int n_data_chunks;
497 loff_t size_or_equiv_obj;
498};
William Juulc051bbe2007-11-15 11:13:05 +0100499
500/*--------------------- Temporary buffers ----------------
501 *
Charles Manning3796e1f2012-05-09 16:55:17 +0000502 * These are chunk-sized working buffers. Each device has a few.
William Juulc051bbe2007-11-15 11:13:05 +0100503 */
504
Charles Manning3796e1f2012-05-09 16:55:17 +0000505struct yaffs_buffer {
506 u8 *buffer;
507 int in_use;
508};
William Juulc051bbe2007-11-15 11:13:05 +0100509
510/*----------------- Device ---------------------------------*/
511
Charles Manning3796e1f2012-05-09 16:55:17 +0000512struct yaffs_param {
513 const YCHAR *name;
William Juulc051bbe2007-11-15 11:13:05 +0100514
Charles Manning3796e1f2012-05-09 16:55:17 +0000515 /*
516 * Entry parameters set up way early. Yaffs sets up the rest.
517 * The structure should be zeroed out before use so that unused
518 * and defualt values are zero.
519 */
William Juulc051bbe2007-11-15 11:13:05 +0100520
Charles Manning3796e1f2012-05-09 16:55:17 +0000521 int inband_tags; /* Use unband tags */
522 u32 total_bytes_per_chunk; /* Should be >= 512, does not need to
523 be a power of 2 */
524 int chunks_per_block; /* does not need to be a power of 2 */
525 int spare_bytes_per_chunk; /* spare area size */
526 int start_block; /* Start block we're allowed to use */
527 int end_block; /* End block we're allowed to use */
528 int n_reserved_blocks; /* Tuneable so that we can reduce
529 * reserved blocks on NOR and RAM. */
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200530
Charles Manning3796e1f2012-05-09 16:55:17 +0000531 int n_caches; /* If <= 0, then short op caching is disabled,
532 * else the number of short op caches.
William Juulc051bbe2007-11-15 11:13:05 +0100533 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000534 int use_nand_ecc; /* Flag to decide whether or not to use
535 * NAND driver ECC on data (yaffs1) */
536 int tags_9bytes; /* Use 9 byte tags */
537 int no_tags_ecc; /* Flag to decide whether or not to do ECC
538 * on packed tags (yaffs2) */
William Juulc051bbe2007-11-15 11:13:05 +0100539
Charles Manning3796e1f2012-05-09 16:55:17 +0000540 int is_yaffs2; /* Use yaffs2 mode on this device */
William Juulc051bbe2007-11-15 11:13:05 +0100541
Charles Manning3796e1f2012-05-09 16:55:17 +0000542 int empty_lost_n_found; /* Auto-empty lost+found directory on mount */
William Juulc051bbe2007-11-15 11:13:05 +0100543
Charles Manning3796e1f2012-05-09 16:55:17 +0000544 int refresh_period; /* How often to check for a block refresh */
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200545
Charles Manning3796e1f2012-05-09 16:55:17 +0000546 /* Checkpoint control. Can be set before or after initialisation */
547 u8 skip_checkpt_rd;
548 u8 skip_checkpt_wr;
William Juulc051bbe2007-11-15 11:13:05 +0100549
Charles Manning3796e1f2012-05-09 16:55:17 +0000550 int enable_xattr; /* Enable xattribs */
William Juulc051bbe2007-11-15 11:13:05 +0100551
Charles Manning3796e1f2012-05-09 16:55:17 +0000552 /* NAND access functions (Must be set before calling YAFFS) */
William Juulc051bbe2007-11-15 11:13:05 +0100553
Charles Manning3796e1f2012-05-09 16:55:17 +0000554 int (*write_chunk_fn) (struct yaffs_dev *dev,
555 int nand_chunk, const u8 *data,
556 const struct yaffs_spare *spare);
557 int (*read_chunk_fn) (struct yaffs_dev *dev,
558 int nand_chunk, u8 *data,
559 struct yaffs_spare *spare);
560 int (*erase_fn) (struct yaffs_dev *dev, int flash_block);
561 int (*initialise_flash_fn) (struct yaffs_dev *dev);
562 int (*deinitialise_flash_fn) (struct yaffs_dev *dev);
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200563
Charles Manning3796e1f2012-05-09 16:55:17 +0000564 /* yaffs2 mode functions */
565 int (*write_chunk_tags_fn) (struct yaffs_dev *dev,
566 int nand_chunk, const u8 *data,
567 const struct yaffs_ext_tags *tags);
568 int (*read_chunk_tags_fn) (struct yaffs_dev *dev,
569 int nand_chunk, u8 *data,
570 struct yaffs_ext_tags *tags);
571 int (*bad_block_fn) (struct yaffs_dev *dev, int block_no);
572 int (*query_block_fn) (struct yaffs_dev *dev, int block_no,
573 enum yaffs_block_state *state,
574 u32 *seq_number);
575
576 /* The remove_obj_fn function must be supplied by OS flavours that
577 * need it.
578 * yaffs direct uses it to implement the faster readdir.
579 * Linux uses it to protect the directory during unlocking.
William Juulc051bbe2007-11-15 11:13:05 +0100580 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000581 void (*remove_obj_fn) (struct yaffs_obj *obj);
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200582
Charles Manning3796e1f2012-05-09 16:55:17 +0000583 /* Callback to mark the superblock dirty */
584 void (*sb_dirty_fn) (struct yaffs_dev *dev);
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200585
Charles Manning3796e1f2012-05-09 16:55:17 +0000586 /* Callback to control garbage collection. */
587 unsigned (*gc_control) (struct yaffs_dev *dev);
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200588
Charles Manning3796e1f2012-05-09 16:55:17 +0000589 /* Debug control flags. Don't use unless you know what you're doing */
590 int use_header_file_size; /* Flag to determine if we should use
591 * file sizes from the header */
592 int disable_lazy_load; /* Disable lazy loading on this device */
593 int wide_tnodes_disabled; /* Set to disable wide tnodes */
594 int disable_soft_del; /* yaffs 1 only: Set to disable the use of
595 * softdeletion. */
William Juulc051bbe2007-11-15 11:13:05 +0100596
Charles Manning3796e1f2012-05-09 16:55:17 +0000597 int defered_dir_update; /* Set to defer directory updates */
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200598
Charles Manning3796e1f2012-05-09 16:55:17 +0000599#ifdef CONFIG_YAFFS_AUTO_UNICODE
600 int auto_unicode;
601#endif
602 int always_check_erased; /* Force chunk erased check always on */
William Juulc051bbe2007-11-15 11:13:05 +0100603
Charles Manning3796e1f2012-05-09 16:55:17 +0000604 int disable_summary;
William Juulc051bbe2007-11-15 11:13:05 +0100605
Charles Manning3796e1f2012-05-09 16:55:17 +0000606 int max_objects; /*
607 * Set to limit the number of objects created.
608 * 0 = no limit.
609 */
610};
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200611
Charles Manning3796e1f2012-05-09 16:55:17 +0000612struct yaffs_dev {
613 struct yaffs_param param;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200614
Charles Manning3796e1f2012-05-09 16:55:17 +0000615 /* Context storage. Holds extra OS specific data for this device */
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200616
Charles Manning3796e1f2012-05-09 16:55:17 +0000617 void *os_context;
618 void *driver_context;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200619
Charles Manning3796e1f2012-05-09 16:55:17 +0000620 struct list_head dev_list;
William Juulc051bbe2007-11-15 11:13:05 +0100621
Charles Manning3796e1f2012-05-09 16:55:17 +0000622 /* Runtime parameters. Set up by YAFFS. */
623 int data_bytes_per_chunk;
William Juulc051bbe2007-11-15 11:13:05 +0100624
Charles Manning3796e1f2012-05-09 16:55:17 +0000625 /* Non-wide tnode stuff */
626 u16 chunk_grp_bits; /* Number of bits that need to be resolved if
627 * the tnodes are not wide enough.
William Juulc051bbe2007-11-15 11:13:05 +0100628 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000629 u16 chunk_grp_size; /* == 2^^chunk_grp_bits */
William Juulc051bbe2007-11-15 11:13:05 +0100630
Charles Manning3796e1f2012-05-09 16:55:17 +0000631 /* Stuff to support wide tnodes */
632 u32 tnode_width;
633 u32 tnode_mask;
634 u32 tnode_size;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200635
Charles Manning3796e1f2012-05-09 16:55:17 +0000636 /* Stuff for figuring out file offset to chunk conversions */
637 u32 chunk_shift; /* Shift value */
638 u32 chunk_div; /* Divisor after shifting: 1 for 2^n sizes */
639 u32 chunk_mask; /* Mask to use for power-of-2 case */
William Juulc051bbe2007-11-15 11:13:05 +0100640
Charles Manning3796e1f2012-05-09 16:55:17 +0000641 int is_mounted;
642 int read_only;
643 int is_checkpointed;
William Juulc051bbe2007-11-15 11:13:05 +0100644
645 /* Stuff to support block offsetting to support start block zero */
Charles Manning3796e1f2012-05-09 16:55:17 +0000646 int internal_start_block;
647 int internal_end_block;
648 int block_offset;
649 int chunk_offset;
William Juulc051bbe2007-11-15 11:13:05 +0100650
651 /* Runtime checkpointing stuff */
Charles Manning3796e1f2012-05-09 16:55:17 +0000652 int checkpt_page_seq; /* running sequence number of checkpt pages */
653 int checkpt_byte_count;
654 int checkpt_byte_offs;
655 u8 *checkpt_buffer;
656 int checkpt_open_write;
657 int blocks_in_checkpt;
658 int checkpt_cur_chunk;
659 int checkpt_cur_block;
660 int checkpt_next_block;
661 int *checkpt_block_list;
662 int checkpt_max_blocks;
663 u32 checkpt_sum;
664 u32 checkpt_xor;
665
666 int checkpoint_blocks_required; /* Number of blocks needed to store
667 * current checkpoint set */
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200668
William Juulc051bbe2007-11-15 11:13:05 +0100669 /* Block Info */
Charles Manning3796e1f2012-05-09 16:55:17 +0000670 struct yaffs_block_info *block_info;
671 u8 *chunk_bits; /* bitmap of chunks in use */
672 unsigned block_info_alt:1; /* allocated using alternative alloc */
673 unsigned chunk_bits_alt:1; /* allocated using alternative alloc */
674 int chunk_bit_stride; /* Number of bytes of chunk_bits per block.
675 * Must be consistent with chunks_per_block.
William Juulc051bbe2007-11-15 11:13:05 +0100676 */
677
Charles Manning3796e1f2012-05-09 16:55:17 +0000678 int n_erased_blocks;
679 int alloc_block; /* Current block being allocated off */
680 u32 alloc_page;
681 int alloc_block_finder; /* Used to search for next allocation block */
William Juulc051bbe2007-11-15 11:13:05 +0100682
Charles Manning3796e1f2012-05-09 16:55:17 +0000683 /* Object and Tnode memory management */
684 void *allocator;
685 int n_obj;
686 int n_tnodes;
William Juulc051bbe2007-11-15 11:13:05 +0100687
Charles Manning3796e1f2012-05-09 16:55:17 +0000688 int n_hardlinks;
William Juulc051bbe2007-11-15 11:13:05 +0100689
Charles Manning3796e1f2012-05-09 16:55:17 +0000690 struct yaffs_obj_bucket obj_bucket[YAFFS_NOBJECT_BUCKETS];
691 u32 bucket_finder;
William Juulc051bbe2007-11-15 11:13:05 +0100692
Charles Manning3796e1f2012-05-09 16:55:17 +0000693 int n_free_chunks;
William Juulc051bbe2007-11-15 11:13:05 +0100694
Charles Manning3796e1f2012-05-09 16:55:17 +0000695 /* Garbage collection control */
696 u32 *gc_cleanup_list; /* objects to delete at the end of a GC. */
697 u32 n_clean_ups;
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200698
Charles Manning3796e1f2012-05-09 16:55:17 +0000699 unsigned has_pending_prioritised_gc; /* We think this device might
700 have pending prioritised gcs */
701 unsigned gc_disable;
702 unsigned gc_block_finder;
703 unsigned gc_dirtiest;
704 unsigned gc_pages_in_use;
705 unsigned gc_not_done;
706 unsigned gc_block;
707 unsigned gc_chunk;
708 unsigned gc_skip;
709 struct yaffs_summary_tags *gc_sum_tags;
William Juulc051bbe2007-11-15 11:13:05 +0100710
711 /* Special directories */
Charles Manning3796e1f2012-05-09 16:55:17 +0000712 struct yaffs_obj *root_dir;
713 struct yaffs_obj *lost_n_found;
William Juulc051bbe2007-11-15 11:13:05 +0100714
Charles Manning3796e1f2012-05-09 16:55:17 +0000715 int buffered_block; /* Which block is buffered here? */
716 int doing_buffered_block_rewrite;
William Juulc051bbe2007-11-15 11:13:05 +0100717
Charles Manning3796e1f2012-05-09 16:55:17 +0000718 struct yaffs_cache *cache;
719 int cache_last_use;
William Juulc051bbe2007-11-15 11:13:05 +0100720
Charles Manning3796e1f2012-05-09 16:55:17 +0000721 /* Stuff for background deletion and unlinked files. */
722 struct yaffs_obj *unlinked_dir; /* Directory where unlinked and deleted
723 files live. */
724 struct yaffs_obj *del_dir; /* Directory where deleted objects are
725 sent to disappear. */
726 struct yaffs_obj *unlinked_deletion; /* Current file being
727 background deleted. */
728 int n_deleted_files; /* Count of files awaiting deletion; */
729 int n_unlinked_files; /* Count of unlinked files. */
730 int n_bg_deletions; /* Count of background deletions. */
William Juulc051bbe2007-11-15 11:13:05 +0100731
Charles Manning3796e1f2012-05-09 16:55:17 +0000732 /* Temporary buffer management */
733 struct yaffs_buffer temp_buffer[YAFFS_N_TEMP_BUFFERS];
734 int max_temp;
735 int temp_in_use;
736 int unmanaged_buffer_allocs;
737 int unmanaged_buffer_deallocs;
William Juulc051bbe2007-11-15 11:13:05 +0100738
Charles Manning3796e1f2012-05-09 16:55:17 +0000739 /* yaffs2 runtime stuff */
740 unsigned seq_number; /* Sequence number of currently
741 allocating block */
742 unsigned oldest_dirty_seq;
743 unsigned oldest_dirty_block;
William Juulc051bbe2007-11-15 11:13:05 +0100744
Charles Manning3796e1f2012-05-09 16:55:17 +0000745 /* Block refreshing */
746 int refresh_skip; /* A skip down counter.
747 * Refresh happens when this gets to zero. */
William Juulc051bbe2007-11-15 11:13:05 +0100748
Charles Manning3796e1f2012-05-09 16:55:17 +0000749 /* Dirty directory handling */
750 struct list_head dirty_dirs; /* List of dirty directories */
William Juulc051bbe2007-11-15 11:13:05 +0100751
Charles Manning3796e1f2012-05-09 16:55:17 +0000752 /* Summary */
753 int chunks_per_summary;
754 struct yaffs_summary_tags *sum_tags;
William Juulc051bbe2007-11-15 11:13:05 +0100755
Charles Manning3796e1f2012-05-09 16:55:17 +0000756 /* Statistics */
757 u32 n_page_writes;
758 u32 n_page_reads;
759 u32 n_erasures;
760 u32 n_erase_failures;
761 u32 n_gc_copies;
762 u32 all_gcs;
763 u32 passive_gc_count;
764 u32 oldest_dirty_gc_count;
765 u32 n_gc_blocks;
766 u32 bg_gcs;
767 u32 n_retried_writes;
768 u32 n_retired_blocks;
769 u32 n_ecc_fixed;
770 u32 n_ecc_unfixed;
771 u32 n_tags_ecc_fixed;
772 u32 n_tags_ecc_unfixed;
773 u32 n_deletions;
774 u32 n_unmarked_deletions;
775 u32 refresh_count;
776 u32 cache_hits;
777 u32 tags_used;
778 u32 summary_used;
William Juulc051bbe2007-11-15 11:13:05 +0100779
Charles Manning3796e1f2012-05-09 16:55:17 +0000780};
Wolfgang Denk74e0dde2008-08-14 14:41:06 +0200781
Charles Manning3796e1f2012-05-09 16:55:17 +0000782/* The CheckpointDevice structure holds the device information that changes
783 *at runtime and must be preserved over unmount/mount cycles.
William Juulc051bbe2007-11-15 11:13:05 +0100784 */
Charles Manning3796e1f2012-05-09 16:55:17 +0000785struct yaffs_checkpt_dev {
786 int struct_type;
787 int n_erased_blocks;
788 int alloc_block; /* Current block being allocated off */
789 u32 alloc_page;
790 int n_free_chunks;
William Juulc051bbe2007-11-15 11:13:05 +0100791
Charles Manning3796e1f2012-05-09 16:55:17 +0000792 int n_deleted_files; /* Count of files awaiting deletion; */
793 int n_unlinked_files; /* Count of unlinked files. */
794 int n_bg_deletions; /* Count of background deletions. */
William Juulc051bbe2007-11-15 11:13:05 +0100795
796 /* yaffs2 runtime stuff */
Charles Manning3796e1f2012-05-09 16:55:17 +0000797 unsigned seq_number; /* Sequence number of currently
798 * allocating block */
William Juulc051bbe2007-11-15 11:13:05 +0100799
Charles Manning3796e1f2012-05-09 16:55:17 +0000800};
William Juulc051bbe2007-11-15 11:13:05 +0100801
Charles Manning3796e1f2012-05-09 16:55:17 +0000802struct yaffs_checkpt_validity {
803 int struct_type;
804 u32 magic;
805 u32 version;
806 u32 head;
807};
William Juulc051bbe2007-11-15 11:13:05 +0100808
Charles Manning3796e1f2012-05-09 16:55:17 +0000809struct yaffs_shadow_fixer {
810 int obj_id;
811 int shadowed_id;
812 struct yaffs_shadow_fixer *next;
813};
William Juulc051bbe2007-11-15 11:13:05 +0100814
Charles Manning3796e1f2012-05-09 16:55:17 +0000815/* Structure for doing xattr modifications */
816struct yaffs_xattr_mod {
817 int set; /* If 0 then this is a deletion */
818 const YCHAR *name;
819 const void *data;
820 int size;
821 int flags;
822 int result;
823};
William Juulc051bbe2007-11-15 11:13:05 +0100824
825/*----------------------- YAFFS Functions -----------------------*/
826
Charles Manning3796e1f2012-05-09 16:55:17 +0000827int yaffs_guts_initialise(struct yaffs_dev *dev);
828void yaffs_deinitialise(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100829
Charles Manning3796e1f2012-05-09 16:55:17 +0000830int yaffs_get_n_free_chunks(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100831
Charles Manning3796e1f2012-05-09 16:55:17 +0000832int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_name,
833 struct yaffs_obj *new_dir, const YCHAR * new_name);
William Juulc051bbe2007-11-15 11:13:05 +0100834
Charles Manning3796e1f2012-05-09 16:55:17 +0000835int yaffs_unlinker(struct yaffs_obj *dir, const YCHAR * name);
836int yaffs_del_obj(struct yaffs_obj *obj);
William Juulc051bbe2007-11-15 11:13:05 +0100837
Charles Manning3796e1f2012-05-09 16:55:17 +0000838int yaffs_get_obj_name(struct yaffs_obj *obj, YCHAR * name, int buffer_size);
839loff_t yaffs_get_obj_length(struct yaffs_obj *obj);
840int yaffs_get_obj_inode(struct yaffs_obj *obj);
841unsigned yaffs_get_obj_type(struct yaffs_obj *obj);
842int yaffs_get_obj_link_count(struct yaffs_obj *obj);
William Juulc051bbe2007-11-15 11:13:05 +0100843
844/* File operations */
Charles Manning3796e1f2012-05-09 16:55:17 +0000845int yaffs_file_rd(struct yaffs_obj *obj, u8 * buffer, loff_t offset,
846 int n_bytes);
847int yaffs_wr_file(struct yaffs_obj *obj, const u8 * buffer, loff_t offset,
848 int n_bytes, int write_trhrough);
849int yaffs_resize_file(struct yaffs_obj *obj, loff_t new_size);
William Juulc051bbe2007-11-15 11:13:05 +0100850
Charles Manning3796e1f2012-05-09 16:55:17 +0000851struct yaffs_obj *yaffs_create_file(struct yaffs_obj *parent,
852 const YCHAR *name, u32 mode, u32 uid,
853 u32 gid);
854
855int yaffs_flush_file(struct yaffs_obj *obj, int update_time, int data_sync);
William Juulc051bbe2007-11-15 11:13:05 +0100856
857/* Flushing and checkpointing */
Charles Manning3796e1f2012-05-09 16:55:17 +0000858void yaffs_flush_whole_cache(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100859
Charles Manning3796e1f2012-05-09 16:55:17 +0000860int yaffs_checkpoint_save(struct yaffs_dev *dev);
861int yaffs_checkpoint_restore(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100862
863/* Directory operations */
Charles Manning3796e1f2012-05-09 16:55:17 +0000864struct yaffs_obj *yaffs_create_dir(struct yaffs_obj *parent, const YCHAR *name,
865 u32 mode, u32 uid, u32 gid);
866struct yaffs_obj *yaffs_find_by_name(struct yaffs_obj *the_dir,
867 const YCHAR *name);
868struct yaffs_obj *yaffs_find_by_number(struct yaffs_dev *dev, u32 number);
William Juulc051bbe2007-11-15 11:13:05 +0100869
870/* Link operations */
Charles Manning3796e1f2012-05-09 16:55:17 +0000871struct yaffs_obj *yaffs_link_obj(struct yaffs_obj *parent, const YCHAR *name,
872 struct yaffs_obj *equiv_obj);
William Juulc051bbe2007-11-15 11:13:05 +0100873
Charles Manning3796e1f2012-05-09 16:55:17 +0000874struct yaffs_obj *yaffs_get_equivalent_obj(struct yaffs_obj *obj);
William Juulc051bbe2007-11-15 11:13:05 +0100875
876/* Symlink operations */
Charles Manning3796e1f2012-05-09 16:55:17 +0000877struct yaffs_obj *yaffs_create_symlink(struct yaffs_obj *parent,
878 const YCHAR *name, u32 mode, u32 uid,
879 u32 gid, const YCHAR *alias);
880YCHAR *yaffs_get_symlink_alias(struct yaffs_obj *obj);
William Juulc051bbe2007-11-15 11:13:05 +0100881
882/* Special inodes (fifos, sockets and devices) */
Charles Manning3796e1f2012-05-09 16:55:17 +0000883struct yaffs_obj *yaffs_create_special(struct yaffs_obj *parent,
884 const YCHAR *name, u32 mode, u32 uid,
885 u32 gid, u32 rdev);
886
887int yaffs_set_xattrib(struct yaffs_obj *obj, const YCHAR *name,
888 const void *value, int size, int flags);
889int yaffs_get_xattrib(struct yaffs_obj *obj, const YCHAR *name, void *value,
890 int size);
891int yaffs_list_xattrib(struct yaffs_obj *obj, char *buffer, int size);
892int yaffs_remove_xattrib(struct yaffs_obj *obj, const YCHAR *name);
William Juulc051bbe2007-11-15 11:13:05 +0100893
894/* Special directories */
Charles Manning3796e1f2012-05-09 16:55:17 +0000895struct yaffs_obj *yaffs_root(struct yaffs_dev *dev);
896struct yaffs_obj *yaffs_lost_n_found(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100897
Charles Manning3796e1f2012-05-09 16:55:17 +0000898void yaffs_handle_defered_free(struct yaffs_obj *obj);
William Juulc051bbe2007-11-15 11:13:05 +0100899
Charles Manning3796e1f2012-05-09 16:55:17 +0000900void yaffs_update_dirty_dirs(struct yaffs_dev *dev);
901
902int yaffs_bg_gc(struct yaffs_dev *dev, unsigned urgency);
William Juulc051bbe2007-11-15 11:13:05 +0100903
904/* Debug dump */
Charles Manning3796e1f2012-05-09 16:55:17 +0000905int yaffs_dump_obj(struct yaffs_obj *obj);
906
907void yaffs_guts_test(struct yaffs_dev *dev);
908
909/* A few useful functions to be used within the core files*/
910void yaffs_chunk_del(struct yaffs_dev *dev, int chunk_id, int mark_flash,
911 int lyn);
912int yaffs_check_ff(u8 *buffer, int n_bytes);
913void yaffs_handle_chunk_error(struct yaffs_dev *dev,
914 struct yaffs_block_info *bi);
915
916u8 *yaffs_get_temp_buffer(struct yaffs_dev *dev);
917void yaffs_release_temp_buffer(struct yaffs_dev *dev, u8 *buffer);
William Juulc051bbe2007-11-15 11:13:05 +0100918
Charles Manning3796e1f2012-05-09 16:55:17 +0000919struct yaffs_obj *yaffs_find_or_create_by_number(struct yaffs_dev *dev,
920 int number,
921 enum yaffs_obj_type type);
922int yaffs_put_chunk_in_file(struct yaffs_obj *in, int inode_chunk,
923 int nand_chunk, int in_scan);
924void yaffs_set_obj_name(struct yaffs_obj *obj, const YCHAR *name);
925void yaffs_set_obj_name_from_oh(struct yaffs_obj *obj,
926 const struct yaffs_obj_hdr *oh);
927void yaffs_add_obj_to_dir(struct yaffs_obj *directory, struct yaffs_obj *obj);
928YCHAR *yaffs_clone_str(const YCHAR *str);
929void yaffs_link_fixup(struct yaffs_dev *dev, struct list_head *hard_list);
930void yaffs_block_became_dirty(struct yaffs_dev *dev, int block_no);
931int yaffs_update_oh(struct yaffs_obj *in, const YCHAR *name,
932 int force, int is_shrink, int shadows,
933 struct yaffs_xattr_mod *xop);
934void yaffs_handle_shadowed_obj(struct yaffs_dev *dev, int obj_id,
935 int backward_scanning);
936int yaffs_check_alloc_available(struct yaffs_dev *dev, int n_chunks);
937struct yaffs_tnode *yaffs_get_tnode(struct yaffs_dev *dev);
938struct yaffs_tnode *yaffs_add_find_tnode_0(struct yaffs_dev *dev,
939 struct yaffs_file_var *file_struct,
940 u32 chunk_id,
941 struct yaffs_tnode *passed_tn);
942
943int yaffs_do_file_wr(struct yaffs_obj *in, const u8 *buffer, loff_t offset,
944 int n_bytes, int write_trhrough);
945void yaffs_resize_file_down(struct yaffs_obj *obj, loff_t new_size);
946void yaffs_skip_rest_of_block(struct yaffs_dev *dev);
947
948int yaffs_count_free_chunks(struct yaffs_dev *dev);
949
950struct yaffs_tnode *yaffs_find_tnode_0(struct yaffs_dev *dev,
951 struct yaffs_file_var *file_struct,
952 u32 chunk_id);
953
954u32 yaffs_get_group_base(struct yaffs_dev *dev, struct yaffs_tnode *tn,
955 unsigned pos);
956
957int yaffs_is_non_empty_dir(struct yaffs_obj *obj);
958
959void yaffs_addr_to_chunk(struct yaffs_dev *dev, loff_t addr,
960 int *chunk_out, u32 *offset_out);
961/*
962 * Marshalling functions to get loff_t file sizes into aand out of
963 * object headers.
964 */
965void yaffs_oh_size_load(struct yaffs_obj_hdr *oh, loff_t fsize);
966loff_t yaffs_oh_to_size(struct yaffs_obj_hdr *oh);
967loff_t yaffs_max_file_size(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100968
William Juulc051bbe2007-11-15 11:13:05 +0100969#endif