2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
5 * Copyright (C) 2002 Aleph One Ltd.
6 * for Toby Churchill Ltd and Brightstar Engineering
8 * Created by Charles Manning <charles@aleph1.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This is the file system front-end to YAFFS that hooks it up to
18 * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with
20 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this
22 * >> inode->u.generic_ip points to the associated yaffs_Object.
25 * * Luc van OostenRyck for numerous patches.
26 * * Nick Bane for numerous patches.
27 * * Nick Bane for 2.5/2.6 integration.
28 * * Andras Toth for mknod rdev issue.
29 * * Michael Fischer for finding the problem with inode inconsistency.
30 * * Some code bodily lifted from JFFS2.
33 const char *yaffs_fs_c_version =
34 "$Id: yaffs_fs.c,v 1.48 2006-05-21 09:39:12 charles Exp $";
35 extern const char *yaffs_guts_c_version;
37 #include <linux/config.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/version.h>
41 #include <linux/slab.h>
42 #include <linux/init.h>
43 #include <linux/list.h>
45 #include <linux/proc_fs.h>
46 #include <linux/smp_lock.h>
47 #include <linux/pagemap.h>
48 #include <linux/mtd/mtd.h>
49 #include <linux/interrupt.h>
50 #include <linux/string.h>
51 #include <linux/ctype.h>
53 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
55 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
56 #include <asm/statfs.h>
57 #define UnlockPage(p) unlock_page(p)
58 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
60 /* FIXME: use sb->s_id instead ? */
61 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
65 #include <linux/locks.h>
66 #define BDEVNAME_SIZE 0
67 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
71 #include <asm/uaccess.h>
74 #include "yaffs_guts.h"
76 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS |
77 YAFFS_TRACE_BAD_BLOCKS |
78 YAFFS_TRACE_CHECKPOINT
81 #include <linux/mtd/mtd.h>
82 #include "yaffs_mtdif.h"
83 #include "yaffs_mtdif2.h"
85 /*#define T(x) printk x */
87 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
88 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
90 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
91 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
93 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
96 static void yaffs_put_super(struct super_block *sb);
98 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
101 static int yaffs_file_flush(struct file *file);
103 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
106 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
108 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
109 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
110 struct nameidata *n);
111 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
112 struct nameidata *n);
114 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
115 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
117 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
118 struct dentry *dentry);
119 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
120 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
121 const char *symname);
122 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
124 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
125 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
128 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
131 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
132 struct inode *new_dir, struct dentry *new_dentry);
133 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
135 static int yaffs_sync_fs(struct super_block *sb);
136 static int yaffs_write_super(struct super_block *sb);
138 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
139 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
141 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
143 static void yaffs_read_inode(struct inode *inode);
145 static void yaffs_put_inode(struct inode *inode);
146 static void yaffs_delete_inode(struct inode *);
147 static void yaffs_clear_inode(struct inode *);
149 static int yaffs_readpage(struct file *file, struct page *page);
150 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
151 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
153 static int yaffs_writepage(struct page *page);
155 static int yaffs_prepare_write(struct file *f, struct page *pg,
156 unsigned offset, unsigned to);
157 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
160 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
162 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
163 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
165 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
168 static struct address_space_operations yaffs_file_address_operations = {
169 .readpage = yaffs_readpage,
170 .writepage = yaffs_writepage,
171 .prepare_write = yaffs_prepare_write,
172 .commit_write = yaffs_commit_write,
175 static struct file_operations yaffs_file_operations = {
176 .read = generic_file_read,
177 .write = generic_file_write,
178 .mmap = generic_file_mmap,
179 .flush = yaffs_file_flush,
180 .fsync = yaffs_sync_object,
181 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
182 .sendfile = generic_file_sendfile,
187 static struct inode_operations yaffs_file_inode_operations = {
188 .setattr = yaffs_setattr,
191 static struct inode_operations yaffs_symlink_inode_operations = {
192 .readlink = yaffs_readlink,
193 .follow_link = yaffs_follow_link,
194 .setattr = yaffs_setattr,
197 static struct inode_operations yaffs_dir_inode_operations = {
198 .create = yaffs_create,
199 .lookup = yaffs_lookup,
201 .unlink = yaffs_unlink,
202 .symlink = yaffs_symlink,
203 .mkdir = yaffs_mkdir,
204 .rmdir = yaffs_unlink,
205 .mknod = yaffs_mknod,
206 .rename = yaffs_rename,
207 .setattr = yaffs_setattr,
210 static struct file_operations yaffs_dir_operations = {
211 .read = generic_read_dir,
212 .readdir = yaffs_readdir,
213 .fsync = yaffs_sync_object,
216 static struct super_operations yaffs_super_ops = {
217 .statfs = yaffs_statfs,
218 .read_inode = yaffs_read_inode,
219 .put_inode = yaffs_put_inode,
220 .put_super = yaffs_put_super,
221 .delete_inode = yaffs_delete_inode,
222 .clear_inode = yaffs_clear_inode,
223 .sync_fs = yaffs_sync_fs,
224 .write_super = yaffs_write_super,
227 static void yaffs_GrossLock(yaffs_Device * dev)
229 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
231 down(&dev->grossLock);
234 static void yaffs_GrossUnlock(yaffs_Device * dev)
236 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
241 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
244 unsigned char *alias;
247 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
249 yaffs_GrossLock(dev);
251 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
253 yaffs_GrossUnlock(dev);
258 ret = vfs_readlink(dentry, buffer, buflen, alias);
263 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
264 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
266 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
269 unsigned char *alias;
271 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
273 yaffs_GrossLock(dev);
275 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
277 yaffs_GrossUnlock(dev);
285 ret = vfs_follow_link(nd, alias);
288 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
289 return ERR_PTR (ret);
295 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
299 * Lookup is used to find objects in the fs
301 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
303 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
306 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
310 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
312 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
314 yaffs_GrossLock(dev);
317 (KERN_DEBUG "yaffs_lookup for %d:%s\n",
318 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
321 yaffs_FindObjectByName(yaffs_InodeToObject(dir),
322 dentry->d_name.name);
324 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
326 /* Can't hold gross lock when calling yaffs_get_inode() */
327 yaffs_GrossUnlock(dev);
331 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
333 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
337 (KERN_DEBUG "yaffs_loookup dentry \n"));
338 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
339 * d_add even if NULL inode */
341 /*dget(dentry); // try to solve directory bug */
342 d_add(dentry, inode);
350 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
354 /* added NCB for 2.5/6 compatability - forces add even if inode is
355 * NULL which creates dentry hash */
356 d_add(dentry, inode);
359 /* return (ERR_PTR(-EIO)); */
363 /* For now put inode is just for debugging
364 * Put inode is called when the inode **structure** is put.
366 static void yaffs_put_inode(struct inode *inode)
369 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
370 atomic_read(&inode->i_count)));
374 /* clear is called to tell the fs to release any per-inode data it holds */
375 static void yaffs_clear_inode(struct inode *inode)
380 obj = yaffs_InodeToObject(inode);
383 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
384 atomic_read(&inode->i_count),
385 obj ? "object exists" : "null object"));
389 yaffs_GrossLock(dev);
391 /* Clear the association between the inode and
395 inode->u.generic_ip = NULL;
397 /* If the object freeing was deferred, then the real
399 * This should fix the inode inconsistency problem.
402 yaffs_HandleDeferedFree(obj);
404 yaffs_GrossUnlock(dev);
409 /* delete is called when the link count is zero and the inode
410 * is put (ie. nobody wants to know about it anymore, time to
412 * NB Must call clear_inode()
414 static void yaffs_delete_inode(struct inode *inode)
416 yaffs_Object *obj = yaffs_InodeToObject(inode);
420 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
421 atomic_read(&inode->i_count),
422 obj ? "object exists" : "null object"));
426 yaffs_GrossLock(dev);
427 yaffs_DeleteFile(obj);
428 yaffs_GrossUnlock(dev);
430 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
431 truncate_inode_pages (&inode->i_data, 0);
436 static int yaffs_file_flush(struct file *file)
438 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
440 yaffs_Device *dev = obj->myDev;
443 (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
444 obj->dirty ? "dirty" : "clean"));
446 yaffs_GrossLock(dev);
448 yaffs_FlushFile(obj, 1);
450 yaffs_GrossUnlock(dev);
455 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
457 /* Lifted from jffs2 */
460 unsigned char *pg_buf;
465 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
466 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
467 (unsigned)PAGE_CACHE_SIZE));
469 obj = yaffs_DentryToObject(f->f_dentry);
473 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
474 BUG_ON(!PageLocked(pg));
481 /* FIXME: Can kmap fail? */
483 yaffs_GrossLock(dev);
486 yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
489 yaffs_GrossUnlock(dev);
495 ClearPageUptodate(pg);
502 flush_dcache_page(pg);
505 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
509 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
511 int ret = yaffs_readpage_nolock(f, pg);
516 static int yaffs_readpage(struct file *f, struct page *pg)
518 return yaffs_readpage_unlock(f, pg);
521 /* writepage inspired by/stolen from smbfs */
523 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
524 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
526 static int yaffs_writepage(struct page *page)
529 struct address_space *mapping = page->mapping;
530 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
532 unsigned long end_index;
540 inode = mapping->host;
544 if (offset > inode->i_size) {
547 "yaffs_writepage at %08x, inode size = %08x!!!\n",
548 (unsigned)(page->index << PAGE_CACHE_SHIFT),
549 (unsigned)inode->i_size));
551 (KERN_DEBUG " -> don't care!!\n"));
556 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
559 if (page->index < end_index) {
560 nBytes = PAGE_CACHE_SIZE;
562 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
569 obj = yaffs_InodeToObject(inode);
570 yaffs_GrossLock(obj->myDev);
573 (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
574 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
576 (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
577 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
580 yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
584 (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
585 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
587 yaffs_GrossUnlock(obj->myDev);
590 SetPageUptodate(page);
594 return (nWritten == nBytes) ? 0 : -ENOSPC;
597 static int yaffs_prepare_write(struct file *f, struct page *pg,
598 unsigned offset, unsigned to)
601 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
602 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
603 return yaffs_readpage_nolock(f, pg);
609 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
613 void *addr = page_address(pg) + offset;
614 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
615 int nBytes = to - offset;
619 unsigned saddr = (unsigned)addr;
622 (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
625 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
627 if (nWritten != nBytes) {
630 "yaffs_commit_write not same size nWritten %d nBytes %d\n",
633 ClearPageUptodate(pg);
639 (KERN_DEBUG "yaffs_commit_write returning %d\n",
640 nWritten == nBytes ? 0 : nWritten));
642 return nWritten == nBytes ? 0 : nWritten;
646 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
649 inode->i_ino = obj->objectId;
650 inode->i_mode = obj->yst_mode;
651 inode->i_uid = obj->yst_uid;
652 inode->i_gid = obj->yst_gid;
653 inode->i_blksize = inode->i_sb->s_blocksize;
654 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
656 inode->i_rdev = old_decode_dev(obj->yst_rdev);
657 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
658 inode->i_atime.tv_nsec = 0;
659 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
660 inode->i_mtime.tv_nsec = 0;
661 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
662 inode->i_ctime.tv_nsec = 0;
664 inode->i_rdev = obj->yst_rdev;
665 inode->i_atime = obj->yst_atime;
666 inode->i_mtime = obj->yst_mtime;
667 inode->i_ctime = obj->yst_ctime;
669 inode->i_size = yaffs_GetObjectFileLength(obj);
670 inode->i_blocks = (inode->i_size + 511) >> 9;
672 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
676 "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
677 inode->i_mode, inode->i_uid, inode->i_gid,
678 (int)inode->i_size, atomic_read(&inode->i_count)));
680 switch (obj->yst_mode & S_IFMT) {
681 default: /* fifo, device or socket */
682 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
683 init_special_inode(inode, obj->yst_mode,
684 old_decode_dev(obj->yst_rdev));
686 init_special_inode(inode, obj->yst_mode,
687 (dev_t) (obj->yst_rdev));
690 case S_IFREG: /* file */
691 inode->i_op = &yaffs_file_inode_operations;
692 inode->i_fop = &yaffs_file_operations;
693 inode->i_mapping->a_ops =
694 &yaffs_file_address_operations;
696 case S_IFDIR: /* directory */
697 inode->i_op = &yaffs_dir_inode_operations;
698 inode->i_fop = &yaffs_dir_operations;
700 case S_IFLNK: /* symlink */
701 inode->i_op = &yaffs_symlink_inode_operations;
705 inode->u.generic_ip = obj;
706 obj->myInode = inode;
710 (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
715 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
722 (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
729 (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
735 (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
737 inode = iget(sb, obj->objectId);
739 /* NB Side effect: iget calls back to yaffs_read_inode(). */
740 /* iget also increments the inode's i_count */
741 /* NB You can't be holding grossLock or deadlock will happen! */
746 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
754 obj = yaffs_DentryToObject(f->f_dentry);
758 yaffs_GrossLock(dev);
760 inode = f->f_dentry->d_inode;
762 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
763 ipos = inode->i_size;
770 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
774 "yaffs_file_write about to write writing %d bytes"
775 "to object %d at %d\n",
776 n, obj->objectId, ipos));
779 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
782 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
787 if (ipos > inode->i_size) {
788 inode->i_size = ipos;
789 inode->i_blocks = (ipos + 511) >> 9;
793 "yaffs_file_write size updated to %d bytes, "
795 ipos, (int)(inode->i_blocks)));
799 yaffs_GrossUnlock(dev);
800 return nWritten == 0 ? -ENOSPC : nWritten;
803 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
807 struct inode *inode = f->f_dentry->d_inode;
808 unsigned long offset, curoffs;
812 char name[YAFFS_MAX_NAME_LENGTH + 1];
814 obj = yaffs_DentryToObject(f->f_dentry);
817 yaffs_GrossLock(dev);
821 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
825 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
827 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
836 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
837 (int)f->f_dentry->d_parent->d_inode->i_ino));
839 (dirent, "..", 2, offset,
840 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
849 /* If the directory has changed since the open or last call to
850 readdir, rewind to after the 2 canned entries. */
852 if (f->f_version != inode->i_version) {
855 f->f_version = inode->i_version;
858 list_for_each(i, &obj->variant.directoryVariant.children) {
860 if (curoffs >= offset) {
861 l = list_entry(i, yaffs_Object, siblings);
863 yaffs_GetObjectName(l, name,
864 YAFFS_MAX_NAME_LENGTH + 1);
866 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
867 yaffs_GetObjectInode(l)));
873 yaffs_GetObjectInode(l),
874 yaffs_GetObjectType(l))
887 yaffs_GrossUnlock(dev);
893 * File creation. Allocate an inode, and we're done..
895 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
896 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
899 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
905 yaffs_Object *obj = NULL;
908 yaffs_Object *parent = yaffs_InodeToObject(dir);
911 uid_t uid = current->fsuid;
912 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
916 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
917 parent->objectId, parent->variantType));
920 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
924 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
926 dentry->d_name.name, mode, rdev));
930 yaffs_GrossLock(dev);
932 switch (mode & S_IFMT) {
934 /* Special (socket, fifo, device...) */
935 T(YAFFS_TRACE_OS, (KERN_DEBUG
936 "yaffs_mknod: making special\n"));
937 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
939 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
940 gid, old_encode_dev(rdev));
943 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
947 case S_IFREG: /* file */
948 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
950 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
953 case S_IFDIR: /* directory */
955 (KERN_DEBUG "yaffs_mknod: making directory\n"));
957 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
960 case S_IFLNK: /* symlink */
961 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
962 obj = NULL; /* Do we ever get here? */
966 /* Can not call yaffs_get_inode() with gross lock held */
967 yaffs_GrossUnlock(dev);
970 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
971 d_instantiate(dentry, inode);
973 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
974 obj->objectId, atomic_read(&inode->i_count)));
978 (KERN_DEBUG "yaffs_mknod failed making object\n"));
985 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
988 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
989 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
991 /* attempt to fix dir bug - didn't work */
999 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1000 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1001 struct nameidata *n)
1003 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1006 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
1007 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1010 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1017 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1018 dentry->d_name.name));
1020 dev = yaffs_InodeToObject(dir)->myDev;
1022 yaffs_GrossLock(dev);
1024 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1026 if (retVal == YAFFS_OK) {
1027 dentry->d_inode->i_nlink--;
1029 yaffs_GrossUnlock(dev);
1030 mark_inode_dirty(dentry->d_inode);
1033 yaffs_GrossUnlock(dev);
1040 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1041 struct dentry *dentry)
1043 struct inode *inode = old_dentry->d_inode;
1044 yaffs_Object *obj = NULL;
1045 yaffs_Object *link = NULL;
1048 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1050 obj = yaffs_InodeToObject(inode);
1053 yaffs_GrossLock(dev);
1055 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1058 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1063 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1064 d_instantiate(dentry, old_dentry->d_inode);
1065 atomic_inc(&old_dentry->d_inode->i_count);
1067 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1068 old_dentry->d_inode->i_nlink,
1069 atomic_read(&old_dentry->d_inode->i_count)));
1073 yaffs_GrossUnlock(dev);
1083 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1084 const char *symname)
1088 uid_t uid = current->fsuid;
1089 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1091 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1093 dev = yaffs_InodeToObject(dir)->myDev;
1094 yaffs_GrossLock(dev);
1095 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1096 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1097 yaffs_GrossUnlock(dev);
1101 struct inode *inode;
1103 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1104 d_instantiate(dentry, inode);
1105 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1108 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1115 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1122 obj = yaffs_DentryToObject(dentry);
1126 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1127 yaffs_GrossLock(dev);
1128 yaffs_FlushFile(obj, 1);
1129 yaffs_GrossUnlock(dev);
1134 * The VFS layer already does all the dentry stuff for rename.
1136 * NB: POSIX says you can rename an object over an old object of the same name
1138 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1139 struct inode *new_dir, struct dentry *new_dentry)
1142 int retVal = YAFFS_FAIL;
1143 yaffs_Object *target;
1145 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1146 dev = yaffs_InodeToObject(old_dir)->myDev;
1148 yaffs_GrossLock(dev);
1150 /* Check if the target is an existing directory that is not empty. */
1152 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1153 new_dentry->d_name.name);
1158 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1159 !list_empty(&target->variant.directoryVariant.children)) {
1161 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1163 retVal = YAFFS_FAIL;
1166 /* Now does unlinking internally using shadowing mechanism */
1167 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1170 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1171 old_dentry->d_name.name,
1172 yaffs_InodeToObject(new_dir),
1173 new_dentry->d_name.name);
1176 yaffs_GrossUnlock(dev);
1178 if (retVal == YAFFS_OK) {
1180 new_dentry->d_inode->i_nlink--;
1181 mark_inode_dirty(new_dentry->d_inode);
1191 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1193 struct inode *inode = dentry->d_inode;
1198 (KERN_DEBUG "yaffs_setattr of object %d\n",
1199 yaffs_InodeToObject(inode)->objectId));
1201 if ((error = inode_change_ok(inode, attr)) == 0) {
1203 dev = yaffs_InodeToObject(inode)->myDev;
1204 yaffs_GrossLock(dev);
1205 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1211 yaffs_GrossUnlock(dev);
1213 error = inode_setattr(inode, attr);
1218 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1219 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1221 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1225 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1226 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1228 yaffs_GrossLock(dev);
1230 buf->f_type = YAFFS_MAGIC;
1231 buf->f_bsize = sb->s_blocksize;
1232 buf->f_namelen = 255;
1233 if (sb->s_blocksize > dev->nBytesPerChunk) {
1236 (dev->endBlock - dev->startBlock +
1237 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1238 dev->nBytesPerChunk);
1240 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1241 dev->nBytesPerChunk);
1245 (dev->endBlock - dev->startBlock +
1246 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1249 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1254 buf->f_bavail = buf->f_bfree;
1256 yaffs_GrossUnlock(dev);
1262 static int yaffs_do_sync_fs(struct super_block *sb)
1265 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1266 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_do_sync_fs\n"));
1269 yaffs_GrossLock(dev);
1272 yaffs_CheckpointSave(dev);
1274 yaffs_GrossUnlock(dev);
1282 static int yaffs_write_super(struct super_block *sb)
1285 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_super\n"));
1286 return 0; /* yaffs_do_sync_fs(sb);*/
1291 static int yaffs_sync_fs(struct super_block *sb)
1294 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_fs\n"));
1296 return 0; /* yaffs_do_sync_fs(sb);*/
1301 static void yaffs_read_inode(struct inode *inode)
1303 /* NB This is called as a side effect of other functions, but
1304 * we had to release the lock to prevent deadlocks, so
1305 * need to lock again.
1309 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1312 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1314 yaffs_GrossLock(dev);
1316 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1318 yaffs_FillInodeFromObject(inode, obj);
1320 yaffs_GrossUnlock(dev);
1323 static LIST_HEAD(yaffs_dev_list);
1325 static void yaffs_put_super(struct super_block *sb)
1327 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1329 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_put_super\n"));
1331 yaffs_GrossLock(dev);
1333 yaffs_FlushEntireDeviceCache(dev);
1335 if (dev->putSuperFunc) {
1336 dev->putSuperFunc(sb);
1339 yaffs_CheckpointSave(dev);
1340 yaffs_Deinitialise(dev);
1342 yaffs_GrossUnlock(dev);
1344 /* we assume this is protected by lock_kernel() in mount/umount */
1345 list_del(&dev->devList);
1347 if(dev->spareBuffer){
1348 YFREE(dev->spareBuffer);
1349 dev->spareBuffer = NULL;
1356 static void yaffs_MTDPutSuper(struct super_block *sb)
1359 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1365 put_mtd_device(mtd);
1369 static void yaffs_MarkSuperBlockDirty(void *vsb)
1371 struct super_block *sb = (struct super_block *)vsb;
1373 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_MarkSuperBlockDirty() sb = %p\n",sb));
1378 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1379 struct super_block *sb,
1380 void *data, int silent)
1383 struct inode *inode = NULL;
1384 struct dentry *root;
1385 yaffs_Device *dev = 0;
1386 char devname_buf[BDEVNAME_SIZE + 1];
1387 struct mtd_info *mtd;
1390 sb->s_magic = YAFFS_MAGIC;
1391 sb->s_op = &yaffs_super_ops;
1394 printk(KERN_INFO "yaffs: sb is NULL\n");
1395 else if (!sb->s_dev)
1396 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1397 else if (!yaffs_devname(sb, devname_buf))
1398 printk(KERN_INFO "yaffs: devname is NULL\n");
1400 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1402 yaffs_devname(sb, devname_buf));
1404 sb->s_blocksize = PAGE_CACHE_SIZE;
1405 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1406 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1408 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1410 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1412 ("yaffs: Write verification disabled. All guarantees "
1413 "null and void\n"));
1416 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1418 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1419 yaffs_devname(sb, devname_buf)));
1421 /* Check it's an mtd device..... */
1422 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1423 return NULL; /* This isn't an mtd device */
1425 /* Get the device */
1426 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1428 T(YAFFS_TRACE_ALWAYS,
1429 ("yaffs: MTD device #%u doesn't appear to exist\n",
1433 /* Check it's NAND */
1434 if (mtd->type != MTD_NANDFLASH) {
1435 T(YAFFS_TRACE_ALWAYS,
1436 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1440 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1441 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1442 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1443 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1444 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1445 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1446 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1447 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1448 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1449 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1450 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1452 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1454 if (yaffsVersion == 1 &&
1455 mtd->oobblock >= 2048) {
1456 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1461 if (yaffsVersion == 2) {
1462 /* Check for version 2 style functions */
1464 !mtd->block_isbad ||
1465 !mtd->block_markbad ||
1469 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1470 T(YAFFS_TRACE_ALWAYS,
1471 ("yaffs: MTD device does not support required "
1476 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1477 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1478 T(YAFFS_TRACE_ALWAYS,
1479 ("yaffs: MTD device does not have the "
1480 "right page sizes\n"));
1484 /* Check for V1 style functions */
1489 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1490 T(YAFFS_TRACE_ALWAYS,
1491 ("yaffs: MTD device does not support required "
1496 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1497 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1498 T(YAFFS_TRACE_ALWAYS,
1499 ("yaffs: MTD device does not support have the "
1500 "right page sizes\n"));
1505 /* OK, so if we got here, we have an MTD that's NAND and looks
1506 * like it has the right capabilities
1507 * Set the yaffs_Device up for mtd
1510 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1511 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1513 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1516 /* Deep shit could not allocate device structure */
1517 T(YAFFS_TRACE_ALWAYS,
1518 ("yaffs_read_super: Failed trying to allocate "
1519 "yaffs_Device. \n"));
1523 memset(dev, 0, sizeof(yaffs_Device));
1524 dev->genericDevice = mtd;
1525 dev->name = mtd->name;
1527 /* Set up the memory size parameters.... */
1529 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1530 dev->startBlock = 0;
1531 dev->endBlock = nBlocks - 1;
1532 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1533 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1534 dev->nReservedBlocks = 5;
1535 dev->nShortOpCaches = 10; /* Enable short op caching */
1537 /* ... and the functions. */
1538 if (yaffsVersion == 2) {
1539 dev->writeChunkWithTagsToNAND =
1540 nandmtd2_WriteChunkWithTagsToNAND;
1541 dev->readChunkWithTagsFromNAND =
1542 nandmtd2_ReadChunkWithTagsFromNAND;
1543 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1544 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1545 dev->spareBuffer = YMALLOC(mtd->oobsize);
1547 dev->nBytesPerChunk = mtd->oobblock;
1548 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1549 nBlocks = mtd->size / mtd->erasesize;
1551 dev->nCheckpointReservedBlocks = 10;
1552 dev->startBlock = 0;
1553 dev->endBlock = nBlocks - 1;
1555 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1556 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1559 /* ... and common functions */
1560 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1561 dev->initialiseNAND = nandmtd_InitialiseNAND;
1563 dev->putSuperFunc = yaffs_MTDPutSuper;
1565 dev->superBlock = (void *)sb;
1566 dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
1569 #ifndef CONFIG_YAFFS_DOES_ECC
1570 dev->useNANDECC = 1;
1573 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
1574 dev->wideTnodesDisabled = 1;
1577 /* we assume this is protected by lock_kernel() in mount/umount */
1578 list_add_tail(&dev->devList, &yaffs_dev_list);
1580 init_MUTEX(&dev->grossLock);
1582 yaffs_GrossLock(dev);
1584 err = yaffs_GutsInitialise(dev);
1587 ("yaffs_read_super: guts initialised %s\n",
1588 (err == YAFFS_OK) ? "OK" : "FAILED"));
1590 /* Release lock before yaffs_get_inode() */
1591 yaffs_GrossUnlock(dev);
1593 /* Create root inode */
1594 if (err == YAFFS_OK)
1595 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1601 inode->i_op = &yaffs_dir_inode_operations;
1602 inode->i_fop = &yaffs_dir_operations;
1604 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1606 root = d_alloc_root(inode);
1608 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1616 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1621 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1622 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1625 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1628 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1629 int flags, const char *dev_name,
1633 return get_sb_bdev(fs, flags, dev_name, data,
1634 yaffs_internal_read_super_mtd);
1637 static struct file_system_type yaffs_fs_type = {
1638 .owner = THIS_MODULE,
1640 .get_sb = yaffs_read_super,
1641 .kill_sb = kill_block_super,
1642 .fs_flags = FS_REQUIRES_DEV,
1645 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1648 return yaffs_internal_read_super(1, sb, data, silent);
1651 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1656 #ifdef CONFIG_YAFFS_YAFFS2
1658 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1659 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1662 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1665 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1666 int flags, const char *dev_name,
1670 return get_sb_bdev(fs, flags, dev_name, data,
1671 yaffs2_internal_read_super_mtd);
1674 static struct file_system_type yaffs2_fs_type = {
1675 .owner = THIS_MODULE,
1677 .get_sb = yaffs2_read_super,
1678 .kill_sb = kill_block_super,
1679 .fs_flags = FS_REQUIRES_DEV,
1682 static struct super_block *yaffs2_read_super(struct super_block *sb,
1683 void *data, int silent)
1685 return yaffs_internal_read_super(2, sb, data, silent);
1688 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1692 #endif /* CONFIG_YAFFS_YAFFS2 */
1694 static struct proc_dir_entry *my_proc_entry;
1696 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1698 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1699 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1700 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1701 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1702 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1703 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1704 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1705 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1706 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1707 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1708 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1709 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1710 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1711 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1713 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1715 sprintf(buf, "passiveGCs......... %d\n",
1716 dev->passiveGarbageCollections);
1717 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1718 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1719 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1720 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1721 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1722 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1723 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1724 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1725 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1727 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1728 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1729 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1734 static int yaffs_proc_read(char *page,
1736 off_t offset, int count, int *eof, void *data)
1738 struct list_head *item;
1743 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1744 * We use 'offset' (*ppos) to indicate where we are in devList.
1745 * This also assumes the user has posted a read buffer large
1746 * enough to hold the complete output; but that's life in /proc.
1751 /* Print header first */
1753 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1754 "\n%s\n%s\n", yaffs_fs_c_version,
1755 yaffs_guts_c_version);
1758 /* hold lock_kernel while traversing yaffs_dev_list */
1761 /* Locate and print the Nth entry. Order N-squared but N is small. */
1762 list_for_each(item, &yaffs_dev_list) {
1763 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1768 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1769 buf = yaffs_dump_dev(buf, dev);
1774 return buf - page < count ? buf - page : count;
1778 * Set the verbosity of the warnings and error messages.
1784 unsigned mask_bitfield;
1786 {"allocate", YAFFS_TRACE_ALLOCATE},
1787 {"always", YAFFS_TRACE_ALWAYS},
1788 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
1789 {"buffers", YAFFS_TRACE_BUFFERS},
1790 {"bug", YAFFS_TRACE_BUG},
1791 {"deletion", YAFFS_TRACE_DELETION},
1792 {"erase", YAFFS_TRACE_ERASE},
1793 {"error", YAFFS_TRACE_ERROR},
1794 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
1795 {"gc", YAFFS_TRACE_GC},
1796 {"mtd", YAFFS_TRACE_MTD},
1797 {"nandaccess", YAFFS_TRACE_NANDACCESS},
1798 {"os", YAFFS_TRACE_OS},
1799 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
1800 {"scan", YAFFS_TRACE_SCAN},
1801 {"tracing", YAFFS_TRACE_TRACING},
1802 {"write", YAFFS_TRACE_WRITE},
1803 {"all", 0xffffffff},
1808 static int yaffs_proc_write(struct file *file, const char *buf,
1809 unsigned long count, void *data)
1811 unsigned rg = 0, mask_bitfield;
1812 char *end, *mask_name;
1818 rg = yaffs_traceMask;
1820 while (!done && (pos < count)) {
1822 while ((pos < count) && isspace(buf[pos])) {
1839 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
1840 if (end > buf + pos) {
1841 mask_name = "numeral";
1842 len = end - (buf + pos);
1846 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1847 len = strlen(mask_flags[i].mask_name);
1848 if (strncmp(buf + pos, mask_flags[i].mask_name, len) == 0) {
1849 mask_name = mask_flags[i].mask_name;
1850 mask_bitfield = mask_flags[i].mask_bitfield;
1857 if (mask_name != NULL) {
1862 rg &= ~mask_bitfield;
1865 rg |= mask_bitfield;
1871 rg |= mask_bitfield;
1877 yaffs_traceMask = rg;
1878 if (rg & YAFFS_TRACE_ALWAYS) {
1879 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1881 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
1882 printk("%c%s\n", flag, mask_flags[i].mask_name);
1889 /* Stuff to handle installation of file systems */
1890 struct file_system_to_install {
1891 struct file_system_type *fst;
1895 static struct file_system_to_install fs_to_install[] = {
1896 //#ifdef CONFIG_YAFFS_YAFFS1
1897 {&yaffs_fs_type, 0},
1899 //#ifdef CONFIG_YAFFS_YAFFS2
1900 {&yaffs2_fs_type, 0},
1905 static int __init init_yaffs_fs(void)
1908 struct file_system_to_install *fsinst;
1910 T(YAFFS_TRACE_ALWAYS,
1911 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1913 /* Install the proc_fs entry */
1914 my_proc_entry = create_proc_entry("yaffs",
1918 if (my_proc_entry) {
1919 my_proc_entry->write_proc = yaffs_proc_write;
1920 my_proc_entry->read_proc = yaffs_proc_read;
1921 my_proc_entry->data = NULL;
1926 /* Now add the file system entries */
1928 fsinst = fs_to_install;
1930 while (fsinst->fst && !error) {
1931 error = register_filesystem(fsinst->fst);
1933 fsinst->installed = 1;
1938 /* Any errors? uninstall */
1940 fsinst = fs_to_install;
1942 while (fsinst->fst) {
1943 if (fsinst->installed) {
1944 unregister_filesystem(fsinst->fst);
1945 fsinst->installed = 0;
1954 static void __exit exit_yaffs_fs(void)
1957 struct file_system_to_install *fsinst;
1959 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1962 remove_proc_entry("yaffs", &proc_root);
1964 fsinst = fs_to_install;
1966 while (fsinst->fst) {
1967 if (fsinst->installed) {
1968 unregister_filesystem(fsinst->fst);
1969 fsinst->installed = 0;
1976 module_init(init_yaffs_fs)
1977 module_exit(exit_yaffs_fs)
1979 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1980 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
1981 MODULE_LICENSE("GPL");