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.77 2009-03-09 07:25:09 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 <linux/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
100 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28))
101 static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size)
103 uint64_t result = partition_size;
104 do_div(result, block_size);
105 return (uint32_t)result;
108 #define YCALCBLOCKS(s, b) ((s)/(b))
111 #include <linux/uaccess.h>
113 #include "yportenv.h"
114 #include "yaffs_guts.h"
116 #include <linux/mtd/mtd.h>
117 #include "yaffs_mtdif.h"
118 #include "yaffs_mtdif1.h"
119 #include "yaffs_mtdif2.h"
121 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS;
122 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
123 unsigned int yaffs_auto_checkpoint = 1;
125 /* Module Parameters */
126 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
127 module_param(yaffs_traceMask, uint, 0644);
128 module_param(yaffs_wr_attempts, uint, 0644);
129 module_param(yaffs_auto_checkpoint, uint, 0644);
131 MODULE_PARM(yaffs_traceMask, "i");
132 MODULE_PARM(yaffs_wr_attempts, "i");
133 MODULE_PARM(yaffs_auto_checkpoint, "i");
136 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
137 /* use iget and read_inode */
138 #define Y_IGET(sb, inum) iget((sb), (inum))
139 static void yaffs_read_inode(struct inode *inode);
142 /* Call local equivalent */
143 #define YAFFS_USE_OWN_IGET
144 #define Y_IGET(sb, inum) yaffs_iget((sb), (inum))
146 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
149 /*#define T(x) printk x */
151 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
152 #define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)
154 #define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip)
157 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
158 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
160 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
161 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
163 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
166 static void yaffs_put_super(struct super_block *sb);
168 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
170 static ssize_t yaffs_hold_space(struct file *f);
171 static void yaffs_release_space(struct file *f);
173 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
174 static int yaffs_file_flush(struct file *file, fl_owner_t id);
176 static int yaffs_file_flush(struct file *file);
179 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
182 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
184 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
185 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
186 struct nameidata *n);
187 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
188 struct nameidata *n);
190 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
191 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
193 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
194 struct dentry *dentry);
195 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
196 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
197 const char *symname);
198 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
200 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
201 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
204 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
207 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
208 struct inode *new_dir, struct dentry *new_dentry);
209 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
211 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
212 static int yaffs_sync_fs(struct super_block *sb, int wait);
213 static void yaffs_write_super(struct super_block *sb);
215 static int yaffs_sync_fs(struct super_block *sb);
216 static int yaffs_write_super(struct super_block *sb);
219 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
220 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
221 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
222 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
224 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
227 #ifdef YAFFS_HAS_PUT_INODE
228 static void yaffs_put_inode(struct inode *inode);
231 static void yaffs_delete_inode(struct inode *);
232 static void yaffs_clear_inode(struct inode *);
234 static int yaffs_readpage(struct file *file, struct page *page);
235 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
236 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
238 static int yaffs_writepage(struct page *page);
242 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
243 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
244 loff_t pos, unsigned len, unsigned flags,
245 struct page **pagep, void **fsdata);
246 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
247 loff_t pos, unsigned len, unsigned copied,
248 struct page *pg, void *fsdadata);
250 static int yaffs_prepare_write(struct file *f, struct page *pg,
251 unsigned offset, unsigned to);
252 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
257 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
259 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
260 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
262 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
265 static struct address_space_operations yaffs_file_address_operations = {
266 .readpage = yaffs_readpage,
267 .writepage = yaffs_writepage,
268 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
269 .write_begin = yaffs_write_begin,
270 .write_end = yaffs_write_end,
272 .prepare_write = yaffs_prepare_write,
273 .commit_write = yaffs_commit_write,
277 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
278 static const struct file_operations yaffs_file_operations = {
279 .read = do_sync_read,
280 .write = do_sync_write,
281 .aio_read = generic_file_aio_read,
282 .aio_write = generic_file_aio_write,
283 .mmap = generic_file_mmap,
284 .flush = yaffs_file_flush,
285 .fsync = yaffs_sync_object,
286 .splice_read = generic_file_splice_read,
287 .splice_write = generic_file_splice_write,
288 .llseek = generic_file_llseek,
291 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
293 static const struct file_operations yaffs_file_operations = {
294 .read = do_sync_read,
295 .write = do_sync_write,
296 .aio_read = generic_file_aio_read,
297 .aio_write = generic_file_aio_write,
298 .mmap = generic_file_mmap,
299 .flush = yaffs_file_flush,
300 .fsync = yaffs_sync_object,
301 .sendfile = generic_file_sendfile,
306 static const struct file_operations yaffs_file_operations = {
307 .read = generic_file_read,
308 .write = generic_file_write,
309 .mmap = generic_file_mmap,
310 .flush = yaffs_file_flush,
311 .fsync = yaffs_sync_object,
312 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
313 .sendfile = generic_file_sendfile,
318 static const struct inode_operations yaffs_file_inode_operations = {
319 .setattr = yaffs_setattr,
322 static const struct inode_operations yaffs_symlink_inode_operations = {
323 .readlink = yaffs_readlink,
324 .follow_link = yaffs_follow_link,
325 .setattr = yaffs_setattr,
328 static const struct inode_operations yaffs_dir_inode_operations = {
329 .create = yaffs_create,
330 .lookup = yaffs_lookup,
332 .unlink = yaffs_unlink,
333 .symlink = yaffs_symlink,
334 .mkdir = yaffs_mkdir,
335 .rmdir = yaffs_unlink,
336 .mknod = yaffs_mknod,
337 .rename = yaffs_rename,
338 .setattr = yaffs_setattr,
341 static const struct file_operations yaffs_dir_operations = {
342 .read = generic_read_dir,
343 .readdir = yaffs_readdir,
344 .fsync = yaffs_sync_object,
347 static const struct super_operations yaffs_super_ops = {
348 .statfs = yaffs_statfs,
350 #ifndef YAFFS_USE_OWN_IGET
351 .read_inode = yaffs_read_inode,
353 #ifdef YAFFS_HAS_PUT_INODE
354 .put_inode = yaffs_put_inode,
356 .put_super = yaffs_put_super,
357 .delete_inode = yaffs_delete_inode,
358 .clear_inode = yaffs_clear_inode,
359 .sync_fs = yaffs_sync_fs,
360 .write_super = yaffs_write_super,
363 static void yaffs_GrossLock(yaffs_Device *dev)
365 T(YAFFS_TRACE_OS, ("yaffs locking %p\n", current));
366 down(&dev->grossLock);
367 T(YAFFS_TRACE_OS, ("yaffs locked %p\n", current));
370 static void yaffs_GrossUnlock(yaffs_Device *dev)
372 T(YAFFS_TRACE_OS, ("yaffs unlocking %p\n", current));
376 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
379 unsigned char *alias;
382 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
384 yaffs_GrossLock(dev);
386 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
388 yaffs_GrossUnlock(dev);
393 ret = vfs_readlink(dentry, buffer, buflen, alias);
398 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
399 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
401 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
404 unsigned char *alias;
406 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
408 yaffs_GrossLock(dev);
410 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
412 yaffs_GrossUnlock(dev);
419 ret = vfs_follow_link(nd, alias);
422 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
429 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
433 * Lookup is used to find objects in the fs
435 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
437 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
440 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
444 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
446 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
448 yaffs_GrossLock(dev);
451 ("yaffs_lookup for %d:%s\n",
452 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
454 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
455 dentry->d_name.name);
457 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
459 /* Can't hold gross lock when calling yaffs_get_inode() */
460 yaffs_GrossUnlock(dev);
464 ("yaffs_lookup found %d\n", obj->objectId));
466 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
470 ("yaffs_loookup dentry \n"));
471 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
472 * d_add even if NULL inode */
474 /*dget(dentry); // try to solve directory bug */
475 d_add(dentry, inode);
483 T(YAFFS_TRACE_OS, ("yaffs_lookup not found\n"));
487 /* added NCB for 2.5/6 compatability - forces add even if inode is
488 * NULL which creates dentry hash */
489 d_add(dentry, inode);
492 /* return (ERR_PTR(-EIO)); */
497 #ifdef YAFFS_HAS_PUT_INODE
499 /* For now put inode is just for debugging
500 * Put inode is called when the inode **structure** is put.
502 static void yaffs_put_inode(struct inode *inode)
505 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
506 atomic_read(&inode->i_count)));
511 /* clear is called to tell the fs to release any per-inode data it holds */
512 static void yaffs_clear_inode(struct inode *inode)
517 obj = yaffs_InodeToObject(inode);
520 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
521 atomic_read(&inode->i_count),
522 obj ? "object exists" : "null object"));
526 yaffs_GrossLock(dev);
528 /* Clear the association between the inode and
532 yaffs_InodeToObjectLV(inode) = NULL;
534 /* If the object freeing was deferred, then the real
536 * This should fix the inode inconsistency problem.
539 yaffs_HandleDeferedFree(obj);
541 yaffs_GrossUnlock(dev);
546 /* delete is called when the link count is zero and the inode
547 * is put (ie. nobody wants to know about it anymore, time to
549 * NB Must call clear_inode()
551 static void yaffs_delete_inode(struct inode *inode)
553 yaffs_Object *obj = yaffs_InodeToObject(inode);
557 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
558 atomic_read(&inode->i_count),
559 obj ? "object exists" : "null object"));
563 yaffs_GrossLock(dev);
564 yaffs_DeleteObject(obj);
565 yaffs_GrossUnlock(dev);
567 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
568 truncate_inode_pages(&inode->i_data, 0);
573 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
574 static int yaffs_file_flush(struct file *file, fl_owner_t id)
576 static int yaffs_file_flush(struct file *file)
579 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
581 yaffs_Device *dev = obj->myDev;
584 ("yaffs_file_flush object %d (%s)\n", obj->objectId,
585 obj->dirty ? "dirty" : "clean"));
587 yaffs_GrossLock(dev);
589 yaffs_FlushFile(obj, 1);
591 yaffs_GrossUnlock(dev);
596 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
598 /* Lifted from jffs2 */
601 unsigned char *pg_buf;
606 T(YAFFS_TRACE_OS, ("yaffs_readpage at %08x, size %08x\n",
607 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
608 (unsigned)PAGE_CACHE_SIZE));
610 obj = yaffs_DentryToObject(f->f_dentry);
614 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
615 BUG_ON(!PageLocked(pg));
622 /* FIXME: Can kmap fail? */
624 yaffs_GrossLock(dev);
627 yaffs_ReadDataFromFile(obj, pg_buf,
628 pg->index << PAGE_CACHE_SHIFT,
631 yaffs_GrossUnlock(dev);
637 ClearPageUptodate(pg);
644 flush_dcache_page(pg);
647 T(YAFFS_TRACE_OS, ("yaffs_readpage done\n"));
651 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
653 int ret = yaffs_readpage_nolock(f, pg);
658 static int yaffs_readpage(struct file *f, struct page *pg)
660 return yaffs_readpage_unlock(f, pg);
663 /* writepage inspired by/stolen from smbfs */
665 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
666 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
668 static int yaffs_writepage(struct page *page)
671 struct address_space *mapping = page->mapping;
672 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
674 unsigned long end_index;
682 inode = mapping->host;
686 if (offset > inode->i_size) {
688 ("yaffs_writepage at %08x, inode size = %08x!!!\n",
689 (unsigned)(page->index << PAGE_CACHE_SHIFT),
690 (unsigned)inode->i_size));
692 (" -> don't care!!\n"));
697 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
700 if (page->index < end_index)
701 nBytes = PAGE_CACHE_SIZE;
703 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
709 obj = yaffs_InodeToObject(inode);
710 yaffs_GrossLock(obj->myDev);
713 ("yaffs_writepage at %08x, size %08x\n",
714 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
716 ("writepag0: obj = %05x, ino = %05x\n",
717 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
719 nWritten = yaffs_WriteDataToFile(obj, buffer,
720 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
723 ("writepag1: obj = %05x, ino = %05x\n",
724 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
726 yaffs_GrossUnlock(obj->myDev);
729 SetPageUptodate(page);
733 return (nWritten == nBytes) ? 0 : -ENOSPC;
737 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
738 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
739 loff_t pos, unsigned len, unsigned flags,
740 struct page **pagep, void **fsdata)
742 struct page *pg = NULL;
743 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
744 uint32_t offset = pos & (PAGE_CACHE_SIZE - 1);
745 uint32_t to = offset + len;
750 T(YAFFS_TRACE_OS, ("start yaffs_write_begin\n"));
752 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28)
753 pg = grab_cache_page_write_begin(mapping, index, flags);
755 pg = __grab_cache_page(mapping, index);
764 space_held = yaffs_hold_space(filp);
771 /* Update page if required */
773 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
774 ret = yaffs_readpage_nolock(filp, pg);
779 /* Happy path return */
780 T(YAFFS_TRACE_OS, ("end yaffs_write_begin - ok\n"));
785 T(YAFFS_TRACE_OS, ("end yaffs_write_begin fail returning %d\n", ret));
787 yaffs_release_space(filp);
790 page_cache_release(pg);
797 static int yaffs_prepare_write(struct file *f, struct page *pg,
798 unsigned offset, unsigned to)
800 T(YAFFS_TRACE_OS, ("yaffs_prepair_write\n"));
802 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
803 return yaffs_readpage_nolock(f, pg);
808 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
809 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
810 loff_t pos, unsigned len, unsigned copied,
811 struct page *pg, void *fsdadata)
815 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
818 addr = kva + offset_into_page;
821 ("yaffs_write_end addr %x pos %x nBytes %d\n",
825 ret = yaffs_file_write(filp, addr, copied, &pos);
829 ("yaffs_write_end not same size ret %d copied %d\n",
832 ClearPageUptodate(pg);
839 yaffs_release_space(filp);
841 page_cache_release(pg);
846 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
851 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
852 int nBytes = to - offset;
861 saddr = (unsigned) addr;
864 ("yaffs_commit_write addr %x pos %x nBytes %d\n",
865 saddr, spos, nBytes));
867 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
869 if (nWritten != nBytes) {
871 ("yaffs_commit_write not same size nWritten %d nBytes %d\n",
874 ClearPageUptodate(pg);
882 ("yaffs_commit_write returning %d\n",
883 nWritten == nBytes ? 0 : nWritten));
885 return nWritten == nBytes ? 0 : nWritten;
890 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
895 /* Check mode against the variant type and attempt to repair if broken. */
896 __u32 mode = obj->yst_mode;
897 switch (obj->variantType) {
898 case YAFFS_OBJECT_TYPE_FILE:
899 if (!S_ISREG(mode)) {
900 obj->yst_mode &= ~S_IFMT;
901 obj->yst_mode |= S_IFREG;
905 case YAFFS_OBJECT_TYPE_SYMLINK:
906 if (!S_ISLNK(mode)) {
907 obj->yst_mode &= ~S_IFMT;
908 obj->yst_mode |= S_IFLNK;
912 case YAFFS_OBJECT_TYPE_DIRECTORY:
913 if (!S_ISDIR(mode)) {
914 obj->yst_mode &= ~S_IFMT;
915 obj->yst_mode |= S_IFDIR;
919 case YAFFS_OBJECT_TYPE_UNKNOWN:
920 case YAFFS_OBJECT_TYPE_HARDLINK:
921 case YAFFS_OBJECT_TYPE_SPECIAL:
927 inode->i_flags |= S_NOATIME;
929 inode->i_ino = obj->objectId;
930 inode->i_mode = obj->yst_mode;
931 inode->i_uid = obj->yst_uid;
932 inode->i_gid = obj->yst_gid;
933 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
934 inode->i_blksize = inode->i_sb->s_blocksize;
936 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
938 inode->i_rdev = old_decode_dev(obj->yst_rdev);
939 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
940 inode->i_atime.tv_nsec = 0;
941 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
942 inode->i_mtime.tv_nsec = 0;
943 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
944 inode->i_ctime.tv_nsec = 0;
946 inode->i_rdev = obj->yst_rdev;
947 inode->i_atime = obj->yst_atime;
948 inode->i_mtime = obj->yst_mtime;
949 inode->i_ctime = obj->yst_ctime;
951 inode->i_size = yaffs_GetObjectFileLength(obj);
952 inode->i_blocks = (inode->i_size + 511) >> 9;
954 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 ("yaffs_FileInode invalid parameters\n"));
997 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1000 struct inode *inode;
1004 ("yaffs_get_inode for NULL super_block!!\n"));
1011 ("yaffs_get_inode for NULL object!!\n"));
1017 ("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;
1053 ("yaffs_file_write: hey obj is null!\n"));
1056 ("yaffs_file_write about to write writing %zu bytes"
1057 "to object %d at %d\n",
1058 n, obj->objectId, ipos));
1060 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1063 ("yaffs_file_write writing %zu bytes, %d written at %d\n",
1064 n, nWritten, ipos));
1069 if (ipos > inode->i_size) {
1070 inode->i_size = ipos;
1071 inode->i_blocks = (ipos + 511) >> 9;
1074 ("yaffs_file_write size updated to %d bytes, "
1076 ipos, (int)(inode->i_blocks)));
1080 yaffs_GrossUnlock(dev);
1081 return nWritten == 0 ? -ENOSPC : nWritten;
1084 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1085 /* For now we just assume few parallel writes and check against a small number. */
1086 /* Todo: need to do this with a counter to handle parallel reads better */
1088 static ssize_t yaffs_hold_space(struct file *f)
1096 obj = yaffs_DentryToObject(f->f_dentry);
1100 yaffs_GrossLock(dev);
1102 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1104 yaffs_GrossUnlock(dev);
1106 return (nFreeChunks > 20) ? 1 : 0;
1109 static void yaffs_release_space(struct file *f)
1115 obj = yaffs_DentryToObject(f->f_dentry);
1119 yaffs_GrossLock(dev);
1122 yaffs_GrossUnlock(dev);
1125 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1129 struct inode *inode = f->f_dentry->d_inode;
1130 unsigned long offset, curoffs;
1131 struct ylist_head *i;
1134 char name[YAFFS_MAX_NAME_LENGTH + 1];
1136 obj = yaffs_DentryToObject(f->f_dentry);
1139 yaffs_GrossLock(dev);
1143 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
1147 ("yaffs_readdir: entry . ino %d \n",
1148 (int)inode->i_ino));
1149 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1156 ("yaffs_readdir: entry .. ino %d \n",
1157 (int)f->f_dentry->d_parent->d_inode->i_ino));
1158 if (filldir(dirent, "..", 2, offset,
1159 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1167 /* If the directory has changed since the open or last call to
1168 readdir, rewind to after the 2 canned entries. */
1170 if (f->f_version != inode->i_version) {
1173 f->f_version = inode->i_version;
1176 ylist_for_each(i, &obj->variant.directoryVariant.children) {
1178 if (curoffs >= offset) {
1179 l = ylist_entry(i, yaffs_Object, siblings);
1181 yaffs_GetObjectName(l, name,
1182 YAFFS_MAX_NAME_LENGTH + 1);
1184 ("yaffs_readdir: %s inode %d\n", name,
1185 yaffs_GetObjectInode(l)));
1191 yaffs_GetObjectInode(l),
1192 yaffs_GetObjectType(l)) < 0)
1202 yaffs_GrossUnlock(dev);
1208 * File creation. Allocate an inode, and we're done..
1211 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1214 #define YCRED(x) (x->cred)
1217 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1218 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1221 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1225 struct inode *inode;
1227 yaffs_Object *obj = NULL;
1230 yaffs_Object *parent = yaffs_InodeToObject(dir);
1232 int error = -ENOSPC;
1233 uid_t uid = YCRED(current)->fsuid;
1234 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1236 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1241 ("yaffs_mknod: parent object %d type %d\n",
1242 parent->objectId, parent->variantType));
1245 ("yaffs_mknod: could not get parent object\n"));
1249 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
1251 dentry->d_name.name, mode, rdev));
1253 dev = parent->myDev;
1255 yaffs_GrossLock(dev);
1257 switch (mode & S_IFMT) {
1259 /* Special (socket, fifo, device...) */
1260 T(YAFFS_TRACE_OS, ("yaffs_mknod: making special\n"));
1261 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1262 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1263 gid, old_encode_dev(rdev));
1265 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1269 case S_IFREG: /* file */
1270 T(YAFFS_TRACE_OS, ("yaffs_mknod: making file\n"));
1271 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1274 case S_IFDIR: /* directory */
1276 ("yaffs_mknod: making directory\n"));
1277 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1280 case S_IFLNK: /* symlink */
1281 T(YAFFS_TRACE_OS, ("yaffs_mknod: making symlink\n"));
1282 obj = NULL; /* Do we ever get here? */
1286 /* Can not call yaffs_get_inode() with gross lock held */
1287 yaffs_GrossUnlock(dev);
1290 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1291 d_instantiate(dentry, inode);
1293 ("yaffs_mknod created object %d count = %d\n",
1294 obj->objectId, atomic_read(&inode->i_count)));
1298 ("yaffs_mknod failed making object\n"));
1305 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1308 T(YAFFS_TRACE_OS, ("yaffs_mkdir\n"));
1309 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1313 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1314 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1315 struct nameidata *n)
1317 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1320 T(YAFFS_TRACE_OS, ("yaffs_create\n"));
1321 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1324 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1331 ("yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1332 dentry->d_name.name));
1334 dev = yaffs_InodeToObject(dir)->myDev;
1336 yaffs_GrossLock(dev);
1338 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1340 if (retVal == YAFFS_OK) {
1341 dentry->d_inode->i_nlink--;
1343 yaffs_GrossUnlock(dev);
1344 mark_inode_dirty(dentry->d_inode);
1347 yaffs_GrossUnlock(dev);
1354 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1355 struct dentry *dentry)
1357 struct inode *inode = old_dentry->d_inode;
1358 yaffs_Object *obj = NULL;
1359 yaffs_Object *link = NULL;
1362 T(YAFFS_TRACE_OS, ("yaffs_link\n"));
1364 obj = yaffs_InodeToObject(inode);
1367 yaffs_GrossLock(dev);
1369 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1370 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1374 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1375 d_instantiate(dentry, old_dentry->d_inode);
1376 atomic_inc(&old_dentry->d_inode->i_count);
1378 ("yaffs_link link count %d i_count %d\n",
1379 old_dentry->d_inode->i_nlink,
1380 atomic_read(&old_dentry->d_inode->i_count)));
1383 yaffs_GrossUnlock(dev);
1391 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1392 const char *symname)
1396 uid_t uid = YCRED(current)->fsuid;
1397 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1399 T(YAFFS_TRACE_OS, ("yaffs_symlink\n"));
1401 dev = yaffs_InodeToObject(dir)->myDev;
1402 yaffs_GrossLock(dev);
1403 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1404 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1405 yaffs_GrossUnlock(dev);
1408 struct inode *inode;
1410 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1411 d_instantiate(dentry, inode);
1412 T(YAFFS_TRACE_OS, ("symlink created OK\n"));
1415 T(YAFFS_TRACE_OS, ("symlink not created\n"));
1421 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1428 obj = yaffs_DentryToObject(dentry);
1432 T(YAFFS_TRACE_OS, ("yaffs_sync_object\n"));
1433 yaffs_GrossLock(dev);
1434 yaffs_FlushFile(obj, 1);
1435 yaffs_GrossUnlock(dev);
1440 * The VFS layer already does all the dentry stuff for rename.
1442 * NB: POSIX says you can rename an object over an old object of the same name
1444 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1445 struct inode *new_dir, struct dentry *new_dentry)
1448 int retVal = YAFFS_FAIL;
1449 yaffs_Object *target;
1451 T(YAFFS_TRACE_OS, ("yaffs_rename\n"));
1452 dev = yaffs_InodeToObject(old_dir)->myDev;
1454 yaffs_GrossLock(dev);
1456 /* Check if the target is an existing directory that is not empty. */
1457 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1458 new_dentry->d_name.name);
1462 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1463 !ylist_empty(&target->variant.directoryVariant.children)) {
1465 T(YAFFS_TRACE_OS, ("target is non-empty dir\n"));
1467 retVal = YAFFS_FAIL;
1469 /* Now does unlinking internally using shadowing mechanism */
1470 T(YAFFS_TRACE_OS, ("calling yaffs_RenameObject\n"));
1472 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1473 old_dentry->d_name.name,
1474 yaffs_InodeToObject(new_dir),
1475 new_dentry->d_name.name);
1477 yaffs_GrossUnlock(dev);
1479 if (retVal == YAFFS_OK) {
1481 new_dentry->d_inode->i_nlink--;
1482 mark_inode_dirty(new_dentry->d_inode);
1491 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1493 struct inode *inode = dentry->d_inode;
1498 ("yaffs_setattr of object %d\n",
1499 yaffs_InodeToObject(inode)->objectId));
1501 error = inode_change_ok(inode, attr);
1503 dev = yaffs_InodeToObject(inode)->myDev;
1504 yaffs_GrossLock(dev);
1505 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1511 yaffs_GrossUnlock(dev);
1513 error = inode_setattr(inode, attr);
1518 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1519 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1521 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1522 struct super_block *sb = dentry->d_sb;
1523 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1524 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1526 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1528 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1530 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1533 T(YAFFS_TRACE_OS, ("yaffs_statfs\n"));
1535 yaffs_GrossLock(dev);
1537 buf->f_type = YAFFS_MAGIC;
1538 buf->f_bsize = sb->s_blocksize;
1539 buf->f_namelen = 255;
1541 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
1542 /* Do this if chunk size is not a power of 2 */
1544 uint64_t bytesInDev;
1547 bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock + 1))) *
1548 ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk));
1550 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
1551 buf->f_blocks = bytesInDev;
1553 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
1554 ((uint64_t)(dev->nDataBytesPerChunk));
1556 do_div(bytesFree, sb->s_blocksize);
1558 buf->f_bfree = bytesFree;
1560 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
1563 (dev->endBlock - dev->startBlock + 1) *
1564 dev->nChunksPerBlock /
1565 (sb->s_blocksize / dev->nDataBytesPerChunk);
1567 yaffs_GetNumberOfFreeChunks(dev) /
1568 (sb->s_blocksize / dev->nDataBytesPerChunk);
1571 (dev->endBlock - dev->startBlock + 1) *
1572 dev->nChunksPerBlock *
1573 (dev->nDataBytesPerChunk / sb->s_blocksize);
1576 yaffs_GetNumberOfFreeChunks(dev) *
1577 (dev->nDataBytesPerChunk / sb->s_blocksize);
1582 buf->f_bavail = buf->f_bfree;
1584 yaffs_GrossUnlock(dev);
1589 static int yaffs_do_sync_fs(struct super_block *sb)
1592 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1593 T(YAFFS_TRACE_OS, ("yaffs_do_sync_fs\n"));
1596 yaffs_GrossLock(dev);
1599 yaffs_FlushEntireDeviceCache(dev);
1600 yaffs_CheckpointSave(dev);
1603 yaffs_GrossUnlock(dev);
1611 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1612 static void yaffs_write_super(struct super_block *sb)
1614 static int yaffs_write_super(struct super_block *sb)
1618 T(YAFFS_TRACE_OS, ("yaffs_write_super\n"));
1619 if (yaffs_auto_checkpoint >= 2)
1620 yaffs_do_sync_fs(sb);
1621 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
1627 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1628 static int yaffs_sync_fs(struct super_block *sb, int wait)
1630 static int yaffs_sync_fs(struct super_block *sb)
1633 T(YAFFS_TRACE_OS, ("yaffs_sync_fs\n"));
1635 if (yaffs_auto_checkpoint >= 1)
1636 yaffs_do_sync_fs(sb);
1641 #ifdef YAFFS_USE_OWN_IGET
1643 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
1645 struct inode *inode;
1647 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1650 ("yaffs_iget for %lu\n", ino));
1652 inode = iget_locked(sb, ino);
1654 return ERR_PTR(-ENOMEM);
1655 if (!(inode->i_state & I_NEW))
1658 /* NB This is called as a side effect of other functions, but
1659 * we had to release the lock to prevent deadlocks, so
1660 * need to lock again.
1663 yaffs_GrossLock(dev);
1665 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1667 yaffs_FillInodeFromObject(inode, obj);
1669 yaffs_GrossUnlock(dev);
1671 unlock_new_inode(inode);
1677 static void yaffs_read_inode(struct inode *inode)
1679 /* NB This is called as a side effect of other functions, but
1680 * we had to release the lock to prevent deadlocks, so
1681 * need to lock again.
1685 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1688 ("yaffs_read_inode for %d\n", (int)inode->i_ino));
1690 yaffs_GrossLock(dev);
1692 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1694 yaffs_FillInodeFromObject(inode, obj);
1696 yaffs_GrossUnlock(dev);
1701 static YLIST_HEAD(yaffs_dev_list);
1703 #if 0 /* not used */
1704 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
1706 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1708 if (*flags & MS_RDONLY) {
1709 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1712 ("yaffs_remount_fs: %s: RO\n", dev->name));
1714 yaffs_GrossLock(dev);
1716 yaffs_FlushEntireDeviceCache(dev);
1718 yaffs_CheckpointSave(dev);
1723 yaffs_GrossUnlock(dev);
1726 ("yaffs_remount_fs: %s: RW\n", dev->name));
1733 static void yaffs_put_super(struct super_block *sb)
1735 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1737 T(YAFFS_TRACE_OS, ("yaffs_put_super\n"));
1739 yaffs_GrossLock(dev);
1741 yaffs_FlushEntireDeviceCache(dev);
1743 yaffs_CheckpointSave(dev);
1745 if (dev->putSuperFunc)
1746 dev->putSuperFunc(sb);
1748 yaffs_Deinitialise(dev);
1750 yaffs_GrossUnlock(dev);
1752 /* we assume this is protected by lock_kernel() in mount/umount */
1753 ylist_del(&dev->devList);
1755 if (dev->spareBuffer) {
1756 YFREE(dev->spareBuffer);
1757 dev->spareBuffer = NULL;
1764 static void yaffs_MTDPutSuper(struct super_block *sb)
1766 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1771 put_mtd_device(mtd);
1775 static void yaffs_MarkSuperBlockDirty(void *vsb)
1777 struct super_block *sb = (struct super_block *)vsb;
1779 T(YAFFS_TRACE_OS, ("yaffs_MarkSuperBlockDirty() sb = %p\n", sb));
1786 int skip_checkpoint_read;
1787 int skip_checkpoint_write;
1791 #define MAX_OPT_LEN 20
1792 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
1794 char cur_opt[MAX_OPT_LEN + 1];
1798 /* Parse through the options which is a comma seperated list */
1800 while (options_str && *options_str && !error) {
1801 memset(cur_opt, 0, MAX_OPT_LEN + 1);
1804 while (*options_str && *options_str != ',') {
1805 if (p < MAX_OPT_LEN) {
1806 cur_opt[p] = *options_str;
1812 if (!strcmp(cur_opt, "inband-tags"))
1813 options->inband_tags = 1;
1814 else if (!strcmp(cur_opt, "no-cache"))
1815 options->no_cache = 1;
1816 else if (!strcmp(cur_opt, "no-checkpoint-read"))
1817 options->skip_checkpoint_read = 1;
1818 else if (!strcmp(cur_opt, "no-checkpoint-write"))
1819 options->skip_checkpoint_write = 1;
1820 else if (!strcmp(cur_opt, "no-checkpoint")) {
1821 options->skip_checkpoint_read = 1;
1822 options->skip_checkpoint_write = 1;
1824 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
1833 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1834 struct super_block *sb,
1835 void *data, int silent)
1838 struct inode *inode = NULL;
1839 struct dentry *root;
1840 yaffs_Device *dev = 0;
1841 char devname_buf[BDEVNAME_SIZE + 1];
1842 struct mtd_info *mtd;
1844 char *data_str = (char *)data;
1846 yaffs_options options;
1848 sb->s_magic = YAFFS_MAGIC;
1849 sb->s_op = &yaffs_super_ops;
1850 sb->s_flags |= MS_NOATIME;
1853 printk(KERN_INFO "yaffs: sb is NULL\n");
1854 else if (!sb->s_dev)
1855 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1856 else if (!yaffs_devname(sb, devname_buf))
1857 printk(KERN_INFO "yaffs: devname is NULL\n");
1859 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1861 yaffs_devname(sb, devname_buf));
1866 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
1868 memset(&options, 0, sizeof(options));
1870 if (yaffs_parse_options(&options, data_str)) {
1871 /* Option parsing failed */
1876 sb->s_blocksize = PAGE_CACHE_SIZE;
1877 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1878 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1880 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1882 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1884 ("yaffs: Write verification disabled. All guarantees "
1885 "null and void\n"));
1888 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1890 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1891 yaffs_devname(sb, devname_buf)));
1893 /* Check it's an mtd device..... */
1894 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1895 return NULL; /* This isn't an mtd device */
1897 /* Get the device */
1898 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1900 T(YAFFS_TRACE_ALWAYS,
1901 ("yaffs: MTD device #%u doesn't appear to exist\n",
1905 /* Check it's NAND */
1906 if (mtd->type != MTD_NANDFLASH) {
1907 T(YAFFS_TRACE_ALWAYS,
1908 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1912 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1913 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1914 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1915 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1916 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1917 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1918 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1919 T(YAFFS_TRACE_OS, (" %s %d\n", WRITE_SIZE_STR, WRITE_SIZE(mtd)));
1920 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1921 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1922 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1923 T(YAFFS_TRACE_OS, (" size %u\n", mtd->size));
1925 T(YAFFS_TRACE_OS, (" size %lld\n", mtd->size));
1928 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1930 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
1931 T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs2\n"));
1935 /* Added NCB 26/5/2006 for completeness */
1936 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
1937 T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs1\n"));
1943 if (yaffsVersion == 2) {
1944 /* Check for version 2 style functions */
1946 !mtd->block_isbad ||
1947 !mtd->block_markbad ||
1950 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1951 !mtd->read_oob || !mtd->write_oob) {
1954 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1956 T(YAFFS_TRACE_ALWAYS,
1957 ("yaffs: MTD device does not support required "
1962 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1963 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
1964 !options.inband_tags) {
1965 T(YAFFS_TRACE_ALWAYS,
1966 ("yaffs: MTD device does not have the "
1967 "right page sizes\n"));
1971 /* Check for V1 style functions */
1975 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1976 !mtd->read_oob || !mtd->write_oob) {
1979 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1981 T(YAFFS_TRACE_ALWAYS,
1982 ("yaffs: MTD device does not support required "
1987 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
1988 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1989 T(YAFFS_TRACE_ALWAYS,
1990 ("yaffs: MTD device does not support have the "
1991 "right page sizes\n"));
1996 /* OK, so if we got here, we have an MTD that's NAND and looks
1997 * like it has the right capabilities
1998 * Set the yaffs_Device up for mtd
2001 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2002 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2004 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2007 /* Deep shit could not allocate device structure */
2008 T(YAFFS_TRACE_ALWAYS,
2009 ("yaffs_read_super: Failed trying to allocate "
2010 "yaffs_Device. \n"));
2014 memset(dev, 0, sizeof(yaffs_Device));
2015 dev->genericDevice = mtd;
2016 dev->name = mtd->name;
2018 /* Set up the memory size parameters.... */
2020 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2022 dev->startBlock = 0;
2023 dev->endBlock = nBlocks - 1;
2024 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2025 dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2026 dev->nReservedBlocks = 5;
2027 dev->nShortOpCaches = (options.no_cache) ? 0 : 10;
2028 dev->inbandTags = options.inband_tags;
2030 /* ... and the functions. */
2031 if (yaffsVersion == 2) {
2032 dev->writeChunkWithTagsToNAND =
2033 nandmtd2_WriteChunkWithTagsToNAND;
2034 dev->readChunkWithTagsFromNAND =
2035 nandmtd2_ReadChunkWithTagsFromNAND;
2036 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2037 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
2038 dev->spareBuffer = YMALLOC(mtd->oobsize);
2040 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2041 dev->totalBytesPerChunk = mtd->writesize;
2042 dev->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2044 dev->totalBytesPerChunk = mtd->oobblock;
2045 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2047 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2049 dev->startBlock = 0;
2050 dev->endBlock = nBlocks - 1;
2052 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2053 /* use the MTD interface in yaffs_mtdif1.c */
2054 dev->writeChunkWithTagsToNAND =
2055 nandmtd1_WriteChunkWithTagsToNAND;
2056 dev->readChunkWithTagsFromNAND =
2057 nandmtd1_ReadChunkWithTagsFromNAND;
2058 dev->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2059 dev->queryNANDBlock = nandmtd1_QueryNANDBlock;
2061 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2062 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2066 /* ... and common functions */
2067 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2068 dev->initialiseNAND = nandmtd_InitialiseNAND;
2070 dev->putSuperFunc = yaffs_MTDPutSuper;
2072 dev->superBlock = (void *)sb;
2073 dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2076 #ifndef CONFIG_YAFFS_DOES_ECC
2077 dev->useNANDECC = 1;
2080 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2081 dev->wideTnodesDisabled = 1;
2084 dev->skipCheckpointRead = options.skip_checkpoint_read;
2085 dev->skipCheckpointWrite = options.skip_checkpoint_write;
2087 /* we assume this is protected by lock_kernel() in mount/umount */
2088 ylist_add_tail(&dev->devList, &yaffs_dev_list);
2090 init_MUTEX(&dev->grossLock);
2092 yaffs_GrossLock(dev);
2094 err = yaffs_GutsInitialise(dev);
2097 ("yaffs_read_super: guts initialised %s\n",
2098 (err == YAFFS_OK) ? "OK" : "FAILED"));
2100 /* Release lock before yaffs_get_inode() */
2101 yaffs_GrossUnlock(dev);
2103 /* Create root inode */
2104 if (err == YAFFS_OK)
2105 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2111 inode->i_op = &yaffs_dir_inode_operations;
2112 inode->i_fop = &yaffs_dir_operations;
2114 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
2116 root = d_alloc_root(inode);
2118 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
2125 sb->s_dirt = !dev->isCheckpointed;
2126 T(YAFFS_TRACE_ALWAYS,
2127 ("yaffs_read_super: isCheckpointed %d\n", dev->isCheckpointed));
2129 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
2134 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2135 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2138 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2141 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2142 static int yaffs_read_super(struct file_system_type *fs,
2143 int flags, const char *dev_name,
2144 void *data, struct vfsmount *mnt)
2147 return get_sb_bdev(fs, flags, dev_name, data,
2148 yaffs_internal_read_super_mtd, mnt);
2151 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2152 int flags, const char *dev_name,
2156 return get_sb_bdev(fs, flags, dev_name, data,
2157 yaffs_internal_read_super_mtd);
2161 static struct file_system_type yaffs_fs_type = {
2162 .owner = THIS_MODULE,
2164 .get_sb = yaffs_read_super,
2165 .kill_sb = kill_block_super,
2166 .fs_flags = FS_REQUIRES_DEV,
2169 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2172 return yaffs_internal_read_super(1, sb, data, silent);
2175 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2180 #ifdef CONFIG_YAFFS_YAFFS2
2182 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2183 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2186 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2189 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2190 static int yaffs2_read_super(struct file_system_type *fs,
2191 int flags, const char *dev_name, void *data,
2192 struct vfsmount *mnt)
2194 return get_sb_bdev(fs, flags, dev_name, data,
2195 yaffs2_internal_read_super_mtd, mnt);
2198 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2199 int flags, const char *dev_name,
2203 return get_sb_bdev(fs, flags, dev_name, data,
2204 yaffs2_internal_read_super_mtd);
2208 static struct file_system_type yaffs2_fs_type = {
2209 .owner = THIS_MODULE,
2211 .get_sb = yaffs2_read_super,
2212 .kill_sb = kill_block_super,
2213 .fs_flags = FS_REQUIRES_DEV,
2216 static struct super_block *yaffs2_read_super(struct super_block *sb,
2217 void *data, int silent)
2219 return yaffs_internal_read_super(2, sb, data, silent);
2222 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
2226 #endif /* CONFIG_YAFFS_YAFFS2 */
2228 static struct proc_dir_entry *my_proc_entry;
2230 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
2232 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
2233 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
2234 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk);
2235 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
2236 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
2237 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
2238 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
2239 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks);
2240 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
2241 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
2242 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
2243 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
2244 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
2245 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
2246 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
2247 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
2248 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
2249 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
2250 buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
2251 buf += sprintf(buf, "passiveGCs......... %d\n",
2252 dev->passiveGarbageCollections);
2253 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
2254 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches);
2255 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
2256 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
2257 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
2258 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
2259 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
2260 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
2261 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
2262 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
2264 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
2265 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
2266 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
2267 buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags);
2272 static int yaffs_proc_read(char *page,
2274 off_t offset, int count, int *eof, void *data)
2276 struct ylist_head *item;
2281 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
2282 * We use 'offset' (*ppos) to indicate where we are in devList.
2283 * This also assumes the user has posted a read buffer large
2284 * enough to hold the complete output; but that's life in /proc.
2289 /* Print header first */
2291 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
2292 "\n%s\n%s\n", yaffs_fs_c_version,
2293 yaffs_guts_c_version);
2296 /* hold lock_kernel while traversing yaffs_dev_list */
2299 /* Locate and print the Nth entry. Order N-squared but N is small. */
2300 ylist_for_each(item, &yaffs_dev_list) {
2301 yaffs_Device *dev = ylist_entry(item, yaffs_Device, devList);
2306 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
2307 buf = yaffs_dump_dev(buf, dev);
2312 return buf - page < count ? buf - page : count;
2316 * Set the verbosity of the warnings and error messages.
2318 * Note that the names can only be a..z or _ with the current code.
2323 unsigned mask_bitfield;
2325 {"allocate", YAFFS_TRACE_ALLOCATE},
2326 {"always", YAFFS_TRACE_ALWAYS},
2327 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
2328 {"buffers", YAFFS_TRACE_BUFFERS},
2329 {"bug", YAFFS_TRACE_BUG},
2330 {"checkpt", YAFFS_TRACE_CHECKPOINT},
2331 {"deletion", YAFFS_TRACE_DELETION},
2332 {"erase", YAFFS_TRACE_ERASE},
2333 {"error", YAFFS_TRACE_ERROR},
2334 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
2335 {"gc", YAFFS_TRACE_GC},
2336 {"mtd", YAFFS_TRACE_MTD},
2337 {"nandaccess", YAFFS_TRACE_NANDACCESS},
2338 {"os", YAFFS_TRACE_OS},
2339 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
2340 {"scan", YAFFS_TRACE_SCAN},
2341 {"tracing", YAFFS_TRACE_TRACING},
2343 {"verify", YAFFS_TRACE_VERIFY},
2344 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
2345 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
2346 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
2348 {"write", YAFFS_TRACE_WRITE},
2349 {"all", 0xffffffff},
2354 #define MAX_MASK_NAME_LENGTH 40
2355 static int yaffs_proc_write(struct file *file, const char *buf,
2356 unsigned long count, void *data)
2358 unsigned rg = 0, mask_bitfield;
2362 char substring[MAX_MASK_NAME_LENGTH + 1];
2368 rg = yaffs_traceMask;
2370 while (!done && (pos < count)) {
2372 while ((pos < count) && isspace(buf[pos]))
2389 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
2391 if (end > buf + pos) {
2392 mask_name = "numeral";
2393 len = end - (buf + pos);
2397 for (x = buf + pos, i = 0;
2398 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
2399 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
2401 substring[i] = '\0';
2403 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2404 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
2405 mask_name = mask_flags[i].mask_name;
2406 mask_bitfield = mask_flags[i].mask_bitfield;
2413 if (mask_name != NULL) {
2417 rg &= ~mask_bitfield;
2420 rg |= mask_bitfield;
2426 rg |= mask_bitfield;
2432 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
2434 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
2436 if (rg & YAFFS_TRACE_ALWAYS) {
2437 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2439 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
2440 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
2447 /* Stuff to handle installation of file systems */
2448 struct file_system_to_install {
2449 struct file_system_type *fst;
2453 static struct file_system_to_install fs_to_install[] = {
2454 {&yaffs_fs_type, 0},
2455 {&yaffs2_fs_type, 0},
2459 static int __init init_yaffs_fs(void)
2462 struct file_system_to_install *fsinst;
2464 T(YAFFS_TRACE_ALWAYS,
2465 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
2467 /* Install the proc_fs entry */
2468 my_proc_entry = create_proc_entry("yaffs",
2472 if (my_proc_entry) {
2473 my_proc_entry->write_proc = yaffs_proc_write;
2474 my_proc_entry->read_proc = yaffs_proc_read;
2475 my_proc_entry->data = NULL;
2479 /* Now add the file system entries */
2481 fsinst = fs_to_install;
2483 while (fsinst->fst && !error) {
2484 error = register_filesystem(fsinst->fst);
2486 fsinst->installed = 1;
2490 /* Any errors? uninstall */
2492 fsinst = fs_to_install;
2494 while (fsinst->fst) {
2495 if (fsinst->installed) {
2496 unregister_filesystem(fsinst->fst);
2497 fsinst->installed = 0;
2506 static void __exit exit_yaffs_fs(void)
2509 struct file_system_to_install *fsinst;
2511 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
2514 remove_proc_entry("yaffs", YPROC_ROOT);
2516 fsinst = fs_to_install;
2518 while (fsinst->fst) {
2519 if (fsinst->installed) {
2520 unregister_filesystem(fsinst->fst);
2521 fsinst->installed = 0;
2527 module_init(init_yaffs_fs)
2528 module_exit(exit_yaffs_fs)
2530 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
2531 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
2532 MODULE_LICENSE("GPL");