2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * Luc van OostenRyck for numerous patches.
10 * Nick Bane for numerous patches.
11 * Nick Bane for 2.5/2.6 integration.
12 * Andras Toth for mknod rdev issue.
13 * Michael Fischer for finding the problem with inode inconsistency.
14 * Some code bodily lifted from JFFS
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
23 * This is the file system front-end to YAFFS that hooks it up to
27 * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with
29 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this
31 * >> inode->u.generic_ip points to the associated yaffs_Object.
34 #include <linux/version.h>
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10))
37 #define YAFFS_COMPILE_BACKGROUND
40 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
41 #define YAFFS_COMPILE_EXPORTFS
45 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
46 #include <linux/config.h>
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <linux/slab.h>
52 #include <linux/init.h>
54 #include <linux/proc_fs.h>
55 #include <linux/smp_lock.h>
56 #include <linux/pagemap.h>
57 #include <linux/mtd/mtd.h>
58 #include <linux/interrupt.h>
59 #include <linux/string.h>
60 #include <linux/ctype.h>
62 #ifdef YAFFS_COMPILE_EXPORTFS
63 #include <linux/exportfs.h>
66 #ifdef YAFFS_COMPILE_BACKGROUND
67 #include <linux/kthread.h>
68 #include <linux/delay.h>
69 #include <linux/freezer.h>
72 #include <asm/div64.h>
74 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
76 #include <linux/statfs.h>
78 #define UnlockPage(p) unlock_page(p)
79 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
81 /* FIXME: use sb->s_id instead ? */
82 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
86 #include <linux/locks.h>
87 #define BDEVNAME_SIZE 0
88 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
90 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0))
91 /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */
97 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
98 #define YPROC_ROOT (&proc_root)
100 #define YPROC_ROOT NULL
103 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
104 #define WRITE_SIZE_STR "writesize"
105 #define WRITE_SIZE(mtd) ((mtd)->writesize)
107 #define WRITE_SIZE_STR "oobblock"
108 #define WRITE_SIZE(mtd) ((mtd)->oobblock)
111 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27))
112 #define YAFFS_USE_WRITE_BEGIN_END 1
114 #define YAFFS_USE_WRITE_BEGIN_END 0
117 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28))
118 static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size)
120 uint64_t result = partition_size;
121 do_div(result, block_size);
122 return (uint32_t)result;
125 #define YCALCBLOCKS(s, b) ((s)/(b))
128 #include <linux/uaccess.h>
129 #include <linux/mtd/mtd.h>
131 #include "yportenv.h"
132 #include "yaffs_trace.h"
133 #include "yaffs_guts.h"
135 #include "yaffs_linux.h"
137 #include "yaffs_mtdif.h"
138 #include "yaffs_mtdif1.h"
139 #include "yaffs_mtdif2.h"
141 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS | YAFFS_TRACE_ALWAYS;
142 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
143 unsigned int yaffs_auto_checkpoint = 1;
144 unsigned int yaffs_gc_control = 1;
146 /* Module Parameters */
147 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
148 module_param(yaffs_traceMask, uint, 0644);
149 module_param(yaffs_wr_attempts, uint, 0644);
150 module_param(yaffs_auto_checkpoint, uint, 0644);
151 module_param(yaffs_gc_control, uint, 0644);
153 MODULE_PARM(yaffs_traceMask, "i");
154 MODULE_PARM(yaffs_wr_attempts, "i");
155 MODULE_PARM(yaffs_auto_checkpoint, "i");
156 MODULE_PARM(yaffs_gc_control, "i");
159 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
160 /* use iget and read_inode */
161 #define Y_IGET(sb, inum) iget((sb), (inum))
162 static void yaffs_read_inode(struct inode *inode);
165 /* Call local equivalent */
166 #define YAFFS_USE_OWN_IGET
167 #define Y_IGET(sb, inum) yaffs_iget((sb), (inum))
169 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
172 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
173 #define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)
175 #define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip)
178 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
179 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
181 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
182 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
184 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
188 #define update_dir_time(dir) do {\
189 (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
192 static void yaffs_put_super(struct super_block *sb);
194 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
196 static ssize_t yaffs_hold_space(struct file *f);
197 static void yaffs_release_space(struct file *f);
199 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
200 static int yaffs_file_flush(struct file *file, fl_owner_t id);
202 static int yaffs_file_flush(struct file *file);
205 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
208 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
210 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
211 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
212 struct nameidata *n);
213 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
214 struct nameidata *n);
216 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
217 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
219 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
220 struct dentry *dentry);
221 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
222 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
223 const char *symname);
224 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
226 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
227 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
230 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
233 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
234 struct inode *new_dir, struct dentry *new_dentry);
235 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
237 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
238 static int yaffs_sync_fs(struct super_block *sb, int wait);
239 static void yaffs_write_super(struct super_block *sb);
241 static int yaffs_sync_fs(struct super_block *sb);
242 static int yaffs_write_super(struct super_block *sb);
245 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
246 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
247 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
248 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
250 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
253 #ifdef YAFFS_HAS_PUT_INODE
254 static void yaffs_put_inode(struct inode *inode);
257 static void yaffs_delete_inode(struct inode *);
258 static void yaffs_clear_inode(struct inode *);
260 static int yaffs_readpage(struct file *file, struct page *page);
261 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
262 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
264 static int yaffs_writepage(struct page *page);
268 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
269 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
270 loff_t pos, unsigned len, unsigned flags,
271 struct page **pagep, void **fsdata);
272 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
273 loff_t pos, unsigned len, unsigned copied,
274 struct page *pg, void *fsdadata);
276 static int yaffs_prepare_write(struct file *f, struct page *pg,
277 unsigned offset, unsigned to);
278 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
283 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
285 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
286 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
288 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
290 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin);
292 static struct address_space_operations yaffs_file_address_operations = {
293 .readpage = yaffs_readpage,
294 .writepage = yaffs_writepage,
295 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
296 .write_begin = yaffs_write_begin,
297 .write_end = yaffs_write_end,
299 .prepare_write = yaffs_prepare_write,
300 .commit_write = yaffs_commit_write,
304 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
305 static const struct file_operations yaffs_file_operations = {
306 .read = do_sync_read,
307 .write = do_sync_write,
308 .aio_read = generic_file_aio_read,
309 .aio_write = generic_file_aio_write,
310 .mmap = generic_file_mmap,
311 .flush = yaffs_file_flush,
312 .fsync = yaffs_sync_object,
313 .splice_read = generic_file_splice_read,
314 .splice_write = generic_file_splice_write,
315 .llseek = generic_file_llseek,
318 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
320 static const struct file_operations yaffs_file_operations = {
321 .read = do_sync_read,
322 .write = do_sync_write,
323 .aio_read = generic_file_aio_read,
324 .aio_write = generic_file_aio_write,
325 .mmap = generic_file_mmap,
326 .flush = yaffs_file_flush,
327 .fsync = yaffs_sync_object,
328 .sendfile = generic_file_sendfile,
333 static const struct file_operations yaffs_file_operations = {
334 .read = generic_file_read,
335 .write = generic_file_write,
336 .mmap = generic_file_mmap,
337 .flush = yaffs_file_flush,
338 .fsync = yaffs_sync_object,
339 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
340 .sendfile = generic_file_sendfile,
345 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
346 static void zero_user_segment(struct page *page, unsigned start, unsigned end)
348 void * kaddr = kmap_atomic(page, KM_USER0);
349 memset(kaddr + start, 0, end - start);
350 kunmap_atomic(kaddr, KM_USER0);
351 flush_dcache_page(page);
356 static const struct inode_operations yaffs_file_inode_operations = {
357 .setattr = yaffs_setattr,
360 static const struct inode_operations yaffs_symlink_inode_operations = {
361 .readlink = yaffs_readlink,
362 .follow_link = yaffs_follow_link,
363 .setattr = yaffs_setattr,
366 static const struct inode_operations yaffs_dir_inode_operations = {
367 .create = yaffs_create,
368 .lookup = yaffs_lookup,
370 .unlink = yaffs_unlink,
371 .symlink = yaffs_symlink,
372 .mkdir = yaffs_mkdir,
373 .rmdir = yaffs_unlink,
374 .mknod = yaffs_mknod,
375 .rename = yaffs_rename,
376 .setattr = yaffs_setattr,
379 static const struct file_operations yaffs_dir_operations = {
380 .read = generic_read_dir,
381 .readdir = yaffs_readdir,
382 .fsync = yaffs_sync_object,
383 .llseek = yaffs_dir_llseek,
386 static const struct super_operations yaffs_super_ops = {
387 .statfs = yaffs_statfs,
389 #ifndef YAFFS_USE_OWN_IGET
390 .read_inode = yaffs_read_inode,
392 #ifdef YAFFS_HAS_PUT_INODE
393 .put_inode = yaffs_put_inode,
395 .put_super = yaffs_put_super,
396 .delete_inode = yaffs_delete_inode,
397 .clear_inode = yaffs_clear_inode,
398 .sync_fs = yaffs_sync_fs,
399 .write_super = yaffs_write_super,
402 static unsigned yaffs_gc_control_callback(yaffs_Device *dev)
404 return yaffs_gc_control;
407 static void yaffs_GrossLock(yaffs_Device *dev)
409 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
410 down(&(yaffs_DeviceToContext(dev)->grossLock));
411 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locked %p\n"), current));
414 static void yaffs_GrossUnlock(yaffs_Device *dev)
416 T(YAFFS_TRACE_LOCK, (TSTR("yaffs unlocking %p\n"), current));
417 up(&(yaffs_DeviceToContext(dev)->grossLock));
420 #ifdef YAFFS_COMPILE_EXPORTFS
422 static struct inode *
423 yaffs2_nfs_get_inode(struct super_block *sb, uint64_t ino, uint32_t generation)
425 return Y_IGET(sb, ino);
428 static struct dentry *
429 yaffs2_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
431 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode) ;
434 static struct dentry *
435 yaffs2_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
437 return generic_fh_to_parent(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode);
440 struct dentry *yaffs2_get_parent(struct dentry *dentry)
443 struct super_block *sb = dentry->d_inode->i_sb;
444 struct dentry *parent = ERR_PTR(-ENOENT);
446 unsigned long parent_ino;
448 yaffs_Object *parent_obj;
450 d_obj = yaffs_InodeToObject(dentry->d_inode);
453 parent_obj = d_obj->parent;
455 parent_ino = yaffs_GetObjectInode(parent_obj);
456 inode = Y_IGET(sb, parent_ino);
459 parent = ERR_CAST(inode);
461 parent = d_obtain_alias(inode);
462 if (!IS_ERR(parent)) {
463 parent = ERR_PTR(-ENOMEM);
473 /* Just declare a zero structure as a NULL value implies
474 * using the default functions of exportfs.
477 static struct export_operations yaffs_export_ops =
479 .fh_to_dentry = yaffs2_fh_to_dentry,
480 .fh_to_parent = yaffs2_fh_to_parent,
481 .get_parent = yaffs2_get_parent,
486 /*-----------------------------------------------------------------*/
487 /* Directory search context allows us to unlock access to yaffs during
488 * filldir without causing problems with the directory being modified.
489 * This is similar to the tried and tested mechanism used in yaffs direct.
491 * A search context iterates along a doubly linked list of siblings in the
492 * directory. If the iterating object is deleted then this would corrupt
493 * the list iteration, likely causing a crash. The search context avoids
494 * this by using the removeObjectCallback to move the search context to the
495 * next object before the object is deleted.
497 * Many readdirs (and thus seach conexts) may be alive simulateously so
498 * each yaffs_Device has a list of these.
500 * A seach context lives for the duration of a readdir.
502 * All these functions must be called while yaffs is locked.
505 struct yaffs_SearchContext {
507 yaffs_Object *dirObj;
508 yaffs_Object *nextReturn;
509 struct ylist_head others;
513 * yaffs_NewSearch() creates a new search context, initialises it and
514 * adds it to the device's search context list.
516 * Called at start of readdir.
518 static struct yaffs_SearchContext * yaffs_NewSearch(yaffs_Object *dir)
520 yaffs_Device *dev = dir->myDev;
521 struct yaffs_SearchContext *sc = YMALLOC(sizeof(struct yaffs_SearchContext));
525 if( ylist_empty(&sc->dirObj->variant.directoryVariant.children))
526 sc->nextReturn = NULL;
528 sc->nextReturn = ylist_entry(
529 dir->variant.directoryVariant.children.next,
530 yaffs_Object,siblings);
531 YINIT_LIST_HEAD(&sc->others);
532 ylist_add(&sc->others,&(yaffs_DeviceToContext(dev)->searchContexts));
538 * yaffs_EndSearch() disposes of a search context and cleans up.
540 static void yaffs_EndSearch(struct yaffs_SearchContext * sc)
543 ylist_del(&sc->others);
549 * yaffs_SearchAdvance() moves a search context to the next object.
550 * Called when the search iterates or when an object removal causes
551 * the search context to be moved to the next object.
553 static void yaffs_SearchAdvance(struct yaffs_SearchContext *sc)
558 if( sc->nextReturn == NULL ||
559 ylist_empty(&sc->dirObj->variant.directoryVariant.children))
560 sc->nextReturn = NULL;
562 struct ylist_head *next = sc->nextReturn->siblings.next;
564 if( next == &sc->dirObj->variant.directoryVariant.children)
565 sc->nextReturn = NULL; /* end of list */
567 sc->nextReturn = ylist_entry(next,yaffs_Object,siblings);
572 * yaffs_RemoveObjectCallback() is called when an object is unlinked.
573 * We check open search contexts and advance any which are currently
574 * on the object being iterated.
576 static void yaffs_RemoveObjectCallback(yaffs_Object *obj)
579 struct ylist_head *i;
580 struct yaffs_SearchContext *sc;
581 struct ylist_head *search_contexts = &(yaffs_DeviceToContext(obj->myDev)->searchContexts);
584 /* Iterate through the directory search contexts.
585 * If any are currently on the object being removed, then advance
586 * the search context to the next object to prevent a hanging pointer.
588 ylist_for_each(i, search_contexts) {
590 sc = ylist_entry(i, struct yaffs_SearchContext,others);
591 if(sc->nextReturn == obj)
592 yaffs_SearchAdvance(sc);
599 /*-----------------------------------------------------------------*/
601 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
604 unsigned char *alias;
607 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
609 yaffs_GrossLock(dev);
611 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
613 yaffs_GrossUnlock(dev);
618 ret = vfs_readlink(dentry, buffer, buflen, alias);
623 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
624 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
626 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
629 unsigned char *alias;
631 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
633 yaffs_GrossLock(dev);
635 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
637 yaffs_GrossUnlock(dev);
644 ret = vfs_follow_link(nd, alias);
647 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
654 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
658 * Lookup is used to find objects in the fs
660 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
662 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
665 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
669 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
671 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
673 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
674 yaffs_GrossLock(dev);
677 (TSTR("yaffs_lookup for %d:%s\n"),
678 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
680 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
681 dentry->d_name.name);
683 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
685 /* Can't hold gross lock when calling yaffs_get_inode() */
686 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
687 yaffs_GrossUnlock(dev);
691 (TSTR("yaffs_lookup found %d\n"), obj->objectId));
693 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
697 (TSTR("yaffs_loookup dentry \n")));
698 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
699 * d_add even if NULL inode */
701 /*dget(dentry); // try to solve directory bug */
702 d_add(dentry, inode);
710 T(YAFFS_TRACE_OS,(TSTR("yaffs_lookup not found\n")));
714 /* added NCB for 2.5/6 compatability - forces add even if inode is
715 * NULL which creates dentry hash */
716 d_add(dentry, inode);
722 #ifdef YAFFS_HAS_PUT_INODE
724 /* For now put inode is just for debugging
725 * Put inode is called when the inode **structure** is put.
727 static void yaffs_put_inode(struct inode *inode)
730 (TSTR("yaffs_put_inode: ino %d, count %d\n"), (int)inode->i_ino,
731 atomic_read(&inode->i_count)));
736 /* clear is called to tell the fs to release any per-inode data it holds */
737 static void yaffs_clear_inode(struct inode *inode)
742 obj = yaffs_InodeToObject(inode);
745 (TSTR("yaffs_clear_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
746 atomic_read(&inode->i_count),
747 obj ? "object exists" : "null object"));
751 yaffs_GrossLock(dev);
753 /* Clear the association between the inode and
757 yaffs_InodeToObjectLV(inode) = NULL;
759 /* If the object freeing was deferred, then the real
761 * This should fix the inode inconsistency problem.
764 yaffs_HandleDeferedFree(obj);
766 yaffs_GrossUnlock(dev);
771 /* delete is called when the link count is zero and the inode
772 * is put (ie. nobody wants to know about it anymore, time to
774 * NB Must call clear_inode()
776 static void yaffs_delete_inode(struct inode *inode)
778 yaffs_Object *obj = yaffs_InodeToObject(inode);
782 (TSTR("yaffs_delete_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
783 atomic_read(&inode->i_count),
784 obj ? "object exists" : "null object"));
788 yaffs_GrossLock(dev);
789 yaffs_DeleteObject(obj);
790 yaffs_GrossUnlock(dev);
792 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
793 truncate_inode_pages(&inode->i_data, 0);
798 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
799 static int yaffs_file_flush(struct file *file, fl_owner_t id)
801 static int yaffs_file_flush(struct file *file)
804 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
806 yaffs_Device *dev = obj->myDev;
809 (TSTR("yaffs_file_flush object %d (%s)\n"), obj->objectId,
810 obj->dirty ? "dirty" : "clean"));
812 yaffs_GrossLock(dev);
814 yaffs_FlushFile(obj, 1, 0);
816 yaffs_GrossUnlock(dev);
821 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
823 /* Lifted from jffs2 */
826 unsigned char *pg_buf;
832 (TSTR("yaffs_readpage_nolock at %08x, size %08x\n"),
833 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
834 (unsigned)PAGE_CACHE_SIZE));
836 obj = yaffs_DentryToObject(f->f_dentry);
840 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
841 BUG_ON(!PageLocked(pg));
848 /* FIXME: Can kmap fail? */
850 yaffs_GrossLock(dev);
852 ret = yaffs_ReadDataFromFile(obj, pg_buf,
853 pg->index << PAGE_CACHE_SHIFT,
856 yaffs_GrossUnlock(dev);
862 ClearPageUptodate(pg);
869 flush_dcache_page(pg);
872 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage_nolock done\n")));
876 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
878 int ret = yaffs_readpage_nolock(f, pg);
883 static int yaffs_readpage(struct file *f, struct page *pg)
887 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage\n")));
888 ret=yaffs_readpage_unlock(f, pg);
889 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage done\n")));
893 /* writepage inspired by/stolen from smbfs */
895 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
896 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
898 static int yaffs_writepage(struct page *page)
901 struct address_space *mapping = page->mapping;
903 unsigned long end_index;
912 inode = mapping->host;
915 i_size = i_size_read(inode);
917 end_index = i_size >> PAGE_CACHE_SHIFT;
919 if(page->index < end_index)
920 nBytes = PAGE_CACHE_SIZE;
922 nBytes = i_size & (PAGE_CACHE_SIZE -1);
924 if (page->index > end_index || !nBytes) {
926 (TSTR("yaffs_writepage at %08x, inode size = %08x!!!\n"),
927 (unsigned)(page->index << PAGE_CACHE_SHIFT),
928 (unsigned)inode->i_size));
930 (TSTR(" -> don't care!!\n")));
932 zero_user_segment(page,0,PAGE_CACHE_SIZE);
933 set_page_writeback(page);
935 end_page_writeback(page);
940 if(nBytes != PAGE_CACHE_SIZE)
941 zero_user_segment(page,nBytes,PAGE_CACHE_SIZE);
947 obj = yaffs_InodeToObject(inode);
948 yaffs_GrossLock(obj->myDev);
951 (TSTR("yaffs_writepage at %08x, size %08x\n"),
952 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
954 (TSTR("writepag0: obj = %05x, ino = %05x\n"),
955 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
957 nWritten = yaffs_WriteDataToFile(obj, buffer,
958 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
961 (TSTR("writepag1: obj = %05x, ino = %05x\n"),
962 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
964 yaffs_GrossUnlock(obj->myDev);
967 set_page_writeback(page);
969 end_page_writeback(page);
972 return (nWritten == nBytes) ? 0 : -ENOSPC;
976 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
977 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
978 loff_t pos, unsigned len, unsigned flags,
979 struct page **pagep, void **fsdata)
981 struct page *pg = NULL;
982 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
988 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
989 pg = grab_cache_page_write_begin(mapping, index, flags);
991 pg = __grab_cache_page(mapping, index);
1000 (TSTR("start yaffs_write_begin index %d(%x) uptodate %d\n"),
1001 (int)index,(int)index,Page_Uptodate(pg) ? 1 : 0));
1004 space_held = yaffs_hold_space(filp);
1011 /* Update page if required */
1013 if (!Page_Uptodate(pg))
1014 ret = yaffs_readpage_nolock(filp, pg);
1019 /* Happy path return */
1020 T(YAFFS_TRACE_OS, (TSTR("end yaffs_write_begin - ok\n")));
1026 (TSTR("end yaffs_write_begin fail returning %d\n"), ret));
1028 yaffs_release_space(filp);
1031 page_cache_release(pg);
1038 static int yaffs_prepare_write(struct file *f, struct page *pg,
1039 unsigned offset, unsigned to)
1041 T(YAFFS_TRACE_OS, (TSTR("yaffs_prepair_write\n")));
1043 if (!Page_Uptodate(pg))
1044 return yaffs_readpage_nolock(f, pg);
1049 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1050 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1051 loff_t pos, unsigned len, unsigned copied,
1052 struct page *pg, void *fsdadata)
1056 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
1059 addr = kva + offset_into_page;
1062 ("yaffs_write_end addr %p pos %x nBytes %d\n",
1063 addr,(unsigned)pos, copied));
1065 ret = yaffs_file_write(filp, addr, copied, &pos);
1067 if (ret != copied) {
1069 (TSTR("yaffs_write_end not same size ret %d copied %d\n"),
1078 yaffs_release_space(filp);
1080 page_cache_release(pg);
1085 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1090 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
1091 int nBytes = to - offset;
1094 unsigned spos = pos;
1098 addr = kva + offset;
1100 saddr = (unsigned) addr;
1103 (TSTR("yaffs_commit_write addr %x pos %x nBytes %d\n"),
1104 saddr, spos, nBytes));
1106 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
1108 if (nWritten != nBytes) {
1110 (TSTR("yaffs_commit_write not same size nWritten %d nBytes %d\n"),
1120 (TSTR("yaffs_commit_write returning %d\n"),
1121 nWritten == nBytes ? 0 : nWritten));
1123 return nWritten == nBytes ? 0 : nWritten;
1128 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
1133 /* Check mode against the variant type and attempt to repair if broken. */
1134 __u32 mode = obj->yst_mode;
1135 switch (obj->variantType) {
1136 case YAFFS_OBJECT_TYPE_FILE:
1137 if (!S_ISREG(mode)) {
1138 obj->yst_mode &= ~S_IFMT;
1139 obj->yst_mode |= S_IFREG;
1143 case YAFFS_OBJECT_TYPE_SYMLINK:
1144 if (!S_ISLNK(mode)) {
1145 obj->yst_mode &= ~S_IFMT;
1146 obj->yst_mode |= S_IFLNK;
1150 case YAFFS_OBJECT_TYPE_DIRECTORY:
1151 if (!S_ISDIR(mode)) {
1152 obj->yst_mode &= ~S_IFMT;
1153 obj->yst_mode |= S_IFDIR;
1157 case YAFFS_OBJECT_TYPE_UNKNOWN:
1158 case YAFFS_OBJECT_TYPE_HARDLINK:
1159 case YAFFS_OBJECT_TYPE_SPECIAL:
1165 inode->i_flags |= S_NOATIME;
1167 inode->i_ino = obj->objectId;
1168 inode->i_mode = obj->yst_mode;
1169 inode->i_uid = obj->yst_uid;
1170 inode->i_gid = obj->yst_gid;
1171 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1172 inode->i_blksize = inode->i_sb->s_blocksize;
1174 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1176 inode->i_rdev = old_decode_dev(obj->yst_rdev);
1177 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
1178 inode->i_atime.tv_nsec = 0;
1179 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
1180 inode->i_mtime.tv_nsec = 0;
1181 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
1182 inode->i_ctime.tv_nsec = 0;
1184 inode->i_rdev = obj->yst_rdev;
1185 inode->i_atime = obj->yst_atime;
1186 inode->i_mtime = obj->yst_mtime;
1187 inode->i_ctime = obj->yst_ctime;
1189 inode->i_size = yaffs_GetObjectFileLength(obj);
1190 inode->i_blocks = (inode->i_size + 511) >> 9;
1192 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1195 (TSTR("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n"),
1196 inode->i_mode, inode->i_uid, inode->i_gid,
1197 (int)inode->i_size, atomic_read(&inode->i_count)));
1199 switch (obj->yst_mode & S_IFMT) {
1200 default: /* fifo, device or socket */
1201 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1202 init_special_inode(inode, obj->yst_mode,
1203 old_decode_dev(obj->yst_rdev));
1205 init_special_inode(inode, obj->yst_mode,
1206 (dev_t) (obj->yst_rdev));
1209 case S_IFREG: /* file */
1210 inode->i_op = &yaffs_file_inode_operations;
1211 inode->i_fop = &yaffs_file_operations;
1212 inode->i_mapping->a_ops =
1213 &yaffs_file_address_operations;
1215 case S_IFDIR: /* directory */
1216 inode->i_op = &yaffs_dir_inode_operations;
1217 inode->i_fop = &yaffs_dir_operations;
1219 case S_IFLNK: /* symlink */
1220 inode->i_op = &yaffs_symlink_inode_operations;
1224 yaffs_InodeToObjectLV(inode) = obj;
1226 obj->myInode = inode;
1230 (TSTR("yaffs_FileInode invalid parameters\n")));
1235 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1238 struct inode *inode;
1242 (TSTR("yaffs_get_inode for NULL super_block!!\n")));
1249 (TSTR("yaffs_get_inode for NULL object!!\n")));
1255 (TSTR("yaffs_get_inode for object %d\n"), obj->objectId));
1257 inode = Y_IGET(sb, obj->objectId);
1261 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1262 /* iget also increments the inode's i_count */
1263 /* NB You can't be holding grossLock or deadlock will happen! */
1268 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1273 struct inode *inode;
1276 obj = yaffs_DentryToObject(f->f_dentry);
1280 yaffs_GrossLock(dev);
1282 inode = f->f_dentry->d_inode;
1284 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
1285 ipos = inode->i_size;
1291 (TSTR("yaffs_file_write: hey obj is null!\n")));
1294 (TSTR("yaffs_file_write about to write writing %u(%x) bytes"
1295 "to object %d at %d(%x)\n"),
1296 (unsigned) n, (unsigned) n, obj->objectId, ipos,ipos));
1298 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1301 (TSTR("yaffs_file_write: %d(%x) bytes written\n"),
1302 (unsigned )n,(unsigned)n));
1307 if (ipos > inode->i_size) {
1308 inode->i_size = ipos;
1309 inode->i_blocks = (ipos + 511) >> 9;
1312 (TSTR("yaffs_file_write size updated to %d bytes, "
1314 ipos, (int)(inode->i_blocks)));
1318 yaffs_GrossUnlock(dev);
1319 return (nWritten == 0) && (n > 0) ? -ENOSPC : nWritten;
1322 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1323 /* For now we just assume few parallel writes and check against a small number. */
1324 /* Todo: need to do this with a counter to handle parallel reads better */
1326 static ssize_t yaffs_hold_space(struct file *f)
1334 obj = yaffs_DentryToObject(f->f_dentry);
1338 yaffs_GrossLock(dev);
1340 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1342 yaffs_GrossUnlock(dev);
1344 return (nFreeChunks > 20) ? 1 : 0;
1347 static void yaffs_release_space(struct file *f)
1353 obj = yaffs_DentryToObject(f->f_dentry);
1357 yaffs_GrossLock(dev);
1360 yaffs_GrossUnlock(dev);
1364 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin)
1372 offset += i_size_read(file->f_path.dentry->d_inode);
1375 offset += file->f_pos;
1380 if (offset != file->f_pos)
1381 file->f_pos = offset;
1390 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1394 struct yaffs_SearchContext *sc;
1395 struct inode *inode = f->f_dentry->d_inode;
1396 unsigned long offset, curoffs;
1400 char name[YAFFS_MAX_NAME_LENGTH + 1];
1402 obj = yaffs_DentryToObject(f->f_dentry);
1405 yaffs_GrossLock(dev);
1407 yaffs_DeviceToContext(dev)->readdirProcess = current;
1411 sc = yaffs_NewSearch(obj);
1417 T(YAFFS_TRACE_OS, (TSTR("yaffs_readdir: starting at %d\n"), (int)offset));
1421 (TSTR("yaffs_readdir: entry . ino %d \n"),
1422 (int)inode->i_ino));
1423 yaffs_GrossUnlock(dev);
1424 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1426 yaffs_GrossLock(dev);
1432 (TSTR("yaffs_readdir: entry .. ino %d \n"),
1433 (int)f->f_dentry->d_parent->d_inode->i_ino));
1434 yaffs_GrossUnlock(dev);
1435 if (filldir(dirent, "..", 2, offset,
1436 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1438 yaffs_GrossLock(dev);
1445 /* If the directory has changed since the open or last call to
1446 readdir, rewind to after the 2 canned entries. */
1447 if (f->f_version != inode->i_version) {
1450 f->f_version = inode->i_version;
1453 while(sc->nextReturn){
1456 if (curoffs >= offset) {
1457 int this_inode = yaffs_GetObjectInode(l);
1458 int this_type = yaffs_GetObjectType(l);
1460 yaffs_GetObjectName(l, name,
1461 YAFFS_MAX_NAME_LENGTH + 1);
1463 (TSTR("yaffs_readdir: %s inode %d\n"),
1464 name, yaffs_GetObjectInode(l)));
1466 yaffs_GrossUnlock(dev);
1476 yaffs_GrossLock(dev);
1481 yaffs_SearchAdvance(sc);
1485 yaffs_DeviceToContext(dev)->readdirProcess = NULL;
1487 yaffs_GrossUnlock(dev);
1489 yaffs_EndSearch(sc);
1497 * File creation. Allocate an inode, and we're done..
1500 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1503 #define YCRED(x) (x->cred)
1506 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1507 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1510 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1514 struct inode *inode;
1516 yaffs_Object *obj = NULL;
1519 yaffs_Object *parent = yaffs_InodeToObject(dir);
1521 int error = -ENOSPC;
1522 uid_t uid = YCRED(current)->fsuid;
1523 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1525 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1530 (TSTR("yaffs_mknod: parent object %d type %d\n"),
1531 parent->objectId, parent->variantType));
1534 (TSTR("yaffs_mknod: could not get parent object\n")));
1538 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
1539 "mode %x dev %x\n"),
1540 dentry->d_name.name, mode, rdev));
1542 dev = parent->myDev;
1544 yaffs_GrossLock(dev);
1546 switch (mode & S_IFMT) {
1548 /* Special (socket, fifo, device...) */
1549 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making special\n")));
1550 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1551 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1552 gid, old_encode_dev(rdev));
1554 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1558 case S_IFREG: /* file */
1559 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making file\n")));
1560 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1563 case S_IFDIR: /* directory */
1565 (TSTR("yaffs_mknod: making directory\n")));
1566 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1569 case S_IFLNK: /* symlink */
1570 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making symlink\n")));
1571 obj = NULL; /* Do we ever get here? */
1575 /* Can not call yaffs_get_inode() with gross lock held */
1576 yaffs_GrossUnlock(dev);
1579 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1580 d_instantiate(dentry, inode);
1581 update_dir_time(dir);
1583 (TSTR("yaffs_mknod created object %d count = %d\n"),
1584 obj->objectId, atomic_read(&inode->i_count)));
1586 yaffs_FillInodeFromObject(dir,parent);
1589 (TSTR("yaffs_mknod failed making object\n")));
1596 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1599 T(YAFFS_TRACE_OS, (TSTR("yaffs_mkdir\n")));
1600 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1604 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1605 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1606 struct nameidata *n)
1608 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1611 T(YAFFS_TRACE_OS,(TSTR("yaffs_create\n")));
1612 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1615 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1623 (TSTR("yaffs_unlink %d:%s\n"),
1625 dentry->d_name.name));
1626 obj = yaffs_InodeToObject(dir);
1629 yaffs_GrossLock(dev);
1631 retVal = yaffs_Unlink(obj, dentry->d_name.name);
1633 if (retVal == YAFFS_OK) {
1634 dentry->d_inode->i_nlink--;
1636 yaffs_GrossUnlock(dev);
1637 mark_inode_dirty(dentry->d_inode);
1638 update_dir_time(dir);
1641 yaffs_GrossUnlock(dev);
1648 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1649 struct dentry *dentry)
1651 struct inode *inode = old_dentry->d_inode;
1652 yaffs_Object *obj = NULL;
1653 yaffs_Object *link = NULL;
1656 T(YAFFS_TRACE_OS, (TSTR("yaffs_link\n")));
1658 obj = yaffs_InodeToObject(inode);
1661 yaffs_GrossLock(dev);
1663 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1664 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1668 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1669 d_instantiate(dentry, old_dentry->d_inode);
1670 atomic_inc(&old_dentry->d_inode->i_count);
1672 (TSTR("yaffs_link link count %d i_count %d\n"),
1673 old_dentry->d_inode->i_nlink,
1674 atomic_read(&old_dentry->d_inode->i_count)));
1677 yaffs_GrossUnlock(dev);
1680 update_dir_time(dir);
1687 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1688 const char *symname)
1692 uid_t uid = YCRED(current)->fsuid;
1693 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1695 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
1697 dev = yaffs_InodeToObject(dir)->myDev;
1698 yaffs_GrossLock(dev);
1699 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1700 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1701 yaffs_GrossUnlock(dev);
1704 struct inode *inode;
1706 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1707 d_instantiate(dentry, inode);
1708 update_dir_time(dir);
1709 T(YAFFS_TRACE_OS, (TSTR("symlink created OK\n")));
1712 T(YAFFS_TRACE_OS, (TSTR("symlink not created\n")));
1718 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1725 obj = yaffs_DentryToObject(dentry);
1729 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
1730 (TSTR("yaffs_sync_object\n")));
1731 yaffs_GrossLock(dev);
1732 yaffs_FlushFile(obj, 1, datasync);
1733 yaffs_GrossUnlock(dev);
1738 * The VFS layer already does all the dentry stuff for rename.
1740 * NB: POSIX says you can rename an object over an old object of the same name
1742 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1743 struct inode *new_dir, struct dentry *new_dentry)
1746 int retVal = YAFFS_FAIL;
1747 yaffs_Object *target;
1749 T(YAFFS_TRACE_OS, (TSTR("yaffs_rename\n")));
1750 dev = yaffs_InodeToObject(old_dir)->myDev;
1752 yaffs_GrossLock(dev);
1754 /* Check if the target is an existing directory that is not empty. */
1755 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1756 new_dentry->d_name.name);
1760 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1761 !ylist_empty(&target->variant.directoryVariant.children)) {
1763 T(YAFFS_TRACE_OS, (TSTR("target is non-empty dir\n")));
1765 retVal = YAFFS_FAIL;
1767 /* Now does unlinking internally using shadowing mechanism */
1768 T(YAFFS_TRACE_OS, (TSTR("calling yaffs_RenameObject\n")));
1770 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1771 old_dentry->d_name.name,
1772 yaffs_InodeToObject(new_dir),
1773 new_dentry->d_name.name);
1775 yaffs_GrossUnlock(dev);
1777 if (retVal == YAFFS_OK) {
1779 new_dentry->d_inode->i_nlink--;
1780 mark_inode_dirty(new_dentry->d_inode);
1783 update_dir_time(old_dir);
1784 if(old_dir != new_dir)
1785 update_dir_time(new_dir);
1792 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1794 struct inode *inode = dentry->d_inode;
1799 (TSTR("yaffs_setattr of object %d\n"),
1800 yaffs_InodeToObject(inode)->objectId));
1802 /* Fail if a requested resize >= 2GB */
1803 if (attr->ia_valid & ATTR_SIZE &&
1804 (attr->ia_size >> 31))
1808 error = inode_change_ok(inode, attr);
1812 error = inode_setattr(inode, attr);
1813 T(YAFFS_TRACE_OS,(TSTR("inode_setattr called\n")));
1814 if (attr->ia_valid & ATTR_SIZE)
1815 truncate_inode_pages(&inode->i_data,attr->ia_size);
1817 dev = yaffs_InodeToObject(inode)->myDev;
1818 if (attr->ia_valid & ATTR_SIZE){
1819 T(YAFFS_TRACE_OS,(TSTR("resize to %d(%x)\n"),
1820 (int)(attr->ia_size),(int)(attr->ia_size)));
1822 yaffs_GrossLock(dev);
1823 result = yaffs_SetAttributes(yaffs_InodeToObject(inode), attr);
1824 if(result == YAFFS_OK) {
1829 yaffs_GrossUnlock(dev);
1834 (TSTR("yaffs_setattr done returning %d\n"),error));
1839 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1840 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1842 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1843 struct super_block *sb = dentry->d_sb;
1844 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1845 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1847 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1849 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1851 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1854 T(YAFFS_TRACE_OS, (TSTR("yaffs_statfs\n")));
1856 yaffs_GrossLock(dev);
1858 buf->f_type = YAFFS_MAGIC;
1859 buf->f_bsize = sb->s_blocksize;
1860 buf->f_namelen = 255;
1862 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
1863 /* Do this if chunk size is not a power of 2 */
1865 uint64_t bytesInDev;
1868 bytesInDev = ((uint64_t)((dev->param.endBlock - dev->param.startBlock + 1))) *
1869 ((uint64_t)(dev->param.nChunksPerBlock * dev->nDataBytesPerChunk));
1871 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
1872 buf->f_blocks = bytesInDev;
1874 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
1875 ((uint64_t)(dev->nDataBytesPerChunk));
1877 do_div(bytesFree, sb->s_blocksize);
1879 buf->f_bfree = bytesFree;
1881 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
1884 (dev->param.endBlock - dev->param.startBlock + 1) *
1885 dev->param.nChunksPerBlock /
1886 (sb->s_blocksize / dev->nDataBytesPerChunk);
1888 yaffs_GetNumberOfFreeChunks(dev) /
1889 (sb->s_blocksize / dev->nDataBytesPerChunk);
1892 (dev->param.endBlock - dev->param.startBlock + 1) *
1893 dev->param.nChunksPerBlock *
1894 (dev->nDataBytesPerChunk / sb->s_blocksize);
1897 yaffs_GetNumberOfFreeChunks(dev) *
1898 (dev->nDataBytesPerChunk / sb->s_blocksize);
1903 buf->f_bavail = buf->f_bfree;
1905 yaffs_GrossUnlock(dev);
1911 static void yaffs_FlushInodes(struct super_block *sb)
1916 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
1917 obj = yaffs_InodeToObject(iptr);
1919 T(YAFFS_TRACE_OS, (TSTR("flushing obj %d\n"),
1921 yaffs_FlushFile(obj,1,0);
1927 static void yaffs_FlushSuperBlock(struct super_block *sb, int do_checkpoint)
1929 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1933 yaffs_FlushInodes(sb);
1934 yaffs_UpdateDirtyDirectories(dev);
1935 yaffs_FlushEntireDeviceCache(dev);
1937 yaffs_CheckpointSave(dev);
1941 static unsigned yaffs_bg_gc_urgency(yaffs_Device *dev)
1943 unsigned erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
1944 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
1945 unsigned scatteredFree = 0; /* Free chunks not in an erased block */
1947 if(erasedChunks < dev->nFreeChunks)
1948 scatteredFree = (dev->nFreeChunks - erasedChunks);
1950 if(!context->bgRunning)
1952 else if(scatteredFree < (dev->param.nChunksPerBlock * 2))
1954 else if(erasedChunks > dev->nFreeChunks/2)
1956 else if(erasedChunks > dev->nFreeChunks/4)
1962 static int yaffs_do_sync_fs(struct super_block *sb,
1963 int request_checkpoint)
1966 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1967 unsigned int oneshot_checkpoint = (yaffs_auto_checkpoint & 4);
1968 unsigned gc_urgent = yaffs_bg_gc_urgency(dev);
1971 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
1972 (TSTR("yaffs_do_sync_fs: gc-urgency %d %s %s%s\n"),
1974 sb->s_dirt ? "dirty" : "clean",
1975 request_checkpoint ? "checkpoint requested" : "no checkpoint",
1976 oneshot_checkpoint ? " one-shot" : "" ));
1978 yaffs_GrossLock(dev);
1979 do_checkpoint = ((request_checkpoint && !gc_urgent) ||
1980 oneshot_checkpoint) &&
1981 !dev->isCheckpointed;
1983 if (sb->s_dirt || do_checkpoint) {
1984 yaffs_FlushSuperBlock(sb, !dev->isCheckpointed && do_checkpoint);
1986 if(oneshot_checkpoint)
1987 yaffs_auto_checkpoint &= ~4;
1989 yaffs_GrossUnlock(dev);
1995 * yaffs background thread functions .
1996 * yaffs_BackgroundThread() the thread function
1997 * yaffs_BackgroundStart() launches the background thread.
1998 * yaffs_BackgroundStop() cleans up the background thread.
2001 * The thread should only run after the yaffs is initialised
2002 * The thread should be stopped before yaffs is unmounted.
2003 * The thread should not do any writing while the fs is in read only.
2006 #ifdef YAFFS_COMPILE_BACKGROUND
2008 void yaffs_background_waker(unsigned long data)
2010 wake_up_process((struct task_struct *)data);
2013 static int yaffs_BackgroundThread(void *data)
2015 yaffs_Device *dev = (yaffs_Device *)data;
2016 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2017 unsigned long now = jiffies;
2018 unsigned long next_dir_update = now;
2019 unsigned long next_gc = now;
2020 unsigned long expires;
2021 unsigned int urgency;
2024 struct timer_list timer;
2026 T(YAFFS_TRACE_BACKGROUND,
2027 (TSTR("yaffs_background starting for dev %p\n"),
2032 while(context->bgRunning){
2033 T(YAFFS_TRACE_BACKGROUND,
2034 (TSTR("yaffs_background\n")));
2036 if(kthread_should_stop())
2042 yaffs_GrossLock(dev);
2046 if(time_after(now, next_dir_update)){
2047 yaffs_UpdateDirtyDirectories(dev);
2048 next_dir_update = now + HZ;
2051 if(time_after(now,next_gc)){
2052 if(!dev->isCheckpointed){
2053 urgency = yaffs_bg_gc_urgency(dev);
2054 gcResult = yaffs_BackgroundGarbageCollect(dev, urgency);
2056 next_gc = now + HZ/20+1;
2057 else if(urgency > 0)
2058 next_gc = now + HZ/10+1;
2060 next_gc = now + HZ * 2;
2062 * gc not running so set to next_dir_update
2063 * to cut down on wake ups
2065 next_gc = next_dir_update;
2067 yaffs_GrossUnlock(dev);
2069 expires = next_dir_update;
2070 if (time_before(next_gc,expires))
2072 if(time_before(expires,now))
2076 timer.expires = expires+1;
2077 timer.data = (unsigned long) current;
2078 timer.function = yaffs_background_waker;
2080 set_current_state(TASK_INTERRUPTIBLE);
2083 del_timer_sync(&timer);
2092 static int yaffs_BackgroundStart(yaffs_Device *dev)
2095 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2097 context->bgRunning = 1;
2099 context->bgThread = kthread_run(yaffs_BackgroundThread,
2100 (void *)dev,"yaffs-bg");
2102 if(IS_ERR(context->bgThread)){
2103 retval = PTR_ERR(context->bgThread);
2104 context->bgThread = NULL;
2105 context->bgRunning = 0;
2110 static void yaffs_BackgroundStop(yaffs_Device *dev)
2112 struct yaffs_LinuxContext *ctxt = yaffs_DeviceToContext(dev);
2114 ctxt->bgRunning = 0;
2116 if( ctxt->bgThread){
2117 kthread_stop(ctxt->bgThread);
2118 ctxt->bgThread = NULL;
2122 static int yaffs_BackgroundThread(void *data)
2127 static int yaffs_BackgroundStart(yaffs_Device *dev)
2132 static void yaffs_BackgroundStop(yaffs_Device *dev)
2138 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2139 static void yaffs_write_super(struct super_block *sb)
2141 static int yaffs_write_super(struct super_block *sb)
2144 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 2);
2146 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2147 (TSTR("yaffs_write_super%s\n"),
2148 request_checkpoint ? " checkpt" : ""));
2150 yaffs_do_sync_fs(sb, request_checkpoint);
2152 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2158 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2159 static int yaffs_sync_fs(struct super_block *sb, int wait)
2161 static int yaffs_sync_fs(struct super_block *sb)
2164 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 1);
2166 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
2167 (TSTR("yaffs_sync_fs%s\n"),
2168 request_checkpoint ? " checkpt" : ""));
2170 yaffs_do_sync_fs(sb, request_checkpoint);
2175 #ifdef YAFFS_USE_OWN_IGET
2177 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2179 struct inode *inode;
2181 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2184 (TSTR("yaffs_iget for %lu\n"), ino));
2186 inode = iget_locked(sb, ino);
2188 return ERR_PTR(-ENOMEM);
2189 if (!(inode->i_state & I_NEW))
2192 /* NB This is called as a side effect of other functions, but
2193 * we had to release the lock to prevent deadlocks, so
2194 * need to lock again.
2197 yaffs_GrossLock(dev);
2199 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2201 yaffs_FillInodeFromObject(inode, obj);
2203 yaffs_GrossUnlock(dev);
2205 unlock_new_inode(inode);
2211 static void yaffs_read_inode(struct inode *inode)
2213 /* NB This is called as a side effect of other functions, but
2214 * we had to release the lock to prevent deadlocks, so
2215 * need to lock again.
2219 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2222 (TSTR("yaffs_read_inode for %d\n"), (int)inode->i_ino));
2224 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2225 yaffs_GrossLock(dev);
2227 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2229 yaffs_FillInodeFromObject(inode, obj);
2231 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2232 yaffs_GrossUnlock(dev);
2237 static YLIST_HEAD(yaffs_context_list);
2238 struct semaphore yaffs_context_lock;
2240 #if 0 /* not used */
2241 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2243 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2245 if (*flags & MS_RDONLY) {
2246 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2249 (TSTR("yaffs_remount_fs: %s: RO\n"), dev->name));
2251 yaffs_GrossLock(dev);
2253 yaffs_FlushSuperBlock(sb,1);
2258 yaffs_GrossUnlock(dev);
2261 (TSTR("yaffs_remount_fs: %s: RW\n"), dev->name));
2268 static void yaffs_put_super(struct super_block *sb)
2270 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2272 T(YAFFS_TRACE_OS, (TSTR("yaffs_put_super\n")));
2274 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2275 (TSTR("Shutting down yaffs background thread\n")));
2276 yaffs_BackgroundStop(dev);
2277 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2278 (TSTR("yaffs background thread shut down\n")));
2280 yaffs_GrossLock(dev);
2282 yaffs_FlushSuperBlock(sb,1);
2284 if (yaffs_DeviceToContext(dev)->putSuperFunc)
2285 yaffs_DeviceToContext(dev)->putSuperFunc(sb);
2288 yaffs_Deinitialise(dev);
2290 yaffs_GrossUnlock(dev);
2292 down(&yaffs_context_lock);
2293 ylist_del_init(&(yaffs_DeviceToContext(dev)->contextList));
2294 up(&yaffs_context_lock);
2296 if (yaffs_DeviceToContext(dev)->spareBuffer) {
2297 YFREE(yaffs_DeviceToContext(dev)->spareBuffer);
2298 yaffs_DeviceToContext(dev)->spareBuffer = NULL;
2305 static void yaffs_MTDPutSuper(struct super_block *sb)
2307 struct mtd_info *mtd = yaffs_DeviceToContext(yaffs_SuperToDevice(sb))->mtd;
2312 put_mtd_device(mtd);
2316 static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev)
2318 struct super_block *sb = yaffs_DeviceToContext(dev)->superBlock;
2320 T(YAFFS_TRACE_OS, (TSTR("yaffs_MarkSuperBlockDirty() sb = %p\n"), sb));
2327 int skip_checkpoint_read;
2328 int skip_checkpoint_write;
2331 int tags_ecc_overridden;
2332 int lazy_loading_enabled;
2333 int lazy_loading_overridden;
2334 int empty_lost_and_found;
2335 int empty_lost_and_found_overridden;
2338 #define MAX_OPT_LEN 30
2339 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2341 char cur_opt[MAX_OPT_LEN + 1];
2345 /* Parse through the options which is a comma seperated list */
2347 while (options_str && *options_str && !error) {
2348 memset(cur_opt, 0, MAX_OPT_LEN + 1);
2351 while(*options_str == ',')
2354 while (*options_str && *options_str != ',') {
2355 if (p < MAX_OPT_LEN) {
2356 cur_opt[p] = *options_str;
2362 if (!strcmp(cur_opt, "inband-tags"))
2363 options->inband_tags = 1;
2364 else if (!strcmp(cur_opt, "tags-ecc-off")){
2365 options->tags_ecc_on = 0;
2366 options->tags_ecc_overridden=1;
2367 } else if (!strcmp(cur_opt, "tags-ecc-on")){
2368 options->tags_ecc_on = 1;
2369 options->tags_ecc_overridden = 1;
2370 } else if (!strcmp(cur_opt, "lazy-loading-off")){
2371 options->lazy_loading_enabled = 0;
2372 options->lazy_loading_overridden=1;
2373 } else if (!strcmp(cur_opt, "lazy-loading-on")){
2374 options->lazy_loading_enabled = 1;
2375 options->lazy_loading_overridden = 1;
2376 } else if (!strcmp(cur_opt, "empty-lost-and-found-off")){
2377 options->empty_lost_and_found = 0;
2378 options->empty_lost_and_found_overridden=1;
2379 } else if (!strcmp(cur_opt, "empty-lost-and-found-on")){
2380 options->empty_lost_and_found = 1;
2381 options->empty_lost_and_found_overridden=1;
2382 } else if (!strcmp(cur_opt, "no-cache"))
2383 options->no_cache = 1;
2384 else if (!strcmp(cur_opt, "no-checkpoint-read"))
2385 options->skip_checkpoint_read = 1;
2386 else if (!strcmp(cur_opt, "no-checkpoint-write"))
2387 options->skip_checkpoint_write = 1;
2388 else if (!strcmp(cur_opt, "no-checkpoint")) {
2389 options->skip_checkpoint_read = 1;
2390 options->skip_checkpoint_write = 1;
2392 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2401 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2402 struct super_block *sb,
2403 void *data, int silent)
2406 struct inode *inode = NULL;
2407 struct dentry *root;
2408 yaffs_Device *dev = 0;
2409 char devname_buf[BDEVNAME_SIZE + 1];
2410 struct mtd_info *mtd;
2412 char *data_str = (char *)data;
2413 struct yaffs_LinuxContext *context = NULL;
2414 yaffs_DeviceParam *param;
2416 yaffs_options options;
2418 sb->s_magic = YAFFS_MAGIC;
2419 sb->s_op = &yaffs_super_ops;
2420 sb->s_flags |= MS_NOATIME;
2422 #ifdef YAFFS_COMPILE_EXPORTFS
2423 sb->s_export_op = &yaffs_export_ops;
2427 printk(KERN_INFO "yaffs: sb is NULL\n");
2428 else if (!sb->s_dev)
2429 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
2430 else if (!yaffs_devname(sb, devname_buf))
2431 printk(KERN_INFO "yaffs: devname is NULL\n");
2433 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
2435 yaffs_devname(sb, devname_buf));
2440 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2442 memset(&options, 0, sizeof(options));
2444 if (yaffs_parse_options(&options, data_str)) {
2445 /* Option parsing failed */
2450 sb->s_blocksize = PAGE_CACHE_SIZE;
2451 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
2454 (TSTR("yaffs_read_super: Using yaffs%d\n"), yaffsVersion));
2456 (TSTR("yaffs_read_super: block size %d\n"),
2457 (int)(sb->s_blocksize)));
2459 T(YAFFS_TRACE_ALWAYS,
2460 (TSTR("yaffs: Attempting MTD mount of %u.%u,\"%s\"\n"),
2461 MAJOR(sb->s_dev), MINOR(sb->s_dev),
2462 yaffs_devname(sb, devname_buf)));
2464 /* Check it's an mtd device..... */
2465 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2466 return NULL; /* This isn't an mtd device */
2468 /* Get the device */
2469 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2471 T(YAFFS_TRACE_ALWAYS,
2472 (TSTR("yaffs: MTD device #%u doesn't appear to exist\n"),
2476 /* Check it's NAND */
2477 if (mtd->type != MTD_NANDFLASH) {
2478 T(YAFFS_TRACE_ALWAYS,
2479 (TSTR("yaffs: MTD device is not NAND it's type %d\n"),
2484 T(YAFFS_TRACE_OS, (TSTR(" erase %p\n"), mtd->erase));
2485 T(YAFFS_TRACE_OS, (TSTR(" read %p\n"), mtd->read));
2486 T(YAFFS_TRACE_OS, (TSTR(" write %p\n"), mtd->write));
2487 T(YAFFS_TRACE_OS, (TSTR(" readoob %p\n"), mtd->read_oob));
2488 T(YAFFS_TRACE_OS, (TSTR(" writeoob %p\n"), mtd->write_oob));
2489 T(YAFFS_TRACE_OS, (TSTR(" block_isbad %p\n"), mtd->block_isbad));
2490 T(YAFFS_TRACE_OS, (TSTR(" block_markbad %p\n"), mtd->block_markbad));
2491 T(YAFFS_TRACE_OS, (TSTR(" %s %d\n"), WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2492 T(YAFFS_TRACE_OS, (TSTR(" oobsize %d\n"), mtd->oobsize));
2493 T(YAFFS_TRACE_OS, (TSTR(" erasesize %d\n"), mtd->erasesize));
2494 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2495 T(YAFFS_TRACE_OS, (TSTR(" size %u\n"), mtd->size));
2497 T(YAFFS_TRACE_OS, (TSTR(" size %lld\n"), mtd->size));
2500 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2502 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2503 T(YAFFS_TRACE_ALWAYS,
2504 (TSTR("yaffs: auto selecting yaffs2\n")));
2508 /* Added NCB 26/5/2006 for completeness */
2509 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2510 T(YAFFS_TRACE_ALWAYS,
2511 (TSTR("yaffs: auto selecting yaffs1\n")));
2517 if (yaffsVersion == 2) {
2518 /* Check for version 2 style functions */
2520 !mtd->block_isbad ||
2521 !mtd->block_markbad ||
2524 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2525 !mtd->read_oob || !mtd->write_oob) {
2528 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2530 T(YAFFS_TRACE_ALWAYS,
2531 (TSTR("yaffs: MTD device does not support required "
2536 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
2537 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
2538 !options.inband_tags) {
2539 T(YAFFS_TRACE_ALWAYS,
2540 (TSTR("yaffs: MTD device does not have the "
2541 "right page sizes\n")));
2545 /* Check for V1 style functions */
2549 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2550 !mtd->read_oob || !mtd->write_oob) {
2553 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2555 T(YAFFS_TRACE_ALWAYS,
2556 (TSTR("yaffs: MTD device does not support required "
2561 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2562 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2563 T(YAFFS_TRACE_ALWAYS,
2564 (TSTR("yaffs: MTD device does not support have the "
2565 "right page sizes\n")));
2570 /* OK, so if we got here, we have an MTD that's NAND and looks
2571 * like it has the right capabilities
2572 * Set the yaffs_Device up for mtd
2575 dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2576 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
2578 if(!dev || !context ){
2588 /* Deep shit could not allocate device structure */
2589 T(YAFFS_TRACE_ALWAYS,
2590 (TSTR("yaffs_read_super: Failed trying to allocate "
2591 "yaffs_Device. \n")));
2594 memset(dev, 0, sizeof(yaffs_Device));
2595 param = &(dev->param);
2597 memset(context,0,sizeof(struct yaffs_LinuxContext));
2598 dev->context = context;
2599 YINIT_LIST_HEAD(&(context->contextList));
2601 context->superBlock = sb;
2605 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2606 sb->s_fs_info = dev;
2608 sb->u.generic_sbp = dev;
2611 yaffs_DeviceToContext(dev)->mtd = mtd;
2612 param->name = mtd->name;
2614 /* Set up the memory size parameters.... */
2616 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2618 param->startBlock = 0;
2619 param->endBlock = nBlocks - 1;
2620 param->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2621 param->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2622 param->nReservedBlocks = 5;
2623 param->nShortOpCaches = (options.no_cache) ? 0 : 10;
2624 param->inbandTags = options.inband_tags;
2626 #ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
2627 param->disableLazyLoad = 1;
2629 if(options.lazy_loading_overridden)
2630 param->disableLazyLoad = !options.lazy_loading_enabled;
2632 #ifdef CONFIG_YAFFS_DISABLE_TAGS_ECC
2633 param->noTagsECC = 1;
2636 #ifdef CONFIG_YAFFS_DISABLE_BACKGROUND
2638 param->deferDirectoryUpdate = 1;
2641 if(options.tags_ecc_overridden)
2642 param->noTagsECC = !options.tags_ecc_on;
2644 #ifdef CONFIG_YAFFS_EMPTY_LOST_AND_FOUND
2645 param->emptyLostAndFound = 1;
2648 #ifdef CONFIG_YAFFS_DISABLE_BLOCK_REFRESHING
2649 param->refreshPeriod = 0;
2651 param->refreshPeriod = 100;
2654 if(options.empty_lost_and_found_overridden)
2655 param->emptyLostAndFound = options.empty_lost_and_found;
2657 /* ... and the functions. */
2658 if (yaffsVersion == 2) {
2659 param->writeChunkWithTagsToNAND =
2660 nandmtd2_WriteChunkWithTagsToNAND;
2661 param->readChunkWithTagsFromNAND =
2662 nandmtd2_ReadChunkWithTagsFromNAND;
2663 param->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2664 param->queryNANDBlock = nandmtd2_QueryNANDBlock;
2665 yaffs_DeviceToContext(dev)->spareBuffer = YMALLOC(mtd->oobsize);
2666 param->isYaffs2 = 1;
2667 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2668 param->totalBytesPerChunk = mtd->writesize;
2669 param->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2671 param->totalBytesPerChunk = mtd->oobblock;
2672 param->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2674 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2676 param->startBlock = 0;
2677 param->endBlock = nBlocks - 1;
2679 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2680 /* use the MTD interface in yaffs_mtdif1.c */
2681 param->writeChunkWithTagsToNAND =
2682 nandmtd1_WriteChunkWithTagsToNAND;
2683 param->readChunkWithTagsFromNAND =
2684 nandmtd1_ReadChunkWithTagsFromNAND;
2685 param->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2686 param->queryNANDBlock = nandmtd1_QueryNANDBlock;
2688 param->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2689 param->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2691 param->isYaffs2 = 0;
2693 /* ... and common functions */
2694 param->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2695 param->initialiseNAND = nandmtd_InitialiseNAND;
2697 yaffs_DeviceToContext(dev)->putSuperFunc = yaffs_MTDPutSuper;
2699 param->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2700 param->gcControl = yaffs_gc_control_callback;
2702 yaffs_DeviceToContext(dev)->superBlock= sb;
2705 #ifndef CONFIG_YAFFS_DOES_ECC
2706 param->useNANDECC = 1;
2709 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2710 param->wideTnodesDisabled = 1;
2713 param->skipCheckpointRead = options.skip_checkpoint_read;
2714 param->skipCheckpointWrite = options.skip_checkpoint_write;
2716 /* we assume this is protected by lock_kernel() in mount/umount */
2717 down(&yaffs_context_lock);
2718 ylist_add_tail(&(yaffs_DeviceToContext(dev)->contextList), &yaffs_context_list);
2719 up(&yaffs_context_lock);
2721 /* Directory search handling...*/
2722 YINIT_LIST_HEAD(&(yaffs_DeviceToContext(dev)->searchContexts));
2723 param->removeObjectCallback = yaffs_RemoveObjectCallback;
2725 init_MUTEX(&(yaffs_DeviceToContext(dev)->grossLock));
2727 yaffs_GrossLock(dev);
2729 err = yaffs_GutsInitialise(dev);
2732 (TSTR("yaffs_read_super: guts initialised %s\n"),
2733 (err == YAFFS_OK) ? "OK" : "FAILED"));
2736 yaffs_BackgroundStart(dev);
2738 if(!context->bgThread)
2739 param->deferDirectoryUpdate = 0;
2742 /* Release lock before yaffs_get_inode() */
2743 yaffs_GrossUnlock(dev);
2745 /* Create root inode */
2746 if (err == YAFFS_OK)
2747 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2753 inode->i_op = &yaffs_dir_inode_operations;
2754 inode->i_fop = &yaffs_dir_operations;
2756 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: got root inode\n")));
2758 root = d_alloc_root(inode);
2760 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: d_alloc_root done\n")));
2767 sb->s_dirt = !dev->isCheckpointed;
2768 T(YAFFS_TRACE_ALWAYS,
2769 (TSTR("yaffs_read_super: isCheckpointed %d\n"),
2770 dev->isCheckpointed));
2772 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: done\n")));
2777 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2778 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2781 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2784 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2785 static int yaffs_read_super(struct file_system_type *fs,
2786 int flags, const char *dev_name,
2787 void *data, struct vfsmount *mnt)
2790 return get_sb_bdev(fs, flags, dev_name, data,
2791 yaffs_internal_read_super_mtd, mnt);
2794 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2795 int flags, const char *dev_name,
2799 return get_sb_bdev(fs, flags, dev_name, data,
2800 yaffs_internal_read_super_mtd);
2804 static struct file_system_type yaffs_fs_type = {
2805 .owner = THIS_MODULE,
2807 .get_sb = yaffs_read_super,
2808 .kill_sb = kill_block_super,
2809 .fs_flags = FS_REQUIRES_DEV,
2812 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2815 return yaffs_internal_read_super(1, sb, data, silent);
2818 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2823 #ifdef CONFIG_YAFFS_YAFFS2
2825 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2826 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2829 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2832 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2833 static int yaffs2_read_super(struct file_system_type *fs,
2834 int flags, const char *dev_name, void *data,
2835 struct vfsmount *mnt)
2837 return get_sb_bdev(fs, flags, dev_name, data,
2838 yaffs2_internal_read_super_mtd, mnt);
2841 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2842 int flags, const char *dev_name,
2846 return get_sb_bdev(fs, flags, dev_name, data,
2847 yaffs2_internal_read_super_mtd);
2851 static struct file_system_type yaffs2_fs_type = {
2852 .owner = THIS_MODULE,
2854 .get_sb = yaffs2_read_super,
2855 .kill_sb = kill_block_super,
2856 .fs_flags = FS_REQUIRES_DEV,
2859 static struct super_block *yaffs2_read_super(struct super_block *sb,
2860 void *data, int silent)
2862 return yaffs_internal_read_super(2, sb, data, silent);
2865 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
2869 #endif /* CONFIG_YAFFS_YAFFS2 */
2871 static struct proc_dir_entry *my_proc_entry;
2872 static struct proc_dir_entry *debug_proc_entry;
2874 static char *yaffs_dump_dev_part0(char *buf, yaffs_Device * dev)
2876 buf += sprintf(buf, "startBlock......... %d\n", dev->param.startBlock);
2877 buf += sprintf(buf, "endBlock........... %d\n", dev->param.endBlock);
2878 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->param.totalBytesPerChunk);
2879 buf += sprintf(buf, "useNANDECC......... %d\n", dev->param.useNANDECC);
2880 buf += sprintf(buf, "noTagsECC.......... %d\n", dev->param.noTagsECC);
2881 buf += sprintf(buf, "isYaffs2........... %d\n", dev->param.isYaffs2);
2882 buf += sprintf(buf, "inbandTags......... %d\n", dev->param.inbandTags);
2883 buf += sprintf(buf, "emptyLostAndFound.. %d\n", dev->param.emptyLostAndFound);
2884 buf += sprintf(buf, "disableLazyLoad.... %d\n", dev->param.disableLazyLoad);
2885 buf += sprintf(buf, "refreshPeriod...... %d\n", dev->param.refreshPeriod);
2886 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->param.nShortOpCaches);
2887 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->param.nReservedBlocks);
2889 buf += sprintf(buf, "\n");
2895 static char *yaffs_dump_dev_part1(char *buf, yaffs_Device * dev)
2897 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
2898 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
2899 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
2900 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
2901 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
2902 buf += sprintf(buf, "\n");
2903 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
2904 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
2905 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
2906 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
2907 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
2908 buf += sprintf(buf, "\n");
2909 buf += sprintf(buf, "nPageWrites........ %u\n", dev->nPageWrites);
2910 buf += sprintf(buf, "nPageReads......... %u\n", dev->nPageReads);
2911 buf += sprintf(buf, "nBlockErasures..... %u\n", dev->nBlockErasures);
2912 buf += sprintf(buf, "nGCCopies.......... %u\n", dev->nGCCopies);
2913 buf += sprintf(buf, "allGCs............. %u\n", dev->allGCs);
2914 buf += sprintf(buf, "passiveGCs......... %u\n", dev->passiveGCs);
2915 buf += sprintf(buf, "oldestDirtyGCs..... %u\n", dev->oldestDirtyGCs);
2916 buf += sprintf(buf, "backgroundGCs...... %u\n", dev->backgroundGCs);
2917 buf += sprintf(buf, "nRetriedWrites..... %u\n", dev->nRetriedWrites);
2918 buf += sprintf(buf, "nRetireBlocks...... %u\n", dev->nRetiredBlocks);
2919 buf += sprintf(buf, "eccFixed........... %u\n", dev->eccFixed);
2920 buf += sprintf(buf, "eccUnfixed......... %u\n", dev->eccUnfixed);
2921 buf += sprintf(buf, "tagsEccFixed....... %u\n", dev->tagsEccFixed);
2922 buf += sprintf(buf, "tagsEccUnfixed..... %u\n", dev->tagsEccUnfixed);
2923 buf += sprintf(buf, "cacheHits.......... %u\n", dev->cacheHits);
2924 buf += sprintf(buf, "nDeletedFiles...... %u\n", dev->nDeletedFiles);
2925 buf += sprintf(buf, "nUnlinkedFiles..... %u\n", dev->nUnlinkedFiles);
2926 buf += sprintf(buf, "refreshCount....... %u\n", dev->refreshCount);
2928 sprintf(buf, "nBackgroudDeletions %u\n", dev->nBackgroundDeletions);
2933 static int yaffs_proc_read(char *page,
2935 off_t offset, int count, int *eof, void *data)
2937 struct ylist_head *item;
2942 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
2943 * We use 'offset' (*ppos) to indicate where we are in devList.
2944 * This also assumes the user has posted a read buffer large
2945 * enough to hold the complete output; but that's life in /proc.
2950 /* Print header first */
2952 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__"\n");
2954 buf += sprintf(buf,"\n");
2958 down(&yaffs_context_lock);
2960 /* Locate and print the Nth entry. Order N-squared but N is small. */
2961 ylist_for_each(item, &yaffs_context_list) {
2962 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
2963 yaffs_Device *dev = dc->dev;
2965 if (n < (step & ~1)) {
2970 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->param.name);
2971 buf = yaffs_dump_dev_part0(buf, dev);
2973 buf = yaffs_dump_dev_part1(buf, dev);
2977 up(&yaffs_context_lock);
2980 return buf - page < count ? buf - page : count;
2983 static int yaffs_stats_proc_read(char *page,
2985 off_t offset, int count, int *eof, void *data)
2987 struct ylist_head *item;
2991 down(&yaffs_context_lock);
2993 /* Locate and print the Nth entry. Order N-squared but N is small. */
2994 ylist_for_each(item, &yaffs_context_list) {
2995 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
2996 yaffs_Device *dev = dc->dev;
3002 erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
3003 nObjects = dev->nObjectsCreated -dev->nFreeObjects;
3004 nTnodes = dev->nTnodesCreated - dev->nFreeTnodes;
3007 buf += sprintf(buf,"%d, %d, %d, %u, %u, %d, %d\n",
3008 n, dev->nFreeChunks, erasedChunks,
3009 dev->backgroundGCs, dev->oldestDirtyGCs,
3012 up(&yaffs_context_lock);
3015 return buf - page < count ? buf - page : count;
3019 * Set the verbosity of the warnings and error messages.
3021 * Note that the names can only be a..z or _ with the current code.
3026 unsigned mask_bitfield;
3028 {"allocate", YAFFS_TRACE_ALLOCATE},
3029 {"always", YAFFS_TRACE_ALWAYS},
3030 {"background", YAFFS_TRACE_BACKGROUND},
3031 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
3032 {"buffers", YAFFS_TRACE_BUFFERS},
3033 {"bug", YAFFS_TRACE_BUG},
3034 {"checkpt", YAFFS_TRACE_CHECKPOINT},
3035 {"deletion", YAFFS_TRACE_DELETION},
3036 {"erase", YAFFS_TRACE_ERASE},
3037 {"error", YAFFS_TRACE_ERROR},
3038 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
3039 {"gc", YAFFS_TRACE_GC},
3040 {"lock", YAFFS_TRACE_LOCK},
3041 {"mtd", YAFFS_TRACE_MTD},
3042 {"nandaccess", YAFFS_TRACE_NANDACCESS},
3043 {"os", YAFFS_TRACE_OS},
3044 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
3045 {"scan", YAFFS_TRACE_SCAN},
3046 {"tracing", YAFFS_TRACE_TRACING},
3047 {"sync", YAFFS_TRACE_SYNC},
3048 {"write", YAFFS_TRACE_WRITE},
3050 {"verify", YAFFS_TRACE_VERIFY},
3051 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
3052 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
3053 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
3055 {"all", 0xffffffff},
3060 #define MAX_MASK_NAME_LENGTH 40
3061 static int yaffs_proc_write_trace_options(struct file *file, const char *buf,
3062 unsigned long count, void *data)
3064 unsigned rg = 0, mask_bitfield;
3068 char substring[MAX_MASK_NAME_LENGTH + 1];
3074 rg = yaffs_traceMask;
3076 while (!done && (pos < count)) {
3078 while ((pos < count) && isspace(buf[pos]))
3095 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3097 if (end > buf + pos) {
3098 mask_name = "numeral";
3099 len = end - (buf + pos);
3103 for (x = buf + pos, i = 0;
3104 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3105 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3107 substring[i] = '\0';
3109 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3110 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3111 mask_name = mask_flags[i].mask_name;
3112 mask_bitfield = mask_flags[i].mask_bitfield;
3119 if (mask_name != NULL) {
3123 rg &= ~mask_bitfield;
3126 rg |= mask_bitfield;
3132 rg |= mask_bitfield;
3138 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3140 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3142 if (rg & YAFFS_TRACE_ALWAYS) {
3143 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3145 flag = ((rg & mask_flags[i].mask_bitfield) ==
3146 mask_flags[i].mask_bitfield) ? '+' : '-';
3147 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3155 static int yaffs_proc_write(struct file *file, const char *buf,
3156 unsigned long count, void *data)
3158 return yaffs_proc_write_trace_options(file, buf, count, data);
3161 /* Stuff to handle installation of file systems */
3162 struct file_system_to_install {
3163 struct file_system_type *fst;
3167 static struct file_system_to_install fs_to_install[] = {
3168 {&yaffs_fs_type, 0},
3169 {&yaffs2_fs_type, 0},
3173 static int __init init_yaffs_fs(void)
3176 struct file_system_to_install *fsinst;
3178 T(YAFFS_TRACE_ALWAYS,
3179 (TSTR("yaffs built " __DATE__ " " __TIME__ " Installing. \n")));
3181 init_MUTEX(&yaffs_context_lock);
3183 /* Install the proc_fs entries */
3184 my_proc_entry = create_proc_entry("yaffs",
3188 if (my_proc_entry) {
3189 my_proc_entry->write_proc = yaffs_proc_write;
3190 my_proc_entry->read_proc = yaffs_proc_read;
3191 my_proc_entry->data = NULL;
3195 debug_proc_entry = create_proc_entry("yaffs_stats",
3199 if (debug_proc_entry) {
3200 debug_proc_entry->write_proc = NULL;
3201 debug_proc_entry->read_proc = yaffs_stats_proc_read;
3202 debug_proc_entry->data = NULL;
3206 /* Now add the file system entries */
3208 fsinst = fs_to_install;
3210 while (fsinst->fst && !error) {
3211 error = register_filesystem(fsinst->fst);
3213 fsinst->installed = 1;
3217 /* Any errors? uninstall */
3219 fsinst = fs_to_install;
3221 while (fsinst->fst) {
3222 if (fsinst->installed) {
3223 unregister_filesystem(fsinst->fst);
3224 fsinst->installed = 0;
3233 static void __exit exit_yaffs_fs(void)
3236 struct file_system_to_install *fsinst;
3238 T(YAFFS_TRACE_ALWAYS,
3239 (TSTR("yaffs built " __DATE__ " " __TIME__ " removing. \n")));
3241 remove_proc_entry("yaffs", YPROC_ROOT);
3242 remove_proc_entry("yaffs_stats", YPROC_ROOT);
3244 fsinst = fs_to_install;
3246 while (fsinst->fst) {
3247 if (fsinst->installed) {
3248 unregister_filesystem(fsinst->fst);
3249 fsinst->installed = 0;
3255 module_init(init_yaffs_fs)
3256 module_exit(exit_yaffs_fs)
3258 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
3259 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
3260 MODULE_LICENSE("GPL");