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 * >> sb->u.generic_sbp points to the yaffs_Device associated with this superblock
19 * >> inode->u.generic_ip points to the associated yaffs_Object.
23 * * Luc van OostenRyck for numerous patches.
24 * * Nick Bane for numerous patches.
25 * * Nick Bane for 2.5/2.6 integration.
26 * * Andras Toth for mknod rdev issue.
27 * * Michael Fischer for finding the problem with inode inconsistency.
28 * * Some code bodily lifted from JFFS2.
32 const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.4 2005-04-24 09:20:24 charles Exp $";
33 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/pagemap.h>
47 #include <linux/mtd/mtd.h>
48 #include <linux/interrupt.h>
49 #include <linux/string.h>
52 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
54 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
55 #include <asm/statfs.h>
56 #define UnlockPage(p) unlock_page(p)
57 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
58 //#define kdevname(x) cdevname(to_kdev_t(x))
59 #define kdevname(x) "(unavailable)" // temporary fix
63 #include <linux/locks.h>
67 #include <asm/uaccess.h>
70 #include "yaffs_guts.h"
75 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS;
76 //unsigned yaffs_traceMask = 0xFFFFFFFF;
79 #ifdef CONFIG_YAFFS_RAM_ENABLED
80 #include "yaffs_nandemul.h"
81 // 2 MB of RAM for emulation
82 #define YAFFS_RAM_EMULATION_SIZE 0x200000
83 #endif //CONFIG_YAFFS_RAM_ENABLED
85 #if CONFIG_YAFFS2_RAM_ENABLED
86 #include "yaffs_nandemul2k.h"
89 #ifdef CONFIG_YAFFS_MTD_ENABLED
90 #include <linux/mtd/mtd.h>
91 #include "yaffs_mtdif.h"
92 #include "yaffs_mtdif2.h"
93 #endif //CONFIG_YAFFS_MTD_ENABLED
95 //#define T(x) printk x
99 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
100 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
101 //NCB #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
103 //#if defined(CONFIG_KERNEL_2_5)
104 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
105 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
107 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
111 static void yaffs_put_super(struct super_block *sb);
114 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
117 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
119 static int yaffs_file_flush(struct file* file);
121 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
123 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
125 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
126 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
127 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
128 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
130 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
131 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
133 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
134 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
135 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
136 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
138 //#if defined(CONFIG_KERNEL_2_5)
139 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
140 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
142 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
144 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
145 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
147 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
148 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
149 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
151 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
153 static void yaffs_read_inode (struct inode *inode);
155 //#if defined(CONFIG_KERNEL_2_5)
156 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
157 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data);
159 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
162 static void yaffs_put_inode (struct inode *inode);
163 static void yaffs_delete_inode(struct inode *);
164 static void yaffs_clear_inode(struct inode *);
166 static int yaffs_readpage(struct file *file, struct page * page);
167 static int yaffs_writepage(struct page *page);
168 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
169 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
171 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
172 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
177 static struct address_space_operations yaffs_file_address_operations = {
178 readpage: yaffs_readpage,
179 writepage: yaffs_writepage,
180 prepare_write: yaffs_prepare_write,
181 commit_write: yaffs_commit_write
185 static struct file_operations yaffs_file_operations = {
187 read: generic_file_read,
188 write: generic_file_write,
190 mmap: generic_file_mmap,
191 flush: yaffs_file_flush,
192 fsync: yaffs_sync_object,
196 static struct inode_operations yaffs_file_inode_operations = {
197 setattr: yaffs_setattr,
201 struct inode_operations yaffs_symlink_inode_operations =
203 readlink: yaffs_readlink,
204 follow_link: yaffs_follow_link,
205 setattr: yaffs_setattr
208 static struct inode_operations yaffs_dir_inode_operations = {
209 create: yaffs_create,
210 lookup: yaffs_lookup,
212 unlink: yaffs_unlink,
213 symlink: yaffs_symlink,
217 rename: yaffs_rename,
218 setattr: yaffs_setattr,
221 static struct file_operations yaffs_dir_operations = {
222 read: generic_read_dir,
223 readdir: yaffs_readdir,
224 fsync: yaffs_sync_object,
228 static struct super_operations yaffs_super_ops = {
229 statfs: yaffs_statfs,
230 read_inode: yaffs_read_inode,
231 put_inode: yaffs_put_inode,
232 put_super: yaffs_put_super,
234 delete_inode: yaffs_delete_inode,
235 clear_inode: yaffs_clear_inode,
240 static void yaffs_GrossLock(yaffs_Device *dev)
242 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
244 down(&dev->grossLock);
247 static void yaffs_GrossUnlock(yaffs_Device *dev)
249 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
254 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
256 unsigned char *alias;
259 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
262 yaffs_GrossLock(dev);
264 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
266 yaffs_GrossUnlock(dev);
271 ret = vfs_readlink(dentry, buffer, buflen, alias);
276 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
278 unsigned char *alias;
280 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
283 yaffs_GrossLock(dev);
285 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
287 yaffs_GrossUnlock(dev);
292 ret = vfs_follow_link(nd,alias);
298 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
301 * Lookup is used to find objects in the fs
303 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
304 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
306 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
308 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
312 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
314 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
317 yaffs_GrossLock(dev);
320 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
322 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
324 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
330 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
332 inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj);
336 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
337 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
339 //dget(dentry); // try to solve directory bug
342 yaffs_GrossUnlock(dev);
352 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
355 yaffs_GrossUnlock(dev);
357 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
361 // return (ERR_PTR(-EIO));
365 // For now put inode is just for debugging
366 // Put inode is called when the inode **structure** is put.
367 static void yaffs_put_inode(struct inode *inode)
369 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
373 // clear is called to tell the fs to release any per-inode data it holds
374 static void yaffs_clear_inode(struct inode *inode)
379 obj = yaffs_InodeToObject(inode);
381 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
382 obj ? "object exists" : "null object"));
387 yaffs_GrossLock(dev);
389 // Clear the association between the inode ant the yaffs_Object.
391 inode->u.generic_ip = NULL;
393 // If the object freeing was deferred, then the real free happens now.
394 // This should fix the inode inconsistency problem.
396 yaffs_HandleDeferedFree(obj);
398 yaffs_GrossUnlock(dev);
404 // delete is called when the link count is zero and the inode
405 // is put (ie. nobody wants to know about it anymore, time to
407 // NB Must call clear_inode()
408 static void yaffs_delete_inode(struct inode *inode)
410 yaffs_Object *obj = yaffs_InodeToObject(inode);
413 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
414 obj ? "object exists" : "null object"));
419 yaffs_GrossLock(dev);
420 yaffs_DeleteFile(obj);
421 yaffs_GrossUnlock(dev);
427 static int yaffs_file_flush(struct file* file)
429 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
431 yaffs_Device *dev = obj->myDev;
433 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
434 obj->dirty ? "dirty" : "clean"));
436 yaffs_GrossLock(dev);
438 yaffs_FlushFile(obj,1);
440 yaffs_GrossUnlock(dev);
447 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
452 unsigned char *pg_buf;
457 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
458 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
460 obj = yaffs_DentryToObject(f->f_dentry);
469 /* FIXME: Can kmap fail? */
471 yaffs_GrossLock(dev);
473 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
475 yaffs_GrossUnlock(dev);
477 if(ret >= 0) ret = 0;
480 ClearPageUptodate(pg);
487 flush_dcache_page(pg);
491 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
495 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
497 int ret = yaffs_readpage_nolock(f,pg);
502 static int yaffs_readpage(struct file *f, struct page * pg)
504 return yaffs_readpage_unlock(f,pg);
507 // writepage inspired by/stolen from smbfs
510 static int yaffs_writepage(struct page *page)
512 struct address_space *mapping = page->mapping;
514 unsigned long end_index;
522 inode = mapping->host;
526 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
529 if (page->index < end_index)
531 nBytes = PAGE_CACHE_SIZE;
535 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
537 // What's happening here?
538 ///* OK, are we completely out? */
539 //if (page->index >= end_index+1 || !offset)
547 obj = yaffs_InodeToObject(inode);
548 yaffs_GrossLock(obj->myDev);
551 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes);
553 yaffs_GrossUnlock(obj->myDev);
556 SetPageUptodate(page);
560 return (nWritten == nBytes) ? 0 : -ENOSPC;
565 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
568 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
569 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
570 return yaffs_readpage_nolock(f,pg);
576 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
579 void *addr = page_address(pg) + offset;
580 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
581 int nBytes = to - offset;
585 unsigned saddr = (unsigned)addr;
587 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
589 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
591 if(nWritten != nBytes)
593 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
595 ClearPageUptodate(pg);
602 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
610 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
614 inode->i_ino = obj->objectId;
615 inode->i_mode = obj->st_mode;
616 inode->i_uid = obj->st_uid;
617 inode->i_gid = obj->st_gid;
618 inode->i_blksize = inode->i_sb->s_blocksize;
619 //#if defined(CONFIG_KERNEL_2_5)
620 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
622 inode->i_rdev = old_decode_dev(obj->st_rdev);
623 inode->i_atime.tv_sec = (time_t)(obj->st_atime);
624 inode->i_atime.tv_nsec = 0;
625 inode->i_mtime.tv_sec = (time_t)obj->st_mtime;
626 inode->i_mtime.tv_nsec =0;
627 inode->i_ctime.tv_sec = (time_t)obj->st_ctime;
628 inode->i_ctime.tv_nsec = 0;
630 inode->i_rdev = obj->st_rdev;
631 inode->i_atime = obj->st_atime;
632 inode->i_mtime = obj->st_mtime;
633 inode->i_ctime = obj->st_ctime;
635 inode->i_size = yaffs_GetObjectFileLength(obj);
636 inode->i_blocks = (inode->i_size + 511) >> 9;
638 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
640 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
641 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
643 switch (obj->st_mode & S_IFMT)
645 default: // fifo, device or socket
646 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
647 init_special_inode(inode, obj->st_mode,old_decode_dev(obj->st_rdev));
649 init_special_inode(inode, obj->st_mode,(dev_t)(obj->st_rdev));
651 case S_IFREG: // file
652 inode->i_op = &yaffs_file_inode_operations;
653 inode->i_fop = &yaffs_file_operations;
654 inode->i_mapping->a_ops = &yaffs_file_address_operations;
656 case S_IFDIR: // directory
657 inode->i_op = &yaffs_dir_inode_operations;
658 inode->i_fop = &yaffs_dir_operations;
660 case S_IFLNK: // symlink
661 inode->i_op = &yaffs_symlink_inode_operations;
666 inode->u.generic_ip = obj;
667 obj->myInode = inode;
672 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
677 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
679 struct inode * inode;
683 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
690 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
695 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
697 inode = iget(sb,obj->objectId);
699 // NB Side effect: iget calls back to yaffs_read_inode().
700 // iget also increments the inode's i_count
707 // No longer used because we use generic rw */
708 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
715 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
717 obj = yaffs_DentryToObject(f->f_dentry);
721 yaffs_GrossLock(dev);
723 inode = f->f_dentry->d_inode;
725 if (*pos < inode->i_size)
727 if (*pos + n > inode->i_size)
729 n = inode->i_size - *pos;
737 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
743 yaffs_GrossUnlock(dev);
747 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
754 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
762 obj = yaffs_DentryToObject(f->f_dentry);
766 yaffs_GrossLock(dev);
768 inode = f->f_dentry->d_inode;
770 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
772 ipos = inode->i_size;
782 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
786 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));
789 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
791 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
796 if(ipos > inode->i_size)
798 inode->i_size = ipos;
799 inode->i_blocks = (ipos + 511)>>9;
801 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
805 yaffs_GrossUnlock(dev);
807 return nWritten != n ? -ENOSPC : nWritten;
812 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
816 struct inode *inode = f->f_dentry->d_inode;
817 unsigned long offset, curoffs;
821 char name[YAFFS_MAX_NAME_LENGTH +1];
823 obj = yaffs_DentryToObject(f->f_dentry);
826 yaffs_GrossLock(dev);
830 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
834 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
835 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
844 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
845 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
855 list_for_each(i,&obj->variant.directoryVariant.children)
858 if(curoffs >= offset)
860 l = list_entry(i, yaffs_Object,siblings);
862 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
863 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
869 yaffs_GetObjectInode(l),
870 yaffs_GetObjectType(l))
884 yaffs_GrossUnlock(dev);
891 * File creation. Allocate an inode, and we're done..
893 //#if defined(CONFIG_KERNEL_2_5)
894 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
895 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
897 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
902 yaffs_Object *obj = NULL;
905 yaffs_Object *parent = yaffs_InodeToObject(dir);
911 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
912 parent->objectId,parent->variantType));
916 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
920 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
921 dentry->d_name.name, mode,rdev));
925 yaffs_GrossLock(dev);
927 switch (mode & S_IFMT)
930 // Special (socket, fifo, device...)
931 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
932 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
933 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,old_encode_dev(rdev));
935 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
937 case S_IFREG: // file
938 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
939 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
941 case S_IFDIR: // directory
942 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
943 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
945 case S_IFLNK: // symlink
946 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
947 obj = NULL; // Do we ever get here?
953 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
954 d_instantiate(dentry, inode);
955 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
960 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
964 yaffs_GrossUnlock(dev);
969 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
972 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
973 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
975 // attempt to fix dir bug - didn't work
984 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
985 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
986 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
988 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
991 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
992 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
996 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
1003 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
1005 dev = yaffs_InodeToObject(dir)->myDev;
1007 yaffs_GrossLock(dev);
1010 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1013 yaffs_GrossUnlock(dev);
1015 if( retVal == YAFFS_OK)
1017 dentry->d_inode->i_nlink--;
1018 mark_inode_dirty(dentry->d_inode);
1031 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1033 struct inode *inode = old_dentry->d_inode;
1034 yaffs_Object *obj = NULL;
1035 yaffs_Object *link=NULL;
1038 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1040 obj = yaffs_InodeToObject(inode);
1043 yaffs_GrossLock(dev);
1045 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1047 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1053 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1054 d_instantiate(dentry, old_dentry->d_inode);
1055 atomic_inc(&old_dentry->d_inode->i_count);
1056 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1057 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1061 yaffs_GrossUnlock(dev);
1075 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1080 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1082 dev = yaffs_InodeToObject(dir)->myDev;
1083 yaffs_GrossLock(dev);
1084 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1085 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1087 yaffs_GrossUnlock(dev);
1092 struct inode* inode;
1094 inode = yaffs_get_inode(dir->i_sb, obj->st_mode, 0, obj);
1095 d_instantiate(dentry, inode);
1096 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1101 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1108 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1114 obj = yaffs_DentryToObject(dentry);
1118 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1119 yaffs_GrossLock(dev);
1120 yaffs_FlushFile(obj,1);
1121 yaffs_GrossUnlock(dev);
1126 * The VFS layer already does all the dentry stuff for rename.
1128 * NB: POSIX says you can rename an object over an old object of the same name
1130 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1133 int retVal = YAFFS_FAIL;
1135 yaffs_Object *target;
1137 dev = yaffs_InodeToObject(old_dir)->myDev;
1139 yaffs_GrossLock(dev);
1141 // Check if the target is an existing directory that is not empty.
1142 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1145 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1146 !list_empty(&target->variant.directoryVariant.children))
1148 retVal = YAFFS_FAIL;
1153 // Unlink the target if it exists
1154 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1157 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1158 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1161 yaffs_GrossUnlock(dev);
1163 if(retVal == YAFFS_OK)
1165 if(removed == YAFFS_OK)
1167 new_dentry->d_inode->i_nlink--;
1168 mark_inode_dirty(new_dentry->d_inode);
1181 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1183 struct inode *inode = dentry->d_inode;
1187 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1189 if((error = inode_change_ok(inode,attr)) == 0)
1192 dev = yaffs_InodeToObject(inode)->myDev;
1193 yaffs_GrossLock(dev);
1194 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1202 yaffs_GrossUnlock(dev);
1203 inode_setattr(inode,attr);
1208 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1209 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1210 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1212 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1215 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1216 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1218 yaffs_GrossLock(dev);
1220 buf->f_type = YAFFS_MAGIC;
1221 buf->f_bsize = sb->s_blocksize;
1222 buf->f_namelen = 255;
1223 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * YAFFS_CHUNKS_PER_BLOCK/
1224 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1227 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1228 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1229 buf->f_bavail = buf->f_bfree;
1231 yaffs_GrossUnlock(dev);
1235 static void yaffs_read_inode (struct inode *inode)
1237 // NB This is called as a side effect of other functions and
1238 // thus gross locking should always be in place already.
1241 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1243 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1245 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1247 yaffs_FillInodeFromObject(inode,obj);
1254 // Currently we only can report a single partition. Need to use lists here
1255 static yaffs_Device *yaffs_dev;
1256 static yaffs_Device *yaffsram_dev;
1260 static void yaffs_put_super(struct super_block *sb)
1262 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1264 yaffs_GrossLock(dev);
1265 if(dev->putSuperFunc)
1267 dev->putSuperFunc(sb);
1269 yaffs_Deinitialise(dev);
1270 yaffs_GrossUnlock(dev);
1272 if(dev == yaffs_dev) yaffs_dev = NULL;
1273 if(dev == yaffsram_dev) yaffsram_dev = NULL;
1279 #ifdef CONFIG_YAFFS_MTD_ENABLED
1281 static void yaffs_MTDPutSuper(struct super_block *sb)
1284 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1291 put_mtd_device(mtd);
1297 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1300 struct inode * inode = NULL;
1301 struct dentry * root;
1305 sb->s_magic = YAFFS_MAGIC;
1306 sb->s_op = &yaffs_super_ops;
1309 printk(KERN_INFO"yaffs: sb is NULL\n");
1311 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1312 else if(! kdevname(sb->s_dev))
1313 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1315 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1319 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1320 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1321 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1323 sb->s_blocksize = PAGE_CACHE_SIZE;
1324 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1326 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1327 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1329 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1330 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1338 #ifdef CONFIG_YAFFS_RAM_ENABLED
1339 // Set the yaffs_Device up for ram emulation
1341 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1344 // Deep shit could not allocate device structure
1345 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1349 memset(dev,0,sizeof(yaffs_Device));
1350 dev->genericDevice = NULL; // Not used for RAM emulation.
1352 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1353 dev->startBlock = 1; // Don't use block 0
1354 dev->endBlock = nBlocks - 1;
1355 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1356 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1357 dev->nReservedBlocks = 5;
1359 if(yaffsVersion == 2)
1361 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
1362 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1363 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
1364 dev->queryNANDBlock = nandemul2k_QueryNANDBlock;
1365 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
1366 dev->initialiseNAND = nandemul2k_InitialiseNAND;
1368 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1369 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();;
1370 nBlocks = nandemul2k_GetNumberOfBlocks();
1371 dev->startBlock = 1; // Don't use block 0
1372 dev->endBlock = nBlocks - 1;
1376 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1377 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1378 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1379 dev->initialiseNAND = nandemul_InitialiseNAND;
1390 #ifdef CONFIG_YAFFS_MTD_ENABLED
1391 struct mtd_info *mtd;
1393 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1394 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)));
1396 // Check it's an mtd device.....
1397 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1399 return NULL; // This isn't an mtd device
1403 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1406 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1411 if(mtd->type != MTD_NANDFLASH)
1413 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1417 T(YAFFS_TRACE_OS,(" erase %x\n",mtd->erase));
1418 T(YAFFS_TRACE_OS,(" read %x\n",mtd->read));
1419 T(YAFFS_TRACE_OS,(" write %x\n",mtd->write));
1420 T(YAFFS_TRACE_OS,(" readoob %x\n",mtd->read_oob));
1421 T(YAFFS_TRACE_OS,(" writeoob %x\n",mtd->write_oob));
1422 T(YAFFS_TRACE_OS,(" block_isbad %x\n",mtd->block_isbad));
1423 T(YAFFS_TRACE_OS,(" block_markbad %x\n",mtd->block_markbad));
1424 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1425 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1426 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1427 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1429 if(yaffsVersion == 2)
1431 // Check for version 2 style functions
1433 !mtd->block_isbad ||
1434 !mtd->block_markbad ||
1437 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1444 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1448 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1449 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1451 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1456 // Check for V1 style functions
1460 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1467 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1471 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1472 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1474 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1480 // OK, so if we got here, we have an MTD that's NAND and looks
1481 // like it has the right capabilities
1482 // Set the yaffs_Device up for mtd
1484 //#if defined(CONFIG_KERNEL_2_5)
1485 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1486 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1488 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1492 // Deep shit could not allocate device structure
1493 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1497 memset(dev,0,sizeof(yaffs_Device));
1498 dev->genericDevice = mtd;
1500 // Set up the memory size parameters....
1502 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1503 dev->startBlock = 1; // Don't use block 0
1504 dev->endBlock = nBlocks - 1;
1505 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1506 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1507 dev->nReservedBlocks = 5;
1508 dev->nShortOpCaches = 10; // Enable short op caching
1511 // ... and the functions.
1512 if(yaffsVersion == 2)
1514 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1515 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1516 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1517 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1518 dev->spareBuffer = YMALLOC(mtd->oobsize);
1520 dev->nBytesPerChunk = mtd->oobblock;
1521 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1522 nBlocks = mtd->size / mtd->erasesize;
1523 dev->startBlock = 1; // Don't use block 0
1524 dev->endBlock = nBlocks - 1;
1528 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1529 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1532 // ... and common functions
1533 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1534 dev->initialiseNAND = nandmtd_InitialiseNAND;
1536 dev->putSuperFunc = yaffs_MTDPutSuper;
1538 #ifdef CONFIG_YAFFS_USE_NANDECC
1539 dev->useNANDECC = 1;
1547 init_MUTEX(&dev->grossLock);
1550 yaffs_GrossLock(dev);
1552 err = yaffs_GutsInitialise(dev);
1554 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1556 // Create root inode
1558 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1560 yaffs_GrossUnlock(dev);
1566 inode->i_op = & yaffs_dir_inode_operations;
1567 inode->i_fop = & yaffs_dir_operations;
1569 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1572 root = d_alloc_root(inode);
1574 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1582 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1587 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1589 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1591 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1593 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1596 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1598 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1600 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1602 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1607 #ifdef CONFIG_YAFFS_MTD_ENABLED
1608 //#if defined(CONFIG_KERNEL_2_5)
1609 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1610 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1613 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1616 /* changes NCB 2.5.70 */
1617 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1618 static struct file_system_type yaffs_fs_type = {
1619 .owner = THIS_MODULE,
1621 .get_sb = yaffs_read_super,
1622 .kill_sb = kill_block_super,
1623 // .kill_sb = kill_litter_super,
1624 .fs_flags = FS_REQUIRES_DEV,
1627 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1629 return yaffs_internal_read_super(1,0,sb,data,silent);
1632 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1635 #endif // CONFIG_YAFFS_MTD_ENABLED
1637 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1639 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1640 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1643 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1646 /* changes NCB 2.5.70 */
1647 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1648 static struct file_system_type yaffs2_fs_type = {
1649 .owner = THIS_MODULE,
1651 .get_sb = yaffs2_read_super,
1652 .kill_sb = kill_block_super,
1653 // .kill_sb = kill_litter_super,
1654 .fs_flags = FS_REQUIRES_DEV,
1657 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1659 return yaffs_internal_read_super(2,0,sb,data,silent);
1662 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1665 #endif // CONFIG_YAFFS2_MTD_ENABLED
1668 #ifdef CONFIG_YAFFS_RAM_ENABLED
1670 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1671 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1674 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_ram);
1678 static struct file_system_type yaffs_ram_fs_type = {
1679 .owner = THIS_MODULE,
1681 .get_sb = yaffs_ram_read_super,
1682 .kill_sb = kill_block_super,
1683 // .kill_sb = kill_litter_super,
1684 .fs_flags = FS_SINGLE,
1687 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1689 return yaffs_internal_read_super(1,1,sb,data,silent);
1692 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1695 #endif // CONFIG_YAFFS_RAM_ENABLED
1697 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1699 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1700 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1703 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_ram);
1707 static struct file_system_type yaffs2_ram_fs_type = {
1708 .owner = THIS_MODULE,
1709 .name = "yaffs2ram",
1710 .get_sb = yaffs2_ram_read_super,
1711 .kill_sb = kill_block_super,
1712 // .kill_sb = kill_litter_super,
1713 .fs_flags = FS_SINGLE,
1716 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1718 return yaffs_internal_read_super(2,1,sb,data,silent);
1721 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1724 #endif // CONFIG_YAFFS2_RAM_ENABLED
1728 static struct proc_dir_entry *my_proc_entry;
1729 static struct proc_dir_entry *my_proc_ram_write_entry;
1731 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1733 buf +=sprintf(buf,"\nDevice %s\n",name);
1734 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1735 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1736 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1737 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1738 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1739 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1740 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1741 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1742 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1743 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1744 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1745 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1746 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1747 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1748 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1749 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1750 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1751 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1752 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1753 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1754 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1755 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1756 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1757 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1758 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1759 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1760 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1761 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1767 static int yaffs_proc_read(
1777 char my_buffer[3000];
1781 if (offset > 0) return 0;
1783 /* Fill the buffer and get its length */
1784 buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1786 if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1787 if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1790 strcpy(page,my_buffer);
1791 return strlen(my_buffer);
1795 static int yaffs_proc_ram_write(
1805 printk(KERN_DEBUG "yaffs write size %d\n",count);
1811 // Stuff to handle installation of file systems
1812 struct file_system_to_install
1814 struct file_system_type *fst;
1818 static struct file_system_to_install fs_to_install[] =
1820 #ifdef CONFIG_YAFFS_RAM_ENABLED
1821 { &yaffs_ram_fs_type, 0},
1823 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1824 { &yaffs2_ram_fs_type,0},
1826 #ifdef CONFIG_YAFFS_MTD_ENABLED
1827 { &yaffs_fs_type,0},
1829 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1830 { &yaffs2_fs_type,0},
1835 static int __init init_yaffs_fs(void)
1838 struct file_system_to_install *fsinst;
1840 yaffs_dev = yaffsram_dev = NULL;
1842 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1846 /* Install the proc_fs entry */
1847 my_proc_entry = create_proc_read_entry("yaffs",
1859 // Now add the file system entries
1861 fsinst = fs_to_install;
1863 while(fsinst->fst && !error)
1865 error = register_filesystem(fsinst->fst);
1868 fsinst->installed = 1;
1873 // Any errors? uninstall
1876 fsinst = fs_to_install;
1880 if(fsinst->installed)
1882 unregister_filesystem(fsinst->fst);
1883 fsinst->installed = 0;
1892 static void __exit exit_yaffs_fs(void)
1895 struct file_system_to_install *fsinst;
1897 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1899 remove_proc_entry("yaffs",&proc_root);
1901 fsinst = fs_to_install;
1905 if(fsinst->installed)
1907 unregister_filesystem(fsinst->fst);
1908 fsinst->installed = 0;
1915 module_init(init_yaffs_fs)
1916 module_exit(exit_yaffs_fs)
1918 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1919 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1920 MODULE_LICENSE("GPL");