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.2 2005-03-16 04:00:36 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 init_special_inode(inode, obj->st_mode,(dev_t)(obj->st_rdev));
648 case S_IFREG: // file
649 inode->i_op = &yaffs_file_inode_operations;
650 inode->i_fop = &yaffs_file_operations;
651 inode->i_mapping->a_ops = &yaffs_file_address_operations;
653 case S_IFDIR: // directory
654 inode->i_op = &yaffs_dir_inode_operations;
655 inode->i_fop = &yaffs_dir_operations;
657 case S_IFLNK: // symlink
658 inode->i_op = &yaffs_symlink_inode_operations;
663 inode->u.generic_ip = obj;
664 obj->myInode = inode;
669 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
674 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
676 struct inode * inode;
680 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
687 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
692 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
694 inode = iget(sb,obj->objectId);
696 // NB Side effect: iget calls back to yaffs_read_inode().
697 // iget also increments the inode's i_count
704 // No longer used because we use generic rw */
705 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
712 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
714 obj = yaffs_DentryToObject(f->f_dentry);
718 yaffs_GrossLock(dev);
720 inode = f->f_dentry->d_inode;
722 if (*pos < inode->i_size)
724 if (*pos + n > inode->i_size)
726 n = inode->i_size - *pos;
734 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
740 yaffs_GrossUnlock(dev);
744 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
751 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
759 obj = yaffs_DentryToObject(f->f_dentry);
763 yaffs_GrossLock(dev);
765 inode = f->f_dentry->d_inode;
767 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
769 ipos = inode->i_size;
779 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
783 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));
786 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
788 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
793 if(ipos > inode->i_size)
795 inode->i_size = ipos;
796 inode->i_blocks = (ipos + 511)>>9;
798 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
802 yaffs_GrossUnlock(dev);
804 return nWritten != n ? -ENOSPC : nWritten;
809 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
813 struct inode *inode = f->f_dentry->d_inode;
814 unsigned long offset, curoffs;
818 char name[YAFFS_MAX_NAME_LENGTH +1];
820 obj = yaffs_DentryToObject(f->f_dentry);
823 yaffs_GrossLock(dev);
827 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
831 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
832 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
841 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
842 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
852 list_for_each(i,&obj->variant.directoryVariant.children)
855 if(curoffs >= offset)
857 l = list_entry(i, yaffs_Object,siblings);
859 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
860 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
866 yaffs_GetObjectInode(l),
867 yaffs_GetObjectType(l))
881 yaffs_GrossUnlock(dev);
888 * File creation. Allocate an inode, and we're done..
890 //#if defined(CONFIG_KERNEL_2_5)
891 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
892 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
894 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
899 yaffs_Object *obj = NULL;
902 yaffs_Object *parent = yaffs_InodeToObject(dir);
908 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
909 parent->objectId,parent->variantType));
913 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
917 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
918 dentry->d_name.name, mode,rdev));
922 yaffs_GrossLock(dev);
924 switch (mode & S_IFMT)
927 // Special (socket, fifo, device...)
928 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
929 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
931 case S_IFREG: // file
932 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
933 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
935 case S_IFDIR: // directory
936 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
937 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
939 case S_IFLNK: // symlink
940 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
941 obj = NULL; // Do we ever get here?
947 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
948 d_instantiate(dentry, inode);
949 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
954 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
958 yaffs_GrossUnlock(dev);
963 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
966 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
967 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
969 // attempt to fix dir bug - didn't work
978 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
979 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
980 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
982 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
985 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
986 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
990 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
997 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
999 dev = yaffs_InodeToObject(dir)->myDev;
1001 yaffs_GrossLock(dev);
1004 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1007 yaffs_GrossUnlock(dev);
1009 if( retVal == YAFFS_OK)
1011 dentry->d_inode->i_nlink--;
1012 mark_inode_dirty(dentry->d_inode);
1025 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1027 struct inode *inode = old_dentry->d_inode;
1028 yaffs_Object *obj = NULL;
1029 yaffs_Object *link=NULL;
1032 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1034 obj = yaffs_InodeToObject(inode);
1037 yaffs_GrossLock(dev);
1039 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1041 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1047 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1048 d_instantiate(dentry, old_dentry->d_inode);
1049 atomic_inc(&old_dentry->d_inode->i_count);
1050 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1051 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1055 yaffs_GrossUnlock(dev);
1069 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1074 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1076 dev = yaffs_InodeToObject(dir)->myDev;
1077 yaffs_GrossLock(dev);
1078 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1079 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1081 yaffs_GrossUnlock(dev);
1086 struct inode* inode;
1088 inode = yaffs_get_inode(dir->i_sb, obj->st_mode, 0, obj);
1089 d_instantiate(dentry, inode);
1090 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1095 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1102 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1108 obj = yaffs_DentryToObject(dentry);
1112 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1113 yaffs_GrossLock(dev);
1114 yaffs_FlushFile(obj,1);
1115 yaffs_GrossUnlock(dev);
1120 * The VFS layer already does all the dentry stuff for rename.
1122 * NB: POSIX says you can rename an object over an old object of the same name
1124 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1127 int retVal = YAFFS_FAIL;
1129 yaffs_Object *target;
1131 dev = yaffs_InodeToObject(old_dir)->myDev;
1133 yaffs_GrossLock(dev);
1135 // Check if the target is an existing directory that is not empty.
1136 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1139 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1140 !list_empty(&target->variant.directoryVariant.children))
1142 retVal = YAFFS_FAIL;
1147 // Unlink the target if it exists
1148 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1151 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1152 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1155 yaffs_GrossUnlock(dev);
1157 if(retVal == YAFFS_OK)
1159 if(removed == YAFFS_OK)
1161 new_dentry->d_inode->i_nlink--;
1162 mark_inode_dirty(new_dentry->d_inode);
1175 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1177 struct inode *inode = dentry->d_inode;
1181 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1183 if((error = inode_change_ok(inode,attr)) == 0)
1186 dev = yaffs_InodeToObject(inode)->myDev;
1187 yaffs_GrossLock(dev);
1188 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1196 yaffs_GrossUnlock(dev);
1197 inode_setattr(inode,attr);
1202 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1203 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1204 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1206 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1209 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1210 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1212 yaffs_GrossLock(dev);
1214 buf->f_type = YAFFS_MAGIC;
1215 buf->f_bsize = sb->s_blocksize;
1216 buf->f_namelen = 255;
1217 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * YAFFS_CHUNKS_PER_BLOCK/
1218 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1221 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1222 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1223 buf->f_bavail = buf->f_bfree;
1225 yaffs_GrossUnlock(dev);
1229 static void yaffs_read_inode (struct inode *inode)
1231 // NB This is called as a side effect of other functions and
1232 // thus gross locking should always be in place already.
1235 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1237 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1239 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1241 yaffs_FillInodeFromObject(inode,obj);
1248 // Currently we only can report a single partition. Need to use lists here
1249 static yaffs_Device *yaffs_dev;
1250 static yaffs_Device *yaffsram_dev;
1254 static void yaffs_put_super(struct super_block *sb)
1256 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1258 yaffs_GrossLock(dev);
1259 if(dev->putSuperFunc)
1261 dev->putSuperFunc(sb);
1263 yaffs_Deinitialise(dev);
1264 yaffs_GrossUnlock(dev);
1266 if(dev == yaffs_dev) yaffs_dev = NULL;
1267 if(dev == yaffsram_dev) yaffsram_dev = NULL;
1273 #ifdef CONFIG_YAFFS_MTD_ENABLED
1275 static void yaffs_MTDPutSuper(struct super_block *sb)
1278 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1285 put_mtd_device(mtd);
1291 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1294 struct inode * inode = NULL;
1295 struct dentry * root;
1299 sb->s_magic = YAFFS_MAGIC;
1300 sb->s_op = &yaffs_super_ops;
1303 printk(KERN_INFO"yaffs: sb is NULL\n");
1305 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1306 else if(! kdevname(sb->s_dev))
1307 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1309 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1313 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1314 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1315 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1317 sb->s_blocksize = PAGE_CACHE_SIZE;
1318 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1320 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1321 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1323 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1324 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1332 #ifdef CONFIG_YAFFS_RAM_ENABLED
1333 // Set the yaffs_Device up for ram emulation
1335 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1338 // Deep shit could not allocate device structure
1339 T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1343 memset(dev,0,sizeof(yaffs_Device));
1344 dev->genericDevice = NULL; // Not used for RAM emulation.
1346 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1347 dev->startBlock = 1; // Don't use block 0
1348 dev->endBlock = nBlocks - 1;
1349 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1350 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1351 dev->nReservedBlocks = 5;
1353 if(yaffsVersion == 2)
1355 dev->writeChunkWithTagsToNAND = nandemul2k_WriteChunkWithTagsToNAND;
1356 dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1357 dev->markNANDBlockBad = nandemul2k_MarkNANDBlockBad;
1358 dev->queryNANDBlock = nandemul2k_QueryNANDBlock;
1359 dev->eraseBlockInNAND = nandemul2k_EraseBlockInNAND;
1360 dev->initialiseNAND = nandemul2k_InitialiseNAND;
1362 dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1363 dev->nBytesPerChunk = nandemul2k_GetBytesPerChunk();;
1364 nBlocks = nandemul2k_GetNumberOfBlocks();
1365 dev->startBlock = 1; // Don't use block 0
1366 dev->endBlock = nBlocks - 1;
1370 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1371 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1372 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1373 dev->initialiseNAND = nandemul_InitialiseNAND;
1384 #ifdef CONFIG_YAFFS_MTD_ENABLED
1385 struct mtd_info *mtd;
1387 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1388 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)));
1390 // Check it's an mtd device.....
1391 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1393 return NULL; // This isn't an mtd device
1397 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1400 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1405 if(mtd->type != MTD_NANDFLASH)
1407 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1411 T(YAFFS_TRACE_OS,(" erase %x\n",mtd->erase));
1412 T(YAFFS_TRACE_OS,(" read %x\n",mtd->read));
1413 T(YAFFS_TRACE_OS,(" write %x\n",mtd->write));
1414 T(YAFFS_TRACE_OS,(" readoob %x\n",mtd->read_oob));
1415 T(YAFFS_TRACE_OS,(" writeoob %x\n",mtd->write_oob));
1416 T(YAFFS_TRACE_OS,(" block_isbad %x\n",mtd->block_isbad));
1417 T(YAFFS_TRACE_OS,(" block_markbad %x\n",mtd->block_markbad));
1418 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1419 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1420 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1421 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1423 if(yaffsVersion == 2)
1425 // Check for version 2 style functions
1427 !mtd->block_isbad ||
1428 !mtd->block_markbad ||
1431 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1438 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1442 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1443 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1445 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1450 // Check for V1 style functions
1454 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1461 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1465 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1466 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1468 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1474 // OK, so if we got here, we have an MTD that's NAND and looks
1475 // like it has the right capabilities
1476 // Set the yaffs_Device up for mtd
1478 //#if defined(CONFIG_KERNEL_2_5)
1479 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1480 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1482 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1486 // Deep shit could not allocate device structure
1487 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1491 memset(dev,0,sizeof(yaffs_Device));
1492 dev->genericDevice = mtd;
1494 // Set up the memory size parameters....
1496 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1497 dev->startBlock = 1; // Don't use block 0
1498 dev->endBlock = nBlocks - 1;
1499 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1500 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1501 dev->nReservedBlocks = 5;
1502 dev->nShortOpCaches = 10; // Enable short op caching
1505 // ... and the functions.
1506 if(yaffsVersion == 2)
1508 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1509 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1510 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1511 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1512 dev->spareBuffer = YMALLOC(mtd->oobsize);
1514 dev->nBytesPerChunk = mtd->oobblock;
1515 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1516 nBlocks = mtd->size / mtd->erasesize;
1517 dev->startBlock = 1; // Don't use block 0
1518 dev->endBlock = nBlocks - 1;
1522 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1523 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1526 // ... and common functions
1527 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1528 dev->initialiseNAND = nandmtd_InitialiseNAND;
1530 dev->putSuperFunc = yaffs_MTDPutSuper;
1532 #ifdef CONFIG_YAFFS_USE_NANDECC
1533 dev->useNANDECC = 1;
1541 init_MUTEX(&dev->grossLock);
1544 yaffs_GrossLock(dev);
1546 err = yaffs_GutsInitialise(dev);
1548 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1550 // Create root inode
1552 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1554 yaffs_GrossUnlock(dev);
1560 inode->i_op = & yaffs_dir_inode_operations;
1561 inode->i_fop = & yaffs_dir_operations;
1563 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1566 root = d_alloc_root(inode);
1568 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1576 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1581 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1583 return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1585 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1587 return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1590 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1592 return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1594 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1596 return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1601 #ifdef CONFIG_YAFFS_MTD_ENABLED
1602 //#if defined(CONFIG_KERNEL_2_5)
1603 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1604 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1607 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1610 /* changes NCB 2.5.70 */
1611 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1612 static struct file_system_type yaffs_fs_type = {
1613 .owner = THIS_MODULE,
1615 .get_sb = yaffs_read_super,
1616 // .kill_sb = kill_block_super,
1617 .kill_sb = kill_litter_super,
1618 .fs_flags = FS_REQUIRES_DEV,
1621 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1623 return yaffs_internal_read_super(1,0,sb,data,silent);
1626 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1629 #endif // CONFIG_YAFFS_MTD_ENABLED
1631 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1633 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1634 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1637 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1640 /* changes NCB 2.5.70 */
1641 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1642 static struct file_system_type yaffs2_fs_type = {
1643 .owner = THIS_MODULE,
1645 .get_sb = yaffs2_read_super,
1646 // .kill_sb = kill_block_super,
1647 .kill_sb = kill_litter_super,
1648 .fs_flags = FS_REQUIRES_DEV,
1651 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1653 return yaffs_internal_read_super(2,0,sb,data,silent);
1656 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1659 #endif // CONFIG_YAFFS2_MTD_ENABLED
1662 #ifdef CONFIG_YAFFS_RAM_ENABLED
1664 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1665 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1668 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_ram);
1672 static struct file_system_type yaffs_ram_fs_type = {
1673 .owner = THIS_MODULE,
1675 .get_sb = yaffs_ram_read_super,
1676 // .kill_sb = kill_block_super,
1677 .kill_sb = kill_litter_super,
1678 .fs_flags = FS_SINGLE,
1681 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1683 return yaffs_internal_read_super(1,1,sb,data,silent);
1686 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1689 #endif // CONFIG_YAFFS_RAM_ENABLED
1691 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1693 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1694 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1697 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_ram);
1701 static struct file_system_type yaffs2_ram_fs_type = {
1702 .owner = THIS_MODULE,
1703 .name = "yaffs2ram",
1704 .get_sb = yaffs2_ram_read_super,
1705 // .kill_sb = kill_block_super,
1706 .kill_sb = kill_litter_super,
1707 .fs_flags = FS_SINGLE,
1710 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1712 return yaffs_internal_read_super(2,1,sb,data,silent);
1715 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1718 #endif // CONFIG_YAFFS2_RAM_ENABLED
1722 static struct proc_dir_entry *my_proc_entry;
1723 static struct proc_dir_entry *my_proc_ram_write_entry;
1725 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1727 buf +=sprintf(buf,"\nDevice %s\n",name);
1728 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1729 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1730 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1731 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1732 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1733 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1734 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1735 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1736 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1737 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1738 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1739 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1740 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1741 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1742 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1743 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1744 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1745 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1746 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1747 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1748 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1749 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1750 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1751 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1752 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1753 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1754 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1755 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1761 static int yaffs_proc_read(
1771 char my_buffer[3000];
1775 if (offset > 0) return 0;
1777 /* Fill the buffer and get its length */
1778 buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1780 if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1781 if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1784 strcpy(page,my_buffer);
1785 return strlen(my_buffer);
1789 static int yaffs_proc_ram_write(
1799 printk(KERN_DEBUG "yaffs write size %d\n",count);
1805 // Stuff to handle installation of file systems
1806 struct file_system_to_install
1808 struct file_system_type *fst;
1812 static struct file_system_to_install fs_to_install[] =
1814 #ifdef CONFIG_YAFFS_RAM_ENABLED
1815 { &yaffs_ram_fs_type, 0},
1817 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1818 { &yaffs2_ram_fs_type,0},
1820 #ifdef CONFIG_YAFFS_MTD_ENABLED
1821 { &yaffs_fs_type,0},
1823 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1824 { &yaffs2_fs_type,0},
1829 static int __init init_yaffs_fs(void)
1832 struct file_system_to_install *fsinst;
1834 yaffs_dev = yaffsram_dev = NULL;
1836 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1840 /* Install the proc_fs entry */
1841 my_proc_entry = create_proc_read_entry("yaffs",
1853 // Now add the file system entries
1855 fsinst = fs_to_install;
1857 while(fsinst->fst && !error)
1859 error = register_filesystem(fsinst->fst);
1862 fsinst->installed = 1;
1867 // Any errors? uninstall
1870 fsinst = fs_to_install;
1874 if(fsinst->installed)
1876 unregister_filesystem(fsinst->fst);
1877 fsinst->installed = 0;
1886 static void __exit exit_yaffs_fs(void)
1889 struct file_system_to_install *fsinst;
1891 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1893 remove_proc_entry("yaffs",&proc_root);
1895 fsinst = fs_to_install;
1899 if(fsinst->installed)
1901 unregister_filesystem(fsinst->fst);
1902 fsinst->installed = 0;
1909 module_init(init_yaffs_fs)
1910 module_exit(exit_yaffs_fs)
1912 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1913 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1914 MODULE_LICENSE("GPL");