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.10 2005-07-26 20:23:30 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 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
169 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
171 static int yaffs_writepage(struct page *page);
173 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
174 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
176 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen);
177 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
182 static struct address_space_operations yaffs_file_address_operations = {
183 .readpage= yaffs_readpage,
184 .writepage= yaffs_writepage,
185 .prepare_write= yaffs_prepare_write,
186 .commit_write= yaffs_commit_write
190 static struct file_operations yaffs_file_operations = {
192 .read= generic_file_read,
193 .write= generic_file_write,
195 .mmap= generic_file_mmap,
196 .flush= yaffs_file_flush,
197 .fsync= yaffs_sync_object,
201 static struct inode_operations yaffs_file_inode_operations = {
202 .setattr= yaffs_setattr,
206 struct inode_operations yaffs_symlink_inode_operations =
208 .readlink= yaffs_readlink,
209 .follow_link= yaffs_follow_link,
210 .setattr= yaffs_setattr
213 static struct inode_operations yaffs_dir_inode_operations = {
214 .create= yaffs_create,
215 .lookup= yaffs_lookup,
217 .unlink= yaffs_unlink,
218 .symlink= yaffs_symlink,
220 .rmdir= yaffs_unlink,
222 .rename= yaffs_rename,
223 .setattr= yaffs_setattr,
226 static struct file_operations yaffs_dir_operations = {
227 .read= generic_read_dir,
228 .readdir= yaffs_readdir,
229 .fsync= yaffs_sync_object,
233 static struct super_operations yaffs_super_ops = {
234 .statfs= yaffs_statfs,
235 .read_inode= yaffs_read_inode,
236 .put_inode= yaffs_put_inode,
237 .put_super= yaffs_put_super,
238 .delete_inode= yaffs_delete_inode,
239 .clear_inode= yaffs_clear_inode,
244 static void yaffs_GrossLock(yaffs_Device *dev)
246 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
248 down(&dev->grossLock);
251 static void yaffs_GrossUnlock(yaffs_Device *dev)
253 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
258 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
260 unsigned char *alias;
263 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
266 yaffs_GrossLock(dev);
268 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
270 yaffs_GrossUnlock(dev);
275 ret = vfs_readlink(dentry, buffer, buflen, alias);
280 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
282 unsigned char *alias;
284 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
287 yaffs_GrossLock(dev);
289 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
291 yaffs_GrossUnlock(dev);
296 ret = vfs_follow_link(nd,alias);
302 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
305 * Lookup is used to find objects in the fs
307 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
308 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
310 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
312 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
316 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
318 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
321 yaffs_GrossLock(dev);
324 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
326 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
328 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
334 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
336 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode,0,obj);
340 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
341 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
343 //dget(dentry); // try to solve directory bug
346 yaffs_GrossUnlock(dev);
356 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
359 yaffs_GrossUnlock(dev);
361 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
365 // return (ERR_PTR(-EIO));
369 // For now put inode is just for debugging
370 // Put inode is called when the inode **structure** is put.
371 static void yaffs_put_inode(struct inode *inode)
373 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
377 // clear is called to tell the fs to release any per-inode data it holds
378 static void yaffs_clear_inode(struct inode *inode)
383 obj = yaffs_InodeToObject(inode);
385 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
386 obj ? "object exists" : "null object"));
391 yaffs_GrossLock(dev);
393 // Clear the association between the inode ant the yaffs_Object.
395 inode->u.generic_ip = NULL;
397 // If the object freeing was deferred, then the real free happens now.
398 // This should fix the inode inconsistency problem.
400 yaffs_HandleDeferedFree(obj);
402 yaffs_GrossUnlock(dev);
408 // delete is called when the link count is zero and the inode
409 // is put (ie. nobody wants to know about it anymore, time to
411 // NB Must call clear_inode()
412 static void yaffs_delete_inode(struct inode *inode)
414 yaffs_Object *obj = yaffs_InodeToObject(inode);
417 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
418 obj ? "object exists" : "null object"));
423 yaffs_GrossLock(dev);
424 yaffs_DeleteFile(obj);
425 yaffs_GrossUnlock(dev);
431 static int yaffs_file_flush(struct file* file)
433 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
435 yaffs_Device *dev = obj->myDev;
437 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
438 obj->dirty ? "dirty" : "clean"));
440 yaffs_GrossLock(dev);
442 yaffs_FlushFile(obj,1);
444 yaffs_GrossUnlock(dev);
451 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
456 unsigned char *pg_buf;
461 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
462 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
464 obj = yaffs_DentryToObject(f->f_dentry);
469 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
470 BUG_ON(!PageLocked(pg));
477 /* FIXME: Can kmap fail? */
479 yaffs_GrossLock(dev);
481 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
483 yaffs_GrossUnlock(dev);
485 if(ret >= 0) ret = 0;
488 ClearPageUptodate(pg);
495 flush_dcache_page(pg);
499 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
503 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
505 int ret = yaffs_readpage_nolock(f,pg);
510 static int yaffs_readpage(struct file *f, struct page * pg)
512 return yaffs_readpage_unlock(f,pg);
515 // writepage inspired by/stolen from smbfs
518 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
519 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
521 static int yaffs_writepage(struct page *page)
524 struct address_space *mapping = page->mapping;
526 unsigned long end_index;
534 inode = mapping->host;
538 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
541 if (page->index < end_index)
543 nBytes = PAGE_CACHE_SIZE;
547 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
549 // What's happening here?
550 ///* OK, are we completely out? */
551 //if (page->index >= end_index+1 || !offset)
559 obj = yaffs_InodeToObject(inode);
560 yaffs_GrossLock(obj->myDev);
563 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
565 yaffs_GrossUnlock(obj->myDev);
568 SetPageUptodate(page);
572 return (nWritten == nBytes) ? 0 : -ENOSPC;
577 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
580 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
581 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
582 return yaffs_readpage_nolock(f,pg);
588 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
591 void *addr = page_address(pg) + offset;
592 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
593 int nBytes = to - offset;
597 unsigned saddr = (unsigned)addr;
599 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
601 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
603 if(nWritten != nBytes)
605 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
607 ClearPageUptodate(pg);
614 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
622 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
626 inode->i_ino = obj->objectId;
627 inode->i_mode = obj->yst_mode;
628 inode->i_uid = obj->yst_uid;
629 inode->i_gid = obj->yst_gid;
630 inode->i_blksize = inode->i_sb->s_blocksize;
631 //#if defined(CONFIG_KERNEL_2_5)
632 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
634 inode->i_rdev = old_decode_dev(obj->yst_rdev);
635 inode->i_atime.tv_sec = (time_t)(obj->yst_atime);
636 inode->i_atime.tv_nsec = 0;
637 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime;
638 inode->i_mtime.tv_nsec =0;
639 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime;
640 inode->i_ctime.tv_nsec = 0;
642 inode->i_rdev = obj->yst_rdev;
643 inode->i_atime = obj->yst_atime;
644 inode->i_mtime = obj->yst_mtime;
645 inode->i_ctime = obj->yst_ctime;
647 inode->i_size = yaffs_GetObjectFileLength(obj);
648 inode->i_blocks = (inode->i_size + 511) >> 9;
650 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
652 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
653 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
655 switch (obj->yst_mode & S_IFMT)
657 default: // fifo, device or socket
658 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
659 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev));
661 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev));
664 case S_IFREG: // file
665 inode->i_op = &yaffs_file_inode_operations;
666 inode->i_fop = &yaffs_file_operations;
667 inode->i_mapping->a_ops = &yaffs_file_address_operations;
669 case S_IFDIR: // directory
670 inode->i_op = &yaffs_dir_inode_operations;
671 inode->i_fop = &yaffs_dir_operations;
673 case S_IFLNK: // symlink
674 inode->i_op = &yaffs_symlink_inode_operations;
679 inode->u.generic_ip = obj;
680 obj->myInode = inode;
685 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
690 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
692 struct inode * inode;
696 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
703 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
708 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
710 inode = iget(sb,obj->objectId);
712 // NB Side effect: iget calls back to yaffs_read_inode().
713 // iget also increments the inode's i_count
720 // No longer used because we use generic rw */
721 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
728 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
730 obj = yaffs_DentryToObject(f->f_dentry);
734 yaffs_GrossLock(dev);
736 inode = f->f_dentry->d_inode;
738 if (*pos < inode->i_size)
740 if (*pos + n > inode->i_size)
742 n = inode->i_size - *pos;
750 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
756 yaffs_GrossUnlock(dev);
760 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
767 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
775 obj = yaffs_DentryToObject(f->f_dentry);
779 yaffs_GrossLock(dev);
781 inode = f->f_dentry->d_inode;
783 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
785 ipos = inode->i_size;
795 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
799 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));
802 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
804 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
809 if(ipos > inode->i_size)
811 inode->i_size = ipos;
812 inode->i_blocks = (ipos + 511)>>9;
814 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
818 yaffs_GrossUnlock(dev);
820 return nWritten != n ? -ENOSPC : nWritten;
825 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
829 struct inode *inode = f->f_dentry->d_inode;
830 unsigned long offset, curoffs;
834 char name[YAFFS_MAX_NAME_LENGTH +1];
836 obj = yaffs_DentryToObject(f->f_dentry);
839 yaffs_GrossLock(dev);
843 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
847 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
848 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
857 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
858 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
868 list_for_each(i,&obj->variant.directoryVariant.children)
871 if(curoffs >= offset)
873 l = list_entry(i, yaffs_Object,siblings);
875 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
876 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
882 yaffs_GetObjectInode(l),
883 yaffs_GetObjectType(l))
897 yaffs_GrossUnlock(dev);
904 * File creation. Allocate an inode, and we're done..
906 //#if defined(CONFIG_KERNEL_2_5)
907 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
908 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
910 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
915 yaffs_Object *obj = NULL;
918 yaffs_Object *parent = yaffs_InodeToObject(dir);
924 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
925 parent->objectId,parent->variantType));
929 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
933 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
934 dentry->d_name.name, mode,rdev));
938 yaffs_GrossLock(dev);
940 switch (mode & S_IFMT)
943 // Special (socket, fifo, device...)
944 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
945 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
946 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,old_encode_dev(rdev));
948 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
951 case S_IFREG: // file
952 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
953 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
955 case S_IFDIR: // directory
956 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
957 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
959 case S_IFLNK: // symlink
960 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
961 obj = NULL; // Do we ever get here?
967 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
968 d_instantiate(dentry, inode);
969 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
974 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
978 yaffs_GrossUnlock(dev);
983 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
986 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
987 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
989 // attempt to fix dir bug - didn't work
998 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
999 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1000 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
1002 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1005 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
1006 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1010 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
1017 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
1019 dev = yaffs_InodeToObject(dir)->myDev;
1021 yaffs_GrossLock(dev);
1024 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1027 yaffs_GrossUnlock(dev);
1029 if( retVal == YAFFS_OK)
1031 dentry->d_inode->i_nlink--;
1032 mark_inode_dirty(dentry->d_inode);
1045 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1047 struct inode *inode = old_dentry->d_inode;
1048 yaffs_Object *obj = NULL;
1049 yaffs_Object *link=NULL;
1052 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1054 obj = yaffs_InodeToObject(inode);
1057 yaffs_GrossLock(dev);
1059 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1061 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1067 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1068 d_instantiate(dentry, old_dentry->d_inode);
1069 atomic_inc(&old_dentry->d_inode->i_count);
1070 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1071 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1075 yaffs_GrossUnlock(dev);
1089 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1094 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1096 dev = yaffs_InodeToObject(dir)->myDev;
1097 yaffs_GrossLock(dev);
1098 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1099 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1101 yaffs_GrossUnlock(dev);
1106 struct inode* inode;
1108 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1109 d_instantiate(dentry, inode);
1110 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1115 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1122 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1128 obj = yaffs_DentryToObject(dentry);
1132 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1133 yaffs_GrossLock(dev);
1134 yaffs_FlushFile(obj,1);
1135 yaffs_GrossUnlock(dev);
1140 * The VFS layer already does all the dentry stuff for rename.
1142 * NB: POSIX says you can rename an object over an old object of the same name
1144 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1147 int retVal = YAFFS_FAIL;
1149 yaffs_Object *target;
1151 dev = yaffs_InodeToObject(old_dir)->myDev;
1153 yaffs_GrossLock(dev);
1155 // Check if the target is an existing directory that is not empty.
1156 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1159 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1160 !list_empty(&target->variant.directoryVariant.children))
1162 retVal = YAFFS_FAIL;
1167 // Unlink the target if it exists
1168 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1171 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1172 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1175 yaffs_GrossUnlock(dev);
1177 if(retVal == YAFFS_OK)
1179 if(removed == YAFFS_OK)
1181 new_dentry->d_inode->i_nlink--;
1182 mark_inode_dirty(new_dentry->d_inode);
1195 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1197 struct inode *inode = dentry->d_inode;
1201 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1203 if((error = inode_change_ok(inode,attr)) == 0)
1206 dev = yaffs_InodeToObject(inode)->myDev;
1207 yaffs_GrossLock(dev);
1208 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1216 yaffs_GrossUnlock(dev);
1218 error = inode_setattr(inode,attr);
1223 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1224 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1225 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1227 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1232 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1233 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1235 yaffs_GrossLock(dev);
1238 buf->f_type = YAFFS_MAGIC;
1239 buf->f_bsize = sb->s_blocksize;
1240 buf->f_namelen = 255;
1241 if(sb->s_blocksize > dev->nBytesPerChunk)
1244 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1245 (sb->s_blocksize/dev->nBytesPerChunk);
1246 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1247 (sb->s_blocksize/dev->nBytesPerChunk);
1252 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1253 (dev->nBytesPerChunk/sb->s_blocksize);
1254 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1255 (dev->nBytesPerChunk/sb->s_blocksize);
1259 buf->f_bavail = buf->f_bfree;
1261 yaffs_GrossUnlock(dev);
1265 static void yaffs_read_inode (struct inode *inode)
1267 // NB This is called as a side effect of other functions and
1268 // thus gross locking should always be in place already.
1271 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1273 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1275 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1277 yaffs_FillInodeFromObject(inode,obj);
1284 // Currently we only can report a single partition. Need to use lists here
1285 static yaffs_Device *yaffs_dev;
1286 static yaffs_Device *yaffsram_dev;
1290 static void yaffs_put_super(struct super_block *sb)
1292 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1294 yaffs_GrossLock(dev);
1295 if(dev->putSuperFunc)
1297 dev->putSuperFunc(sb);
1299 yaffs_Deinitialise(dev);
1300 yaffs_GrossUnlock(dev);
1302 if(dev == yaffs_dev) yaffs_dev = NULL;
1303 if(dev == yaffsram_dev) yaffsram_dev = NULL;
1309 #ifdef CONFIG_YAFFS_MTD_ENABLED
1311 static void yaffs_MTDPutSuper(struct super_block *sb)
1314 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1321 put_mtd_device(mtd);
1327 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1330 struct inode * inode = NULL;
1331 struct dentry * root;
1335 sb->s_magic = YAFFS_MAGIC;
1336 sb->s_op = &yaffs_super_ops;
1339 printk(KERN_INFO"yaffs: sb is NULL\n");
1341 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1342 else if(! kdevname(sb->s_dev))
1343 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1345 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1349 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1350 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1351 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1353 sb->s_blocksize = PAGE_CACHE_SIZE;
1354 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1356 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1357 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1359 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1360 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1368 #ifdef CONFIG_YAFFS_RAM_ENABLED
1369 // Set the yaffs_Device up for ram emulation
1372 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1373 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1375 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1380 // Deep shit could not allocate device structure
1381 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1385 memset(dev,0,sizeof(yaffs_Device));
1386 dev->genericDevice = NULL; // Not used for RAM emulation.
1388 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1389 dev->startBlock = 0;
1390 dev->endBlock = nBlocks - 1;
1391 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1392 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1393 dev->nReservedBlocks = 5;
1395 if(yaffsVersion == 2)
1397 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
1398 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1399 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
1400 dev->queryNANDBlock = nandemul2k_QueryNANDBlock;
1401 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
1402 dev->initialiseNAND = nandemul2k_InitialiseNAND;
1404 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1405 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();;
1406 nBlocks = nandemul2k_GetNumberOfBlocks();
1407 dev->startBlock = 0;
1408 dev->endBlock = nBlocks - 1;
1412 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1413 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1414 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1415 dev->initialiseNAND = nandemul_InitialiseNAND;
1426 #ifdef CONFIG_YAFFS_MTD_ENABLED
1427 struct mtd_info *mtd;
1429 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1430 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)));
1432 // Check it's an mtd device.....
1433 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1435 return NULL; // This isn't an mtd device
1439 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1442 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1447 if(mtd->type != MTD_NANDFLASH)
1449 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1453 T(YAFFS_TRACE_OS,(" erase %p\n",mtd->erase));
1454 T(YAFFS_TRACE_OS,(" read %p\n",mtd->read));
1455 T(YAFFS_TRACE_OS,(" write %p\n",mtd->write));
1456 T(YAFFS_TRACE_OS,(" readoob %p\n",mtd->read_oob));
1457 T(YAFFS_TRACE_OS,(" writeoob %p\n",mtd->write_oob));
1458 T(YAFFS_TRACE_OS,(" block_isbad %p\n",mtd->block_isbad));
1459 T(YAFFS_TRACE_OS,(" block_markbad %p\n",mtd->block_markbad));
1460 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1461 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1462 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1463 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1465 if(yaffsVersion == 2)
1467 // Check for version 2 style functions
1469 !mtd->block_isbad ||
1470 !mtd->block_markbad ||
1473 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1480 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1484 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1485 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1487 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1492 // Check for V1 style functions
1496 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1503 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1507 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1508 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1510 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1516 // OK, so if we got here, we have an MTD that's NAND and looks
1517 // like it has the right capabilities
1518 // Set the yaffs_Device up for mtd
1520 //#if defined(CONFIG_KERNEL_2_5)
1521 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1522 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1524 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1528 // Deep shit could not allocate device structure
1529 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1533 memset(dev,0,sizeof(yaffs_Device));
1534 dev->genericDevice = mtd;
1536 // Set up the memory size parameters....
1538 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1539 dev->startBlock = 0;
1540 dev->endBlock = nBlocks - 1;
1541 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1542 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1543 dev->nReservedBlocks = 5;
1544 dev->nShortOpCaches = 10; // Enable short op caching
1547 // ... and the functions.
1548 if(yaffsVersion == 2)
1550 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1551 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1552 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1553 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1554 dev->spareBuffer = YMALLOC(mtd->oobsize);
1556 dev->nBytesPerChunk = mtd->oobblock;
1557 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1558 nBlocks = mtd->size / mtd->erasesize;
1559 dev->startBlock = 0;
1560 dev->endBlock = nBlocks - 1;
1564 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1565 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1568 // ... and common functions
1569 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1570 dev->initialiseNAND = nandmtd_InitialiseNAND;
1572 dev->putSuperFunc = yaffs_MTDPutSuper;
1574 #ifdef CONFIG_YAFFS_USE_NANDECC
1575 dev->useNANDECC = 1;
1583 init_MUTEX(&dev->grossLock);
1586 yaffs_GrossLock(dev);
1588 err = yaffs_GutsInitialise(dev);
1590 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1592 // Create root inode
1594 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1596 yaffs_GrossUnlock(dev);
1602 inode->i_op = & yaffs_dir_inode_operations;
1603 inode->i_fop = & yaffs_dir_operations;
1605 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1608 root = d_alloc_root(inode);
1610 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1618 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1623 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1625 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1627 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1629 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1632 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1634 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1636 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1638 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1643 #ifdef CONFIG_YAFFS_MTD_ENABLED
1644 //#if defined(CONFIG_KERNEL_2_5)
1645 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1646 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1649 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1652 /* changes NCB 2.5.70 */
1653 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1654 static struct file_system_type yaffs_fs_type = {
1655 .owner = THIS_MODULE,
1657 .get_sb = yaffs_read_super,
1658 .kill_sb = kill_block_super,
1659 // .kill_sb = kill_litter_super,
1660 .fs_flags = FS_REQUIRES_DEV,
1663 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1665 return yaffs_internal_read_super(1,0,sb,data,silent);
1668 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1671 #endif // CONFIG_YAFFS_MTD_ENABLED
1673 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1675 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1676 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1679 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1682 /* changes NCB 2.5.70 */
1683 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1684 static struct file_system_type yaffs2_fs_type = {
1685 .owner = THIS_MODULE,
1687 .get_sb = yaffs2_read_super,
1688 .kill_sb = kill_block_super,
1689 // .kill_sb = kill_litter_super,
1690 .fs_flags = FS_REQUIRES_DEV,
1693 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1695 return yaffs_internal_read_super(2,0,sb,data,silent);
1698 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1701 #endif // CONFIG_YAFFS2_MTD_ENABLED
1704 #ifdef CONFIG_YAFFS_RAM_ENABLED
1706 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1707 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1710 return get_sb_nodev(fs, flags, data, yaffs_internal_read_super_ram);
1714 static struct file_system_type yaffs_ram_fs_type = {
1715 .owner = THIS_MODULE,
1717 .get_sb = yaffs_ram_read_super,
1718 .kill_sb = kill_litter_super,
1722 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1724 return yaffs_internal_read_super(1,1,sb,data,silent);
1727 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1730 #endif // CONFIG_YAFFS_RAM_ENABLED
1732 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1734 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1735 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1738 return get_sb_nodev(fs, flags, data, yaffs2_internal_read_super_ram);
1742 static struct file_system_type yaffs2_ram_fs_type = {
1743 .owner = THIS_MODULE,
1744 .name = "yaffs2ram",
1745 .get_sb = yaffs2_ram_read_super,
1746 .kill_sb = kill_litter_super,
1750 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1752 return yaffs_internal_read_super(2,1,sb,data,silent);
1755 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1758 #endif // CONFIG_YAFFS2_RAM_ENABLED
1762 static struct proc_dir_entry *my_proc_entry;
1763 static struct proc_dir_entry *my_proc_ram_write_entry;
1765 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1767 buf +=sprintf(buf,"\nDevice %s\n",name);
1768 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1769 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1770 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1771 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1772 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1773 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1774 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1775 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1776 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1777 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1778 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1779 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1780 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1781 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1782 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1783 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1784 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1785 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1786 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1787 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1788 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1789 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1790 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1791 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1792 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1793 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1794 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1795 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1801 static int yaffs_proc_read(
1811 char my_buffer[3000];
1815 if (offset > 0) return 0;
1817 /* Fill the buffer and get its length */
1818 buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1820 if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1821 if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1824 strcpy(page,my_buffer);
1825 return strlen(my_buffer);
1829 static int yaffs_proc_ram_write(
1839 printk(KERN_DEBUG "yaffs write size %d\n",count);
1845 // Stuff to handle installation of file systems
1846 struct file_system_to_install
1848 struct file_system_type *fst;
1852 static struct file_system_to_install fs_to_install[] =
1854 #ifdef CONFIG_YAFFS_RAM_ENABLED
1855 { &yaffs_ram_fs_type, 0},
1857 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1858 { &yaffs2_ram_fs_type,0},
1860 #ifdef CONFIG_YAFFS_MTD_ENABLED
1861 { &yaffs_fs_type,0},
1863 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1864 { &yaffs2_fs_type,0},
1869 static int __init init_yaffs_fs(void)
1872 struct file_system_to_install *fsinst;
1874 yaffs_dev = yaffsram_dev = NULL;
1876 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1880 /* Install the proc_fs entry */
1881 my_proc_entry = create_proc_read_entry("yaffs",
1893 // Now add the file system entries
1895 fsinst = fs_to_install;
1897 while(fsinst->fst && !error)
1899 error = register_filesystem(fsinst->fst);
1902 fsinst->installed = 1;
1907 // Any errors? uninstall
1910 fsinst = fs_to_install;
1914 if(fsinst->installed)
1916 unregister_filesystem(fsinst->fst);
1917 fsinst->installed = 0;
1926 static void __exit exit_yaffs_fs(void)
1929 struct file_system_to_install *fsinst;
1931 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1933 remove_proc_entry("yaffs",&proc_root);
1935 fsinst = fs_to_install;
1939 if(fsinst->installed)
1941 unregister_filesystem(fsinst->fst);
1942 fsinst->installed = 0;
1949 module_init(init_yaffs_fs)
1950 module_exit(exit_yaffs_fs)
1952 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1953 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1954 MODULE_LICENSE("GPL");