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.49 2006-05-25 01:26:57 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;
914 if((dir->i_mode & S_ISGID) && S_ISDIR(mode))
919 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
920 parent->objectId, parent->variantType));
923 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
927 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
929 dentry->d_name.name, mode, rdev));
933 yaffs_GrossLock(dev);
935 switch (mode & S_IFMT) {
937 /* Special (socket, fifo, device...) */
938 T(YAFFS_TRACE_OS, (KERN_DEBUG
939 "yaffs_mknod: making special\n"));
940 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
942 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
943 gid, old_encode_dev(rdev));
946 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
950 case S_IFREG: /* file */
951 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
953 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
956 case S_IFDIR: /* directory */
958 (KERN_DEBUG "yaffs_mknod: making directory\n"));
960 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
963 case S_IFLNK: /* symlink */
964 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
965 obj = NULL; /* Do we ever get here? */
969 /* Can not call yaffs_get_inode() with gross lock held */
970 yaffs_GrossUnlock(dev);
973 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
974 d_instantiate(dentry, inode);
976 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
977 obj->objectId, atomic_read(&inode->i_count)));
981 (KERN_DEBUG "yaffs_mknod failed making object\n"));
988 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
991 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
992 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
994 /* attempt to fix dir bug - didn't work */
1002 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1003 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1004 struct nameidata *n)
1006 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1009 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
1010 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1013 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1020 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1021 dentry->d_name.name));
1023 dev = yaffs_InodeToObject(dir)->myDev;
1025 yaffs_GrossLock(dev);
1027 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1029 if (retVal == YAFFS_OK) {
1030 dentry->d_inode->i_nlink--;
1032 yaffs_GrossUnlock(dev);
1033 mark_inode_dirty(dentry->d_inode);
1036 yaffs_GrossUnlock(dev);
1043 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1044 struct dentry *dentry)
1046 struct inode *inode = old_dentry->d_inode;
1047 yaffs_Object *obj = NULL;
1048 yaffs_Object *link = NULL;
1051 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1053 obj = yaffs_InodeToObject(inode);
1056 yaffs_GrossLock(dev);
1058 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1061 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1066 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1067 d_instantiate(dentry, old_dentry->d_inode);
1068 atomic_inc(&old_dentry->d_inode->i_count);
1070 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1071 old_dentry->d_inode->i_nlink,
1072 atomic_read(&old_dentry->d_inode->i_count)));
1076 yaffs_GrossUnlock(dev);
1086 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1087 const char *symname)
1091 uid_t uid = current->fsuid;
1092 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1094 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1096 dev = yaffs_InodeToObject(dir)->myDev;
1097 yaffs_GrossLock(dev);
1098 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1099 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1100 yaffs_GrossUnlock(dev);
1104 struct inode *inode;
1106 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1107 d_instantiate(dentry, inode);
1108 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1111 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1118 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1125 obj = yaffs_DentryToObject(dentry);
1129 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1130 yaffs_GrossLock(dev);
1131 yaffs_FlushFile(obj, 1);
1132 yaffs_GrossUnlock(dev);
1137 * The VFS layer already does all the dentry stuff for rename.
1139 * NB: POSIX says you can rename an object over an old object of the same name
1141 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1142 struct inode *new_dir, struct dentry *new_dentry)
1145 int retVal = YAFFS_FAIL;
1146 yaffs_Object *target;
1148 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1149 dev = yaffs_InodeToObject(old_dir)->myDev;
1151 yaffs_GrossLock(dev);
1153 /* Check if the target is an existing directory that is not empty. */
1155 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1156 new_dentry->d_name.name);
1161 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1162 !list_empty(&target->variant.directoryVariant.children)) {
1164 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1166 retVal = YAFFS_FAIL;
1169 /* Now does unlinking internally using shadowing mechanism */
1170 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1173 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1174 old_dentry->d_name.name,
1175 yaffs_InodeToObject(new_dir),
1176 new_dentry->d_name.name);
1179 yaffs_GrossUnlock(dev);
1181 if (retVal == YAFFS_OK) {
1183 new_dentry->d_inode->i_nlink--;
1184 mark_inode_dirty(new_dentry->d_inode);
1194 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1196 struct inode *inode = dentry->d_inode;
1201 (KERN_DEBUG "yaffs_setattr of object %d\n",
1202 yaffs_InodeToObject(inode)->objectId));
1204 if ((error = inode_change_ok(inode, attr)) == 0) {
1206 dev = yaffs_InodeToObject(inode)->myDev;
1207 yaffs_GrossLock(dev);
1208 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1214 yaffs_GrossUnlock(dev);
1216 error = inode_setattr(inode, attr);
1221 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1222 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1224 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1228 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1229 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1231 yaffs_GrossLock(dev);
1233 buf->f_type = YAFFS_MAGIC;
1234 buf->f_bsize = sb->s_blocksize;
1235 buf->f_namelen = 255;
1236 if (sb->s_blocksize > dev->nBytesPerChunk) {
1239 (dev->endBlock - dev->startBlock +
1240 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1241 dev->nBytesPerChunk);
1243 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1244 dev->nBytesPerChunk);
1248 (dev->endBlock - dev->startBlock +
1249 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1252 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1257 buf->f_bavail = buf->f_bfree;
1259 yaffs_GrossUnlock(dev);
1265 static int yaffs_do_sync_fs(struct super_block *sb)
1268 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1269 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_do_sync_fs\n"));
1272 yaffs_GrossLock(dev);
1275 yaffs_CheckpointSave(dev);
1277 yaffs_GrossUnlock(dev);
1285 static int yaffs_write_super(struct super_block *sb)
1288 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_super\n"));
1289 return 0; /* yaffs_do_sync_fs(sb);*/
1294 static int yaffs_sync_fs(struct super_block *sb)
1297 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_fs\n"));
1299 return 0; /* yaffs_do_sync_fs(sb);*/
1304 static void yaffs_read_inode(struct inode *inode)
1306 /* NB This is called as a side effect of other functions, but
1307 * we had to release the lock to prevent deadlocks, so
1308 * need to lock again.
1312 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1315 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1317 yaffs_GrossLock(dev);
1319 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1321 yaffs_FillInodeFromObject(inode, obj);
1323 yaffs_GrossUnlock(dev);
1326 static LIST_HEAD(yaffs_dev_list);
1328 static void yaffs_put_super(struct super_block *sb)
1330 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1332 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_put_super\n"));
1334 yaffs_GrossLock(dev);
1336 yaffs_FlushEntireDeviceCache(dev);
1338 if (dev->putSuperFunc) {
1339 dev->putSuperFunc(sb);
1342 yaffs_CheckpointSave(dev);
1343 yaffs_Deinitialise(dev);
1345 yaffs_GrossUnlock(dev);
1347 /* we assume this is protected by lock_kernel() in mount/umount */
1348 list_del(&dev->devList);
1350 if(dev->spareBuffer){
1351 YFREE(dev->spareBuffer);
1352 dev->spareBuffer = NULL;
1359 static void yaffs_MTDPutSuper(struct super_block *sb)
1362 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1368 put_mtd_device(mtd);
1372 static void yaffs_MarkSuperBlockDirty(void *vsb)
1374 struct super_block *sb = (struct super_block *)vsb;
1376 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_MarkSuperBlockDirty() sb = %p\n",sb));
1381 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1382 struct super_block *sb,
1383 void *data, int silent)
1386 struct inode *inode = NULL;
1387 struct dentry *root;
1388 yaffs_Device *dev = 0;
1389 char devname_buf[BDEVNAME_SIZE + 1];
1390 struct mtd_info *mtd;
1393 sb->s_magic = YAFFS_MAGIC;
1394 sb->s_op = &yaffs_super_ops;
1397 printk(KERN_INFO "yaffs: sb is NULL\n");
1398 else if (!sb->s_dev)
1399 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1400 else if (!yaffs_devname(sb, devname_buf))
1401 printk(KERN_INFO "yaffs: devname is NULL\n");
1403 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1405 yaffs_devname(sb, devname_buf));
1407 sb->s_blocksize = PAGE_CACHE_SIZE;
1408 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1409 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1411 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1413 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1415 ("yaffs: Write verification disabled. All guarantees "
1416 "null and void\n"));
1419 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1421 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1422 yaffs_devname(sb, devname_buf)));
1424 /* Check it's an mtd device..... */
1425 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1426 return NULL; /* This isn't an mtd device */
1428 /* Get the device */
1429 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1431 T(YAFFS_TRACE_ALWAYS,
1432 ("yaffs: MTD device #%u doesn't appear to exist\n",
1436 /* Check it's NAND */
1437 if (mtd->type != MTD_NANDFLASH) {
1438 T(YAFFS_TRACE_ALWAYS,
1439 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1443 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1444 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1445 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1446 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1447 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1448 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1449 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1450 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1451 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1452 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1453 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1455 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1457 if (yaffsVersion == 1 &&
1458 mtd->oobblock >= 2048) {
1459 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1464 if (yaffsVersion == 2) {
1465 /* Check for version 2 style functions */
1467 !mtd->block_isbad ||
1468 !mtd->block_markbad ||
1472 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1473 T(YAFFS_TRACE_ALWAYS,
1474 ("yaffs: MTD device does not support required "
1479 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1480 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1481 T(YAFFS_TRACE_ALWAYS,
1482 ("yaffs: MTD device does not have the "
1483 "right page sizes\n"));
1487 /* Check for V1 style functions */
1492 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1493 T(YAFFS_TRACE_ALWAYS,
1494 ("yaffs: MTD device does not support required "
1499 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1500 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1501 T(YAFFS_TRACE_ALWAYS,
1502 ("yaffs: MTD device does not support have the "
1503 "right page sizes\n"));
1508 /* OK, so if we got here, we have an MTD that's NAND and looks
1509 * like it has the right capabilities
1510 * Set the yaffs_Device up for mtd
1513 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1514 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1516 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1519 /* Deep shit could not allocate device structure */
1520 T(YAFFS_TRACE_ALWAYS,
1521 ("yaffs_read_super: Failed trying to allocate "
1522 "yaffs_Device. \n"));
1526 memset(dev, 0, sizeof(yaffs_Device));
1527 dev->genericDevice = mtd;
1528 dev->name = mtd->name;
1530 /* Set up the memory size parameters.... */
1532 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1533 dev->startBlock = 0;
1534 dev->endBlock = nBlocks - 1;
1535 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1536 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1537 dev->nReservedBlocks = 5;
1538 dev->nShortOpCaches = 10; /* Enable short op caching */
1540 /* ... and the functions. */
1541 if (yaffsVersion == 2) {
1542 dev->writeChunkWithTagsToNAND =
1543 nandmtd2_WriteChunkWithTagsToNAND;
1544 dev->readChunkWithTagsFromNAND =
1545 nandmtd2_ReadChunkWithTagsFromNAND;
1546 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1547 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1548 dev->spareBuffer = YMALLOC(mtd->oobsize);
1550 dev->nBytesPerChunk = mtd->oobblock;
1551 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1552 nBlocks = mtd->size / mtd->erasesize;
1554 dev->nCheckpointReservedBlocks = 10;
1555 dev->startBlock = 0;
1556 dev->endBlock = nBlocks - 1;
1558 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1559 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1562 /* ... and common functions */
1563 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1564 dev->initialiseNAND = nandmtd_InitialiseNAND;
1566 dev->putSuperFunc = yaffs_MTDPutSuper;
1568 dev->superBlock = (void *)sb;
1569 dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
1572 #ifndef CONFIG_YAFFS_DOES_ECC
1573 dev->useNANDECC = 1;
1576 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
1577 dev->wideTnodesDisabled = 1;
1580 /* we assume this is protected by lock_kernel() in mount/umount */
1581 list_add_tail(&dev->devList, &yaffs_dev_list);
1583 init_MUTEX(&dev->grossLock);
1585 yaffs_GrossLock(dev);
1587 err = yaffs_GutsInitialise(dev);
1590 ("yaffs_read_super: guts initialised %s\n",
1591 (err == YAFFS_OK) ? "OK" : "FAILED"));
1593 /* Release lock before yaffs_get_inode() */
1594 yaffs_GrossUnlock(dev);
1596 /* Create root inode */
1597 if (err == YAFFS_OK)
1598 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1604 inode->i_op = &yaffs_dir_inode_operations;
1605 inode->i_fop = &yaffs_dir_operations;
1607 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1609 root = d_alloc_root(inode);
1611 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1619 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1624 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1625 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1628 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1631 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1632 int flags, const char *dev_name,
1636 return get_sb_bdev(fs, flags, dev_name, data,
1637 yaffs_internal_read_super_mtd);
1640 static struct file_system_type yaffs_fs_type = {
1641 .owner = THIS_MODULE,
1643 .get_sb = yaffs_read_super,
1644 .kill_sb = kill_block_super,
1645 .fs_flags = FS_REQUIRES_DEV,
1648 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1651 return yaffs_internal_read_super(1, sb, data, silent);
1654 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1659 #ifdef CONFIG_YAFFS_YAFFS2
1661 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1662 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1665 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1668 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1669 int flags, const char *dev_name,
1673 return get_sb_bdev(fs, flags, dev_name, data,
1674 yaffs2_internal_read_super_mtd);
1677 static struct file_system_type yaffs2_fs_type = {
1678 .owner = THIS_MODULE,
1680 .get_sb = yaffs2_read_super,
1681 .kill_sb = kill_block_super,
1682 .fs_flags = FS_REQUIRES_DEV,
1685 static struct super_block *yaffs2_read_super(struct super_block *sb,
1686 void *data, int silent)
1688 return yaffs_internal_read_super(2, sb, data, silent);
1691 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1695 #endif /* CONFIG_YAFFS_YAFFS2 */
1697 static struct proc_dir_entry *my_proc_entry;
1699 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1701 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1702 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1703 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1704 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1705 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1706 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1707 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1708 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1709 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1710 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1711 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1712 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1713 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1714 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1716 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1718 sprintf(buf, "passiveGCs......... %d\n",
1719 dev->passiveGarbageCollections);
1720 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1721 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1722 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1723 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1724 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1725 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1726 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1727 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1728 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1730 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1731 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1732 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1737 static int yaffs_proc_read(char *page,
1739 off_t offset, int count, int *eof, void *data)
1741 struct list_head *item;
1746 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1747 * We use 'offset' (*ppos) to indicate where we are in devList.
1748 * This also assumes the user has posted a read buffer large
1749 * enough to hold the complete output; but that's life in /proc.
1754 /* Print header first */
1756 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1757 "\n%s\n%s\n", yaffs_fs_c_version,
1758 yaffs_guts_c_version);
1761 /* hold lock_kernel while traversing yaffs_dev_list */
1764 /* Locate and print the Nth entry. Order N-squared but N is small. */
1765 list_for_each(item, &yaffs_dev_list) {
1766 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1771 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1772 buf = yaffs_dump_dev(buf, dev);
1777 return buf - page < count ? buf - page : count;
1781 * Set the verbosity of the warnings and error messages.
1787 unsigned mask_bitfield;
1789 {"allocate", YAFFS_TRACE_ALLOCATE},
1790 {"always", YAFFS_TRACE_ALWAYS},
1791 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
1792 {"buffers", YAFFS_TRACE_BUFFERS},
1793 {"bug", YAFFS_TRACE_BUG},
1794 {"deletion", YAFFS_TRACE_DELETION},
1795 {"erase", YAFFS_TRACE_ERASE},
1796 {"error", YAFFS_TRACE_ERROR},
1797 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
1798 {"gc", YAFFS_TRACE_GC},
1799 {"mtd", YAFFS_TRACE_MTD},
1800 {"nandaccess", YAFFS_TRACE_NANDACCESS},
1801 {"os", YAFFS_TRACE_OS},
1802 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
1803 {"scan", YAFFS_TRACE_SCAN},
1804 {"tracing", YAFFS_TRACE_TRACING},
1805 {"write", YAFFS_TRACE_WRITE},
1806 {"all", 0xffffffff},
1811 static int yaffs_proc_write(struct file *file, const char *buf,
1812 unsigned long count, void *data)
1814 unsigned rg = 0, mask_bitfield;
1815 char *end, *mask_name;
1821 rg = yaffs_traceMask;
1823 while (!done && (pos < count)) {
1825 while ((pos < count) && isspace(buf[pos])) {
1842 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
1843 if (end > buf + pos) {
1844 mask_name = "numeral";
1845 len = end - (buf + pos);
1849 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1850 len = strlen(mask_flags[i].mask_name);
1851 if (strncmp(buf + pos, mask_flags[i].mask_name, len) == 0) {
1852 mask_name = mask_flags[i].mask_name;
1853 mask_bitfield = mask_flags[i].mask_bitfield;
1860 if (mask_name != NULL) {
1865 rg &= ~mask_bitfield;
1868 rg |= mask_bitfield;
1874 rg |= mask_bitfield;
1880 yaffs_traceMask = rg;
1881 if (rg & YAFFS_TRACE_ALWAYS) {
1882 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1884 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
1885 printk("%c%s\n", flag, mask_flags[i].mask_name);
1892 /* Stuff to handle installation of file systems */
1893 struct file_system_to_install {
1894 struct file_system_type *fst;
1898 static struct file_system_to_install fs_to_install[] = {
1899 //#ifdef CONFIG_YAFFS_YAFFS1
1900 {&yaffs_fs_type, 0},
1902 //#ifdef CONFIG_YAFFS_YAFFS2
1903 {&yaffs2_fs_type, 0},
1908 static int __init init_yaffs_fs(void)
1911 struct file_system_to_install *fsinst;
1913 T(YAFFS_TRACE_ALWAYS,
1914 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1916 /* Install the proc_fs entry */
1917 my_proc_entry = create_proc_entry("yaffs",
1921 if (my_proc_entry) {
1922 my_proc_entry->write_proc = yaffs_proc_write;
1923 my_proc_entry->read_proc = yaffs_proc_read;
1924 my_proc_entry->data = NULL;
1929 /* Now add the file system entries */
1931 fsinst = fs_to_install;
1933 while (fsinst->fst && !error) {
1934 error = register_filesystem(fsinst->fst);
1936 fsinst->installed = 1;
1941 /* Any errors? uninstall */
1943 fsinst = fs_to_install;
1945 while (fsinst->fst) {
1946 if (fsinst->installed) {
1947 unregister_filesystem(fsinst->fst);
1948 fsinst->installed = 0;
1957 static void __exit exit_yaffs_fs(void)
1960 struct file_system_to_install *fsinst;
1962 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1965 remove_proc_entry("yaffs", &proc_root);
1967 fsinst = fs_to_install;
1969 while (fsinst->fst) {
1970 if (fsinst->installed) {
1971 unregister_filesystem(fsinst->fst);
1972 fsinst->installed = 0;
1979 module_init(init_yaffs_fs)
1980 module_exit(exit_yaffs_fs)
1982 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1983 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
1984 MODULE_LICENSE("GPL");