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 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
206 static int yaffs_sync_object(struct file *file, int datasync);
208 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
212 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
214 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
215 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
216 struct nameidata *n);
217 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
218 struct nameidata *n);
220 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
221 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
223 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
224 struct dentry *dentry);
225 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
226 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
227 const char *symname);
228 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
230 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
231 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
234 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
237 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
238 struct inode *new_dir, struct dentry *new_dentry);
239 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
241 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
242 static int yaffs_sync_fs(struct super_block *sb, int wait);
243 static void yaffs_write_super(struct super_block *sb);
245 static int yaffs_sync_fs(struct super_block *sb);
246 static int yaffs_write_super(struct super_block *sb);
249 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
250 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
251 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
252 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
254 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
257 #ifdef YAFFS_HAS_PUT_INODE
258 static void yaffs_put_inode(struct inode *inode);
261 static void yaffs_delete_inode(struct inode *);
262 static void yaffs_clear_inode(struct inode *);
264 static int yaffs_readpage(struct file *file, struct page *page);
265 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
266 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
268 static int yaffs_writepage(struct page *page);
272 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
273 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
274 loff_t pos, unsigned len, unsigned flags,
275 struct page **pagep, void **fsdata);
276 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
277 loff_t pos, unsigned len, unsigned copied,
278 struct page *pg, void *fsdadata);
280 static int yaffs_prepare_write(struct file *f, struct page *pg,
281 unsigned offset, unsigned to);
282 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
287 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
289 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
290 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
292 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
294 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin);
296 static struct address_space_operations yaffs_file_address_operations = {
297 .readpage = yaffs_readpage,
298 .writepage = yaffs_writepage,
299 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
300 .write_begin = yaffs_write_begin,
301 .write_end = yaffs_write_end,
303 .prepare_write = yaffs_prepare_write,
304 .commit_write = yaffs_commit_write,
308 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
309 static const struct file_operations yaffs_file_operations = {
310 .read = do_sync_read,
311 .write = do_sync_write,
312 .aio_read = generic_file_aio_read,
313 .aio_write = generic_file_aio_write,
314 .mmap = generic_file_mmap,
315 .flush = yaffs_file_flush,
316 .fsync = yaffs_sync_object,
317 .splice_read = generic_file_splice_read,
318 .splice_write = generic_file_splice_write,
319 .llseek = generic_file_llseek,
322 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
324 static const struct file_operations yaffs_file_operations = {
325 .read = do_sync_read,
326 .write = do_sync_write,
327 .aio_read = generic_file_aio_read,
328 .aio_write = generic_file_aio_write,
329 .mmap = generic_file_mmap,
330 .flush = yaffs_file_flush,
331 .fsync = yaffs_sync_object,
332 .sendfile = generic_file_sendfile,
337 static const struct file_operations yaffs_file_operations = {
338 .read = generic_file_read,
339 .write = generic_file_write,
340 .mmap = generic_file_mmap,
341 .flush = yaffs_file_flush,
342 .fsync = yaffs_sync_object,
343 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
344 .sendfile = generic_file_sendfile,
349 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
350 static void zero_user_segment(struct page *page, unsigned start, unsigned end)
352 void * kaddr = kmap_atomic(page, KM_USER0);
353 memset(kaddr + start, 0, end - start);
354 kunmap_atomic(kaddr, KM_USER0);
355 flush_dcache_page(page);
360 static const struct inode_operations yaffs_file_inode_operations = {
361 .setattr = yaffs_setattr,
364 static const struct inode_operations yaffs_symlink_inode_operations = {
365 .readlink = yaffs_readlink,
366 .follow_link = yaffs_follow_link,
367 .setattr = yaffs_setattr,
370 static const struct inode_operations yaffs_dir_inode_operations = {
371 .create = yaffs_create,
372 .lookup = yaffs_lookup,
374 .unlink = yaffs_unlink,
375 .symlink = yaffs_symlink,
376 .mkdir = yaffs_mkdir,
377 .rmdir = yaffs_unlink,
378 .mknod = yaffs_mknod,
379 .rename = yaffs_rename,
380 .setattr = yaffs_setattr,
383 static const struct file_operations yaffs_dir_operations = {
384 .read = generic_read_dir,
385 .readdir = yaffs_readdir,
386 .fsync = yaffs_sync_object,
387 .llseek = yaffs_dir_llseek,
390 static const struct super_operations yaffs_super_ops = {
391 .statfs = yaffs_statfs,
393 #ifndef YAFFS_USE_OWN_IGET
394 .read_inode = yaffs_read_inode,
396 #ifdef YAFFS_HAS_PUT_INODE
397 .put_inode = yaffs_put_inode,
399 .put_super = yaffs_put_super,
400 .delete_inode = yaffs_delete_inode,
401 .clear_inode = yaffs_clear_inode,
402 .sync_fs = yaffs_sync_fs,
403 .write_super = yaffs_write_super,
406 static unsigned yaffs_gc_control_callback(yaffs_Device *dev)
408 return yaffs_gc_control;
411 static void yaffs_GrossLock(yaffs_Device *dev)
413 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
414 down(&(yaffs_DeviceToContext(dev)->grossLock));
415 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locked %p\n"), current));
418 static void yaffs_GrossUnlock(yaffs_Device *dev)
420 T(YAFFS_TRACE_LOCK, (TSTR("yaffs unlocking %p\n"), current));
421 up(&(yaffs_DeviceToContext(dev)->grossLock));
424 #ifdef YAFFS_COMPILE_EXPORTFS
426 static struct inode *
427 yaffs2_nfs_get_inode(struct super_block *sb, uint64_t ino, uint32_t generation)
429 return Y_IGET(sb, ino);
432 static struct dentry *
433 yaffs2_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
435 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode) ;
438 static struct dentry *
439 yaffs2_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
441 return generic_fh_to_parent(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode);
444 struct dentry *yaffs2_get_parent(struct dentry *dentry)
447 struct super_block *sb = dentry->d_inode->i_sb;
448 struct dentry *parent = ERR_PTR(-ENOENT);
450 unsigned long parent_ino;
452 yaffs_Object *parent_obj;
454 d_obj = yaffs_InodeToObject(dentry->d_inode);
457 parent_obj = d_obj->parent;
459 parent_ino = yaffs_GetObjectInode(parent_obj);
460 inode = Y_IGET(sb, parent_ino);
463 parent = ERR_CAST(inode);
465 parent = d_obtain_alias(inode);
466 if (!IS_ERR(parent)) {
467 parent = ERR_PTR(-ENOMEM);
477 /* Just declare a zero structure as a NULL value implies
478 * using the default functions of exportfs.
481 static struct export_operations yaffs_export_ops =
483 .fh_to_dentry = yaffs2_fh_to_dentry,
484 .fh_to_parent = yaffs2_fh_to_parent,
485 .get_parent = yaffs2_get_parent,
490 /*-----------------------------------------------------------------*/
491 /* Directory search context allows us to unlock access to yaffs during
492 * filldir without causing problems with the directory being modified.
493 * This is similar to the tried and tested mechanism used in yaffs direct.
495 * A search context iterates along a doubly linked list of siblings in the
496 * directory. If the iterating object is deleted then this would corrupt
497 * the list iteration, likely causing a crash. The search context avoids
498 * this by using the removeObjectCallback to move the search context to the
499 * next object before the object is deleted.
501 * Many readdirs (and thus seach conexts) may be alive simulateously so
502 * each yaffs_Device has a list of these.
504 * A seach context lives for the duration of a readdir.
506 * All these functions must be called while yaffs is locked.
509 struct yaffs_SearchContext {
511 yaffs_Object *dirObj;
512 yaffs_Object *nextReturn;
513 struct ylist_head others;
517 * yaffs_NewSearch() creates a new search context, initialises it and
518 * adds it to the device's search context list.
520 * Called at start of readdir.
522 static struct yaffs_SearchContext * yaffs_NewSearch(yaffs_Object *dir)
524 yaffs_Device *dev = dir->myDev;
525 struct yaffs_SearchContext *sc = YMALLOC(sizeof(struct yaffs_SearchContext));
529 if( ylist_empty(&sc->dirObj->variant.directoryVariant.children))
530 sc->nextReturn = NULL;
532 sc->nextReturn = ylist_entry(
533 dir->variant.directoryVariant.children.next,
534 yaffs_Object,siblings);
535 YINIT_LIST_HEAD(&sc->others);
536 ylist_add(&sc->others,&(yaffs_DeviceToContext(dev)->searchContexts));
542 * yaffs_EndSearch() disposes of a search context and cleans up.
544 static void yaffs_EndSearch(struct yaffs_SearchContext * sc)
547 ylist_del(&sc->others);
553 * yaffs_SearchAdvance() moves a search context to the next object.
554 * Called when the search iterates or when an object removal causes
555 * the search context to be moved to the next object.
557 static void yaffs_SearchAdvance(struct yaffs_SearchContext *sc)
562 if( sc->nextReturn == NULL ||
563 ylist_empty(&sc->dirObj->variant.directoryVariant.children))
564 sc->nextReturn = NULL;
566 struct ylist_head *next = sc->nextReturn->siblings.next;
568 if( next == &sc->dirObj->variant.directoryVariant.children)
569 sc->nextReturn = NULL; /* end of list */
571 sc->nextReturn = ylist_entry(next,yaffs_Object,siblings);
576 * yaffs_RemoveObjectCallback() is called when an object is unlinked.
577 * We check open search contexts and advance any which are currently
578 * on the object being iterated.
580 static void yaffs_RemoveObjectCallback(yaffs_Object *obj)
583 struct ylist_head *i;
584 struct yaffs_SearchContext *sc;
585 struct ylist_head *search_contexts = &(yaffs_DeviceToContext(obj->myDev)->searchContexts);
588 /* Iterate through the directory search contexts.
589 * If any are currently on the object being removed, then advance
590 * the search context to the next object to prevent a hanging pointer.
592 ylist_for_each(i, search_contexts) {
594 sc = ylist_entry(i, struct yaffs_SearchContext,others);
595 if(sc->nextReturn == obj)
596 yaffs_SearchAdvance(sc);
603 /*-----------------------------------------------------------------*/
605 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
608 unsigned char *alias;
611 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
613 yaffs_GrossLock(dev);
615 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
617 yaffs_GrossUnlock(dev);
622 ret = vfs_readlink(dentry, buffer, buflen, alias);
627 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
628 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
630 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
633 unsigned char *alias;
635 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
637 yaffs_GrossLock(dev);
639 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
641 yaffs_GrossUnlock(dev);
648 ret = vfs_follow_link(nd, alias);
651 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
658 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
662 * Lookup is used to find objects in the fs
664 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
666 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
669 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
673 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
675 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
677 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
678 yaffs_GrossLock(dev);
681 (TSTR("yaffs_lookup for %d:%s\n"),
682 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
684 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
685 dentry->d_name.name);
687 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
689 /* Can't hold gross lock when calling yaffs_get_inode() */
690 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
691 yaffs_GrossUnlock(dev);
695 (TSTR("yaffs_lookup found %d\n"), obj->objectId));
697 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
701 (TSTR("yaffs_loookup dentry \n")));
702 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
703 * d_add even if NULL inode */
705 /*dget(dentry); // try to solve directory bug */
706 d_add(dentry, inode);
714 T(YAFFS_TRACE_OS,(TSTR("yaffs_lookup not found\n")));
718 /* added NCB for 2.5/6 compatability - forces add even if inode is
719 * NULL which creates dentry hash */
720 d_add(dentry, inode);
726 #ifdef YAFFS_HAS_PUT_INODE
728 /* For now put inode is just for debugging
729 * Put inode is called when the inode **structure** is put.
731 static void yaffs_put_inode(struct inode *inode)
734 (TSTR("yaffs_put_inode: ino %d, count %d\n"), (int)inode->i_ino,
735 atomic_read(&inode->i_count)));
740 /* clear is called to tell the fs to release any per-inode data it holds */
741 static void yaffs_clear_inode(struct inode *inode)
746 obj = yaffs_InodeToObject(inode);
749 (TSTR("yaffs_clear_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
750 atomic_read(&inode->i_count),
751 obj ? "object exists" : "null object"));
755 yaffs_GrossLock(dev);
757 /* Clear the association between the inode and
761 yaffs_InodeToObjectLV(inode) = NULL;
763 /* If the object freeing was deferred, then the real
765 * This should fix the inode inconsistency problem.
768 yaffs_HandleDeferedFree(obj);
770 yaffs_GrossUnlock(dev);
775 /* delete is called when the link count is zero and the inode
776 * is put (ie. nobody wants to know about it anymore, time to
778 * NB Must call clear_inode()
780 static void yaffs_delete_inode(struct inode *inode)
782 yaffs_Object *obj = yaffs_InodeToObject(inode);
786 (TSTR("yaffs_delete_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
787 atomic_read(&inode->i_count),
788 obj ? "object exists" : "null object"));
792 yaffs_GrossLock(dev);
793 yaffs_DeleteObject(obj);
794 yaffs_GrossUnlock(dev);
796 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
797 truncate_inode_pages(&inode->i_data, 0);
802 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
803 static int yaffs_file_flush(struct file *file, fl_owner_t id)
805 static int yaffs_file_flush(struct file *file)
808 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
810 yaffs_Device *dev = obj->myDev;
813 (TSTR("yaffs_file_flush object %d (%s)\n"), obj->objectId,
814 obj->dirty ? "dirty" : "clean"));
816 yaffs_GrossLock(dev);
818 yaffs_FlushFile(obj, 1, 0);
820 yaffs_GrossUnlock(dev);
825 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
827 /* Lifted from jffs2 */
830 unsigned char *pg_buf;
836 (TSTR("yaffs_readpage_nolock at %08x, size %08x\n"),
837 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
838 (unsigned)PAGE_CACHE_SIZE));
840 obj = yaffs_DentryToObject(f->f_dentry);
844 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
845 BUG_ON(!PageLocked(pg));
852 /* FIXME: Can kmap fail? */
854 yaffs_GrossLock(dev);
856 ret = yaffs_ReadDataFromFile(obj, pg_buf,
857 pg->index << PAGE_CACHE_SHIFT,
860 yaffs_GrossUnlock(dev);
866 ClearPageUptodate(pg);
873 flush_dcache_page(pg);
876 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage_nolock done\n")));
880 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
882 int ret = yaffs_readpage_nolock(f, pg);
887 static int yaffs_readpage(struct file *f, struct page *pg)
891 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage\n")));
892 ret=yaffs_readpage_unlock(f, pg);
893 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage done\n")));
897 /* writepage inspired by/stolen from smbfs */
899 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
900 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
902 static int yaffs_writepage(struct page *page)
905 struct address_space *mapping = page->mapping;
907 unsigned long end_index;
916 inode = mapping->host;
919 i_size = i_size_read(inode);
921 end_index = i_size >> PAGE_CACHE_SHIFT;
923 if(page->index < end_index)
924 nBytes = PAGE_CACHE_SIZE;
926 nBytes = i_size & (PAGE_CACHE_SIZE -1);
928 if (page->index > end_index || !nBytes) {
930 (TSTR("yaffs_writepage at %08x, inode size = %08x!!!\n"),
931 (unsigned)(page->index << PAGE_CACHE_SHIFT),
932 (unsigned)inode->i_size));
934 (TSTR(" -> don't care!!\n")));
936 zero_user_segment(page,0,PAGE_CACHE_SIZE);
937 set_page_writeback(page);
939 end_page_writeback(page);
944 if(nBytes != PAGE_CACHE_SIZE)
945 zero_user_segment(page,nBytes,PAGE_CACHE_SIZE);
951 obj = yaffs_InodeToObject(inode);
952 yaffs_GrossLock(obj->myDev);
955 (TSTR("yaffs_writepage at %08x, size %08x\n"),
956 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
958 (TSTR("writepag0: obj = %05x, ino = %05x\n"),
959 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
961 nWritten = yaffs_WriteDataToFile(obj, buffer,
962 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
965 (TSTR("writepag1: obj = %05x, ino = %05x\n"),
966 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
968 yaffs_GrossUnlock(obj->myDev);
971 set_page_writeback(page);
973 end_page_writeback(page);
976 return (nWritten == nBytes) ? 0 : -ENOSPC;
980 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
981 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
982 loff_t pos, unsigned len, unsigned flags,
983 struct page **pagep, void **fsdata)
985 struct page *pg = NULL;
986 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
992 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
993 pg = grab_cache_page_write_begin(mapping, index, flags);
995 pg = __grab_cache_page(mapping, index);
1004 (TSTR("start yaffs_write_begin index %d(%x) uptodate %d\n"),
1005 (int)index,(int)index,Page_Uptodate(pg) ? 1 : 0));
1008 space_held = yaffs_hold_space(filp);
1015 /* Update page if required */
1017 if (!Page_Uptodate(pg))
1018 ret = yaffs_readpage_nolock(filp, pg);
1023 /* Happy path return */
1024 T(YAFFS_TRACE_OS, (TSTR("end yaffs_write_begin - ok\n")));
1030 (TSTR("end yaffs_write_begin fail returning %d\n"), ret));
1032 yaffs_release_space(filp);
1035 page_cache_release(pg);
1042 static int yaffs_prepare_write(struct file *f, struct page *pg,
1043 unsigned offset, unsigned to)
1045 T(YAFFS_TRACE_OS, (TSTR("yaffs_prepair_write\n")));
1047 if (!Page_Uptodate(pg))
1048 return yaffs_readpage_nolock(f, pg);
1053 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1054 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1055 loff_t pos, unsigned len, unsigned copied,
1056 struct page *pg, void *fsdadata)
1060 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
1063 addr = kva + offset_into_page;
1066 ("yaffs_write_end addr %p pos %x nBytes %d\n",
1067 addr,(unsigned)pos, copied));
1069 ret = yaffs_file_write(filp, addr, copied, &pos);
1071 if (ret != copied) {
1073 (TSTR("yaffs_write_end not same size ret %d copied %d\n"),
1082 yaffs_release_space(filp);
1084 page_cache_release(pg);
1089 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1094 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
1095 int nBytes = to - offset;
1098 unsigned spos = pos;
1102 addr = kva + offset;
1104 saddr = (unsigned) addr;
1107 (TSTR("yaffs_commit_write addr %x pos %x nBytes %d\n"),
1108 saddr, spos, nBytes));
1110 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
1112 if (nWritten != nBytes) {
1114 (TSTR("yaffs_commit_write not same size nWritten %d nBytes %d\n"),
1124 (TSTR("yaffs_commit_write returning %d\n"),
1125 nWritten == nBytes ? 0 : nWritten));
1127 return nWritten == nBytes ? 0 : nWritten;
1132 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
1137 /* Check mode against the variant type and attempt to repair if broken. */
1138 __u32 mode = obj->yst_mode;
1139 switch (obj->variantType) {
1140 case YAFFS_OBJECT_TYPE_FILE:
1141 if (!S_ISREG(mode)) {
1142 obj->yst_mode &= ~S_IFMT;
1143 obj->yst_mode |= S_IFREG;
1147 case YAFFS_OBJECT_TYPE_SYMLINK:
1148 if (!S_ISLNK(mode)) {
1149 obj->yst_mode &= ~S_IFMT;
1150 obj->yst_mode |= S_IFLNK;
1154 case YAFFS_OBJECT_TYPE_DIRECTORY:
1155 if (!S_ISDIR(mode)) {
1156 obj->yst_mode &= ~S_IFMT;
1157 obj->yst_mode |= S_IFDIR;
1161 case YAFFS_OBJECT_TYPE_UNKNOWN:
1162 case YAFFS_OBJECT_TYPE_HARDLINK:
1163 case YAFFS_OBJECT_TYPE_SPECIAL:
1169 inode->i_flags |= S_NOATIME;
1171 inode->i_ino = obj->objectId;
1172 inode->i_mode = obj->yst_mode;
1173 inode->i_uid = obj->yst_uid;
1174 inode->i_gid = obj->yst_gid;
1175 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1176 inode->i_blksize = inode->i_sb->s_blocksize;
1178 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1180 inode->i_rdev = old_decode_dev(obj->yst_rdev);
1181 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
1182 inode->i_atime.tv_nsec = 0;
1183 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
1184 inode->i_mtime.tv_nsec = 0;
1185 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
1186 inode->i_ctime.tv_nsec = 0;
1188 inode->i_rdev = obj->yst_rdev;
1189 inode->i_atime = obj->yst_atime;
1190 inode->i_mtime = obj->yst_mtime;
1191 inode->i_ctime = obj->yst_ctime;
1193 inode->i_size = yaffs_GetObjectFileLength(obj);
1194 inode->i_blocks = (inode->i_size + 511) >> 9;
1196 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1199 (TSTR("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n"),
1200 inode->i_mode, inode->i_uid, inode->i_gid,
1201 (int)inode->i_size, atomic_read(&inode->i_count)));
1203 switch (obj->yst_mode & S_IFMT) {
1204 default: /* fifo, device or socket */
1205 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1206 init_special_inode(inode, obj->yst_mode,
1207 old_decode_dev(obj->yst_rdev));
1209 init_special_inode(inode, obj->yst_mode,
1210 (dev_t) (obj->yst_rdev));
1213 case S_IFREG: /* file */
1214 inode->i_op = &yaffs_file_inode_operations;
1215 inode->i_fop = &yaffs_file_operations;
1216 inode->i_mapping->a_ops =
1217 &yaffs_file_address_operations;
1219 case S_IFDIR: /* directory */
1220 inode->i_op = &yaffs_dir_inode_operations;
1221 inode->i_fop = &yaffs_dir_operations;
1223 case S_IFLNK: /* symlink */
1224 inode->i_op = &yaffs_symlink_inode_operations;
1228 yaffs_InodeToObjectLV(inode) = obj;
1230 obj->myInode = inode;
1234 (TSTR("yaffs_FileInode invalid parameters\n")));
1239 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1242 struct inode *inode;
1246 (TSTR("yaffs_get_inode for NULL super_block!!\n")));
1253 (TSTR("yaffs_get_inode for NULL object!!\n")));
1259 (TSTR("yaffs_get_inode for object %d\n"), obj->objectId));
1261 inode = Y_IGET(sb, obj->objectId);
1265 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1266 /* iget also increments the inode's i_count */
1267 /* NB You can't be holding grossLock or deadlock will happen! */
1272 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1277 struct inode *inode;
1280 obj = yaffs_DentryToObject(f->f_dentry);
1284 yaffs_GrossLock(dev);
1286 inode = f->f_dentry->d_inode;
1288 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
1289 ipos = inode->i_size;
1295 (TSTR("yaffs_file_write: hey obj is null!\n")));
1298 (TSTR("yaffs_file_write about to write writing %u(%x) bytes"
1299 "to object %d at %d(%x)\n"),
1300 (unsigned) n, (unsigned) n, obj->objectId, ipos,ipos));
1302 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1305 (TSTR("yaffs_file_write: %d(%x) bytes written\n"),
1306 (unsigned )n,(unsigned)n));
1311 if (ipos > inode->i_size) {
1312 inode->i_size = ipos;
1313 inode->i_blocks = (ipos + 511) >> 9;
1316 (TSTR("yaffs_file_write size updated to %d bytes, "
1318 ipos, (int)(inode->i_blocks)));
1322 yaffs_GrossUnlock(dev);
1323 return (nWritten == 0) && (n > 0) ? -ENOSPC : nWritten;
1326 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1327 /* For now we just assume few parallel writes and check against a small number. */
1328 /* Todo: need to do this with a counter to handle parallel reads better */
1330 static ssize_t yaffs_hold_space(struct file *f)
1338 obj = yaffs_DentryToObject(f->f_dentry);
1342 yaffs_GrossLock(dev);
1344 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1346 yaffs_GrossUnlock(dev);
1348 return (nFreeChunks > 20) ? 1 : 0;
1351 static void yaffs_release_space(struct file *f)
1357 obj = yaffs_DentryToObject(f->f_dentry);
1361 yaffs_GrossLock(dev);
1364 yaffs_GrossUnlock(dev);
1368 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin)
1376 offset += i_size_read(file->f_path.dentry->d_inode);
1379 offset += file->f_pos;
1384 if (offset != file->f_pos)
1385 file->f_pos = offset;
1394 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1398 struct yaffs_SearchContext *sc;
1399 struct inode *inode = f->f_dentry->d_inode;
1400 unsigned long offset, curoffs;
1404 char name[YAFFS_MAX_NAME_LENGTH + 1];
1406 obj = yaffs_DentryToObject(f->f_dentry);
1409 yaffs_GrossLock(dev);
1411 yaffs_DeviceToContext(dev)->readdirProcess = current;
1415 sc = yaffs_NewSearch(obj);
1421 T(YAFFS_TRACE_OS, (TSTR("yaffs_readdir: starting at %d\n"), (int)offset));
1425 (TSTR("yaffs_readdir: entry . ino %d \n"),
1426 (int)inode->i_ino));
1427 yaffs_GrossUnlock(dev);
1428 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1430 yaffs_GrossLock(dev);
1436 (TSTR("yaffs_readdir: entry .. ino %d \n"),
1437 (int)f->f_dentry->d_parent->d_inode->i_ino));
1438 yaffs_GrossUnlock(dev);
1439 if (filldir(dirent, "..", 2, offset,
1440 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1442 yaffs_GrossLock(dev);
1449 /* If the directory has changed since the open or last call to
1450 readdir, rewind to after the 2 canned entries. */
1451 if (f->f_version != inode->i_version) {
1454 f->f_version = inode->i_version;
1457 while(sc->nextReturn){
1460 if (curoffs >= offset) {
1461 int this_inode = yaffs_GetObjectInode(l);
1462 int this_type = yaffs_GetObjectType(l);
1464 yaffs_GetObjectName(l, name,
1465 YAFFS_MAX_NAME_LENGTH + 1);
1467 (TSTR("yaffs_readdir: %s inode %d\n"),
1468 name, yaffs_GetObjectInode(l)));
1470 yaffs_GrossUnlock(dev);
1480 yaffs_GrossLock(dev);
1485 yaffs_SearchAdvance(sc);
1489 yaffs_DeviceToContext(dev)->readdirProcess = NULL;
1491 yaffs_GrossUnlock(dev);
1493 yaffs_EndSearch(sc);
1501 * File creation. Allocate an inode, and we're done..
1504 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1507 #define YCRED(x) (x->cred)
1510 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1511 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1514 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1518 struct inode *inode;
1520 yaffs_Object *obj = NULL;
1523 yaffs_Object *parent = yaffs_InodeToObject(dir);
1525 int error = -ENOSPC;
1526 uid_t uid = YCRED(current)->fsuid;
1527 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1529 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1534 (TSTR("yaffs_mknod: parent object %d type %d\n"),
1535 parent->objectId, parent->variantType));
1538 (TSTR("yaffs_mknod: could not get parent object\n")));
1542 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
1543 "mode %x dev %x\n"),
1544 dentry->d_name.name, mode, rdev));
1546 dev = parent->myDev;
1548 yaffs_GrossLock(dev);
1550 switch (mode & S_IFMT) {
1552 /* Special (socket, fifo, device...) */
1553 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making special\n")));
1554 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1555 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1556 gid, old_encode_dev(rdev));
1558 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1562 case S_IFREG: /* file */
1563 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making file\n")));
1564 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1567 case S_IFDIR: /* directory */
1569 (TSTR("yaffs_mknod: making directory\n")));
1570 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1573 case S_IFLNK: /* symlink */
1574 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making symlink\n")));
1575 obj = NULL; /* Do we ever get here? */
1579 /* Can not call yaffs_get_inode() with gross lock held */
1580 yaffs_GrossUnlock(dev);
1583 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1584 d_instantiate(dentry, inode);
1585 update_dir_time(dir);
1587 (TSTR("yaffs_mknod created object %d count = %d\n"),
1588 obj->objectId, atomic_read(&inode->i_count)));
1590 yaffs_FillInodeFromObject(dir,parent);
1593 (TSTR("yaffs_mknod failed making object\n")));
1600 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1603 T(YAFFS_TRACE_OS, (TSTR("yaffs_mkdir\n")));
1604 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1608 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1609 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1610 struct nameidata *n)
1612 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1615 T(YAFFS_TRACE_OS,(TSTR("yaffs_create\n")));
1616 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1619 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1627 (TSTR("yaffs_unlink %d:%s\n"),
1629 dentry->d_name.name));
1630 obj = yaffs_InodeToObject(dir);
1633 yaffs_GrossLock(dev);
1635 retVal = yaffs_Unlink(obj, dentry->d_name.name);
1637 if (retVal == YAFFS_OK) {
1638 dentry->d_inode->i_nlink--;
1640 yaffs_GrossUnlock(dev);
1641 mark_inode_dirty(dentry->d_inode);
1642 update_dir_time(dir);
1645 yaffs_GrossUnlock(dev);
1652 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1653 struct dentry *dentry)
1655 struct inode *inode = old_dentry->d_inode;
1656 yaffs_Object *obj = NULL;
1657 yaffs_Object *link = NULL;
1660 T(YAFFS_TRACE_OS, (TSTR("yaffs_link\n")));
1662 obj = yaffs_InodeToObject(inode);
1665 yaffs_GrossLock(dev);
1667 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1668 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1672 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1673 d_instantiate(dentry, old_dentry->d_inode);
1674 atomic_inc(&old_dentry->d_inode->i_count);
1676 (TSTR("yaffs_link link count %d i_count %d\n"),
1677 old_dentry->d_inode->i_nlink,
1678 atomic_read(&old_dentry->d_inode->i_count)));
1681 yaffs_GrossUnlock(dev);
1684 update_dir_time(dir);
1691 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1692 const char *symname)
1696 uid_t uid = YCRED(current)->fsuid;
1697 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1699 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
1701 dev = yaffs_InodeToObject(dir)->myDev;
1702 yaffs_GrossLock(dev);
1703 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1704 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1705 yaffs_GrossUnlock(dev);
1708 struct inode *inode;
1710 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1711 d_instantiate(dentry, inode);
1712 update_dir_time(dir);
1713 T(YAFFS_TRACE_OS, (TSTR("symlink created OK\n")));
1716 T(YAFFS_TRACE_OS, (TSTR("symlink not created\n")));
1722 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1723 static int yaffs_sync_object(struct file *file, int datasync)
1725 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1732 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1733 struct dentry *dentry = file->f_path.dentry;
1736 obj = yaffs_DentryToObject(dentry);
1740 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
1741 (TSTR("yaffs_sync_object\n")));
1742 yaffs_GrossLock(dev);
1743 yaffs_FlushFile(obj, 1, datasync);
1744 yaffs_GrossUnlock(dev);
1749 * The VFS layer already does all the dentry stuff for rename.
1751 * NB: POSIX says you can rename an object over an old object of the same name
1753 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1754 struct inode *new_dir, struct dentry *new_dentry)
1757 int retVal = YAFFS_FAIL;
1758 yaffs_Object *target;
1760 T(YAFFS_TRACE_OS, (TSTR("yaffs_rename\n")));
1761 dev = yaffs_InodeToObject(old_dir)->myDev;
1763 yaffs_GrossLock(dev);
1765 /* Check if the target is an existing directory that is not empty. */
1766 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1767 new_dentry->d_name.name);
1771 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1772 !ylist_empty(&target->variant.directoryVariant.children)) {
1774 T(YAFFS_TRACE_OS, (TSTR("target is non-empty dir\n")));
1776 retVal = YAFFS_FAIL;
1778 /* Now does unlinking internally using shadowing mechanism */
1779 T(YAFFS_TRACE_OS, (TSTR("calling yaffs_RenameObject\n")));
1781 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1782 old_dentry->d_name.name,
1783 yaffs_InodeToObject(new_dir),
1784 new_dentry->d_name.name);
1786 yaffs_GrossUnlock(dev);
1788 if (retVal == YAFFS_OK) {
1790 new_dentry->d_inode->i_nlink--;
1791 mark_inode_dirty(new_dentry->d_inode);
1794 update_dir_time(old_dir);
1795 if(old_dir != new_dir)
1796 update_dir_time(new_dir);
1803 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1805 struct inode *inode = dentry->d_inode;
1810 (TSTR("yaffs_setattr of object %d\n"),
1811 yaffs_InodeToObject(inode)->objectId));
1813 /* Fail if a requested resize >= 2GB */
1814 if (attr->ia_valid & ATTR_SIZE &&
1815 (attr->ia_size >> 31))
1819 error = inode_change_ok(inode, attr);
1823 error = inode_setattr(inode, attr);
1824 T(YAFFS_TRACE_OS,(TSTR("inode_setattr called\n")));
1825 if (attr->ia_valid & ATTR_SIZE)
1826 truncate_inode_pages(&inode->i_data,attr->ia_size);
1828 dev = yaffs_InodeToObject(inode)->myDev;
1829 if (attr->ia_valid & ATTR_SIZE){
1830 T(YAFFS_TRACE_OS,(TSTR("resize to %d(%x)\n"),
1831 (int)(attr->ia_size),(int)(attr->ia_size)));
1833 yaffs_GrossLock(dev);
1834 result = yaffs_SetAttributes(yaffs_InodeToObject(inode), attr);
1835 if(result == YAFFS_OK) {
1840 yaffs_GrossUnlock(dev);
1845 (TSTR("yaffs_setattr done returning %d\n"),error));
1850 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1851 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1853 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1854 struct super_block *sb = dentry->d_sb;
1855 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1856 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1858 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1860 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1862 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1865 T(YAFFS_TRACE_OS, (TSTR("yaffs_statfs\n")));
1867 yaffs_GrossLock(dev);
1869 buf->f_type = YAFFS_MAGIC;
1870 buf->f_bsize = sb->s_blocksize;
1871 buf->f_namelen = 255;
1873 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
1874 /* Do this if chunk size is not a power of 2 */
1876 uint64_t bytesInDev;
1879 bytesInDev = ((uint64_t)((dev->param.endBlock - dev->param.startBlock + 1))) *
1880 ((uint64_t)(dev->param.nChunksPerBlock * dev->nDataBytesPerChunk));
1882 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
1883 buf->f_blocks = bytesInDev;
1885 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
1886 ((uint64_t)(dev->nDataBytesPerChunk));
1888 do_div(bytesFree, sb->s_blocksize);
1890 buf->f_bfree = bytesFree;
1892 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
1895 (dev->param.endBlock - dev->param.startBlock + 1) *
1896 dev->param.nChunksPerBlock /
1897 (sb->s_blocksize / dev->nDataBytesPerChunk);
1899 yaffs_GetNumberOfFreeChunks(dev) /
1900 (sb->s_blocksize / dev->nDataBytesPerChunk);
1903 (dev->param.endBlock - dev->param.startBlock + 1) *
1904 dev->param.nChunksPerBlock *
1905 (dev->nDataBytesPerChunk / sb->s_blocksize);
1908 yaffs_GetNumberOfFreeChunks(dev) *
1909 (dev->nDataBytesPerChunk / sb->s_blocksize);
1914 buf->f_bavail = buf->f_bfree;
1916 yaffs_GrossUnlock(dev);
1922 static void yaffs_FlushInodes(struct super_block *sb)
1927 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
1928 obj = yaffs_InodeToObject(iptr);
1930 T(YAFFS_TRACE_OS, (TSTR("flushing obj %d\n"),
1932 yaffs_FlushFile(obj,1,0);
1938 static void yaffs_FlushSuperBlock(struct super_block *sb, int do_checkpoint)
1940 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1944 yaffs_FlushInodes(sb);
1945 yaffs_UpdateDirtyDirectories(dev);
1946 yaffs_FlushEntireDeviceCache(dev);
1948 yaffs_CheckpointSave(dev);
1952 static unsigned yaffs_bg_gc_urgency(yaffs_Device *dev)
1954 unsigned erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
1955 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
1956 unsigned scatteredFree = 0; /* Free chunks not in an erased block */
1958 if(erasedChunks < dev->nFreeChunks)
1959 scatteredFree = (dev->nFreeChunks - erasedChunks);
1961 if(!context->bgRunning)
1963 else if(scatteredFree < (dev->param.nChunksPerBlock * 2))
1965 else if(erasedChunks > dev->nFreeChunks/2)
1967 else if(erasedChunks > dev->nFreeChunks/4)
1973 static int yaffs_do_sync_fs(struct super_block *sb,
1974 int request_checkpoint)
1977 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1978 unsigned int oneshot_checkpoint = (yaffs_auto_checkpoint & 4);
1979 unsigned gc_urgent = yaffs_bg_gc_urgency(dev);
1982 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
1983 (TSTR("yaffs_do_sync_fs: gc-urgency %d %s %s%s\n"),
1985 sb->s_dirt ? "dirty" : "clean",
1986 request_checkpoint ? "checkpoint requested" : "no checkpoint",
1987 oneshot_checkpoint ? " one-shot" : "" ));
1989 yaffs_GrossLock(dev);
1990 do_checkpoint = ((request_checkpoint && !gc_urgent) ||
1991 oneshot_checkpoint) &&
1992 !dev->isCheckpointed;
1994 if (sb->s_dirt || do_checkpoint) {
1995 yaffs_FlushSuperBlock(sb, !dev->isCheckpointed && do_checkpoint);
1997 if(oneshot_checkpoint)
1998 yaffs_auto_checkpoint &= ~4;
2000 yaffs_GrossUnlock(dev);
2006 * yaffs background thread functions .
2007 * yaffs_BackgroundThread() the thread function
2008 * yaffs_BackgroundStart() launches the background thread.
2009 * yaffs_BackgroundStop() cleans up the background thread.
2012 * The thread should only run after the yaffs is initialised
2013 * The thread should be stopped before yaffs is unmounted.
2014 * The thread should not do any writing while the fs is in read only.
2017 #ifdef YAFFS_COMPILE_BACKGROUND
2019 void yaffs_background_waker(unsigned long data)
2021 wake_up_process((struct task_struct *)data);
2024 static int yaffs_BackgroundThread(void *data)
2026 yaffs_Device *dev = (yaffs_Device *)data;
2027 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2028 unsigned long now = jiffies;
2029 unsigned long next_dir_update = now;
2030 unsigned long next_gc = now;
2031 unsigned long expires;
2032 unsigned int urgency;
2035 struct timer_list timer;
2037 T(YAFFS_TRACE_BACKGROUND,
2038 (TSTR("yaffs_background starting for dev %p\n"),
2043 while(context->bgRunning){
2044 T(YAFFS_TRACE_BACKGROUND,
2045 (TSTR("yaffs_background\n")));
2047 if(kthread_should_stop())
2053 yaffs_GrossLock(dev);
2057 if(time_after(now, next_dir_update)){
2058 yaffs_UpdateDirtyDirectories(dev);
2059 next_dir_update = now + HZ;
2062 if(time_after(now,next_gc)){
2063 if(!dev->isCheckpointed){
2064 urgency = yaffs_bg_gc_urgency(dev);
2065 gcResult = yaffs_BackgroundGarbageCollect(dev, urgency);
2067 next_gc = now + HZ/20+1;
2068 else if(urgency > 0)
2069 next_gc = now + HZ/10+1;
2071 next_gc = now + HZ * 2;
2073 * gc not running so set to next_dir_update
2074 * to cut down on wake ups
2076 next_gc = next_dir_update;
2078 yaffs_GrossUnlock(dev);
2080 expires = next_dir_update;
2081 if (time_before(next_gc,expires))
2083 if(time_before(expires,now))
2086 init_timer_on_stack(&timer);
2087 timer.expires = expires+1;
2088 timer.data = (unsigned long) current;
2089 timer.function = yaffs_background_waker;
2091 set_current_state(TASK_INTERRUPTIBLE);
2094 del_timer_sync(&timer);
2103 static int yaffs_BackgroundStart(yaffs_Device *dev)
2106 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2108 context->bgRunning = 1;
2110 context->bgThread = kthread_run(yaffs_BackgroundThread,
2111 (void *)dev,"yaffs-bg");
2113 if(IS_ERR(context->bgThread)){
2114 retval = PTR_ERR(context->bgThread);
2115 context->bgThread = NULL;
2116 context->bgRunning = 0;
2121 static void yaffs_BackgroundStop(yaffs_Device *dev)
2123 struct yaffs_LinuxContext *ctxt = yaffs_DeviceToContext(dev);
2125 ctxt->bgRunning = 0;
2127 if( ctxt->bgThread){
2128 kthread_stop(ctxt->bgThread);
2129 ctxt->bgThread = NULL;
2133 static int yaffs_BackgroundThread(void *data)
2138 static int yaffs_BackgroundStart(yaffs_Device *dev)
2143 static void yaffs_BackgroundStop(yaffs_Device *dev)
2149 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2150 static void yaffs_write_super(struct super_block *sb)
2152 static int yaffs_write_super(struct super_block *sb)
2155 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 2);
2157 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2158 (TSTR("yaffs_write_super%s\n"),
2159 request_checkpoint ? " checkpt" : ""));
2161 yaffs_do_sync_fs(sb, request_checkpoint);
2163 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2169 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2170 static int yaffs_sync_fs(struct super_block *sb, int wait)
2172 static int yaffs_sync_fs(struct super_block *sb)
2175 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 1);
2177 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
2178 (TSTR("yaffs_sync_fs%s\n"),
2179 request_checkpoint ? " checkpt" : ""));
2181 yaffs_do_sync_fs(sb, request_checkpoint);
2186 #ifdef YAFFS_USE_OWN_IGET
2188 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2190 struct inode *inode;
2192 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2195 (TSTR("yaffs_iget for %lu\n"), ino));
2197 inode = iget_locked(sb, ino);
2199 return ERR_PTR(-ENOMEM);
2200 if (!(inode->i_state & I_NEW))
2203 /* NB This is called as a side effect of other functions, but
2204 * we had to release the lock to prevent deadlocks, so
2205 * need to lock again.
2208 yaffs_GrossLock(dev);
2210 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2212 yaffs_FillInodeFromObject(inode, obj);
2214 yaffs_GrossUnlock(dev);
2216 unlock_new_inode(inode);
2222 static void yaffs_read_inode(struct inode *inode)
2224 /* NB This is called as a side effect of other functions, but
2225 * we had to release the lock to prevent deadlocks, so
2226 * need to lock again.
2230 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2233 (TSTR("yaffs_read_inode for %d\n"), (int)inode->i_ino));
2235 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2236 yaffs_GrossLock(dev);
2238 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2240 yaffs_FillInodeFromObject(inode, obj);
2242 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2243 yaffs_GrossUnlock(dev);
2248 static YLIST_HEAD(yaffs_context_list);
2249 struct semaphore yaffs_context_lock;
2251 #if 0 /* not used */
2252 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2254 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2256 if (*flags & MS_RDONLY) {
2257 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2260 (TSTR("yaffs_remount_fs: %s: RO\n"), dev->name));
2262 yaffs_GrossLock(dev);
2264 yaffs_FlushSuperBlock(sb,1);
2269 yaffs_GrossUnlock(dev);
2272 (TSTR("yaffs_remount_fs: %s: RW\n"), dev->name));
2279 static void yaffs_put_super(struct super_block *sb)
2281 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2283 T(YAFFS_TRACE_OS, (TSTR("yaffs_put_super\n")));
2285 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2286 (TSTR("Shutting down yaffs background thread\n")));
2287 yaffs_BackgroundStop(dev);
2288 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2289 (TSTR("yaffs background thread shut down\n")));
2291 yaffs_GrossLock(dev);
2293 yaffs_FlushSuperBlock(sb,1);
2295 if (yaffs_DeviceToContext(dev)->putSuperFunc)
2296 yaffs_DeviceToContext(dev)->putSuperFunc(sb);
2299 yaffs_Deinitialise(dev);
2301 yaffs_GrossUnlock(dev);
2303 down(&yaffs_context_lock);
2304 ylist_del_init(&(yaffs_DeviceToContext(dev)->contextList));
2305 up(&yaffs_context_lock);
2307 if (yaffs_DeviceToContext(dev)->spareBuffer) {
2308 YFREE(yaffs_DeviceToContext(dev)->spareBuffer);
2309 yaffs_DeviceToContext(dev)->spareBuffer = NULL;
2316 static void yaffs_MTDPutSuper(struct super_block *sb)
2318 struct mtd_info *mtd = yaffs_DeviceToContext(yaffs_SuperToDevice(sb))->mtd;
2323 put_mtd_device(mtd);
2327 static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev)
2329 struct super_block *sb = yaffs_DeviceToContext(dev)->superBlock;
2331 T(YAFFS_TRACE_OS, (TSTR("yaffs_MarkSuperBlockDirty() sb = %p\n"), sb));
2338 int skip_checkpoint_read;
2339 int skip_checkpoint_write;
2342 int tags_ecc_overridden;
2343 int lazy_loading_enabled;
2344 int lazy_loading_overridden;
2345 int empty_lost_and_found;
2346 int empty_lost_and_found_overridden;
2349 #define MAX_OPT_LEN 30
2350 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2352 char cur_opt[MAX_OPT_LEN + 1];
2356 /* Parse through the options which is a comma seperated list */
2358 while (options_str && *options_str && !error) {
2359 memset(cur_opt, 0, MAX_OPT_LEN + 1);
2362 while(*options_str == ',')
2365 while (*options_str && *options_str != ',') {
2366 if (p < MAX_OPT_LEN) {
2367 cur_opt[p] = *options_str;
2373 if (!strcmp(cur_opt, "inband-tags"))
2374 options->inband_tags = 1;
2375 else if (!strcmp(cur_opt, "tags-ecc-off")){
2376 options->tags_ecc_on = 0;
2377 options->tags_ecc_overridden=1;
2378 } else if (!strcmp(cur_opt, "tags-ecc-on")){
2379 options->tags_ecc_on = 1;
2380 options->tags_ecc_overridden = 1;
2381 } else if (!strcmp(cur_opt, "lazy-loading-off")){
2382 options->lazy_loading_enabled = 0;
2383 options->lazy_loading_overridden=1;
2384 } else if (!strcmp(cur_opt, "lazy-loading-on")){
2385 options->lazy_loading_enabled = 1;
2386 options->lazy_loading_overridden = 1;
2387 } else if (!strcmp(cur_opt, "empty-lost-and-found-off")){
2388 options->empty_lost_and_found = 0;
2389 options->empty_lost_and_found_overridden=1;
2390 } else if (!strcmp(cur_opt, "empty-lost-and-found-on")){
2391 options->empty_lost_and_found = 1;
2392 options->empty_lost_and_found_overridden=1;
2393 } else if (!strcmp(cur_opt, "no-cache"))
2394 options->no_cache = 1;
2395 else if (!strcmp(cur_opt, "no-checkpoint-read"))
2396 options->skip_checkpoint_read = 1;
2397 else if (!strcmp(cur_opt, "no-checkpoint-write"))
2398 options->skip_checkpoint_write = 1;
2399 else if (!strcmp(cur_opt, "no-checkpoint")) {
2400 options->skip_checkpoint_read = 1;
2401 options->skip_checkpoint_write = 1;
2403 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2412 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2413 struct super_block *sb,
2414 void *data, int silent)
2417 struct inode *inode = NULL;
2418 struct dentry *root;
2419 yaffs_Device *dev = 0;
2420 char devname_buf[BDEVNAME_SIZE + 1];
2421 struct mtd_info *mtd;
2423 char *data_str = (char *)data;
2424 struct yaffs_LinuxContext *context = NULL;
2425 yaffs_DeviceParam *param;
2427 yaffs_options options;
2429 sb->s_magic = YAFFS_MAGIC;
2430 sb->s_op = &yaffs_super_ops;
2431 sb->s_flags |= MS_NOATIME;
2433 #ifdef YAFFS_COMPILE_EXPORTFS
2434 sb->s_export_op = &yaffs_export_ops;
2438 printk(KERN_INFO "yaffs: sb is NULL\n");
2439 else if (!sb->s_dev)
2440 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
2441 else if (!yaffs_devname(sb, devname_buf))
2442 printk(KERN_INFO "yaffs: devname is NULL\n");
2444 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
2446 yaffs_devname(sb, devname_buf));
2451 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2453 memset(&options, 0, sizeof(options));
2455 if (yaffs_parse_options(&options, data_str)) {
2456 /* Option parsing failed */
2461 sb->s_blocksize = PAGE_CACHE_SIZE;
2462 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
2465 (TSTR("yaffs_read_super: Using yaffs%d\n"), yaffsVersion));
2467 (TSTR("yaffs_read_super: block size %d\n"),
2468 (int)(sb->s_blocksize)));
2470 T(YAFFS_TRACE_ALWAYS,
2471 (TSTR("yaffs: Attempting MTD mount of %u.%u,\"%s\"\n"),
2472 MAJOR(sb->s_dev), MINOR(sb->s_dev),
2473 yaffs_devname(sb, devname_buf)));
2475 /* Check it's an mtd device..... */
2476 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2477 return NULL; /* This isn't an mtd device */
2479 /* Get the device */
2480 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2482 T(YAFFS_TRACE_ALWAYS,
2483 (TSTR("yaffs: MTD device #%u doesn't appear to exist\n"),
2487 /* Check it's NAND */
2488 if (mtd->type != MTD_NANDFLASH) {
2489 T(YAFFS_TRACE_ALWAYS,
2490 (TSTR("yaffs: MTD device is not NAND it's type %d\n"),
2495 T(YAFFS_TRACE_OS, (TSTR(" erase %p\n"), mtd->erase));
2496 T(YAFFS_TRACE_OS, (TSTR(" read %p\n"), mtd->read));
2497 T(YAFFS_TRACE_OS, (TSTR(" write %p\n"), mtd->write));
2498 T(YAFFS_TRACE_OS, (TSTR(" readoob %p\n"), mtd->read_oob));
2499 T(YAFFS_TRACE_OS, (TSTR(" writeoob %p\n"), mtd->write_oob));
2500 T(YAFFS_TRACE_OS, (TSTR(" block_isbad %p\n"), mtd->block_isbad));
2501 T(YAFFS_TRACE_OS, (TSTR(" block_markbad %p\n"), mtd->block_markbad));
2502 T(YAFFS_TRACE_OS, (TSTR(" %s %d\n"), WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2503 T(YAFFS_TRACE_OS, (TSTR(" oobsize %d\n"), mtd->oobsize));
2504 T(YAFFS_TRACE_OS, (TSTR(" erasesize %d\n"), mtd->erasesize));
2505 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2506 T(YAFFS_TRACE_OS, (TSTR(" size %u\n"), mtd->size));
2508 T(YAFFS_TRACE_OS, (TSTR(" size %lld\n"), mtd->size));
2511 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2513 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2514 T(YAFFS_TRACE_ALWAYS,
2515 (TSTR("yaffs: auto selecting yaffs2\n")));
2519 /* Added NCB 26/5/2006 for completeness */
2520 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2521 T(YAFFS_TRACE_ALWAYS,
2522 (TSTR("yaffs: auto selecting yaffs1\n")));
2528 if (yaffsVersion == 2) {
2529 /* Check for version 2 style functions */
2531 !mtd->block_isbad ||
2532 !mtd->block_markbad ||
2535 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2536 !mtd->read_oob || !mtd->write_oob) {
2539 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2541 T(YAFFS_TRACE_ALWAYS,
2542 (TSTR("yaffs: MTD device does not support required "
2547 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
2548 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
2549 !options.inband_tags) {
2550 T(YAFFS_TRACE_ALWAYS,
2551 (TSTR("yaffs: MTD device does not have the "
2552 "right page sizes\n")));
2556 /* Check for V1 style functions */
2560 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2561 !mtd->read_oob || !mtd->write_oob) {
2564 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2566 T(YAFFS_TRACE_ALWAYS,
2567 (TSTR("yaffs: MTD device does not support required "
2572 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2573 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2574 T(YAFFS_TRACE_ALWAYS,
2575 (TSTR("yaffs: MTD device does not support have the "
2576 "right page sizes\n")));
2581 /* OK, so if we got here, we have an MTD that's NAND and looks
2582 * like it has the right capabilities
2583 * Set the yaffs_Device up for mtd
2586 dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2587 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
2589 if(!dev || !context ){
2599 /* Deep shit could not allocate device structure */
2600 T(YAFFS_TRACE_ALWAYS,
2601 (TSTR("yaffs_read_super: Failed trying to allocate "
2602 "yaffs_Device. \n")));
2605 memset(dev, 0, sizeof(yaffs_Device));
2606 param = &(dev->param);
2608 memset(context,0,sizeof(struct yaffs_LinuxContext));
2609 dev->context = context;
2610 YINIT_LIST_HEAD(&(context->contextList));
2612 context->superBlock = sb;
2616 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2617 sb->s_fs_info = dev;
2619 sb->u.generic_sbp = dev;
2622 yaffs_DeviceToContext(dev)->mtd = mtd;
2623 param->name = mtd->name;
2625 /* Set up the memory size parameters.... */
2627 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2629 param->startBlock = 0;
2630 param->endBlock = nBlocks - 1;
2631 param->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2632 param->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2633 param->nReservedBlocks = 5;
2634 param->nShortOpCaches = (options.no_cache) ? 0 : 10;
2635 param->inbandTags = options.inband_tags;
2637 #ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
2638 param->disableLazyLoad = 1;
2640 if(options.lazy_loading_overridden)
2641 param->disableLazyLoad = !options.lazy_loading_enabled;
2643 #ifdef CONFIG_YAFFS_DISABLE_TAGS_ECC
2644 param->noTagsECC = 1;
2647 #ifdef CONFIG_YAFFS_DISABLE_BACKGROUND
2649 param->deferDirectoryUpdate = 1;
2652 if(options.tags_ecc_overridden)
2653 param->noTagsECC = !options.tags_ecc_on;
2655 #ifdef CONFIG_YAFFS_EMPTY_LOST_AND_FOUND
2656 param->emptyLostAndFound = 1;
2659 #ifdef CONFIG_YAFFS_DISABLE_BLOCK_REFRESHING
2660 param->refreshPeriod = 0;
2662 param->refreshPeriod = 500;
2665 if(options.empty_lost_and_found_overridden)
2666 param->emptyLostAndFound = options.empty_lost_and_found;
2668 /* ... and the functions. */
2669 if (yaffsVersion == 2) {
2670 param->writeChunkWithTagsToNAND =
2671 nandmtd2_WriteChunkWithTagsToNAND;
2672 param->readChunkWithTagsFromNAND =
2673 nandmtd2_ReadChunkWithTagsFromNAND;
2674 param->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2675 param->queryNANDBlock = nandmtd2_QueryNANDBlock;
2676 yaffs_DeviceToContext(dev)->spareBuffer = YMALLOC(mtd->oobsize);
2677 param->isYaffs2 = 1;
2678 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2679 param->totalBytesPerChunk = mtd->writesize;
2680 param->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2682 param->totalBytesPerChunk = mtd->oobblock;
2683 param->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2685 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2687 param->startBlock = 0;
2688 param->endBlock = nBlocks - 1;
2690 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2691 /* use the MTD interface in yaffs_mtdif1.c */
2692 param->writeChunkWithTagsToNAND =
2693 nandmtd1_WriteChunkWithTagsToNAND;
2694 param->readChunkWithTagsFromNAND =
2695 nandmtd1_ReadChunkWithTagsFromNAND;
2696 param->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2697 param->queryNANDBlock = nandmtd1_QueryNANDBlock;
2699 param->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2700 param->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2702 param->isYaffs2 = 0;
2704 /* ... and common functions */
2705 param->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2706 param->initialiseNAND = nandmtd_InitialiseNAND;
2708 yaffs_DeviceToContext(dev)->putSuperFunc = yaffs_MTDPutSuper;
2710 param->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2711 param->gcControl = yaffs_gc_control_callback;
2713 yaffs_DeviceToContext(dev)->superBlock= sb;
2716 #ifndef CONFIG_YAFFS_DOES_ECC
2717 param->useNANDECC = 1;
2720 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2721 param->wideTnodesDisabled = 1;
2724 param->skipCheckpointRead = options.skip_checkpoint_read;
2725 param->skipCheckpointWrite = options.skip_checkpoint_write;
2727 /* we assume this is protected by lock_kernel() in mount/umount */
2728 down(&yaffs_context_lock);
2729 ylist_add_tail(&(yaffs_DeviceToContext(dev)->contextList), &yaffs_context_list);
2730 up(&yaffs_context_lock);
2732 /* Directory search handling...*/
2733 YINIT_LIST_HEAD(&(yaffs_DeviceToContext(dev)->searchContexts));
2734 param->removeObjectCallback = yaffs_RemoveObjectCallback;
2736 init_MUTEX(&(yaffs_DeviceToContext(dev)->grossLock));
2738 yaffs_GrossLock(dev);
2740 err = yaffs_GutsInitialise(dev);
2743 (TSTR("yaffs_read_super: guts initialised %s\n"),
2744 (err == YAFFS_OK) ? "OK" : "FAILED"));
2747 yaffs_BackgroundStart(dev);
2749 if(!context->bgThread)
2750 param->deferDirectoryUpdate = 0;
2753 /* Release lock before yaffs_get_inode() */
2754 yaffs_GrossUnlock(dev);
2756 /* Create root inode */
2757 if (err == YAFFS_OK)
2758 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2764 inode->i_op = &yaffs_dir_inode_operations;
2765 inode->i_fop = &yaffs_dir_operations;
2767 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: got root inode\n")));
2769 root = d_alloc_root(inode);
2771 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: d_alloc_root done\n")));
2778 sb->s_dirt = !dev->isCheckpointed;
2779 T(YAFFS_TRACE_ALWAYS,
2780 (TSTR("yaffs_read_super: isCheckpointed %d\n"),
2781 dev->isCheckpointed));
2783 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: done\n")));
2788 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2789 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2792 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2795 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2796 static int yaffs_read_super(struct file_system_type *fs,
2797 int flags, const char *dev_name,
2798 void *data, struct vfsmount *mnt)
2801 return get_sb_bdev(fs, flags, dev_name, data,
2802 yaffs_internal_read_super_mtd, mnt);
2805 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2806 int flags, const char *dev_name,
2810 return get_sb_bdev(fs, flags, dev_name, data,
2811 yaffs_internal_read_super_mtd);
2815 static struct file_system_type yaffs_fs_type = {
2816 .owner = THIS_MODULE,
2818 .get_sb = yaffs_read_super,
2819 .kill_sb = kill_block_super,
2820 .fs_flags = FS_REQUIRES_DEV,
2823 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2826 return yaffs_internal_read_super(1, sb, data, silent);
2829 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2834 #ifdef CONFIG_YAFFS_YAFFS2
2836 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2837 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2840 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2843 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2844 static int yaffs2_read_super(struct file_system_type *fs,
2845 int flags, const char *dev_name, void *data,
2846 struct vfsmount *mnt)
2848 return get_sb_bdev(fs, flags, dev_name, data,
2849 yaffs2_internal_read_super_mtd, mnt);
2852 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2853 int flags, const char *dev_name,
2857 return get_sb_bdev(fs, flags, dev_name, data,
2858 yaffs2_internal_read_super_mtd);
2862 static struct file_system_type yaffs2_fs_type = {
2863 .owner = THIS_MODULE,
2865 .get_sb = yaffs2_read_super,
2866 .kill_sb = kill_block_super,
2867 .fs_flags = FS_REQUIRES_DEV,
2870 static struct super_block *yaffs2_read_super(struct super_block *sb,
2871 void *data, int silent)
2873 return yaffs_internal_read_super(2, sb, data, silent);
2876 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
2880 #endif /* CONFIG_YAFFS_YAFFS2 */
2882 static struct proc_dir_entry *my_proc_entry;
2883 static struct proc_dir_entry *debug_proc_entry;
2885 static char *yaffs_dump_dev_part0(char *buf, yaffs_Device * dev)
2887 buf += sprintf(buf, "startBlock......... %d\n", dev->param.startBlock);
2888 buf += sprintf(buf, "endBlock........... %d\n", dev->param.endBlock);
2889 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->param.totalBytesPerChunk);
2890 buf += sprintf(buf, "useNANDECC......... %d\n", dev->param.useNANDECC);
2891 buf += sprintf(buf, "noTagsECC.......... %d\n", dev->param.noTagsECC);
2892 buf += sprintf(buf, "isYaffs2........... %d\n", dev->param.isYaffs2);
2893 buf += sprintf(buf, "inbandTags......... %d\n", dev->param.inbandTags);
2894 buf += sprintf(buf, "emptyLostAndFound.. %d\n", dev->param.emptyLostAndFound);
2895 buf += sprintf(buf, "disableLazyLoad.... %d\n", dev->param.disableLazyLoad);
2896 buf += sprintf(buf, "refreshPeriod...... %d\n", dev->param.refreshPeriod);
2897 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->param.nShortOpCaches);
2898 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->param.nReservedBlocks);
2900 buf += sprintf(buf, "\n");
2906 static char *yaffs_dump_dev_part1(char *buf, yaffs_Device * dev)
2908 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
2909 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
2910 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
2911 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
2912 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
2913 buf += sprintf(buf, "\n");
2914 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
2915 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
2916 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
2917 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
2918 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
2919 buf += sprintf(buf, "\n");
2920 buf += sprintf(buf, "nPageWrites........ %u\n", dev->nPageWrites);
2921 buf += sprintf(buf, "nPageReads......... %u\n", dev->nPageReads);
2922 buf += sprintf(buf, "nBlockErasures..... %u\n", dev->nBlockErasures);
2923 buf += sprintf(buf, "nGCCopies.......... %u\n", dev->nGCCopies);
2924 buf += sprintf(buf, "allGCs............. %u\n", dev->allGCs);
2925 buf += sprintf(buf, "passiveGCs......... %u\n", dev->passiveGCs);
2926 buf += sprintf(buf, "oldestDirtyGCs..... %u\n", dev->oldestDirtyGCs);
2927 buf += sprintf(buf, "backgroundGCs...... %u\n", dev->backgroundGCs);
2928 buf += sprintf(buf, "nRetriedWrites..... %u\n", dev->nRetriedWrites);
2929 buf += sprintf(buf, "nRetireBlocks...... %u\n", dev->nRetiredBlocks);
2930 buf += sprintf(buf, "eccFixed........... %u\n", dev->eccFixed);
2931 buf += sprintf(buf, "eccUnfixed......... %u\n", dev->eccUnfixed);
2932 buf += sprintf(buf, "tagsEccFixed....... %u\n", dev->tagsEccFixed);
2933 buf += sprintf(buf, "tagsEccUnfixed..... %u\n", dev->tagsEccUnfixed);
2934 buf += sprintf(buf, "cacheHits.......... %u\n", dev->cacheHits);
2935 buf += sprintf(buf, "nDeletedFiles...... %u\n", dev->nDeletedFiles);
2936 buf += sprintf(buf, "nUnlinkedFiles..... %u\n", dev->nUnlinkedFiles);
2937 buf += sprintf(buf, "refreshCount....... %u\n", dev->refreshCount);
2939 sprintf(buf, "nBackgroudDeletions %u\n", dev->nBackgroundDeletions);
2944 static int yaffs_proc_read(char *page,
2946 off_t offset, int count, int *eof, void *data)
2948 struct ylist_head *item;
2953 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
2954 * We use 'offset' (*ppos) to indicate where we are in devList.
2955 * This also assumes the user has posted a read buffer large
2956 * enough to hold the complete output; but that's life in /proc.
2961 /* Print header first */
2963 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__"\n");
2965 buf += sprintf(buf,"\n");
2969 down(&yaffs_context_lock);
2971 /* Locate and print the Nth entry. Order N-squared but N is small. */
2972 ylist_for_each(item, &yaffs_context_list) {
2973 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
2974 yaffs_Device *dev = dc->dev;
2976 if (n < (step & ~1)) {
2981 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->param.name);
2982 buf = yaffs_dump_dev_part0(buf, dev);
2984 buf = yaffs_dump_dev_part1(buf, dev);
2988 up(&yaffs_context_lock);
2991 return buf - page < count ? buf - page : count;
2994 static int yaffs_stats_proc_read(char *page,
2996 off_t offset, int count, int *eof, void *data)
2998 struct ylist_head *item;
3002 down(&yaffs_context_lock);
3004 /* Locate and print the Nth entry. Order N-squared but N is small. */
3005 ylist_for_each(item, &yaffs_context_list) {
3006 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3007 yaffs_Device *dev = dc->dev;
3013 erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
3014 nObjects = dev->nObjectsCreated -dev->nFreeObjects;
3015 nTnodes = dev->nTnodesCreated - dev->nFreeTnodes;
3018 buf += sprintf(buf,"%d, %d, %d, %u, %u, %d, %d\n",
3019 n, dev->nFreeChunks, erasedChunks,
3020 dev->backgroundGCs, dev->oldestDirtyGCs,
3023 up(&yaffs_context_lock);
3026 return buf - page < count ? buf - page : count;
3030 * Set the verbosity of the warnings and error messages.
3032 * Note that the names can only be a..z or _ with the current code.
3037 unsigned mask_bitfield;
3039 {"allocate", YAFFS_TRACE_ALLOCATE},
3040 {"always", YAFFS_TRACE_ALWAYS},
3041 {"background", YAFFS_TRACE_BACKGROUND},
3042 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
3043 {"buffers", YAFFS_TRACE_BUFFERS},
3044 {"bug", YAFFS_TRACE_BUG},
3045 {"checkpt", YAFFS_TRACE_CHECKPOINT},
3046 {"deletion", YAFFS_TRACE_DELETION},
3047 {"erase", YAFFS_TRACE_ERASE},
3048 {"error", YAFFS_TRACE_ERROR},
3049 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
3050 {"gc", YAFFS_TRACE_GC},
3051 {"lock", YAFFS_TRACE_LOCK},
3052 {"mtd", YAFFS_TRACE_MTD},
3053 {"nandaccess", YAFFS_TRACE_NANDACCESS},
3054 {"os", YAFFS_TRACE_OS},
3055 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
3056 {"scan", YAFFS_TRACE_SCAN},
3057 {"tracing", YAFFS_TRACE_TRACING},
3058 {"sync", YAFFS_TRACE_SYNC},
3059 {"write", YAFFS_TRACE_WRITE},
3061 {"verify", YAFFS_TRACE_VERIFY},
3062 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
3063 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
3064 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
3066 {"all", 0xffffffff},
3071 #define MAX_MASK_NAME_LENGTH 40
3072 static int yaffs_proc_write_trace_options(struct file *file, const char *buf,
3073 unsigned long count, void *data)
3075 unsigned rg = 0, mask_bitfield;
3079 char substring[MAX_MASK_NAME_LENGTH + 1];
3085 rg = yaffs_traceMask;
3087 while (!done && (pos < count)) {
3089 while ((pos < count) && isspace(buf[pos]))
3106 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3108 if (end > buf + pos) {
3109 mask_name = "numeral";
3110 len = end - (buf + pos);
3114 for (x = buf + pos, i = 0;
3115 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3116 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3118 substring[i] = '\0';
3120 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3121 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3122 mask_name = mask_flags[i].mask_name;
3123 mask_bitfield = mask_flags[i].mask_bitfield;
3130 if (mask_name != NULL) {
3134 rg &= ~mask_bitfield;
3137 rg |= mask_bitfield;
3143 rg |= mask_bitfield;
3149 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3151 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3153 if (rg & YAFFS_TRACE_ALWAYS) {
3154 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3156 flag = ((rg & mask_flags[i].mask_bitfield) ==
3157 mask_flags[i].mask_bitfield) ? '+' : '-';
3158 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3166 static int yaffs_proc_write(struct file *file, const char *buf,
3167 unsigned long count, void *data)
3169 return yaffs_proc_write_trace_options(file, buf, count, data);
3172 /* Stuff to handle installation of file systems */
3173 struct file_system_to_install {
3174 struct file_system_type *fst;
3178 static struct file_system_to_install fs_to_install[] = {
3179 {&yaffs_fs_type, 0},
3180 {&yaffs2_fs_type, 0},
3184 static int __init init_yaffs_fs(void)
3187 struct file_system_to_install *fsinst;
3189 T(YAFFS_TRACE_ALWAYS,
3190 (TSTR("yaffs built " __DATE__ " " __TIME__ " Installing. \n")));
3192 #ifdef CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED
3193 T(YAFFS_TRACE_ALWAYS,
3194 (TSTR(" \n\n\n\nYAFFS-WARNING CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED selected.\n\n\n\n")));
3200 init_MUTEX(&yaffs_context_lock);
3202 /* Install the proc_fs entries */
3203 my_proc_entry = create_proc_entry("yaffs",
3207 if (my_proc_entry) {
3208 my_proc_entry->write_proc = yaffs_proc_write;
3209 my_proc_entry->read_proc = yaffs_proc_read;
3210 my_proc_entry->data = NULL;
3214 debug_proc_entry = create_proc_entry("yaffs_stats",
3218 if (debug_proc_entry) {
3219 debug_proc_entry->write_proc = NULL;
3220 debug_proc_entry->read_proc = yaffs_stats_proc_read;
3221 debug_proc_entry->data = NULL;
3225 /* Now add the file system entries */
3227 fsinst = fs_to_install;
3229 while (fsinst->fst && !error) {
3230 error = register_filesystem(fsinst->fst);
3232 fsinst->installed = 1;
3236 /* Any errors? uninstall */
3238 fsinst = fs_to_install;
3240 while (fsinst->fst) {
3241 if (fsinst->installed) {
3242 unregister_filesystem(fsinst->fst);
3243 fsinst->installed = 0;
3252 static void __exit exit_yaffs_fs(void)
3255 struct file_system_to_install *fsinst;
3257 T(YAFFS_TRACE_ALWAYS,
3258 (TSTR("yaffs built " __DATE__ " " __TIME__ " removing. \n")));
3260 remove_proc_entry("yaffs", YPROC_ROOT);
3261 remove_proc_entry("yaffs_stats", YPROC_ROOT);
3263 fsinst = fs_to_install;
3265 while (fsinst->fst) {
3266 if (fsinst->installed) {
3267 unregister_filesystem(fsinst->fst);
3268 fsinst->installed = 0;
3274 module_init(init_yaffs_fs)
3275 module_exit(exit_yaffs_fs)
3277 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
3278 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
3279 MODULE_LICENSE("GPL");