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 this superblock
19 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this superblock
20 * >> inode->u.generic_ip points to the associated yaffs_Object.
24 * * Luc van OostenRyck for numerous patches.
25 * * Nick Bane for numerous patches.
26 * * Nick Bane for 2.5/2.6 integration.
27 * * Andras Toth for mknod rdev issue.
28 * * Michael Fischer for finding the problem with inode inconsistency.
29 * * Some code bodily lifted from JFFS2.
33 const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.17 2005-07-31 04:08:08 marty Exp $";
34 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>
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)
59 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf) // FIXME: use sb->s_id instead ?
63 #include <linux/locks.h>
64 #define BDEVNAME_SIZE 0
65 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
69 #include <asm/uaccess.h>
72 #include "yaffs_guts.h"
77 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS;
78 //unsigned yaffs_traceMask = 0xFFFFFFFF;
81 #ifdef CONFIG_YAFFS_RAM_ENABLED
82 #include "yaffs_nandemul.h"
83 // 2 MB of RAM for emulation
84 #define YAFFS_RAM_EMULATION_SIZE 0x200000
85 #endif //CONFIG_YAFFS_RAM_ENABLED
87 #if CONFIG_YAFFS2_RAM_ENABLED
88 #include "yaffs_nandemul2k.h"
91 #ifdef CONFIG_YAFFS_MTD_ENABLED
92 #include <linux/mtd/mtd.h>
93 #include "yaffs_mtdif.h"
94 #include "yaffs_mtdif2.h"
95 #endif //CONFIG_YAFFS_MTD_ENABLED
97 //#define T(x) printk x
101 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
102 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
103 //NCB #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
105 //#if defined(CONFIG_KERNEL_2_5)
106 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
107 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
109 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
113 static void yaffs_put_super(struct super_block *sb);
116 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
119 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
121 static int yaffs_file_flush(struct file* file);
123 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
125 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
127 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
128 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
129 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
130 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
132 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
133 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
135 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
136 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
137 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
138 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
140 //#if defined(CONFIG_KERNEL_2_5)
141 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
142 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
144 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
146 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
147 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
149 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
150 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
151 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
153 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
155 static void yaffs_read_inode (struct inode *inode);
157 static void yaffs_put_inode (struct inode *inode);
158 static void yaffs_delete_inode(struct inode *);
159 static void yaffs_clear_inode(struct inode *);
161 static int yaffs_readpage(struct file *file, struct page * page);
162 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
163 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
165 static int yaffs_writepage(struct page *page);
167 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
168 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
170 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen);
171 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
175 static struct address_space_operations yaffs_file_address_operations = {
176 .readpage = yaffs_readpage,
177 .writepage = yaffs_writepage,
178 .prepare_write = yaffs_prepare_write,
179 .commit_write = yaffs_commit_write,
182 static struct file_operations yaffs_file_operations = {
183 .read = generic_file_read,
184 .write = generic_file_write,
185 .mmap = generic_file_mmap,
186 .flush = yaffs_file_flush,
187 .fsync = yaffs_sync_object,
190 static struct inode_operations yaffs_file_inode_operations = {
191 .setattr = yaffs_setattr,
194 static struct inode_operations yaffs_symlink_inode_operations = {
195 .readlink = yaffs_readlink,
196 .follow_link = yaffs_follow_link,
197 .setattr = yaffs_setattr,
200 static struct inode_operations yaffs_dir_inode_operations = {
201 .create = yaffs_create,
202 .lookup = yaffs_lookup,
204 .unlink = yaffs_unlink,
205 .symlink = yaffs_symlink,
206 .mkdir = yaffs_mkdir,
207 .rmdir = yaffs_unlink,
208 .mknod = yaffs_mknod,
209 .rename = yaffs_rename,
210 .setattr = yaffs_setattr,
213 static struct file_operations yaffs_dir_operations = {
214 .read = generic_read_dir,
215 .readdir = yaffs_readdir,
216 .fsync = yaffs_sync_object,
219 static struct super_operations yaffs_super_ops = {
220 .statfs = yaffs_statfs,
221 .read_inode = yaffs_read_inode,
222 .put_inode = yaffs_put_inode,
223 .put_super = yaffs_put_super,
224 .delete_inode = yaffs_delete_inode,
225 .clear_inode = yaffs_clear_inode,
230 static void yaffs_GrossLock(yaffs_Device *dev)
232 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
234 down(&dev->grossLock);
237 static void yaffs_GrossUnlock(yaffs_Device *dev)
239 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
244 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
246 unsigned char *alias;
249 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
252 yaffs_GrossLock(dev);
254 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
256 yaffs_GrossUnlock(dev);
261 ret = vfs_readlink(dentry, buffer, buflen, alias);
266 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
268 unsigned char *alias;
270 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
273 yaffs_GrossLock(dev);
275 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
277 yaffs_GrossUnlock(dev);
282 ret = vfs_follow_link(nd,alias);
288 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
291 * Lookup is used to find objects in the fs
293 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
294 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
296 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
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;
307 yaffs_GrossLock(dev);
310 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
312 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
314 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
320 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
322 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode,0,obj);
326 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
327 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
329 //dget(dentry); // try to solve directory bug
332 yaffs_GrossUnlock(dev);
342 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
345 yaffs_GrossUnlock(dev);
347 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
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.
357 static void yaffs_put_inode(struct inode *inode)
359 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
363 // clear is called to tell the fs to release any per-inode data it holds
364 static void yaffs_clear_inode(struct inode *inode)
369 obj = yaffs_InodeToObject(inode);
371 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
372 obj ? "object exists" : "null object"));
377 yaffs_GrossLock(dev);
379 // Clear the association between the inode ant the yaffs_Object.
381 inode->u.generic_ip = NULL;
383 // If the object freeing was deferred, then the real free happens now.
384 // This should fix the inode inconsistency problem.
386 yaffs_HandleDeferedFree(obj);
388 yaffs_GrossUnlock(dev);
394 // delete is called when the link count is zero and the inode
395 // is put (ie. nobody wants to know about it anymore, time to
397 // NB Must call clear_inode()
398 static void yaffs_delete_inode(struct inode *inode)
400 yaffs_Object *obj = yaffs_InodeToObject(inode);
403 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
404 obj ? "object exists" : "null object"));
409 yaffs_GrossLock(dev);
410 yaffs_DeleteFile(obj);
411 yaffs_GrossUnlock(dev);
417 static int yaffs_file_flush(struct file* file)
419 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
421 yaffs_Device *dev = obj->myDev;
423 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
424 obj->dirty ? "dirty" : "clean"));
426 yaffs_GrossLock(dev);
428 yaffs_FlushFile(obj,1);
430 yaffs_GrossUnlock(dev);
437 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
442 unsigned char *pg_buf;
447 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
448 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
450 obj = yaffs_DentryToObject(f->f_dentry);
455 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
456 BUG_ON(!PageLocked(pg));
463 /* FIXME: Can kmap fail? */
465 yaffs_GrossLock(dev);
467 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
469 yaffs_GrossUnlock(dev);
471 if(ret >= 0) ret = 0;
474 ClearPageUptodate(pg);
481 flush_dcache_page(pg);
485 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
489 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
491 int ret = yaffs_readpage_nolock(f,pg);
496 static int yaffs_readpage(struct file *f, struct page * pg)
498 return yaffs_readpage_unlock(f,pg);
501 // writepage inspired by/stolen from smbfs
504 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
505 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
507 static int yaffs_writepage(struct page *page)
510 struct address_space *mapping = page->mapping;
512 unsigned long end_index;
520 inode = mapping->host;
524 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
527 if (page->index < end_index)
529 nBytes = PAGE_CACHE_SIZE;
533 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
535 // What's happening here?
536 ///* OK, are we completely out? */
537 //if (page->index >= end_index+1 || !offset)
545 obj = yaffs_InodeToObject(inode);
546 yaffs_GrossLock(obj->myDev);
549 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
551 yaffs_GrossUnlock(obj->myDev);
554 SetPageUptodate(page);
558 return (nWritten == nBytes) ? 0 : -ENOSPC;
563 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
566 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
567 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
568 return yaffs_readpage_nolock(f,pg);
574 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
577 void *addr = page_address(pg) + offset;
578 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
579 int nBytes = to - offset;
583 unsigned saddr = (unsigned)addr;
585 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
587 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
589 if(nWritten != nBytes)
591 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
593 ClearPageUptodate(pg);
600 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
608 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
612 inode->i_ino = obj->objectId;
613 inode->i_mode = obj->yst_mode;
614 inode->i_uid = obj->yst_uid;
615 inode->i_gid = obj->yst_gid;
616 inode->i_blksize = inode->i_sb->s_blocksize;
617 //#if defined(CONFIG_KERNEL_2_5)
618 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
620 inode->i_rdev = old_decode_dev(obj->yst_rdev);
621 inode->i_atime.tv_sec = (time_t)(obj->yst_atime);
622 inode->i_atime.tv_nsec = 0;
623 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime;
624 inode->i_mtime.tv_nsec =0;
625 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime;
626 inode->i_ctime.tv_nsec = 0;
628 inode->i_rdev = obj->yst_rdev;
629 inode->i_atime = obj->yst_atime;
630 inode->i_mtime = obj->yst_mtime;
631 inode->i_ctime = obj->yst_ctime;
633 inode->i_size = yaffs_GetObjectFileLength(obj);
634 inode->i_blocks = (inode->i_size + 511) >> 9;
636 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
638 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
639 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
641 switch (obj->yst_mode & S_IFMT)
643 default: // fifo, device or socket
644 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
645 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev));
647 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev));
650 case S_IFREG: // file
651 inode->i_op = &yaffs_file_inode_operations;
652 inode->i_fop = &yaffs_file_operations;
653 inode->i_mapping->a_ops = &yaffs_file_address_operations;
655 case S_IFDIR: // directory
656 inode->i_op = &yaffs_dir_inode_operations;
657 inode->i_fop = &yaffs_dir_operations;
659 case S_IFLNK: // symlink
660 inode->i_op = &yaffs_symlink_inode_operations;
665 inode->u.generic_ip = obj;
666 obj->myInode = inode;
671 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
676 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
678 struct inode * inode;
682 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
689 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
694 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
696 inode = iget(sb,obj->objectId);
698 // NB Side effect: iget calls back to yaffs_read_inode().
699 // iget also increments the inode's i_count
706 // No longer used because we use generic rw */
707 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
714 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
716 obj = yaffs_DentryToObject(f->f_dentry);
720 yaffs_GrossLock(dev);
722 inode = f->f_dentry->d_inode;
724 if (*pos < inode->i_size)
726 if (*pos + n > inode->i_size)
728 n = inode->i_size - *pos;
736 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
742 yaffs_GrossUnlock(dev);
746 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
753 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
761 obj = yaffs_DentryToObject(f->f_dentry);
765 yaffs_GrossLock(dev);
767 inode = f->f_dentry->d_inode;
769 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
771 ipos = inode->i_size;
781 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
785 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos));
788 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
790 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
795 if(ipos > inode->i_size)
797 inode->i_size = ipos;
798 inode->i_blocks = (ipos + 511)>>9;
800 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
804 yaffs_GrossUnlock(dev);
806 return nWritten != n ? -ENOSPC : nWritten;
811 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
815 struct inode *inode = f->f_dentry->d_inode;
816 unsigned long offset, curoffs;
820 char name[YAFFS_MAX_NAME_LENGTH +1];
822 obj = yaffs_DentryToObject(f->f_dentry);
825 yaffs_GrossLock(dev);
829 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
833 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
834 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
843 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
844 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
854 list_for_each(i,&obj->variant.directoryVariant.children)
857 if(curoffs >= offset)
859 l = list_entry(i, yaffs_Object,siblings);
861 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
862 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
868 yaffs_GetObjectInode(l),
869 yaffs_GetObjectType(l))
883 yaffs_GrossUnlock(dev);
890 * File creation. Allocate an inode, and we're done..
892 //#if defined(CONFIG_KERNEL_2_5)
893 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
894 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
896 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
901 yaffs_Object *obj = NULL;
904 yaffs_Object *parent = yaffs_InodeToObject(dir);
907 uid_t uid = current->fsuid;
908 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
912 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
913 parent->objectId,parent->variantType));
917 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
921 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
922 dentry->d_name.name, mode,rdev));
926 yaffs_GrossLock(dev);
928 switch (mode & S_IFMT)
931 // Special (socket, fifo, device...)
932 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
933 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
934 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,old_encode_dev(rdev));
936 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,rdev);
939 case S_IFREG: // file
940 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
941 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,uid, gid);
943 case S_IFDIR: // directory
944 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
945 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,uid, gid);
947 case S_IFLNK: // symlink
948 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
949 obj = NULL; // Do we ever get here?
955 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
956 d_instantiate(dentry, inode);
957 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
962 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
966 yaffs_GrossUnlock(dev);
971 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
974 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
975 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
977 // attempt to fix dir bug - didn't work
986 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
987 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
988 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
990 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
993 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
994 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
998 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
1005 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
1007 dev = yaffs_InodeToObject(dir)->myDev;
1009 yaffs_GrossLock(dev);
1012 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1015 yaffs_GrossUnlock(dev);
1017 if( retVal == YAFFS_OK)
1019 dentry->d_inode->i_nlink--;
1020 mark_inode_dirty(dentry->d_inode);
1033 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1035 struct inode *inode = old_dentry->d_inode;
1036 yaffs_Object *obj = NULL;
1037 yaffs_Object *link=NULL;
1040 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1042 obj = yaffs_InodeToObject(inode);
1045 yaffs_GrossLock(dev);
1047 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1049 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1055 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1056 d_instantiate(dentry, old_dentry->d_inode);
1057 atomic_inc(&old_dentry->d_inode->i_count);
1058 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1059 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1063 yaffs_GrossUnlock(dev);
1077 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1081 uid_t uid = current->fsuid;
1082 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1084 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1086 dev = yaffs_InodeToObject(dir)->myDev;
1087 yaffs_GrossLock(dev);
1088 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1089 S_IFLNK | S_IRWXUGO, uid, gid,
1091 yaffs_GrossUnlock(dev);
1096 struct inode* inode;
1098 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1099 d_instantiate(dentry, inode);
1100 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1105 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1112 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1118 obj = yaffs_DentryToObject(dentry);
1122 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1123 yaffs_GrossLock(dev);
1124 yaffs_FlushFile(obj,1);
1125 yaffs_GrossUnlock(dev);
1130 * The VFS layer already does all the dentry stuff for rename.
1132 * NB: POSIX says you can rename an object over an old object of the same name
1134 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1137 int retVal = YAFFS_FAIL;
1139 yaffs_Object *target;
1141 dev = yaffs_InodeToObject(old_dir)->myDev;
1143 yaffs_GrossLock(dev);
1145 // Check if the target is an existing directory that is not empty.
1146 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1149 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1150 !list_empty(&target->variant.directoryVariant.children))
1152 retVal = YAFFS_FAIL;
1157 // Unlink the target if it exists
1158 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1161 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1162 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1165 yaffs_GrossUnlock(dev);
1167 if(retVal == YAFFS_OK)
1169 if(removed == YAFFS_OK)
1171 new_dentry->d_inode->i_nlink--;
1172 mark_inode_dirty(new_dentry->d_inode);
1185 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1187 struct inode *inode = dentry->d_inode;
1191 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1193 if((error = inode_change_ok(inode,attr)) == 0)
1196 dev = yaffs_InodeToObject(inode)->myDev;
1197 yaffs_GrossLock(dev);
1198 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1206 yaffs_GrossUnlock(dev);
1208 error = inode_setattr(inode,attr);
1213 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1214 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1215 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1217 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1222 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1223 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1225 yaffs_GrossLock(dev);
1228 buf->f_type = YAFFS_MAGIC;
1229 buf->f_bsize = sb->s_blocksize;
1230 buf->f_namelen = 255;
1231 if(sb->s_blocksize > dev->nBytesPerChunk)
1234 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1235 (sb->s_blocksize/dev->nBytesPerChunk);
1236 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1237 (sb->s_blocksize/dev->nBytesPerChunk);
1242 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1243 (dev->nBytesPerChunk/sb->s_blocksize);
1244 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1245 (dev->nBytesPerChunk/sb->s_blocksize);
1249 buf->f_bavail = buf->f_bfree;
1251 yaffs_GrossUnlock(dev);
1255 static void yaffs_read_inode (struct inode *inode)
1257 // NB This is called as a side effect of other functions and
1258 // thus gross locking should always be in place already.
1261 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1263 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1265 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1267 yaffs_FillInodeFromObject(inode,obj);
1271 static LIST_HEAD(yaffs_dev_list);
1273 static void yaffs_put_super(struct super_block *sb)
1275 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1277 yaffs_GrossLock(dev);
1278 if(dev->putSuperFunc)
1280 dev->putSuperFunc(sb);
1282 yaffs_Deinitialise(dev);
1283 yaffs_GrossUnlock(dev);
1285 /* we assume this is protected by lock_kernel() in mount/umount */
1286 list_del(&dev->devList);
1292 #ifdef CONFIG_YAFFS_MTD_ENABLED
1294 static void yaffs_MTDPutSuper(struct super_block *sb)
1297 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1304 put_mtd_device(mtd);
1310 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1313 struct inode * inode = NULL;
1314 struct dentry * root;
1315 yaffs_Device *dev = 0;
1316 char devname_buf[BDEVNAME_SIZE+1];
1319 sb->s_magic = YAFFS_MAGIC;
1320 sb->s_op = &yaffs_super_ops;
1323 printk(KERN_INFO"yaffs: sb is NULL\n");
1325 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1326 else if(!yaffs_devname(sb, devname_buf))
1327 printk(KERN_INFO"yaffs: devname is NULL\n");
1329 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, yaffs_devname(sb, devname_buf));
1333 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1334 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1335 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1337 sb->s_blocksize = PAGE_CACHE_SIZE;
1338 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1340 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1341 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1343 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1344 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1352 #ifdef CONFIG_YAFFS_RAM_ENABLED
1353 // Set the yaffs_Device up for ram emulation
1356 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1357 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1359 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1364 // Deep shit could not allocate device structure
1365 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1369 memset(dev,0,sizeof(yaffs_Device));
1370 dev->genericDevice = NULL; // Not used for RAM emulation.
1371 dev->name = sb->s_type->name;
1373 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1374 dev->startBlock = 0;
1375 dev->endBlock = nBlocks - 1;
1376 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1377 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1378 dev->nReservedBlocks = 5;
1380 if(yaffsVersion == 2)
1382 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
1383 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1384 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
1385 dev->queryNANDBlock = nandemul2k_QueryNANDBlock;
1386 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
1387 dev->initialiseNAND = nandemul2k_InitialiseNAND;
1389 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1390 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();;
1391 nBlocks = nandemul2k_GetNumberOfBlocks();
1392 dev->startBlock = 0;
1393 dev->endBlock = nBlocks - 1;
1397 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1398 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1399 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1400 dev->initialiseNAND = nandemul_InitialiseNAND;
1408 #if defined(CONFIG_YAFFS_MTD_ENABLED) || defined(CONFIG_YAFFS2_MTD_ENABLED)
1409 struct mtd_info *mtd;
1411 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1412 MAJOR(sb->s_dev),MINOR(sb->s_dev), yaffs_devname(sb, devname_buf)));
1414 // Check it's an mtd device.....
1415 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1417 return NULL; // This isn't an mtd device
1421 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1424 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1429 if(mtd->type != MTD_NANDFLASH)
1431 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1435 T(YAFFS_TRACE_OS,(" erase %p\n",mtd->erase));
1436 T(YAFFS_TRACE_OS,(" read %p\n",mtd->read));
1437 T(YAFFS_TRACE_OS,(" write %p\n",mtd->write));
1438 T(YAFFS_TRACE_OS,(" readoob %p\n",mtd->read_oob));
1439 T(YAFFS_TRACE_OS,(" writeoob %p\n",mtd->write_oob));
1440 T(YAFFS_TRACE_OS,(" block_isbad %p\n",mtd->block_isbad));
1441 T(YAFFS_TRACE_OS,(" block_markbad %p\n",mtd->block_markbad));
1442 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1443 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1444 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1445 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1447 if(yaffsVersion == 2)
1449 // Check for version 2 style functions
1451 !mtd->block_isbad ||
1452 !mtd->block_markbad ||
1455 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1462 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1466 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1467 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1469 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1474 // Check for V1 style functions
1478 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1485 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1489 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1490 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1492 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1498 // OK, so if we got here, we have an MTD that's NAND and looks
1499 // like it has the right capabilities
1500 // Set the yaffs_Device up for mtd
1502 //#if defined(CONFIG_KERNEL_2_5)
1503 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1504 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1506 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1510 // Deep shit could not allocate device structure
1511 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1515 memset(dev,0,sizeof(yaffs_Device));
1516 dev->genericDevice = mtd;
1517 dev->name = mtd->name;
1519 // Set up the memory size parameters....
1521 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1522 dev->startBlock = 0;
1523 dev->endBlock = nBlocks - 1;
1524 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1525 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1526 dev->nReservedBlocks = 5;
1527 dev->nShortOpCaches = 10; // Enable short op caching
1530 // ... and the functions.
1531 if(yaffsVersion == 2)
1533 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1534 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1535 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1536 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1537 dev->spareBuffer = YMALLOC(mtd->oobsize);
1539 dev->nBytesPerChunk = mtd->oobblock;
1540 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1541 nBlocks = mtd->size / mtd->erasesize;
1542 dev->startBlock = 0;
1543 dev->endBlock = nBlocks - 1;
1547 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1548 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1551 // ... and common functions
1552 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1553 dev->initialiseNAND = nandmtd_InitialiseNAND;
1555 dev->putSuperFunc = yaffs_MTDPutSuper;
1557 #ifdef CONFIG_YAFFS_USE_NANDECC
1558 dev->useNANDECC = 1;
1563 /* we assume this is protected by lock_kernel() in mount/umount */
1564 list_add_tail(&dev->devList, &yaffs_dev_list);
1566 init_MUTEX(&dev->grossLock);
1569 yaffs_GrossLock(dev);
1571 err = yaffs_GutsInitialise(dev);
1573 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1575 // Create root inode
1577 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1579 yaffs_GrossUnlock(dev);
1585 inode->i_op = & yaffs_dir_inode_operations;
1586 inode->i_fop = & yaffs_dir_operations;
1588 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1591 root = d_alloc_root(inode);
1593 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1601 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1607 #ifdef CONFIG_YAFFS_MTD_ENABLED
1609 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1610 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1612 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1615 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1618 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1621 /* changes NCB 2.5.70 */
1622 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1623 static struct file_system_type yaffs_fs_type = {
1624 .owner = THIS_MODULE,
1626 .get_sb = yaffs_read_super,
1627 .kill_sb = kill_block_super,
1628 // .kill_sb = kill_litter_super,
1629 .fs_flags = FS_REQUIRES_DEV,
1632 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1634 return yaffs_internal_read_super(1,0,sb,data,silent);
1637 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1640 #endif // CONFIG_YAFFS_MTD_ENABLED
1642 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1644 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1645 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1647 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1650 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1653 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1656 /* changes NCB 2.5.70 */
1657 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1658 static struct file_system_type yaffs2_fs_type = {
1659 .owner = THIS_MODULE,
1661 .get_sb = yaffs2_read_super,
1662 .kill_sb = kill_block_super,
1663 // .kill_sb = kill_litter_super,
1664 .fs_flags = FS_REQUIRES_DEV,
1667 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1669 return yaffs_internal_read_super(2,0,sb,data,silent);
1672 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1675 #endif // CONFIG_YAFFS2_MTD_ENABLED
1678 #ifdef CONFIG_YAFFS_RAM_ENABLED
1680 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1681 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1683 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1686 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1689 return get_sb_nodev(fs, flags, data, yaffs_internal_read_super_ram);
1693 static struct file_system_type yaffs_ram_fs_type = {
1694 .owner = THIS_MODULE,
1696 .get_sb = yaffs_ram_read_super,
1697 .kill_sb = kill_litter_super,
1701 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1703 return yaffs_internal_read_super(1,1,sb,data,silent);
1706 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1709 #endif // CONFIG_YAFFS_RAM_ENABLED
1711 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1713 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1714 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1716 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1719 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1722 return get_sb_nodev(fs, flags, data, yaffs2_internal_read_super_ram);
1726 static struct file_system_type yaffs2_ram_fs_type = {
1727 .owner = THIS_MODULE,
1728 .name = "yaffs2ram",
1729 .get_sb = yaffs2_ram_read_super,
1730 .kill_sb = kill_litter_super,
1734 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1736 return yaffs_internal_read_super(2,1,sb,data,silent);
1739 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1742 #endif // CONFIG_YAFFS2_RAM_ENABLED
1746 static struct proc_dir_entry *my_proc_entry;
1747 static struct proc_dir_entry *my_proc_ram_write_entry;
1749 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev)
1751 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1752 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1753 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1754 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1755 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1756 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1757 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1758 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1759 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1760 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1761 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1762 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1763 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1764 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1765 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1766 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1767 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1768 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1769 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1770 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1771 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1772 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1773 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1774 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1775 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1776 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1777 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1778 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1783 static int yaffs_proc_read(
1792 struct list_head *item;
1797 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1798 * We use 'offset' (*ppos) to indicate where we are in devList.
1799 * This also assumes the user has posted a read buffer large
1800 * enough to hold the complete output; but that's life in /proc.
1805 /* Print header first */
1807 buf += sprintf(buf, "YAFFS built:" __DATE__ " "__TIME__
1808 "\n%s\n%s\n", yaffs_fs_c_version, yaffs_guts_c_version);
1811 /* hold lock_kernel while traversing yaffs_dev_list */
1814 /* Locate and print the Nth entry. Order N-squared but N is small. */
1815 list_for_each(item, &yaffs_dev_list) {
1816 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1821 buf += sprintf(buf,"\nDevice %d \"%s\"\n", n, dev->name);
1822 buf = yaffs_dump_dev(buf, dev);
1827 return buf-page < count ? buf-page : count;
1830 static int yaffs_proc_ram_write(
1840 printk(KERN_DEBUG "yaffs write size %d\n",count);
1846 // Stuff to handle installation of file systems
1847 struct file_system_to_install
1849 struct file_system_type *fst;
1853 static struct file_system_to_install fs_to_install[] =
1855 #ifdef CONFIG_YAFFS_RAM_ENABLED
1856 { &yaffs_ram_fs_type, 0},
1858 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1859 { &yaffs2_ram_fs_type,0},
1861 #ifdef CONFIG_YAFFS_MTD_ENABLED
1862 { &yaffs_fs_type,0},
1864 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1865 { &yaffs2_fs_type,0},
1870 static int __init init_yaffs_fs(void)
1873 struct file_system_to_install *fsinst;
1875 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1879 /* Install the proc_fs entry */
1880 my_proc_entry = create_proc_read_entry("yaffs",
1892 // Now add the file system entries
1894 fsinst = fs_to_install;
1896 while(fsinst->fst && !error)
1898 error = register_filesystem(fsinst->fst);
1901 fsinst->installed = 1;
1906 // Any errors? uninstall
1909 fsinst = fs_to_install;
1913 if(fsinst->installed)
1915 unregister_filesystem(fsinst->fst);
1916 fsinst->installed = 0;
1925 static void __exit exit_yaffs_fs(void)
1928 struct file_system_to_install *fsinst;
1930 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1932 remove_proc_entry("yaffs",&proc_root);
1934 fsinst = fs_to_install;
1938 if(fsinst->installed)
1940 unregister_filesystem(fsinst->fst);
1941 fsinst->installed = 0;
1948 module_init(init_yaffs_fs)
1949 module_exit(exit_yaffs_fs)
1951 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1952 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1953 MODULE_LICENSE("GPL");