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.41 2006-01-27 23:54:21 tpoynor 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 | YAFFS_TRACE_BAD_BLOCKS /* | 0xFFFFFFFF */;
78 #include <linux/mtd/mtd.h>
79 #include "yaffs_mtdif.h"
80 #include "yaffs_mtdif2.h"
82 /*#define T(x) printk x */
84 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
85 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
87 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
88 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
90 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
93 static void yaffs_put_super(struct super_block *sb);
95 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
98 static int yaffs_file_flush(struct file *file);
100 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
103 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
105 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
106 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
107 struct nameidata *n);
108 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
109 struct nameidata *n);
111 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
112 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
114 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
115 struct dentry *dentry);
116 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
117 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
118 const char *symname);
119 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
121 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
122 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
125 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
128 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
129 struct inode *new_dir, struct dentry *new_dentry);
130 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
132 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
133 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
135 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
137 static void yaffs_read_inode(struct inode *inode);
139 static void yaffs_put_inode(struct inode *inode);
140 static void yaffs_delete_inode(struct inode *);
141 static void yaffs_clear_inode(struct inode *);
143 static int yaffs_readpage(struct file *file, struct page *page);
144 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
145 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
147 static int yaffs_writepage(struct page *page);
149 static int yaffs_prepare_write(struct file *f, struct page *pg,
150 unsigned offset, unsigned to);
151 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
154 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
156 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
157 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
159 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
162 static struct address_space_operations yaffs_file_address_operations = {
163 .readpage = yaffs_readpage,
164 .writepage = yaffs_writepage,
165 .prepare_write = yaffs_prepare_write,
166 .commit_write = yaffs_commit_write,
169 static struct file_operations yaffs_file_operations = {
170 .read = generic_file_read,
171 .write = generic_file_write,
172 .mmap = generic_file_mmap,
173 .flush = yaffs_file_flush,
174 .fsync = yaffs_sync_object,
175 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
176 .sendfile = generic_file_sendfile,
181 static struct inode_operations yaffs_file_inode_operations = {
182 .setattr = yaffs_setattr,
185 static struct inode_operations yaffs_symlink_inode_operations = {
186 .readlink = yaffs_readlink,
187 .follow_link = yaffs_follow_link,
188 .setattr = yaffs_setattr,
191 static struct inode_operations yaffs_dir_inode_operations = {
192 .create = yaffs_create,
193 .lookup = yaffs_lookup,
195 .unlink = yaffs_unlink,
196 .symlink = yaffs_symlink,
197 .mkdir = yaffs_mkdir,
198 .rmdir = yaffs_unlink,
199 .mknod = yaffs_mknod,
200 .rename = yaffs_rename,
201 .setattr = yaffs_setattr,
204 static struct file_operations yaffs_dir_operations = {
205 .read = generic_read_dir,
206 .readdir = yaffs_readdir,
207 .fsync = yaffs_sync_object,
210 static struct super_operations yaffs_super_ops = {
211 .statfs = yaffs_statfs,
212 .read_inode = yaffs_read_inode,
213 .put_inode = yaffs_put_inode,
214 .put_super = yaffs_put_super,
215 .delete_inode = yaffs_delete_inode,
216 .clear_inode = yaffs_clear_inode,
219 static void yaffs_GrossLock(yaffs_Device * dev)
221 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
223 down(&dev->grossLock);
226 static void yaffs_GrossUnlock(yaffs_Device * dev)
228 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
233 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
236 unsigned char *alias;
239 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
241 yaffs_GrossLock(dev);
243 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
245 yaffs_GrossUnlock(dev);
250 ret = vfs_readlink(dentry, buffer, buflen, alias);
255 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
256 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
258 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
261 unsigned char *alias;
263 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
265 yaffs_GrossLock(dev);
267 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
269 yaffs_GrossUnlock(dev);
277 ret = vfs_follow_link(nd, alias);
280 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
281 return ERR_PTR (ret);
287 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
291 * Lookup is used to find objects in the fs
293 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
295 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
298 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
302 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
304 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
306 yaffs_GrossLock(dev);
309 (KERN_DEBUG "yaffs_lookup for %d:%s\n",
310 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
313 yaffs_FindObjectByName(yaffs_InodeToObject(dir),
314 dentry->d_name.name);
316 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
318 /* Can't hold gross lock when calling yaffs_get_inode() */
319 yaffs_GrossUnlock(dev);
323 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
325 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
329 (KERN_DEBUG "yaffs_loookup dentry \n"));
330 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
331 * d_add even if NULL inode */
333 /*dget(dentry); // try to solve directory bug */
334 d_add(dentry, inode);
342 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
346 /* added NCB for 2.5/6 compatability - forces add even if inode is
347 * NULL which creates dentry hash */
348 d_add(dentry, inode);
351 /* return (ERR_PTR(-EIO)); */
355 /* For now put inode is just for debugging
356 * Put inode is called when the inode **structure** is put.
358 static void yaffs_put_inode(struct inode *inode)
361 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
362 atomic_read(&inode->i_count)));
366 /* clear is called to tell the fs to release any per-inode data it holds */
367 static void yaffs_clear_inode(struct inode *inode)
372 obj = yaffs_InodeToObject(inode);
375 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
376 atomic_read(&inode->i_count),
377 obj ? "object exists" : "null object"));
381 yaffs_GrossLock(dev);
383 /* Clear the association between the inode and
387 inode->u.generic_ip = NULL;
389 /* If the object freeing was deferred, then the real
391 * This should fix the inode inconsistency problem.
394 yaffs_HandleDeferedFree(obj);
396 yaffs_GrossUnlock(dev);
401 /* delete is called when the link count is zero and the inode
402 * is put (ie. nobody wants to know about it anymore, time to
404 * NB Must call clear_inode()
406 static void yaffs_delete_inode(struct inode *inode)
408 yaffs_Object *obj = yaffs_InodeToObject(inode);
412 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
413 atomic_read(&inode->i_count),
414 obj ? "object exists" : "null object"));
418 yaffs_GrossLock(dev);
419 yaffs_DeleteFile(obj);
420 yaffs_GrossUnlock(dev);
422 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
423 truncate_inode_pages (&inode->i_data, 0);
428 static int yaffs_file_flush(struct file *file)
430 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
432 yaffs_Device *dev = obj->myDev;
435 (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
436 obj->dirty ? "dirty" : "clean"));
438 yaffs_GrossLock(dev);
440 yaffs_FlushFile(obj, 1);
442 yaffs_GrossUnlock(dev);
447 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
449 /* Lifted from jffs2 */
452 unsigned char *pg_buf;
457 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
458 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
459 (unsigned)PAGE_CACHE_SIZE));
461 obj = yaffs_DentryToObject(f->f_dentry);
465 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
466 BUG_ON(!PageLocked(pg));
473 /* FIXME: Can kmap fail? */
475 yaffs_GrossLock(dev);
478 yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
481 yaffs_GrossUnlock(dev);
487 ClearPageUptodate(pg);
494 flush_dcache_page(pg);
497 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
501 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
503 int ret = yaffs_readpage_nolock(f, pg);
508 static int yaffs_readpage(struct file *f, struct page *pg)
510 return yaffs_readpage_unlock(f, pg);
513 /* writepage inspired by/stolen from smbfs */
515 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
516 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
518 static int yaffs_writepage(struct page *page)
521 struct address_space *mapping = page->mapping;
522 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
524 unsigned long end_index;
532 inode = mapping->host;
536 if (offset > inode->i_size) {
539 "yaffs_writepage at %08x, inode size = %08x!!!\n",
540 (unsigned)(page->index << PAGE_CACHE_SHIFT),
541 (unsigned)inode->i_size));
543 (KERN_DEBUG " -> don't care!!\n"));
548 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
551 if (page->index < end_index) {
552 nBytes = PAGE_CACHE_SIZE;
554 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
561 obj = yaffs_InodeToObject(inode);
562 yaffs_GrossLock(obj->myDev);
565 (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
566 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
568 (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
569 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
572 yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
576 (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
577 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
579 yaffs_GrossUnlock(obj->myDev);
582 SetPageUptodate(page);
586 return (nWritten == nBytes) ? 0 : -ENOSPC;
589 static int yaffs_prepare_write(struct file *f, struct page *pg,
590 unsigned offset, unsigned to)
593 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
594 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
595 return yaffs_readpage_nolock(f, pg);
601 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
605 void *addr = page_address(pg) + offset;
606 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
607 int nBytes = to - offset;
611 unsigned saddr = (unsigned)addr;
614 (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
617 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
619 if (nWritten != nBytes) {
622 "yaffs_commit_write not same size nWritten %d nBytes %d\n",
625 ClearPageUptodate(pg);
631 (KERN_DEBUG "yaffs_commit_write returning %d\n",
632 nWritten == nBytes ? 0 : nWritten));
634 return nWritten == nBytes ? 0 : nWritten;
638 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
641 inode->i_ino = obj->objectId;
642 inode->i_mode = obj->yst_mode;
643 inode->i_uid = obj->yst_uid;
644 inode->i_gid = obj->yst_gid;
645 inode->i_blksize = inode->i_sb->s_blocksize;
646 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
648 inode->i_rdev = old_decode_dev(obj->yst_rdev);
649 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
650 inode->i_atime.tv_nsec = 0;
651 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
652 inode->i_mtime.tv_nsec = 0;
653 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
654 inode->i_ctime.tv_nsec = 0;
656 inode->i_rdev = obj->yst_rdev;
657 inode->i_atime = obj->yst_atime;
658 inode->i_mtime = obj->yst_mtime;
659 inode->i_ctime = obj->yst_ctime;
661 inode->i_size = yaffs_GetObjectFileLength(obj);
662 inode->i_blocks = (inode->i_size + 511) >> 9;
664 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
668 "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
669 inode->i_mode, inode->i_uid, inode->i_gid,
670 (int)inode->i_size, atomic_read(&inode->i_count)));
672 switch (obj->yst_mode & S_IFMT) {
673 default: /* fifo, device or socket */
674 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
675 init_special_inode(inode, obj->yst_mode,
676 old_decode_dev(obj->yst_rdev));
678 init_special_inode(inode, obj->yst_mode,
679 (dev_t) (obj->yst_rdev));
682 case S_IFREG: /* file */
683 inode->i_op = &yaffs_file_inode_operations;
684 inode->i_fop = &yaffs_file_operations;
685 inode->i_mapping->a_ops =
686 &yaffs_file_address_operations;
688 case S_IFDIR: /* directory */
689 inode->i_op = &yaffs_dir_inode_operations;
690 inode->i_fop = &yaffs_dir_operations;
692 case S_IFLNK: /* symlink */
693 inode->i_op = &yaffs_symlink_inode_operations;
697 inode->u.generic_ip = obj;
698 obj->myInode = inode;
702 (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
707 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
714 (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
721 (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
727 (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
729 inode = iget(sb, obj->objectId);
731 /* NB Side effect: iget calls back to yaffs_read_inode(). */
732 /* iget also increments the inode's i_count */
733 /* NB You can't be holding grossLock or deadlock will happen! */
738 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
746 obj = yaffs_DentryToObject(f->f_dentry);
750 yaffs_GrossLock(dev);
752 inode = f->f_dentry->d_inode;
754 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
755 ipos = inode->i_size;
762 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
766 "yaffs_file_write about to write writing %d bytes"
767 "to object %d at %d\n",
768 n, obj->objectId, ipos));
771 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
774 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
779 if (ipos > inode->i_size) {
780 inode->i_size = ipos;
781 inode->i_blocks = (ipos + 511) >> 9;
785 "yaffs_file_write size updated to %d bytes, "
787 ipos, (int)(inode->i_blocks)));
791 yaffs_GrossUnlock(dev);
792 return nWritten == 0 ? -ENOSPC : nWritten;
795 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
799 struct inode *inode = f->f_dentry->d_inode;
800 unsigned long offset, curoffs;
804 char name[YAFFS_MAX_NAME_LENGTH + 1];
806 obj = yaffs_DentryToObject(f->f_dentry);
809 yaffs_GrossLock(dev);
813 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
817 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
819 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
828 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
829 (int)f->f_dentry->d_parent->d_inode->i_ino));
831 (dirent, "..", 2, offset,
832 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
841 list_for_each(i, &obj->variant.directoryVariant.children) {
843 if (curoffs >= offset) {
844 l = list_entry(i, yaffs_Object, siblings);
846 yaffs_GetObjectName(l, name,
847 YAFFS_MAX_NAME_LENGTH + 1);
849 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
850 yaffs_GetObjectInode(l)));
856 yaffs_GetObjectInode(l),
857 yaffs_GetObjectType(l))
870 yaffs_GrossUnlock(dev);
876 * File creation. Allocate an inode, and we're done..
878 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
879 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
882 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
888 yaffs_Object *obj = NULL;
891 yaffs_Object *parent = yaffs_InodeToObject(dir);
894 uid_t uid = current->fsuid;
895 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
899 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
900 parent->objectId, parent->variantType));
903 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
907 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
909 dentry->d_name.name, mode, rdev));
913 yaffs_GrossLock(dev);
915 switch (mode & S_IFMT) {
917 /* Special (socket, fifo, device...) */
918 T(YAFFS_TRACE_OS, (KERN_DEBUG
919 "yaffs_mknod: making special\n"));
920 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
922 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
923 gid, old_encode_dev(rdev));
926 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
930 case S_IFREG: /* file */
931 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
933 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
936 case S_IFDIR: /* directory */
938 (KERN_DEBUG "yaffs_mknod: making directory\n"));
940 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
943 case S_IFLNK: /* symlink */
944 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
945 obj = NULL; /* Do we ever get here? */
949 /* Can not call yaffs_get_inode() with gross lock held */
950 yaffs_GrossUnlock(dev);
953 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
954 d_instantiate(dentry, inode);
956 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
957 obj->objectId, atomic_read(&inode->i_count)));
961 (KERN_DEBUG "yaffs_mknod failed making object\n"));
968 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
971 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
972 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
974 /* attempt to fix dir bug - didn't work */
982 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
983 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
986 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
989 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
990 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
993 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1000 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1001 dentry->d_name.name));
1003 dev = yaffs_InodeToObject(dir)->myDev;
1005 yaffs_GrossLock(dev);
1007 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1009 yaffs_GrossUnlock(dev);
1011 if (retVal == YAFFS_OK) {
1012 dentry->d_inode->i_nlink--;
1013 mark_inode_dirty(dentry->d_inode);
1023 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1024 struct dentry *dentry)
1026 struct inode *inode = old_dentry->d_inode;
1027 yaffs_Object *obj = NULL;
1028 yaffs_Object *link = NULL;
1031 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1033 obj = yaffs_InodeToObject(inode);
1036 yaffs_GrossLock(dev);
1038 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1041 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1046 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1047 d_instantiate(dentry, old_dentry->d_inode);
1048 atomic_inc(&old_dentry->d_inode->i_count);
1050 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1051 old_dentry->d_inode->i_nlink,
1052 atomic_read(&old_dentry->d_inode->i_count)));
1056 yaffs_GrossUnlock(dev);
1066 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1067 const char *symname)
1071 uid_t uid = current->fsuid;
1072 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1074 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1076 dev = yaffs_InodeToObject(dir)->myDev;
1077 yaffs_GrossLock(dev);
1078 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1079 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1080 yaffs_GrossUnlock(dev);
1084 struct inode *inode;
1086 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1087 d_instantiate(dentry, inode);
1088 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1091 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1098 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1105 obj = yaffs_DentryToObject(dentry);
1109 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1110 yaffs_GrossLock(dev);
1111 yaffs_FlushFile(obj, 1);
1112 yaffs_GrossUnlock(dev);
1117 * The VFS layer already does all the dentry stuff for rename.
1119 * NB: POSIX says you can rename an object over an old object of the same name
1121 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1122 struct inode *new_dir, struct dentry *new_dentry)
1125 int retVal = YAFFS_FAIL;
1126 yaffs_Object *target;
1128 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1129 dev = yaffs_InodeToObject(old_dir)->myDev;
1131 yaffs_GrossLock(dev);
1133 /* Check if the target is an existing directory that is not empty. */
1135 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1136 new_dentry->d_name.name);
1141 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1142 !list_empty(&target->variant.directoryVariant.children)) {
1144 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1146 retVal = YAFFS_FAIL;
1149 /* Now does unlinking internally using shadowing mechanism */
1150 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1153 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1154 old_dentry->d_name.name,
1155 yaffs_InodeToObject(new_dir),
1156 new_dentry->d_name.name);
1159 yaffs_GrossUnlock(dev);
1161 if (retVal == YAFFS_OK) {
1163 new_dentry->d_inode->i_nlink--;
1164 mark_inode_dirty(new_dentry->d_inode);
1174 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1176 struct inode *inode = dentry->d_inode;
1181 (KERN_DEBUG "yaffs_setattr of object %d\n",
1182 yaffs_InodeToObject(inode)->objectId));
1184 if ((error = inode_change_ok(inode, attr)) == 0) {
1186 dev = yaffs_InodeToObject(inode)->myDev;
1187 yaffs_GrossLock(dev);
1188 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1194 yaffs_GrossUnlock(dev);
1196 error = inode_setattr(inode, attr);
1201 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1202 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1204 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1208 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1209 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1211 yaffs_GrossLock(dev);
1213 buf->f_type = YAFFS_MAGIC;
1214 buf->f_bsize = sb->s_blocksize;
1215 buf->f_namelen = 255;
1216 if (sb->s_blocksize > dev->nBytesPerChunk) {
1219 (dev->endBlock - dev->startBlock +
1220 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1221 dev->nBytesPerChunk);
1223 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1224 dev->nBytesPerChunk);
1228 (dev->endBlock - dev->startBlock +
1229 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1232 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1237 buf->f_bavail = buf->f_bfree;
1239 yaffs_GrossUnlock(dev);
1243 static void yaffs_read_inode(struct inode *inode)
1245 /* NB This is called as a side effect of other functions, but
1246 * we had to release the lock to prevent deadlocks, so
1247 * need to lock again.
1251 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1254 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1256 yaffs_GrossLock(dev);
1258 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1260 yaffs_FillInodeFromObject(inode, obj);
1262 yaffs_GrossUnlock(dev);
1265 static LIST_HEAD(yaffs_dev_list);
1267 static void yaffs_put_super(struct super_block *sb)
1269 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1271 yaffs_GrossLock(dev);
1272 if (dev->putSuperFunc) {
1273 dev->putSuperFunc(sb);
1275 yaffs_Deinitialise(dev);
1276 yaffs_GrossUnlock(dev);
1278 /* we assume this is protected by lock_kernel() in mount/umount */
1279 list_del(&dev->devList);
1285 static void yaffs_MTDPutSuper(struct super_block *sb)
1288 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1294 put_mtd_device(mtd);
1298 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1299 struct super_block *sb,
1300 void *data, int silent)
1303 struct inode *inode = NULL;
1304 struct dentry *root;
1305 yaffs_Device *dev = 0;
1306 char devname_buf[BDEVNAME_SIZE + 1];
1307 struct mtd_info *mtd;
1310 sb->s_magic = YAFFS_MAGIC;
1311 sb->s_op = &yaffs_super_ops;
1314 printk(KERN_INFO "yaffs: sb is NULL\n");
1315 else if (!sb->s_dev)
1316 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1317 else if (!yaffs_devname(sb, devname_buf))
1318 printk(KERN_INFO "yaffs: devname is NULL\n");
1320 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1322 yaffs_devname(sb, devname_buf));
1324 sb->s_blocksize = PAGE_CACHE_SIZE;
1325 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1326 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1328 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1330 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1332 ("yaffs: Write verification disabled. All guarantees "
1333 "null and void\n"));
1336 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1338 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1339 yaffs_devname(sb, devname_buf)));
1341 /* Check it's an mtd device..... */
1342 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1343 return NULL; /* This isn't an mtd device */
1345 /* Get the device */
1346 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1348 T(YAFFS_TRACE_ALWAYS,
1349 ("yaffs: MTD device #%u doesn't appear to exist\n",
1353 /* Check it's NAND */
1354 if (mtd->type != MTD_NANDFLASH) {
1355 T(YAFFS_TRACE_ALWAYS,
1356 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1360 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1361 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1362 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1363 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1364 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1365 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1366 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1367 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1368 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1369 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1370 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1372 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1374 if (yaffsVersion == 1 &&
1375 mtd->oobblock >= 2048) {
1376 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1381 if (yaffsVersion == 2) {
1382 /* Check for version 2 style functions */
1384 !mtd->block_isbad ||
1385 !mtd->block_markbad ||
1389 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1390 T(YAFFS_TRACE_ALWAYS,
1391 ("yaffs: MTD device does not support required "
1396 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1397 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1398 T(YAFFS_TRACE_ALWAYS,
1399 ("yaffs: MTD device does not support have the "
1400 "right page sizes\n"));
1404 /* Check for V1 style functions */
1409 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1410 T(YAFFS_TRACE_ALWAYS,
1411 ("yaffs: MTD device does not support required "
1416 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1417 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1418 T(YAFFS_TRACE_ALWAYS,
1419 ("yaffs: MTD device does not support have the "
1420 "right page sizes\n"));
1425 /* OK, so if we got here, we have an MTD that's NAND and looks
1426 * like it has the right capabilities
1427 * Set the yaffs_Device up for mtd
1430 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1431 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1433 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1436 /* Deep shit could not allocate device structure */
1437 T(YAFFS_TRACE_ALWAYS,
1438 ("yaffs_read_super: Failed trying to allocate "
1439 "yaffs_Device. \n"));
1443 memset(dev, 0, sizeof(yaffs_Device));
1444 dev->genericDevice = mtd;
1445 dev->name = mtd->name;
1447 /* Set up the memory size parameters.... */
1449 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1450 dev->startBlock = 0;
1451 dev->endBlock = nBlocks - 1;
1452 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1453 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1454 dev->nReservedBlocks = 5;
1455 dev->nShortOpCaches = 10; /* Enable short op caching */
1457 /* ... and the functions. */
1458 if (yaffsVersion == 2) {
1459 dev->writeChunkWithTagsToNAND =
1460 nandmtd2_WriteChunkWithTagsToNAND;
1461 dev->readChunkWithTagsFromNAND =
1462 nandmtd2_ReadChunkWithTagsFromNAND;
1463 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1464 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1465 dev->spareBuffer = YMALLOC(mtd->oobsize);
1467 dev->nBytesPerChunk = mtd->oobblock;
1468 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1469 nBlocks = mtd->size / mtd->erasesize;
1470 dev->startBlock = 0;
1471 dev->endBlock = nBlocks - 1;
1473 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1474 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1477 /* ... and common functions */
1478 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1479 dev->initialiseNAND = nandmtd_InitialiseNAND;
1481 dev->putSuperFunc = yaffs_MTDPutSuper;
1483 #ifndef CONFIG_YAFFS_DOES_ECC
1484 dev->useNANDECC = 1;
1487 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
1488 dev->wideTnodesDisabled = 1;
1491 /* we assume this is protected by lock_kernel() in mount/umount */
1492 list_add_tail(&dev->devList, &yaffs_dev_list);
1494 init_MUTEX(&dev->grossLock);
1496 yaffs_GrossLock(dev);
1498 err = yaffs_GutsInitialise(dev);
1501 ("yaffs_read_super: guts initialised %s\n",
1502 (err == YAFFS_OK) ? "OK" : "FAILED"));
1504 /* Release lock before yaffs_get_inode() */
1505 yaffs_GrossUnlock(dev);
1507 /* Create root inode */
1508 if (err == YAFFS_OK)
1509 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1515 inode->i_op = &yaffs_dir_inode_operations;
1516 inode->i_fop = &yaffs_dir_operations;
1518 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1520 root = d_alloc_root(inode);
1522 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1530 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1535 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1536 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1539 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1542 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1543 int flags, const char *dev_name,
1547 return get_sb_bdev(fs, flags, dev_name, data,
1548 yaffs_internal_read_super_mtd);
1551 static struct file_system_type yaffs_fs_type = {
1552 .owner = THIS_MODULE,
1554 .get_sb = yaffs_read_super,
1555 .kill_sb = kill_block_super,
1556 .fs_flags = FS_REQUIRES_DEV,
1559 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1562 return yaffs_internal_read_super(1, sb, data, silent);
1565 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1570 #ifdef CONFIG_YAFFS_YAFFS2
1572 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1573 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1576 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1579 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1580 int flags, const char *dev_name,
1584 return get_sb_bdev(fs, flags, dev_name, data,
1585 yaffs2_internal_read_super_mtd);
1588 static struct file_system_type yaffs2_fs_type = {
1589 .owner = THIS_MODULE,
1591 .get_sb = yaffs2_read_super,
1592 .kill_sb = kill_block_super,
1593 .fs_flags = FS_REQUIRES_DEV,
1596 static struct super_block *yaffs2_read_super(struct super_block *sb,
1597 void *data, int silent)
1599 return yaffs_internal_read_super(2, sb, data, silent);
1602 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1606 #endif /* CONFIG_YAFFS_YAFFS2 */
1608 static struct proc_dir_entry *my_proc_entry;
1610 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1612 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1613 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1614 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1615 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1616 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1617 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1618 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1619 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1620 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1621 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1622 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1623 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1624 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1625 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1627 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1629 sprintf(buf, "passiveGCs......... %d\n",
1630 dev->passiveGarbageCollections);
1631 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1632 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1633 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1634 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1635 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1636 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1637 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1638 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1639 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1641 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1642 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1643 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1648 static int yaffs_proc_read(char *page,
1650 off_t offset, int count, int *eof, void *data)
1652 struct list_head *item;
1657 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1658 * We use 'offset' (*ppos) to indicate where we are in devList.
1659 * This also assumes the user has posted a read buffer large
1660 * enough to hold the complete output; but that's life in /proc.
1665 /* Print header first */
1667 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1668 "\n%s\n%s\n", yaffs_fs_c_version,
1669 yaffs_guts_c_version);
1672 /* hold lock_kernel while traversing yaffs_dev_list */
1675 /* Locate and print the Nth entry. Order N-squared but N is small. */
1676 list_for_each(item, &yaffs_dev_list) {
1677 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1682 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1683 buf = yaffs_dump_dev(buf, dev);
1688 return buf - page < count ? buf - page : count;
1692 * Set the verbosity of the warnings and error messages.
1698 unsigned mask_bitfield;
1700 {"allocate", YAFFS_TRACE_ALLOCATE},
1701 {"always", YAFFS_TRACE_ALWAYS},
1702 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
1703 {"buffers", YAFFS_TRACE_BUFFERS},
1704 {"bug", YAFFS_TRACE_BUG},
1705 {"deletion", YAFFS_TRACE_DELETION},
1706 {"erase", YAFFS_TRACE_ERASE},
1707 {"error", YAFFS_TRACE_ERROR},
1708 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
1709 {"gc", YAFFS_TRACE_GC},
1710 {"mtd", YAFFS_TRACE_MTD},
1711 {"nandaccess", YAFFS_TRACE_NANDACCESS},
1712 {"os", YAFFS_TRACE_OS},
1713 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
1714 {"scan", YAFFS_TRACE_SCAN},
1715 {"tracing", YAFFS_TRACE_TRACING},
1716 {"write", YAFFS_TRACE_WRITE},
1717 {"all", 0xffffffff},
1722 static int yaffs_proc_write(struct file *file, const char *buf,
1723 unsigned long count, void *data)
1725 unsigned rg = 0, mask_bitfield;
1726 char *end, *mask_name;
1732 rg = yaffs_traceMask;
1734 while (!done && (pos < count)) {
1736 while ((pos < count) && isspace(buf[pos])) {
1753 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
1754 if (end > buf + pos) {
1755 mask_name = "numeral";
1756 len = end - (buf + pos);
1760 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1761 len = strlen(mask_flags[i].mask_name);
1762 if (strncmp(buf + pos, mask_flags[i].mask_name, len) == 0) {
1763 mask_name = mask_flags[i].mask_name;
1764 mask_bitfield = mask_flags[i].mask_bitfield;
1771 if (mask_name != NULL) {
1776 rg &= ~mask_bitfield;
1779 rg |= mask_bitfield;
1785 rg |= mask_bitfield;
1791 yaffs_traceMask = rg;
1792 if (rg & YAFFS_TRACE_ALWAYS) {
1793 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
1795 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
1796 printk("%c%s\n", flag, mask_flags[i].mask_name);
1803 /* Stuff to handle installation of file systems */
1804 struct file_system_to_install {
1805 struct file_system_type *fst;
1809 static struct file_system_to_install fs_to_install[] = {
1810 //#ifdef CONFIG_YAFFS_YAFFS1
1811 {&yaffs_fs_type, 0},
1813 //#ifdef CONFIG_YAFFS_YAFFS2
1814 {&yaffs2_fs_type, 0},
1819 static int __init init_yaffs_fs(void)
1822 struct file_system_to_install *fsinst;
1824 T(YAFFS_TRACE_ALWAYS,
1825 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1827 /* Install the proc_fs entry */
1828 my_proc_entry = create_proc_entry("yaffs",
1832 if (my_proc_entry) {
1833 my_proc_entry->write_proc = yaffs_proc_write;
1834 my_proc_entry->read_proc = yaffs_proc_read;
1835 my_proc_entry->data = NULL;
1840 /* Now add the file system entries */
1842 fsinst = fs_to_install;
1844 while (fsinst->fst && !error) {
1845 error = register_filesystem(fsinst->fst);
1847 fsinst->installed = 1;
1852 /* Any errors? uninstall */
1854 fsinst = fs_to_install;
1856 while (fsinst->fst) {
1857 if (fsinst->installed) {
1858 unregister_filesystem(fsinst->fst);
1859 fsinst->installed = 0;
1868 static void __exit exit_yaffs_fs(void)
1871 struct file_system_to_install *fsinst;
1873 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1876 remove_proc_entry("yaffs", &proc_root);
1878 fsinst = fs_to_install;
1880 while (fsinst->fst) {
1881 if (fsinst->installed) {
1882 unregister_filesystem(fsinst->fst);
1883 fsinst->installed = 0;
1890 module_init(init_yaffs_fs)
1891 module_exit(exit_yaffs_fs)
1893 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1894 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1895 MODULE_LICENSE("GPL");