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.8 2005-07-18 23:16:04 charles Exp $";
34 extern const char *yaffs_guts_c_version;
38 #include <linux/config.h>
39 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/version.h>
42 #include <linux/slab.h>
43 #include <linux/init.h>
44 #include <linux/list.h>
46 #include <linux/proc_fs.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 kdevname(x) cdevname(to_kdev_t(x))
60 #define kdevname(x) "(unavailable)" // temporary fix
64 #include <linux/locks.h>
68 #include <asm/uaccess.h>
71 #include "yaffs_guts.h"
76 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS;
77 //unsigned yaffs_traceMask = 0xFFFFFFFF;
80 #ifdef CONFIG_YAFFS_RAM_ENABLED
81 #include "yaffs_nandemul.h"
82 // 2 MB of RAM for emulation
83 #define YAFFS_RAM_EMULATION_SIZE 0x200000
84 #endif //CONFIG_YAFFS_RAM_ENABLED
86 #if CONFIG_YAFFS2_RAM_ENABLED
87 #include "yaffs_nandemul2k.h"
90 #ifdef CONFIG_YAFFS_MTD_ENABLED
91 #include <linux/mtd/mtd.h>
92 #include "yaffs_mtdif.h"
93 #include "yaffs_mtdif2.h"
94 #endif //CONFIG_YAFFS_MTD_ENABLED
96 //#define T(x) printk x
100 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
101 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
102 //NCB #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
104 //#if defined(CONFIG_KERNEL_2_5)
105 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
106 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
108 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
112 static void yaffs_put_super(struct super_block *sb);
115 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
118 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
120 static int yaffs_file_flush(struct file* file);
122 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
124 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
126 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
127 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
128 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
129 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
131 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
132 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
134 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
135 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
136 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
137 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
139 //#if defined(CONFIG_KERNEL_2_5)
140 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
141 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
143 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
145 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
146 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
148 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
149 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
150 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
152 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
154 static void yaffs_read_inode (struct inode *inode);
156 //#if defined(CONFIG_KERNEL_2_5)
157 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
158 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data);
160 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
163 static void yaffs_put_inode (struct inode *inode);
164 static void yaffs_delete_inode(struct inode *);
165 static void yaffs_clear_inode(struct inode *);
167 static int yaffs_readpage(struct file *file, struct page * page);
168 static int yaffs_writepage(struct page *page);
169 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
170 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
172 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
173 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
178 static struct address_space_operations yaffs_file_address_operations = {
179 readpage: yaffs_readpage,
180 writepage: yaffs_writepage,
181 prepare_write: yaffs_prepare_write,
182 commit_write: yaffs_commit_write
186 static struct file_operations yaffs_file_operations = {
188 read: generic_file_read,
189 write: generic_file_write,
191 mmap: generic_file_mmap,
192 flush: yaffs_file_flush,
193 fsync: yaffs_sync_object,
197 static struct inode_operations yaffs_file_inode_operations = {
198 setattr: yaffs_setattr,
202 struct inode_operations yaffs_symlink_inode_operations =
204 readlink: yaffs_readlink,
205 follow_link: yaffs_follow_link,
206 setattr: yaffs_setattr
209 static struct inode_operations yaffs_dir_inode_operations = {
210 create: yaffs_create,
211 lookup: yaffs_lookup,
213 unlink: yaffs_unlink,
214 symlink: yaffs_symlink,
218 rename: yaffs_rename,
219 setattr: yaffs_setattr,
222 static struct file_operations yaffs_dir_operations = {
223 read: generic_read_dir,
224 readdir: yaffs_readdir,
225 fsync: yaffs_sync_object,
229 static struct super_operations yaffs_super_ops = {
230 statfs: yaffs_statfs,
231 read_inode: yaffs_read_inode,
232 put_inode: yaffs_put_inode,
233 put_super: yaffs_put_super,
235 delete_inode: yaffs_delete_inode,
236 clear_inode: yaffs_clear_inode,
241 static void yaffs_GrossLock(yaffs_Device *dev)
243 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
245 down(&dev->grossLock);
248 static void yaffs_GrossUnlock(yaffs_Device *dev)
250 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
255 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
257 unsigned char *alias;
260 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
263 yaffs_GrossLock(dev);
265 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
267 yaffs_GrossUnlock(dev);
272 ret = vfs_readlink(dentry, buffer, buflen, alias);
277 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
279 unsigned char *alias;
281 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
284 yaffs_GrossLock(dev);
286 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
288 yaffs_GrossUnlock(dev);
293 ret = vfs_follow_link(nd,alias);
299 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
302 * Lookup is used to find objects in the fs
304 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
305 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
307 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
309 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
313 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
315 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
318 yaffs_GrossLock(dev);
321 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
323 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
325 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
331 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
333 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode,0,obj);
337 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
338 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
340 //dget(dentry); // try to solve directory bug
343 yaffs_GrossUnlock(dev);
353 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
356 yaffs_GrossUnlock(dev);
358 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
362 // return (ERR_PTR(-EIO));
366 // For now put inode is just for debugging
367 // Put inode is called when the inode **structure** is put.
368 static void yaffs_put_inode(struct inode *inode)
370 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, 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);
382 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
383 obj ? "object exists" : "null object"));
388 yaffs_GrossLock(dev);
390 // Clear the association between the inode ant the yaffs_Object.
392 inode->u.generic_ip = NULL;
394 // If the object freeing was deferred, then the real free happens now.
395 // This should fix the inode inconsistency problem.
397 yaffs_HandleDeferedFree(obj);
399 yaffs_GrossUnlock(dev);
405 // delete is called when the link count is zero and the inode
406 // is put (ie. nobody wants to know about it anymore, time to
408 // NB Must call clear_inode()
409 static void yaffs_delete_inode(struct inode *inode)
411 yaffs_Object *obj = yaffs_InodeToObject(inode);
414 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
415 obj ? "object exists" : "null object"));
420 yaffs_GrossLock(dev);
421 yaffs_DeleteFile(obj);
422 yaffs_GrossUnlock(dev);
428 static int yaffs_file_flush(struct file* file)
430 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
432 yaffs_Device *dev = obj->myDev;
434 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
435 obj->dirty ? "dirty" : "clean"));
437 yaffs_GrossLock(dev);
439 yaffs_FlushFile(obj,1);
441 yaffs_GrossUnlock(dev);
448 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
453 unsigned char *pg_buf;
458 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
459 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
461 obj = yaffs_DentryToObject(f->f_dentry);
470 /* FIXME: Can kmap fail? */
472 yaffs_GrossLock(dev);
474 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
476 yaffs_GrossUnlock(dev);
478 if(ret >= 0) ret = 0;
481 ClearPageUptodate(pg);
488 flush_dcache_page(pg);
492 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
496 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
498 int ret = yaffs_readpage_nolock(f,pg);
503 static int yaffs_readpage(struct file *f, struct page * pg)
505 return yaffs_readpage_unlock(f,pg);
508 // writepage inspired by/stolen from smbfs
511 static int yaffs_writepage(struct page *page)
513 struct address_space *mapping = page->mapping;
515 unsigned long end_index;
523 inode = mapping->host;
527 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
530 if (page->index < end_index)
532 nBytes = PAGE_CACHE_SIZE;
536 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
538 // What's happening here?
539 ///* OK, are we completely out? */
540 //if (page->index >= end_index+1 || !offset)
548 obj = yaffs_InodeToObject(inode);
549 yaffs_GrossLock(obj->myDev);
552 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
554 yaffs_GrossUnlock(obj->myDev);
557 SetPageUptodate(page);
561 return (nWritten == nBytes) ? 0 : -ENOSPC;
566 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
569 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
570 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
571 return yaffs_readpage_nolock(f,pg);
577 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
580 void *addr = page_address(pg) + offset;
581 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
582 int nBytes = to - offset;
586 unsigned saddr = (unsigned)addr;
588 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
590 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
592 if(nWritten != nBytes)
594 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
596 ClearPageUptodate(pg);
603 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
611 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
615 inode->i_ino = obj->objectId;
616 inode->i_mode = obj->yst_mode;
617 inode->i_uid = obj->yst_uid;
618 inode->i_gid = obj->yst_gid;
619 inode->i_blksize = inode->i_sb->s_blocksize;
620 //#if defined(CONFIG_KERNEL_2_5)
621 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
623 inode->i_rdev = old_decode_dev(obj->yst_rdev);
624 inode->i_atime.tv_sec = (time_t)(obj->yst_atime);
625 inode->i_atime.tv_nsec = 0;
626 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime;
627 inode->i_mtime.tv_nsec =0;
628 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime;
629 inode->i_ctime.tv_nsec = 0;
631 inode->i_rdev = obj->yst_rdev;
632 inode->i_atime = obj->yst_atime;
633 inode->i_mtime = obj->yst_mtime;
634 inode->i_ctime = obj->yst_ctime;
636 inode->i_size = yaffs_GetObjectFileLength(obj);
637 inode->i_blocks = (inode->i_size + 511) >> 9;
639 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
641 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
642 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
644 switch (obj->yst_mode & S_IFMT)
646 default: // fifo, device or socket
647 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
648 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev));
650 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev));
652 case S_IFREG: // file
653 inode->i_op = &yaffs_file_inode_operations;
654 inode->i_fop = &yaffs_file_operations;
655 inode->i_mapping->a_ops = &yaffs_file_address_operations;
657 case S_IFDIR: // directory
658 inode->i_op = &yaffs_dir_inode_operations;
659 inode->i_fop = &yaffs_dir_operations;
661 case S_IFLNK: // symlink
662 inode->i_op = &yaffs_symlink_inode_operations;
667 inode->u.generic_ip = obj;
668 obj->myInode = inode;
673 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
678 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
680 struct inode * inode;
684 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
691 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
696 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
698 inode = iget(sb,obj->objectId);
700 // NB Side effect: iget calls back to yaffs_read_inode().
701 // iget also increments the inode's i_count
708 // No longer used because we use generic rw */
709 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
716 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
718 obj = yaffs_DentryToObject(f->f_dentry);
722 yaffs_GrossLock(dev);
724 inode = f->f_dentry->d_inode;
726 if (*pos < inode->i_size)
728 if (*pos + n > inode->i_size)
730 n = inode->i_size - *pos;
738 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
744 yaffs_GrossUnlock(dev);
748 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
755 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
763 obj = yaffs_DentryToObject(f->f_dentry);
767 yaffs_GrossLock(dev);
769 inode = f->f_dentry->d_inode;
771 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
773 ipos = inode->i_size;
783 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
787 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));
790 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
792 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
797 if(ipos > inode->i_size)
799 inode->i_size = ipos;
800 inode->i_blocks = (ipos + 511)>>9;
802 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
806 yaffs_GrossUnlock(dev);
808 return nWritten != n ? -ENOSPC : nWritten;
813 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
817 struct inode *inode = f->f_dentry->d_inode;
818 unsigned long offset, curoffs;
822 char name[YAFFS_MAX_NAME_LENGTH +1];
824 obj = yaffs_DentryToObject(f->f_dentry);
827 yaffs_GrossLock(dev);
831 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
835 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
836 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
845 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
846 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
856 list_for_each(i,&obj->variant.directoryVariant.children)
859 if(curoffs >= offset)
861 l = list_entry(i, yaffs_Object,siblings);
863 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
864 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
870 yaffs_GetObjectInode(l),
871 yaffs_GetObjectType(l))
885 yaffs_GrossUnlock(dev);
892 * File creation. Allocate an inode, and we're done..
894 //#if defined(CONFIG_KERNEL_2_5)
895 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
896 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
898 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
903 yaffs_Object *obj = NULL;
906 yaffs_Object *parent = yaffs_InodeToObject(dir);
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,current->uid, current->gid,old_encode_dev(rdev));
936 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
938 case S_IFREG: // file
939 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
940 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
942 case S_IFDIR: // directory
943 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
944 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
946 case S_IFLNK: // symlink
947 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
948 obj = NULL; // Do we ever get here?
954 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
955 d_instantiate(dentry, inode);
956 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
961 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
965 yaffs_GrossUnlock(dev);
970 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
973 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
974 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
976 // attempt to fix dir bug - didn't work
985 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
986 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
987 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
989 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
992 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
993 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
997 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
1004 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
1006 dev = yaffs_InodeToObject(dir)->myDev;
1008 yaffs_GrossLock(dev);
1011 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1014 yaffs_GrossUnlock(dev);
1016 if( retVal == YAFFS_OK)
1018 dentry->d_inode->i_nlink--;
1019 mark_inode_dirty(dentry->d_inode);
1032 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1034 struct inode *inode = old_dentry->d_inode;
1035 yaffs_Object *obj = NULL;
1036 yaffs_Object *link=NULL;
1039 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1041 obj = yaffs_InodeToObject(inode);
1044 yaffs_GrossLock(dev);
1046 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1048 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1054 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1055 d_instantiate(dentry, old_dentry->d_inode);
1056 atomic_inc(&old_dentry->d_inode->i_count);
1057 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1058 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1062 yaffs_GrossUnlock(dev);
1076 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1081 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1083 dev = yaffs_InodeToObject(dir)->myDev;
1084 yaffs_GrossLock(dev);
1085 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1086 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1088 yaffs_GrossUnlock(dev);
1093 struct inode* inode;
1095 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1096 d_instantiate(dentry, inode);
1097 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1102 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1109 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1115 obj = yaffs_DentryToObject(dentry);
1119 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1120 yaffs_GrossLock(dev);
1121 yaffs_FlushFile(obj,1);
1122 yaffs_GrossUnlock(dev);
1127 * The VFS layer already does all the dentry stuff for rename.
1129 * NB: POSIX says you can rename an object over an old object of the same name
1131 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1134 int retVal = YAFFS_FAIL;
1136 yaffs_Object *target;
1138 dev = yaffs_InodeToObject(old_dir)->myDev;
1140 yaffs_GrossLock(dev);
1142 // Check if the target is an existing directory that is not empty.
1143 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1146 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1147 !list_empty(&target->variant.directoryVariant.children))
1149 retVal = YAFFS_FAIL;
1154 // Unlink the target if it exists
1155 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1158 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1159 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1162 yaffs_GrossUnlock(dev);
1164 if(retVal == YAFFS_OK)
1166 if(removed == YAFFS_OK)
1168 new_dentry->d_inode->i_nlink--;
1169 mark_inode_dirty(new_dentry->d_inode);
1182 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1184 struct inode *inode = dentry->d_inode;
1188 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1190 if((error = inode_change_ok(inode,attr)) == 0)
1193 dev = yaffs_InodeToObject(inode)->myDev;
1194 yaffs_GrossLock(dev);
1195 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1203 yaffs_GrossUnlock(dev);
1204 error = inode_setattr(inode,attr);
1209 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1210 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1211 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1213 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1218 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1219 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1221 yaffs_GrossLock(dev);
1224 buf->f_type = YAFFS_MAGIC;
1225 buf->f_bsize = sb->s_blocksize;
1226 buf->f_namelen = 255;
1227 if(sb->s_blocksize > dev->nBytesPerChunk)
1230 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1231 (sb->s_blocksize/dev->nBytesPerChunk);
1232 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1233 (sb->s_blocksize/dev->nBytesPerChunk);
1238 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1239 (dev->nBytesPerChunk/sb->s_blocksize);
1240 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1241 (dev->nBytesPerChunk/sb->s_blocksize);
1245 buf->f_bavail = buf->f_bfree;
1247 yaffs_GrossUnlock(dev);
1251 static void yaffs_read_inode (struct inode *inode)
1253 // NB This is called as a side effect of other functions and
1254 // thus gross locking should always be in place already.
1257 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1259 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1261 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1263 yaffs_FillInodeFromObject(inode,obj);
1270 // Currently we only can report a single partition. Need to use lists here
1271 static yaffs_Device *yaffs_dev;
1272 static yaffs_Device *yaffsram_dev;
1276 static void yaffs_put_super(struct super_block *sb)
1278 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1280 yaffs_GrossLock(dev);
1281 if(dev->putSuperFunc)
1283 dev->putSuperFunc(sb);
1285 yaffs_Deinitialise(dev);
1286 yaffs_GrossUnlock(dev);
1288 if(dev == yaffs_dev) yaffs_dev = NULL;
1289 if(dev == yaffsram_dev) yaffsram_dev = NULL;
1295 #ifdef CONFIG_YAFFS_MTD_ENABLED
1297 static void yaffs_MTDPutSuper(struct super_block *sb)
1300 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1307 put_mtd_device(mtd);
1313 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1316 struct inode * inode = NULL;
1317 struct dentry * root;
1321 sb->s_magic = YAFFS_MAGIC;
1322 sb->s_op = &yaffs_super_ops;
1325 printk(KERN_INFO"yaffs: sb is NULL\n");
1327 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1328 else if(! kdevname(sb->s_dev))
1329 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1331 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1335 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1336 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1337 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1339 sb->s_blocksize = PAGE_CACHE_SIZE;
1340 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1342 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1343 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1345 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1346 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1354 #ifdef CONFIG_YAFFS_RAM_ENABLED
1355 // Set the yaffs_Device up for ram emulation
1358 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1359 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1361 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1366 // Deep shit could not allocate device structure
1367 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1371 memset(dev,0,sizeof(yaffs_Device));
1372 dev->genericDevice = NULL; // Not used for RAM emulation.
1374 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1375 dev->startBlock = 0;
1376 dev->endBlock = nBlocks - 1;
1377 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1378 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1379 dev->nReservedBlocks = 5;
1381 if(yaffsVersion == 2)
1383 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
1384 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1385 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
1386 dev->queryNANDBlock = nandemul2k_QueryNANDBlock;
1387 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
1388 dev->initialiseNAND = nandemul2k_InitialiseNAND;
1390 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1391 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();;
1392 nBlocks = nandemul2k_GetNumberOfBlocks();
1393 dev->startBlock = 0;
1394 dev->endBlock = nBlocks - 1;
1398 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1399 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1400 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1401 dev->initialiseNAND = nandemul_InitialiseNAND;
1412 #ifdef CONFIG_YAFFS_MTD_ENABLED
1413 struct mtd_info *mtd;
1415 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1416 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)));
1418 // Check it's an mtd device.....
1419 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1421 return NULL; // This isn't an mtd device
1425 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1428 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1433 if(mtd->type != MTD_NANDFLASH)
1435 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1439 T(YAFFS_TRACE_OS,(" erase %x\n",mtd->erase));
1440 T(YAFFS_TRACE_OS,(" read %x\n",mtd->read));
1441 T(YAFFS_TRACE_OS,(" write %x\n",mtd->write));
1442 T(YAFFS_TRACE_OS,(" readoob %x\n",mtd->read_oob));
1443 T(YAFFS_TRACE_OS,(" writeoob %x\n",mtd->write_oob));
1444 T(YAFFS_TRACE_OS,(" block_isbad %x\n",mtd->block_isbad));
1445 T(YAFFS_TRACE_OS,(" block_markbad %x\n",mtd->block_markbad));
1446 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1447 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1448 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1449 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1451 if(yaffsVersion == 2)
1453 // Check for version 2 style functions
1455 !mtd->block_isbad ||
1456 !mtd->block_markbad ||
1459 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1466 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1470 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1471 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1473 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1478 // Check for V1 style functions
1482 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1489 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1493 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1494 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1496 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1502 // OK, so if we got here, we have an MTD that's NAND and looks
1503 // like it has the right capabilities
1504 // Set the yaffs_Device up for mtd
1506 //#if defined(CONFIG_KERNEL_2_5)
1507 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1508 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1510 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1514 // Deep shit could not allocate device structure
1515 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1519 memset(dev,0,sizeof(yaffs_Device));
1520 dev->genericDevice = mtd;
1522 // Set up the memory size parameters....
1524 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1525 dev->startBlock = 0;
1526 dev->endBlock = nBlocks - 1;
1527 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1528 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1529 dev->nReservedBlocks = 5;
1530 dev->nShortOpCaches = 10; // Enable short op caching
1533 // ... and the functions.
1534 if(yaffsVersion == 2)
1536 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1537 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1538 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1539 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1540 dev->spareBuffer = YMALLOC(mtd->oobsize);
1542 dev->nBytesPerChunk = mtd->oobblock;
1543 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1544 nBlocks = mtd->size / mtd->erasesize;
1545 dev->startBlock = 0;
1546 dev->endBlock = nBlocks - 1;
1550 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1551 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1554 // ... and common functions
1555 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1556 dev->initialiseNAND = nandmtd_InitialiseNAND;
1558 dev->putSuperFunc = yaffs_MTDPutSuper;
1560 #ifdef CONFIG_YAFFS_USE_NANDECC
1561 dev->useNANDECC = 1;
1569 init_MUTEX(&dev->grossLock);
1572 yaffs_GrossLock(dev);
1574 err = yaffs_GutsInitialise(dev);
1576 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1578 // Create root inode
1580 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1582 yaffs_GrossUnlock(dev);
1588 inode->i_op = & yaffs_dir_inode_operations;
1589 inode->i_fop = & yaffs_dir_operations;
1591 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1594 root = d_alloc_root(inode);
1596 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1604 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1609 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1611 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1613 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1615 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1618 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1620 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1622 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1624 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1629 #ifdef CONFIG_YAFFS_MTD_ENABLED
1630 //#if defined(CONFIG_KERNEL_2_5)
1631 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1632 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1635 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1638 /* changes NCB 2.5.70 */
1639 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
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 // .kill_sb = kill_litter_super,
1646 .fs_flags = FS_REQUIRES_DEV,
1649 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1651 return yaffs_internal_read_super(1,0,sb,data,silent);
1654 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1657 #endif // CONFIG_YAFFS_MTD_ENABLED
1659 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1661 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1662 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1665 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1668 /* changes NCB 2.5.70 */
1669 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1670 static struct file_system_type yaffs2_fs_type = {
1671 .owner = THIS_MODULE,
1673 .get_sb = yaffs2_read_super,
1674 .kill_sb = kill_block_super,
1675 // .kill_sb = kill_litter_super,
1676 .fs_flags = FS_REQUIRES_DEV,
1679 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1681 return yaffs_internal_read_super(2,0,sb,data,silent);
1684 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1687 #endif // CONFIG_YAFFS2_MTD_ENABLED
1690 #ifdef CONFIG_YAFFS_RAM_ENABLED
1692 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1693 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1696 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_ram);
1700 static struct file_system_type yaffs_ram_fs_type = {
1701 .owner = THIS_MODULE,
1703 .get_sb = yaffs_ram_read_super,
1704 .kill_sb = kill_block_super,
1705 // .kill_sb = kill_litter_super,
1709 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1711 return yaffs_internal_read_super(1,1,sb,data,silent);
1714 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1717 #endif // CONFIG_YAFFS_RAM_ENABLED
1719 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1721 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1722 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1725 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_ram);
1729 static struct file_system_type yaffs2_ram_fs_type = {
1730 .owner = THIS_MODULE,
1731 .name = "yaffs2ram",
1732 .get_sb = yaffs2_ram_read_super,
1733 .kill_sb = kill_block_super,
1734 // .kill_sb = kill_litter_super,
1738 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1740 return yaffs_internal_read_super(2,1,sb,data,silent);
1743 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1746 #endif // CONFIG_YAFFS2_RAM_ENABLED
1750 static struct proc_dir_entry *my_proc_entry;
1751 static struct proc_dir_entry *my_proc_ram_write_entry;
1753 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1755 buf +=sprintf(buf,"\nDevice %s\n",name);
1756 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1757 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1758 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1759 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1760 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1761 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1762 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1763 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1764 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1765 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1766 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1767 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1768 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1769 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1770 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1771 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1772 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1773 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1774 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1775 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1776 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1777 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1778 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1779 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1780 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1781 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1782 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1783 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1789 static int yaffs_proc_read(
1799 char my_buffer[3000];
1803 if (offset > 0) return 0;
1805 /* Fill the buffer and get its length */
1806 buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1808 if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1809 if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1812 strcpy(page,my_buffer);
1813 return strlen(my_buffer);
1817 static int yaffs_proc_ram_write(
1827 printk(KERN_DEBUG "yaffs write size %d\n",count);
1833 // Stuff to handle installation of file systems
1834 struct file_system_to_install
1836 struct file_system_type *fst;
1840 static struct file_system_to_install fs_to_install[] =
1842 #ifdef CONFIG_YAFFS_RAM_ENABLED
1843 { &yaffs_ram_fs_type, 0},
1845 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1846 { &yaffs2_ram_fs_type,0},
1848 #ifdef CONFIG_YAFFS_MTD_ENABLED
1849 { &yaffs_fs_type,0},
1851 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1852 { &yaffs2_fs_type,0},
1857 static int __init init_yaffs_fs(void)
1860 struct file_system_to_install *fsinst;
1862 yaffs_dev = yaffsram_dev = NULL;
1864 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1868 /* Install the proc_fs entry */
1869 my_proc_entry = create_proc_read_entry("yaffs",
1881 // Now add the file system entries
1883 fsinst = fs_to_install;
1885 while(fsinst->fst && !error)
1887 error = register_filesystem(fsinst->fst);
1890 fsinst->installed = 1;
1895 // Any errors? uninstall
1898 fsinst = fs_to_install;
1902 if(fsinst->installed)
1904 unregister_filesystem(fsinst->fst);
1905 fsinst->installed = 0;
1914 static void __exit exit_yaffs_fs(void)
1917 struct file_system_to_install *fsinst;
1919 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1921 remove_proc_entry("yaffs",&proc_root);
1923 fsinst = fs_to_install;
1927 if(fsinst->installed)
1929 unregister_filesystem(fsinst->fst);
1930 fsinst->installed = 0;
1937 module_init(init_yaffs_fs)
1938 module_exit(exit_yaffs_fs)
1940 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1941 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1942 MODULE_LICENSE("GPL");