2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 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 const char *yaffs_fs_c_version =
35 "$Id: yaffs_fs.c,v 1.71 2009-01-22 00:45:54 charles Exp $";
36 extern const char *yaffs_guts_c_version;
38 #include <linux/version.h>
39 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
40 #include <linux/config.h>
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/init.h>
47 #include <linux/proc_fs.h>
48 #include <linux/smp_lock.h>
49 #include <linux/pagemap.h>
50 #include <linux/mtd/mtd.h>
51 #include <linux/interrupt.h>
52 #include <linux/string.h>
53 #include <linux/ctype.h>
55 #include "asm/div64.h"
57 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
59 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
60 #include <asm/statfs.h>
61 #define UnlockPage(p) unlock_page(p)
62 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
64 /* FIXME: use sb->s_id instead ? */
65 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
69 #include <linux/locks.h>
70 #define BDEVNAME_SIZE 0
71 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
73 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
74 /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */
80 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26))
81 #define YPROC_ROOT &proc_root
83 #define YPROC_ROOT NULL
86 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
87 #define WRITE_SIZE_STR "writesize"
88 #define WRITE_SIZE(mtd) (mtd)->writesize
90 #define WRITE_SIZE_STR "oobblock"
91 #define WRITE_SIZE(mtd) (mtd)->oobblock
94 #if(LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
95 #define YAFFS_USE_WRITE_BEGIN_END 1
97 #define YAFFS_USE_WRITE_BEGIN_END 0
101 #include <asm/uaccess.h>
103 #include "yportenv.h"
104 #include "yaffs_guts.h"
106 #include <linux/mtd/mtd.h>
107 #include "yaffs_mtdif.h"
108 #include "yaffs_mtdif1.h"
109 #include "yaffs_mtdif2.h"
111 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS;
112 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
113 unsigned int yaffs_auto_checkpoint = 1;
115 /* Module Parameters */
116 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
117 module_param(yaffs_traceMask,uint,0644);
118 module_param(yaffs_wr_attempts,uint,0644);
119 module_param(yaffs_auto_checkpoint,uint,0644);
121 MODULE_PARM(yaffs_traceMask,"i");
122 MODULE_PARM(yaffs_wr_attempts,"i");
123 MODULE_PARM(yaffs_auto_checkpoint,"i");
126 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
127 /* use iget and read_inode */
128 #define Y_IGET(sb,inum) iget((sb),(inum))
129 static void yaffs_read_inode(struct inode *inode);
132 /* Call local equivalent */
133 #define YAFFS_USE_OWN_IGET
134 #define Y_IGET(sb,inum) yaffs_iget((sb),(inum))
136 static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino);
139 /*#define T(x) printk x */
141 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
142 #define yaffs_InodeToObjectLV(iptr) (iptr)->i_private
144 #define yaffs_InodeToObjectLV(iptr) (iptr)->u.generic_ip
147 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
148 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
150 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
151 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
153 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
156 static void yaffs_put_super(struct super_block *sb);
158 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
160 static ssize_t yaffs_hold_space(struct file *f);
161 static void yaffs_release_space(struct file *f);
163 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
164 static int yaffs_file_flush(struct file *file, fl_owner_t id);
166 static int yaffs_file_flush(struct file *file);
169 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
172 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
174 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
175 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
176 struct nameidata *n);
177 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
178 struct nameidata *n);
180 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
181 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
183 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
184 struct dentry *dentry);
185 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
186 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
187 const char *symname);
188 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
190 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
191 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
194 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
197 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
198 struct inode *new_dir, struct dentry *new_dentry);
199 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
201 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
202 static int yaffs_sync_fs(struct super_block *sb, int wait);
203 static void yaffs_write_super(struct super_block *sb);
205 static int yaffs_sync_fs(struct super_block *sb);
206 static int yaffs_write_super(struct super_block *sb);
209 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
210 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
211 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
212 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
214 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
217 #ifdef YAFFS_HAS_PUT_INODE
218 static void yaffs_put_inode(struct inode *inode);
221 static void yaffs_delete_inode(struct inode *);
222 static void yaffs_clear_inode(struct inode *);
224 static int yaffs_readpage(struct file *file, struct page *page);
225 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
226 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
228 static int yaffs_writepage(struct page *page);
232 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
233 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
234 loff_t pos, unsigned len, unsigned flags,
235 struct page **pagep, void **fsdata);
236 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
237 loff_t pos, unsigned len, unsigned copied,
238 struct page *pg, void *fsdadata);
240 static int yaffs_prepare_write(struct file *f, struct page *pg,
241 unsigned offset, unsigned to);
242 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
247 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
249 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
250 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
252 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
255 static struct address_space_operations yaffs_file_address_operations = {
256 .readpage = yaffs_readpage,
257 .writepage = yaffs_writepage,
258 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
259 .write_begin = yaffs_write_begin,
260 .write_end = yaffs_write_end,
262 .prepare_write = yaffs_prepare_write,
263 .commit_write = yaffs_commit_write,
267 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
268 static struct file_operations yaffs_file_operations = {
269 .read = do_sync_read,
270 .write = do_sync_write,
271 .aio_read = generic_file_aio_read,
272 .aio_write = generic_file_aio_write,
273 .mmap = generic_file_mmap,
274 .flush = yaffs_file_flush,
275 .fsync = yaffs_sync_object,
276 .splice_read = generic_file_splice_read,
277 .splice_write = generic_file_splice_write,
278 .llseek = generic_file_llseek,
281 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
283 static struct file_operations yaffs_file_operations = {
284 .read = do_sync_read,
285 .write = do_sync_write,
286 .aio_read = generic_file_aio_read,
287 .aio_write = generic_file_aio_write,
288 .mmap = generic_file_mmap,
289 .flush = yaffs_file_flush,
290 .fsync = yaffs_sync_object,
291 .sendfile = generic_file_sendfile,
296 static struct file_operations yaffs_file_operations = {
297 .read = generic_file_read,
298 .write = generic_file_write,
299 .mmap = generic_file_mmap,
300 .flush = yaffs_file_flush,
301 .fsync = yaffs_sync_object,
302 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
303 .sendfile = generic_file_sendfile,
308 static struct inode_operations yaffs_file_inode_operations = {
309 .setattr = yaffs_setattr,
312 static struct inode_operations yaffs_symlink_inode_operations = {
313 .readlink = yaffs_readlink,
314 .follow_link = yaffs_follow_link,
315 .setattr = yaffs_setattr,
318 static struct inode_operations yaffs_dir_inode_operations = {
319 .create = yaffs_create,
320 .lookup = yaffs_lookup,
322 .unlink = yaffs_unlink,
323 .symlink = yaffs_symlink,
324 .mkdir = yaffs_mkdir,
325 .rmdir = yaffs_unlink,
326 .mknod = yaffs_mknod,
327 .rename = yaffs_rename,
328 .setattr = yaffs_setattr,
331 static struct file_operations yaffs_dir_operations = {
332 .read = generic_read_dir,
333 .readdir = yaffs_readdir,
334 .fsync = yaffs_sync_object,
337 static struct super_operations yaffs_super_ops = {
338 .statfs = yaffs_statfs,
340 #ifndef YAFFS_USE_OWN_IGET
341 .read_inode = yaffs_read_inode,
343 #ifdef YAFFS_HAS_PUT_INODE
344 .put_inode = yaffs_put_inode,
346 .put_super = yaffs_put_super,
347 .delete_inode = yaffs_delete_inode,
348 .clear_inode = yaffs_clear_inode,
349 .sync_fs = yaffs_sync_fs,
350 .write_super = yaffs_write_super,
353 static void yaffs_GrossLock(yaffs_Device * dev)
355 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
357 down(&dev->grossLock);
360 static void yaffs_GrossUnlock(yaffs_Device * dev)
362 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
367 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
370 unsigned char *alias;
373 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
375 yaffs_GrossLock(dev);
377 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
379 yaffs_GrossUnlock(dev);
384 ret = vfs_readlink(dentry, buffer, buflen, alias);
389 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
390 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
392 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
395 unsigned char *alias;
397 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
399 yaffs_GrossLock(dev);
401 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
403 yaffs_GrossUnlock(dev);
411 ret = vfs_follow_link(nd, alias);
414 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
415 return ERR_PTR (ret);
421 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
425 * Lookup is used to find objects in the fs
427 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
429 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
432 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
436 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
438 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
440 yaffs_GrossLock(dev);
443 (KERN_DEBUG "yaffs_lookup for %d:%s\n",
444 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
447 yaffs_FindObjectByName(yaffs_InodeToObject(dir),
448 dentry->d_name.name);
450 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
452 /* Can't hold gross lock when calling yaffs_get_inode() */
453 yaffs_GrossUnlock(dev);
457 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
459 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
463 (KERN_DEBUG "yaffs_loookup dentry \n"));
464 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
465 * d_add even if NULL inode */
467 /*dget(dentry); // try to solve directory bug */
468 d_add(dentry, inode);
476 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
480 /* added NCB for 2.5/6 compatability - forces add even if inode is
481 * NULL which creates dentry hash */
482 d_add(dentry, inode);
485 /* return (ERR_PTR(-EIO)); */
490 #ifdef YAFFS_HAS_PUT_INODE
492 /* For now put inode is just for debugging
493 * Put inode is called when the inode **structure** is put.
495 static void yaffs_put_inode(struct inode *inode)
498 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
499 atomic_read(&inode->i_count)));
504 /* clear is called to tell the fs to release any per-inode data it holds */
505 static void yaffs_clear_inode(struct inode *inode)
510 obj = yaffs_InodeToObject(inode);
513 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
514 atomic_read(&inode->i_count),
515 obj ? "object exists" : "null object"));
519 yaffs_GrossLock(dev);
521 /* Clear the association between the inode and
525 yaffs_InodeToObjectLV(inode) = NULL;
527 /* If the object freeing was deferred, then the real
529 * This should fix the inode inconsistency problem.
532 yaffs_HandleDeferedFree(obj);
534 yaffs_GrossUnlock(dev);
539 /* delete is called when the link count is zero and the inode
540 * is put (ie. nobody wants to know about it anymore, time to
542 * NB Must call clear_inode()
544 static void yaffs_delete_inode(struct inode *inode)
546 yaffs_Object *obj = yaffs_InodeToObject(inode);
550 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
551 atomic_read(&inode->i_count),
552 obj ? "object exists" : "null object"));
556 yaffs_GrossLock(dev);
557 yaffs_DeleteFile(obj);
558 yaffs_GrossUnlock(dev);
560 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
561 truncate_inode_pages (&inode->i_data, 0);
566 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
567 static int yaffs_file_flush(struct file *file, fl_owner_t id)
569 static int yaffs_file_flush(struct file *file)
572 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
574 yaffs_Device *dev = obj->myDev;
577 (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
578 obj->dirty ? "dirty" : "clean"));
580 yaffs_GrossLock(dev);
582 yaffs_FlushFile(obj, 1);
584 yaffs_GrossUnlock(dev);
589 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
591 /* Lifted from jffs2 */
594 unsigned char *pg_buf;
599 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
600 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
601 (unsigned)PAGE_CACHE_SIZE));
603 obj = yaffs_DentryToObject(f->f_dentry);
607 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
608 BUG_ON(!PageLocked(pg));
615 /* FIXME: Can kmap fail? */
617 yaffs_GrossLock(dev);
620 yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
623 yaffs_GrossUnlock(dev);
629 ClearPageUptodate(pg);
636 flush_dcache_page(pg);
639 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
643 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
645 int ret = yaffs_readpage_nolock(f, pg);
650 static int yaffs_readpage(struct file *f, struct page *pg)
652 return yaffs_readpage_unlock(f, pg);
655 /* writepage inspired by/stolen from smbfs */
657 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
658 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
660 static int yaffs_writepage(struct page *page)
663 struct address_space *mapping = page->mapping;
664 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
666 unsigned long end_index;
674 inode = mapping->host;
678 if (offset > inode->i_size) {
681 "yaffs_writepage at %08x, inode size = %08x!!!\n",
682 (unsigned)(page->index << PAGE_CACHE_SHIFT),
683 (unsigned)inode->i_size));
685 (KERN_DEBUG " -> don't care!!\n"));
690 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
693 if (page->index < end_index) {
694 nBytes = PAGE_CACHE_SIZE;
696 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
703 obj = yaffs_InodeToObject(inode);
704 yaffs_GrossLock(obj->myDev);
707 (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
708 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
710 (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
711 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
714 yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
718 (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
719 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
721 yaffs_GrossUnlock(obj->myDev);
724 SetPageUptodate(page);
728 return (nWritten == nBytes) ? 0 : -ENOSPC;
732 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
733 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
734 loff_t pos, unsigned len, unsigned flags,
735 struct page **pagep, void **fsdata)
738 struct page *pg = NULL;
739 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
740 uint32_t offset = pos & (PAGE_CACHE_SIZE - 1);
741 uint32_t to = offset + len;
746 T(YAFFS_TRACE_OS, (KERN_DEBUG "start yaffs_write_begin\n"));
748 pg = __grab_cache_page(mapping,index);
755 space_held = yaffs_hold_space(filp);
762 /* Update page if required */
764 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
765 ret = yaffs_readpage_nolock(filp, pg);
770 /* Happy path return */
771 T(YAFFS_TRACE_OS, (KERN_DEBUG "end yaffs_write_begin - ok\n"));
776 T(YAFFS_TRACE_OS, (KERN_DEBUG "end yaffs_write_begin fail returning %d\n",ret));
778 yaffs_release_space(filp);
782 page_cache_release(pg);
789 static int yaffs_prepare_write(struct file *f, struct page *pg,
790 unsigned offset, unsigned to)
793 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
794 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
795 return yaffs_readpage_nolock(f, pg);
801 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
802 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
803 loff_t pos, unsigned len, unsigned copied,
804 struct page *pg, void *fsdadata)
808 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
809 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE -1);
814 addr = kva + offset_into_page;
817 (KERN_DEBUG "yaffs_write_end addr %x pos %x nBytes %d\n", (unsigned) addr,
820 ret = yaffs_file_write(filp, addr, copied, &pos);
825 "yaffs_write_end not same size ret %d copied %d\n",
828 ClearPageUptodate(pg);
835 yaffs_release_space(filp);
837 page_cache_release(pg);
842 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
848 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
849 int nBytes = to - offset;
858 saddr = (unsigned) addr;
861 (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
864 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
866 if (nWritten != nBytes) {
869 "yaffs_commit_write not same size nWritten %d nBytes %d\n",
872 ClearPageUptodate(pg);
880 (KERN_DEBUG "yaffs_commit_write returning %d\n",
881 nWritten == nBytes ? 0 : nWritten));
883 return nWritten == nBytes ? 0 : nWritten;
889 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
894 /* Check mode against the variant type and attempt to repair if broken. */
895 __u32 mode = obj->yst_mode;
896 switch( obj->variantType ){
897 case YAFFS_OBJECT_TYPE_FILE :
898 if( ! S_ISREG(mode) ){
899 obj->yst_mode &= ~S_IFMT;
900 obj->yst_mode |= S_IFREG;
904 case YAFFS_OBJECT_TYPE_SYMLINK :
905 if( ! S_ISLNK(mode) ){
906 obj->yst_mode &= ~S_IFMT;
907 obj->yst_mode |= S_IFLNK;
911 case YAFFS_OBJECT_TYPE_DIRECTORY :
912 if( ! S_ISDIR(mode) ){
913 obj->yst_mode &= ~S_IFMT;
914 obj->yst_mode |= S_IFDIR;
918 case YAFFS_OBJECT_TYPE_UNKNOWN :
919 case YAFFS_OBJECT_TYPE_HARDLINK :
920 case YAFFS_OBJECT_TYPE_SPECIAL :
926 inode->i_flags |= S_NOATIME;
928 inode->i_ino = obj->objectId;
929 inode->i_mode = obj->yst_mode;
930 inode->i_uid = obj->yst_uid;
931 inode->i_gid = obj->yst_gid;
932 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
933 inode->i_blksize = inode->i_sb->s_blocksize;
935 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
937 inode->i_rdev = old_decode_dev(obj->yst_rdev);
938 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
939 inode->i_atime.tv_nsec = 0;
940 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
941 inode->i_mtime.tv_nsec = 0;
942 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
943 inode->i_ctime.tv_nsec = 0;
945 inode->i_rdev = obj->yst_rdev;
946 inode->i_atime = obj->yst_atime;
947 inode->i_mtime = obj->yst_mtime;
948 inode->i_ctime = obj->yst_ctime;
950 inode->i_size = yaffs_GetObjectFileLength(obj);
951 inode->i_blocks = (inode->i_size + 511) >> 9;
953 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
957 "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
958 inode->i_mode, inode->i_uid, inode->i_gid,
959 (int)inode->i_size, atomic_read(&inode->i_count)));
961 switch (obj->yst_mode & S_IFMT) {
962 default: /* fifo, device or socket */
963 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
964 init_special_inode(inode, obj->yst_mode,
965 old_decode_dev(obj->yst_rdev));
967 init_special_inode(inode, obj->yst_mode,
968 (dev_t) (obj->yst_rdev));
971 case S_IFREG: /* file */
972 inode->i_op = &yaffs_file_inode_operations;
973 inode->i_fop = &yaffs_file_operations;
974 inode->i_mapping->a_ops =
975 &yaffs_file_address_operations;
977 case S_IFDIR: /* directory */
978 inode->i_op = &yaffs_dir_inode_operations;
979 inode->i_fop = &yaffs_dir_operations;
981 case S_IFLNK: /* symlink */
982 inode->i_op = &yaffs_symlink_inode_operations;
986 yaffs_InodeToObjectLV(inode) = obj;
988 obj->myInode = inode;
992 (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
997 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1000 struct inode *inode;
1004 (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
1011 (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
1017 (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
1019 inode = Y_IGET(sb, obj->objectId);
1023 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1024 /* iget also increments the inode's i_count */
1025 /* NB You can't be holding grossLock or deadlock will happen! */
1030 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1035 struct inode *inode;
1038 obj = yaffs_DentryToObject(f->f_dentry);
1042 yaffs_GrossLock(dev);
1044 inode = f->f_dentry->d_inode;
1046 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
1047 ipos = inode->i_size;
1054 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
1058 "yaffs_file_write about to write writing %d bytes"
1059 "to object %d at %d\n",
1060 n, obj->objectId, ipos));
1063 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1066 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
1067 n, nWritten, ipos));
1071 if (ipos > inode->i_size) {
1072 inode->i_size = ipos;
1073 inode->i_blocks = (ipos + 511) >> 9;
1077 "yaffs_file_write size updated to %d bytes, "
1079 ipos, (int)(inode->i_blocks)));
1083 yaffs_GrossUnlock(dev);
1084 return nWritten == 0 ? -ENOSPC : nWritten;
1087 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1088 /* For now we just assume few parallel writes and check against a small number. */
1089 /* Todo: need to do this with a counter to handle parallel reads better */
1091 static ssize_t yaffs_hold_space(struct file *f)
1099 obj = yaffs_DentryToObject(f->f_dentry);
1103 yaffs_GrossLock(dev);
1105 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1107 yaffs_GrossUnlock(dev);
1109 return (nFreeChunks > 20) ? 1 : 0;
1112 static void yaffs_release_space(struct file *f)
1118 obj = yaffs_DentryToObject(f->f_dentry);
1122 yaffs_GrossLock(dev);
1125 yaffs_GrossUnlock(dev);
1129 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1133 struct inode *inode = f->f_dentry->d_inode;
1134 unsigned long offset, curoffs;
1135 struct ylist_head *i;
1138 char name[YAFFS_MAX_NAME_LENGTH + 1];
1140 obj = yaffs_DentryToObject(f->f_dentry);
1143 yaffs_GrossLock(dev);
1147 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
1151 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
1152 (int)inode->i_ino));
1153 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
1162 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
1163 (int)f->f_dentry->d_parent->d_inode->i_ino));
1165 (dirent, "..", 2, offset,
1166 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
1175 /* If the directory has changed since the open or last call to
1176 readdir, rewind to after the 2 canned entries. */
1178 if (f->f_version != inode->i_version) {
1181 f->f_version = inode->i_version;
1184 ylist_for_each(i, &obj->variant.directoryVariant.children) {
1186 if (curoffs >= offset) {
1187 l = ylist_entry(i, yaffs_Object, siblings);
1189 yaffs_GetObjectName(l, name,
1190 YAFFS_MAX_NAME_LENGTH + 1);
1192 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
1193 yaffs_GetObjectInode(l)));
1199 yaffs_GetObjectInode(l),
1200 yaffs_GetObjectType(l))
1213 yaffs_GrossUnlock(dev);
1219 * File creation. Allocate an inode, and we're done..
1221 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1222 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1225 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1229 struct inode *inode;
1231 yaffs_Object *obj = NULL;
1234 yaffs_Object *parent = yaffs_InodeToObject(dir);
1236 int error = -ENOSPC;
1237 uid_t uid = current->fsuid;
1238 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1240 if((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1245 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
1246 parent->objectId, parent->variantType));
1249 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
1253 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
1255 dentry->d_name.name, mode, rdev));
1257 dev = parent->myDev;
1259 yaffs_GrossLock(dev);
1261 switch (mode & S_IFMT) {
1263 /* Special (socket, fifo, device...) */
1264 T(YAFFS_TRACE_OS, (KERN_DEBUG
1265 "yaffs_mknod: making special\n"));
1266 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1268 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1269 gid, old_encode_dev(rdev));
1272 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1276 case S_IFREG: /* file */
1277 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
1279 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1282 case S_IFDIR: /* directory */
1284 (KERN_DEBUG "yaffs_mknod: making directory\n"));
1286 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1289 case S_IFLNK: /* symlink */
1290 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
1291 obj = NULL; /* Do we ever get here? */
1295 /* Can not call yaffs_get_inode() with gross lock held */
1296 yaffs_GrossUnlock(dev);
1299 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1300 d_instantiate(dentry, inode);
1302 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
1303 obj->objectId, atomic_read(&inode->i_count)));
1307 (KERN_DEBUG "yaffs_mknod failed making object\n"));
1314 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1317 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
1318 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1320 /* attempt to fix dir bug - didn't work */
1328 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1329 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1330 struct nameidata *n)
1332 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1335 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
1336 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1339 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1346 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1347 dentry->d_name.name));
1349 dev = yaffs_InodeToObject(dir)->myDev;
1351 yaffs_GrossLock(dev);
1353 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1355 if (retVal == YAFFS_OK) {
1356 dentry->d_inode->i_nlink--;
1358 yaffs_GrossUnlock(dev);
1359 mark_inode_dirty(dentry->d_inode);
1362 yaffs_GrossUnlock(dev);
1369 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1370 struct dentry *dentry)
1372 struct inode *inode = old_dentry->d_inode;
1373 yaffs_Object *obj = NULL;
1374 yaffs_Object *link = NULL;
1377 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1379 obj = yaffs_InodeToObject(inode);
1382 yaffs_GrossLock(dev);
1384 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1387 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1392 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1393 d_instantiate(dentry, old_dentry->d_inode);
1394 atomic_inc(&old_dentry->d_inode->i_count);
1396 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1397 old_dentry->d_inode->i_nlink,
1398 atomic_read(&old_dentry->d_inode->i_count)));
1402 yaffs_GrossUnlock(dev);
1412 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1413 const char *symname)
1417 uid_t uid = current->fsuid;
1418 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1420 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1422 dev = yaffs_InodeToObject(dir)->myDev;
1423 yaffs_GrossLock(dev);
1424 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1425 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1426 yaffs_GrossUnlock(dev);
1430 struct inode *inode;
1432 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1433 d_instantiate(dentry, inode);
1434 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1437 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1444 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1451 obj = yaffs_DentryToObject(dentry);
1455 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1456 yaffs_GrossLock(dev);
1457 yaffs_FlushFile(obj, 1);
1458 yaffs_GrossUnlock(dev);
1463 * The VFS layer already does all the dentry stuff for rename.
1465 * NB: POSIX says you can rename an object over an old object of the same name
1467 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1468 struct inode *new_dir, struct dentry *new_dentry)
1471 int retVal = YAFFS_FAIL;
1472 yaffs_Object *target;
1474 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1475 dev = yaffs_InodeToObject(old_dir)->myDev;
1477 yaffs_GrossLock(dev);
1479 /* Check if the target is an existing directory that is not empty. */
1481 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1482 new_dentry->d_name.name);
1487 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1488 !ylist_empty(&target->variant.directoryVariant.children)) {
1490 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1492 retVal = YAFFS_FAIL;
1495 /* Now does unlinking internally using shadowing mechanism */
1496 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1499 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1500 old_dentry->d_name.name,
1501 yaffs_InodeToObject(new_dir),
1502 new_dentry->d_name.name);
1505 yaffs_GrossUnlock(dev);
1507 if (retVal == YAFFS_OK) {
1509 new_dentry->d_inode->i_nlink--;
1510 mark_inode_dirty(new_dentry->d_inode);
1520 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1522 struct inode *inode = dentry->d_inode;
1527 (KERN_DEBUG "yaffs_setattr of object %d\n",
1528 yaffs_InodeToObject(inode)->objectId));
1530 if ((error = inode_change_ok(inode, attr)) == 0) {
1532 dev = yaffs_InodeToObject(inode)->myDev;
1533 yaffs_GrossLock(dev);
1534 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1540 yaffs_GrossUnlock(dev);
1542 error = inode_setattr(inode, attr);
1547 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1548 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1550 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1551 struct super_block *sb = dentry->d_sb;
1552 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1553 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1555 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1557 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1559 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1562 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1564 yaffs_GrossLock(dev);
1566 buf->f_type = YAFFS_MAGIC;
1567 buf->f_bsize = sb->s_blocksize;
1568 buf->f_namelen = 255;
1570 if(dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)){
1571 /* Do this if chunk size is not a power of 2 */
1573 uint64_t bytesInDev;
1576 bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock +1))) *
1577 ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk));
1579 do_div(bytesInDev,sb->s_blocksize); /* bytesInDev becomes the number of blocks */
1580 buf->f_blocks = bytesInDev;
1582 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
1583 ((uint64_t)(dev->nDataBytesPerChunk));
1585 do_div(bytesFree,sb->s_blocksize);
1587 buf->f_bfree = bytesFree;
1589 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
1592 (dev->endBlock - dev->startBlock + 1) *
1593 dev->nChunksPerBlock /
1594 (sb->s_blocksize / dev->nDataBytesPerChunk);
1596 yaffs_GetNumberOfFreeChunks(dev) /
1597 (sb->s_blocksize / dev->nDataBytesPerChunk);
1600 (dev->endBlock - dev->startBlock + 1) *
1601 dev->nChunksPerBlock *
1602 (dev->nDataBytesPerChunk / sb->s_blocksize);
1605 yaffs_GetNumberOfFreeChunks(dev) *
1606 (dev->nDataBytesPerChunk / sb->s_blocksize);
1612 buf->f_bavail = buf->f_bfree;
1614 yaffs_GrossUnlock(dev);
1619 static int yaffs_do_sync_fs(struct super_block *sb)
1622 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1623 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_do_sync_fs\n"));
1626 yaffs_GrossLock(dev);
1629 yaffs_FlushEntireDeviceCache(dev);
1630 yaffs_CheckpointSave(dev);
1633 yaffs_GrossUnlock(dev);
1641 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1642 static void yaffs_write_super(struct super_block *sb)
1644 static int yaffs_write_super(struct super_block *sb)
1648 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_super\n"));
1649 if (yaffs_auto_checkpoint >= 2)
1650 yaffs_do_sync_fs(sb);
1651 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
1657 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1658 static int yaffs_sync_fs(struct super_block *sb, int wait)
1660 static int yaffs_sync_fs(struct super_block *sb)
1664 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_fs\n"));
1666 if (yaffs_auto_checkpoint >= 1)
1667 yaffs_do_sync_fs(sb);
1673 #ifdef YAFFS_USE_OWN_IGET
1675 static struct inode * yaffs_iget(struct super_block *sb, unsigned long ino)
1677 struct inode *inode;
1679 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1682 (KERN_DEBUG "yaffs_iget for %lu\n", ino));
1684 inode = iget_locked(sb, ino);
1686 return ERR_PTR(-ENOMEM);
1687 if (!(inode->i_state & I_NEW))
1690 /* NB This is called as a side effect of other functions, but
1691 * we had to release the lock to prevent deadlocks, so
1692 * need to lock again.
1695 yaffs_GrossLock(dev);
1697 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1699 yaffs_FillInodeFromObject(inode, obj);
1701 yaffs_GrossUnlock(dev);
1703 unlock_new_inode(inode);
1709 static void yaffs_read_inode(struct inode *inode)
1711 /* NB This is called as a side effect of other functions, but
1712 * we had to release the lock to prevent deadlocks, so
1713 * need to lock again.
1717 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1720 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1722 yaffs_GrossLock(dev);
1724 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1726 yaffs_FillInodeFromObject(inode, obj);
1728 yaffs_GrossUnlock(dev);
1733 static YLIST_HEAD(yaffs_dev_list);
1736 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
1738 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1740 if( *flags & MS_RDONLY ) {
1741 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1744 (KERN_DEBUG "yaffs_remount_fs: %s: RO\n", dev->name ));
1746 yaffs_GrossLock(dev);
1748 yaffs_FlushEntireDeviceCache(dev);
1750 yaffs_CheckpointSave(dev);
1755 yaffs_GrossUnlock(dev);
1759 (KERN_DEBUG "yaffs_remount_fs: %s: RW\n", dev->name ));
1766 static void yaffs_put_super(struct super_block *sb)
1768 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1770 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_put_super\n"));
1772 yaffs_GrossLock(dev);
1774 yaffs_FlushEntireDeviceCache(dev);
1776 yaffs_CheckpointSave(dev);
1778 if (dev->putSuperFunc) {
1779 dev->putSuperFunc(sb);
1782 yaffs_Deinitialise(dev);
1784 yaffs_GrossUnlock(dev);
1786 /* we assume this is protected by lock_kernel() in mount/umount */
1787 ylist_del(&dev->devList);
1789 if(dev->spareBuffer){
1790 YFREE(dev->spareBuffer);
1791 dev->spareBuffer = NULL;
1798 static void yaffs_MTDPutSuper(struct super_block *sb)
1801 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1807 put_mtd_device(mtd);
1811 static void yaffs_MarkSuperBlockDirty(void *vsb)
1813 struct super_block *sb = (struct super_block *)vsb;
1815 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_MarkSuperBlockDirty() sb = %p\n",sb));
1822 int skip_checkpoint_read;
1823 int skip_checkpoint_write;
1827 #define MAX_OPT_LEN 20
1828 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
1830 char cur_opt[MAX_OPT_LEN+1];
1834 /* Parse through the options which is a comma seperated list */
1836 while(options_str && *options_str && !error){
1837 memset(cur_opt,0,MAX_OPT_LEN+1);
1840 while(*options_str && *options_str != ','){
1841 if(p < MAX_OPT_LEN){
1842 cur_opt[p] = *options_str;
1848 if(!strcmp(cur_opt,"inband-tags"))
1849 options->inband_tags = 1;
1850 else if(!strcmp(cur_opt,"no-cache"))
1851 options->no_cache = 1;
1852 else if(!strcmp(cur_opt,"no-checkpoint-read"))
1853 options->skip_checkpoint_read = 1;
1854 else if(!strcmp(cur_opt,"no-checkpoint-write"))
1855 options->skip_checkpoint_write = 1;
1856 else if(!strcmp(cur_opt,"no-checkpoint")){
1857 options->skip_checkpoint_read = 1;
1858 options->skip_checkpoint_write = 1;
1860 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",cur_opt);
1869 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1870 struct super_block *sb,
1871 void *data, int silent)
1874 struct inode *inode = NULL;
1875 struct dentry *root;
1876 yaffs_Device *dev = 0;
1877 char devname_buf[BDEVNAME_SIZE + 1];
1878 struct mtd_info *mtd;
1880 char *data_str = (char *)data;
1882 yaffs_options options;
1884 sb->s_magic = YAFFS_MAGIC;
1885 sb->s_op = &yaffs_super_ops;
1886 sb->s_flags |= MS_NOATIME;
1889 printk(KERN_INFO "yaffs: sb is NULL\n");
1890 else if (!sb->s_dev)
1891 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1892 else if (!yaffs_devname(sb, devname_buf))
1893 printk(KERN_INFO "yaffs: devname is NULL\n");
1895 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1897 yaffs_devname(sb, devname_buf));
1902 printk(KERN_INFO "yaffs: passed flags \"%s\"\n",data_str);
1904 memset(&options,0,sizeof(options));
1906 if(yaffs_parse_options(&options,data_str)){
1907 /* Option parsing failed */
1912 sb->s_blocksize = PAGE_CACHE_SIZE;
1913 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1914 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1916 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1918 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1920 ("yaffs: Write verification disabled. All guarantees "
1921 "null and void\n"));
1924 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1926 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1927 yaffs_devname(sb, devname_buf)));
1929 /* Check it's an mtd device..... */
1930 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1931 return NULL; /* This isn't an mtd device */
1933 /* Get the device */
1934 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1936 T(YAFFS_TRACE_ALWAYS,
1937 ("yaffs: MTD device #%u doesn't appear to exist\n",
1941 /* Check it's NAND */
1942 if (mtd->type != MTD_NANDFLASH) {
1943 T(YAFFS_TRACE_ALWAYS,
1944 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1948 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1949 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1950 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1951 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1952 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1953 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1954 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1955 T(YAFFS_TRACE_OS, (" %s %d\n", WRITE_SIZE_STR, WRITE_SIZE(mtd)));
1956 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1957 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1958 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1960 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1962 if (yaffsVersion == 1 &&
1963 WRITE_SIZE(mtd) >= 2048) {
1964 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1968 /* Added NCB 26/5/2006 for completeness */
1969 if (yaffsVersion == 2 &&
1970 !options.inband_tags &&
1971 WRITE_SIZE(mtd) == 512){
1972 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n"));
1978 if (yaffsVersion == 2) {
1979 /* Check for version 2 style functions */
1981 !mtd->block_isbad ||
1982 !mtd->block_markbad ||
1985 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1986 !mtd->read_oob || !mtd->write_oob) {
1989 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1991 T(YAFFS_TRACE_ALWAYS,
1992 ("yaffs: MTD device does not support required "
1997 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1998 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
1999 !options.inband_tags) {
2000 T(YAFFS_TRACE_ALWAYS,
2001 ("yaffs: MTD device does not have the "
2002 "right page sizes\n"));
2006 /* Check for V1 style functions */
2010 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2011 !mtd->read_oob || !mtd->write_oob) {
2014 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2016 T(YAFFS_TRACE_ALWAYS,
2017 ("yaffs: MTD device does not support required "
2022 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2023 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2024 T(YAFFS_TRACE_ALWAYS,
2025 ("yaffs: MTD device does not support have the "
2026 "right page sizes\n"));
2031 /* OK, so if we got here, we have an MTD that's NAND and looks
2032 * like it has the right capabilities
2033 * Set the yaffs_Device up for mtd
2036 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2037 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2039 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2042 /* Deep shit could not allocate device structure */
2043 T(YAFFS_TRACE_ALWAYS,
2044 ("yaffs_read_super: Failed trying to allocate "
2045 "yaffs_Device. \n"));
2049 memset(dev, 0, sizeof(yaffs_Device));
2050 dev->genericDevice = mtd;
2051 dev->name = mtd->name;
2053 /* Set up the memory size parameters.... */
2055 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
2056 dev->startBlock = 0;
2057 dev->endBlock = nBlocks - 1;
2058 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2059 dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2060 dev->nReservedBlocks = 5;
2061 dev->nShortOpCaches = (options.no_cache) ? 0 : 10;
2062 dev->inbandTags = options.inband_tags;
2064 /* ... and the functions. */
2065 if (yaffsVersion == 2) {
2066 dev->writeChunkWithTagsToNAND =
2067 nandmtd2_WriteChunkWithTagsToNAND;
2068 dev->readChunkWithTagsFromNAND =
2069 nandmtd2_ReadChunkWithTagsFromNAND;
2070 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2071 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
2072 dev->spareBuffer = YMALLOC(mtd->oobsize);
2074 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2075 dev->totalBytesPerChunk = mtd->writesize;
2076 dev->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2078 dev->totalBytesPerChunk = mtd->oobblock;
2079 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2081 nBlocks = mtd->size / mtd->erasesize;
2083 dev->startBlock = 0;
2084 dev->endBlock = nBlocks - 1;
2086 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2087 /* use the MTD interface in yaffs_mtdif1.c */
2088 dev->writeChunkWithTagsToNAND =
2089 nandmtd1_WriteChunkWithTagsToNAND;
2090 dev->readChunkWithTagsFromNAND =
2091 nandmtd1_ReadChunkWithTagsFromNAND;
2092 dev->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2093 dev->queryNANDBlock = nandmtd1_QueryNANDBlock;
2095 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2096 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2100 /* ... and common functions */
2101 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2102 dev->initialiseNAND = nandmtd_InitialiseNAND;
2104 dev->putSuperFunc = yaffs_MTDPutSuper;
2106 dev->superBlock = (void *)sb;
2107 dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2110 #ifndef CONFIG_YAFFS_DOES_ECC
2111 dev->useNANDECC = 1;
2114 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2115 dev->wideTnodesDisabled = 1;
2118 dev->skipCheckpointRead = options.skip_checkpoint_read;
2119 dev->skipCheckpointWrite = options.skip_checkpoint_write;
2121 /* we assume this is protected by lock_kernel() in mount/umount */
2122 ylist_add_tail(&dev->devList, &yaffs_dev_list);
2124 init_MUTEX(&dev->grossLock);
2126 yaffs_GrossLock(dev);
2128 err = yaffs_GutsInitialise(dev);
2131 ("yaffs_read_super: guts initialised %s\n",
2132 (err == YAFFS_OK) ? "OK" : "FAILED"));
2134 /* Release lock before yaffs_get_inode() */
2135 yaffs_GrossUnlock(dev);
2137 /* Create root inode */
2138 if (err == YAFFS_OK)
2139 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2145 inode->i_op = &yaffs_dir_inode_operations;
2146 inode->i_fop = &yaffs_dir_operations;
2148 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
2150 root = d_alloc_root(inode);
2152 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
2159 sb->s_dirt = !dev->isCheckpointed;
2160 T(YAFFS_TRACE_ALWAYS,
2161 ("yaffs_read_super: isCheckpointed %d\n", dev->isCheckpointed));
2163 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
2168 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2169 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2172 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2175 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2176 static int yaffs_read_super(struct file_system_type *fs,
2177 int flags, const char *dev_name,
2178 void *data, struct vfsmount *mnt)
2181 return get_sb_bdev(fs, flags, dev_name, data,
2182 yaffs_internal_read_super_mtd, mnt);
2185 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2186 int flags, const char *dev_name,
2190 return get_sb_bdev(fs, flags, dev_name, data,
2191 yaffs_internal_read_super_mtd);
2195 static struct file_system_type yaffs_fs_type = {
2196 .owner = THIS_MODULE,
2198 .get_sb = yaffs_read_super,
2199 .kill_sb = kill_block_super,
2200 .fs_flags = FS_REQUIRES_DEV,
2203 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2206 return yaffs_internal_read_super(1, sb, data, silent);
2209 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2214 #ifdef CONFIG_YAFFS_YAFFS2
2216 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2217 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2220 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2223 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2224 static int yaffs2_read_super(struct file_system_type *fs,
2225 int flags, const char *dev_name, void *data,
2226 struct vfsmount *mnt)
2228 return get_sb_bdev(fs, flags, dev_name, data,
2229 yaffs2_internal_read_super_mtd, mnt);
2232 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2233 int flags, const char *dev_name,
2237 return get_sb_bdev(fs, flags, dev_name, data,
2238 yaffs2_internal_read_super_mtd);
2242 static struct file_system_type yaffs2_fs_type = {
2243 .owner = THIS_MODULE,
2245 .get_sb = yaffs2_read_super,
2246 .kill_sb = kill_block_super,
2247 .fs_flags = FS_REQUIRES_DEV,
2250 static struct super_block *yaffs2_read_super(struct super_block *sb,
2251 void *data, int silent)
2253 return yaffs_internal_read_super(2, sb, data, silent);
2256 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
2260 #endif /* CONFIG_YAFFS_YAFFS2 */
2262 static struct proc_dir_entry *my_proc_entry;
2264 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
2266 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
2267 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
2268 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk);
2269 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
2270 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
2271 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
2272 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
2273 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks);
2274 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
2275 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
2276 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
2277 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
2278 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
2279 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
2280 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
2281 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
2282 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
2283 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
2284 buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
2285 buf += sprintf(buf, "passiveGCs......... %d\n",
2286 dev->passiveGarbageCollections);
2287 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
2288 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches);
2289 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
2290 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
2291 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
2292 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
2293 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
2294 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
2295 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
2296 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
2298 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
2299 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
2300 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
2301 buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags);
2306 static int yaffs_proc_read(char *page,
2308 off_t offset, int count, int *eof, void *data)
2310 struct ylist_head *item;
2315 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
2316 * We use 'offset' (*ppos) to indicate where we are in devList.
2317 * This also assumes the user has posted a read buffer large
2318 * enough to hold the complete output; but that's life in /proc.
2323 /* Print header first */
2325 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
2326 "\n%s\n%s\n", yaffs_fs_c_version,
2327 yaffs_guts_c_version);
2330 /* hold lock_kernel while traversing yaffs_dev_list */
2333 /* Locate and print the Nth entry. Order N-squared but N is small. */
2334 ylist_for_each(item, &yaffs_dev_list) {
2335 yaffs_Device *dev = ylist_entry(item, yaffs_Device, devList);
2340 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
2341 buf = yaffs_dump_dev(buf, dev);
2346 return buf - page < count ? buf - page : count;
2350 * Set the verbosity of the warnings and error messages.
2352 * Note that the names can only be a..z or _ with the current code.
2357 unsigned mask_bitfield;
2359 {"allocate", YAFFS_TRACE_ALLOCATE},
2360 {"always", YAFFS_TRACE_ALWAYS},
2361 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
2362 {"buffers", YAFFS_TRACE_BUFFERS},
2363 {"bug", YAFFS_TRACE_BUG},
2364 {"checkpt", YAFFS_TRACE_CHECKPOINT},
2365 {"deletion", YAFFS_TRACE_DELETION},
2366 {"erase", YAFFS_TRACE_ERASE},
2367 {"error", YAFFS_TRACE_ERROR},
2368 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
2369 {"gc", YAFFS_TRACE_GC},
2370 {"mtd", YAFFS_TRACE_MTD},
2371 {"nandaccess", YAFFS_TRACE_NANDACCESS},
2372 {"os", YAFFS_TRACE_OS},
2373 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
2374 {"scan", YAFFS_TRACE_SCAN},
2375 {"tracing", YAFFS_TRACE_TRACING},
2377 {"verify", YAFFS_TRACE_VERIFY},
2378 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
2379 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
2380 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
2382 {"write", YAFFS_TRACE_WRITE},
2383 {"all", 0xffffffff},
2388 #define MAX_MASK_NAME_LENGTH 40
2389 static int yaffs_proc_write(struct file *file, const char *buf,
2390 unsigned long count, void *data)
2392 unsigned rg = 0, mask_bitfield;
2396 char substring[MAX_MASK_NAME_LENGTH+1];
2402 rg = yaffs_traceMask;
2404 while (!done && (pos < count)) {
2406 while ((pos < count) && isspace(buf[pos])) {
2424 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
2425 if (end > buf + pos) {
2426 mask_name = "numeral";
2427 len = end - (buf + pos);
2431 for(x = buf + pos, i = 0;
2432 (*x == '_' || (*x >='a' && *x <= 'z')) &&
2433 i <MAX_MASK_NAME_LENGTH; x++, i++, pos++)
2435 substring[i] = '\0';
2437 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2438 if(strcmp(substring,mask_flags[i].mask_name) == 0){
2439 mask_name = mask_flags[i].mask_name;
2440 mask_bitfield = mask_flags[i].mask_bitfield;
2447 if (mask_name != NULL) {
2451 rg &= ~mask_bitfield;
2454 rg |= mask_bitfield;
2460 rg |= mask_bitfield;
2466 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
2468 printk("new trace = 0x%08X\n",yaffs_traceMask);
2470 if (rg & YAFFS_TRACE_ALWAYS) {
2471 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2473 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
2474 printk("%c%s\n", flag, mask_flags[i].mask_name);
2481 /* Stuff to handle installation of file systems */
2482 struct file_system_to_install {
2483 struct file_system_type *fst;
2487 static struct file_system_to_install fs_to_install[] = {
2488 //#ifdef CONFIG_YAFFS_YAFFS1
2489 {&yaffs_fs_type, 0},
2491 //#ifdef CONFIG_YAFFS_YAFFS2
2492 {&yaffs2_fs_type, 0},
2497 static int __init init_yaffs_fs(void)
2500 struct file_system_to_install *fsinst;
2502 T(YAFFS_TRACE_ALWAYS,
2503 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
2505 /* Install the proc_fs entry */
2506 my_proc_entry = create_proc_entry("yaffs",
2510 if (my_proc_entry) {
2511 my_proc_entry->write_proc = yaffs_proc_write;
2512 my_proc_entry->read_proc = yaffs_proc_read;
2513 my_proc_entry->data = NULL;
2518 /* Now add the file system entries */
2520 fsinst = fs_to_install;
2522 while (fsinst->fst && !error) {
2523 error = register_filesystem(fsinst->fst);
2525 fsinst->installed = 1;
2530 /* Any errors? uninstall */
2532 fsinst = fs_to_install;
2534 while (fsinst->fst) {
2535 if (fsinst->installed) {
2536 unregister_filesystem(fsinst->fst);
2537 fsinst->installed = 0;
2546 static void __exit exit_yaffs_fs(void)
2549 struct file_system_to_install *fsinst;
2551 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
2554 remove_proc_entry("yaffs", YPROC_ROOT);
2556 fsinst = fs_to_install;
2558 while (fsinst->fst) {
2559 if (fsinst->installed) {
2560 unregister_filesystem(fsinst->fst);
2561 fsinst->installed = 0;
2568 module_init(init_yaffs_fs)
2569 module_exit(exit_yaffs_fs)
2571 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
2572 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
2573 MODULE_LICENSE("GPL");