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.36 2004-12-23 18:06:45 charles Exp $";
33 extern const char *yaffs_guts_c_version;
36 #include <linux/config.h>
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/version.h>
40 #include <linux/slab.h>
41 #include <linux/init.h>
42 #include <linux/list.h>
44 #include <linux/proc_fs.h>
45 #include <linux/pagemap.h>
46 #include <linux/mtd/mtd.h>
47 #include <linux/interrupt.h>
48 #include <linux/string.h>
51 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
53 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
54 #include <asm/statfs.h>
55 #define UnlockPage(p) unlock_page(p)
56 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
57 //#define kdevname(x) cdevname(to_kdev_t(x))
58 #define kdevname(x) "(unavailable)" // temporary fix
62 #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;
77 #ifdef CONFIG_YAFFS_RAM_ENABLED
78 #include "yaffs_nandemul.h"
79 // 2 MB of RAM for emulation
80 #define YAFFS_RAM_EMULATION_SIZE 0x200000
81 #endif //CONFIG_YAFFS_RAM_ENABLED
83 #ifdef CONFIG_YAFFS_MTD_ENABLED
84 #include <linux/mtd/mtd.h>
85 #include "yaffs_mtdif.h"
86 #endif //CONFIG_YAFFS_MTD_ENABLED
88 //#define T(x) printk x
92 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
93 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
94 //NCB #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
96 //#if defined(CONFIG_KERNEL_2_5)
97 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
98 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
100 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
104 static void yaffs_put_super(struct super_block *sb);
106 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
107 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
108 static int yaffs_file_flush(struct file* file);
110 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
112 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
114 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
115 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
116 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
117 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
119 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
120 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
122 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
123 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
124 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
125 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
127 //#if defined(CONFIG_KERNEL_2_5)
128 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
129 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
131 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
133 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
134 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
136 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
137 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
138 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
140 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
142 static void yaffs_read_inode (struct inode *inode);
144 //#if defined(CONFIG_KERNEL_2_5)
145 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
146 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data);
148 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
151 static void yaffs_put_inode (struct inode *inode);
152 static void yaffs_delete_inode(struct inode *);
153 static void yaffs_clear_inode(struct inode *);
155 static int yaffs_readpage(struct file *file, struct page * page);
156 static int yaffs_writepage(struct page *page);
157 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
158 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
160 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
161 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
166 static struct address_space_operations yaffs_file_address_operations = {
167 readpage: yaffs_readpage,
168 writepage: yaffs_writepage,
169 prepare_write: yaffs_prepare_write,
170 commit_write: yaffs_commit_write
174 static struct file_operations yaffs_file_operations = {
175 #ifdef CONFIG_YAFFS_USE_GENERIC_RW
176 read: generic_file_read,
177 write: generic_file_write,
179 read: yaffs_file_read,
180 write: yaffs_file_write,
182 mmap: generic_file_mmap,
183 flush: yaffs_file_flush,
184 fsync: yaffs_sync_object,
186 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
187 sendfile: generic_file_sendfile,
192 static struct inode_operations yaffs_file_inode_operations = {
193 setattr: yaffs_setattr,
197 struct inode_operations yaffs_symlink_inode_operations =
199 readlink: yaffs_readlink,
200 follow_link: yaffs_follow_link,
201 setattr: yaffs_setattr
204 static struct inode_operations yaffs_dir_inode_operations = {
205 create: yaffs_create,
206 lookup: yaffs_lookup,
208 unlink: yaffs_unlink,
209 symlink: yaffs_symlink,
213 rename: yaffs_rename,
214 setattr: yaffs_setattr,
217 static struct file_operations yaffs_dir_operations = {
218 read: generic_read_dir,
219 readdir: yaffs_readdir,
220 fsync: yaffs_sync_object,
224 static struct super_operations yaffs_super_ops = {
225 statfs: yaffs_statfs,
226 read_inode: yaffs_read_inode,
227 put_inode: yaffs_put_inode,
228 put_super: yaffs_put_super,
230 delete_inode: yaffs_delete_inode,
231 clear_inode: yaffs_clear_inode,
236 static void yaffs_GrossLock(yaffs_Device *dev)
238 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
240 down(&dev->grossLock);
243 static void yaffs_GrossUnlock(yaffs_Device *dev)
245 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
250 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
252 unsigned char *alias;
255 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
258 yaffs_GrossLock(dev);
260 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
262 yaffs_GrossUnlock(dev);
267 ret = vfs_readlink(dentry, buffer, buflen, alias);
272 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
274 unsigned char *alias;
276 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
279 yaffs_GrossLock(dev);
281 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
283 yaffs_GrossUnlock(dev);
288 ret = vfs_follow_link(nd,alias);
294 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
297 * Lookup is used to find objects in the fs
299 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
300 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
302 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
304 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
308 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
310 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
313 yaffs_GrossLock(dev);
316 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
318 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
320 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
326 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
328 inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj);
332 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
333 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
335 //dget(dentry); // try to solve directory bug
338 yaffs_GrossUnlock(dev);
348 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
351 yaffs_GrossUnlock(dev);
353 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
357 // return (ERR_PTR(-EIO));
361 // For now put inode is just for debugging
362 // Put inode is called when the inode **structure** is put.
363 static void yaffs_put_inode(struct inode *inode)
365 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
369 // clear is called to tell the fs to release any per-inode data it holds
370 static void yaffs_clear_inode(struct inode *inode)
375 obj = yaffs_InodeToObject(inode);
377 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
378 obj ? "object exists" : "null object"));
383 yaffs_GrossLock(dev);
385 // Clear the association between the inode ant the yaffs_Object.
387 inode->u.generic_ip = NULL;
389 // If the object freeing was deferred, then the real free happens now.
390 // This should fix the inode inconsistency problem.
392 yaffs_HandleDeferedFree(obj);
394 yaffs_GrossUnlock(dev);
400 // delete is called when the link count is zero and the inode
401 // is put (ie. nobody wants to know about it anymore, time to
403 // NB Must call clear_inode()
404 static void yaffs_delete_inode(struct inode *inode)
406 yaffs_Object *obj = yaffs_InodeToObject(inode);
409 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
410 obj ? "object exists" : "null object"));
415 yaffs_GrossLock(dev);
416 yaffs_DeleteFile(obj);
417 yaffs_GrossUnlock(dev);
423 static int yaffs_file_flush(struct file* file)
425 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
427 yaffs_Device *dev = obj->myDev;
429 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
430 obj->dirty ? "dirty" : "clean"));
432 yaffs_GrossLock(dev);
434 yaffs_FlushFile(obj,1);
436 yaffs_GrossUnlock(dev);
443 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
448 unsigned char *pg_buf;
453 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
454 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
456 obj = yaffs_DentryToObject(f->f_dentry);
465 /* FIXME: Can kmap fail? */
467 yaffs_GrossLock(dev);
469 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
471 yaffs_GrossUnlock(dev);
473 if(ret >= 0) ret = 0;
476 ClearPageUptodate(pg);
483 flush_dcache_page(pg);
487 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
491 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
493 int ret = yaffs_readpage_nolock(f,pg);
498 static int yaffs_readpage(struct file *f, struct page * pg)
500 return yaffs_readpage_unlock(f,pg);
503 // writepage inspired by/stolen from smbfs
506 static int yaffs_writepage(struct page *page)
508 struct address_space *mapping = page->mapping;
510 unsigned long end_index;
518 inode = mapping->host;
522 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
525 if (page->index < end_index)
527 nBytes = PAGE_CACHE_SIZE;
531 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
533 // What's happening here?
534 ///* OK, are we completely out? */
535 //if (page->index >= end_index+1 || !offset)
543 obj = yaffs_InodeToObject(inode);
544 yaffs_GrossLock(obj->myDev);
547 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes);
549 yaffs_GrossUnlock(obj->myDev);
552 SetPageUptodate(page);
556 return (nWritten == nBytes) ? 0 : -ENOSPC;
561 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
564 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
565 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
566 return yaffs_readpage_nolock(f,pg);
572 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
575 void *addr = page_address(pg) + offset;
576 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
577 int nBytes = to - offset;
581 unsigned saddr = (unsigned)addr;
583 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
585 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
587 if(nWritten != nBytes)
589 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
591 ClearPageUptodate(pg);
598 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
606 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
610 inode->i_ino = obj->objectId;
611 inode->i_mode = obj->st_mode;
612 inode->i_uid = obj->st_uid;
613 inode->i_gid = obj->st_gid;
614 inode->i_blksize = inode->i_sb->s_blocksize;
615 //#if defined(CONFIG_KERNEL_2_5)
616 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
618 inode->i_rdev = old_decode_dev(obj->st_rdev);
619 inode->i_atime.tv_sec = (time_t)(obj->st_atime);
620 inode->i_atime.tv_nsec = 0;
621 inode->i_mtime.tv_sec = (time_t)obj->st_mtime;
622 inode->i_mtime.tv_nsec =0;
623 inode->i_ctime.tv_sec = (time_t)obj->st_ctime;
624 inode->i_ctime.tv_nsec = 0;
626 inode->i_rdev = obj->st_rdev;
627 inode->i_atime = obj->st_atime;
628 inode->i_mtime = obj->st_mtime;
629 inode->i_ctime = obj->st_ctime;
631 inode->i_size = yaffs_GetObjectFileLength(obj);
632 inode->i_blocks = (inode->i_size + 511) >> 9;
634 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
636 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
637 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
639 switch (obj->st_mode & S_IFMT)
641 default: // fifo, device or socket
642 init_special_inode(inode, obj->st_mode,(dev_t)(obj->st_rdev));
644 case S_IFREG: // file
645 inode->i_op = &yaffs_file_inode_operations;
646 inode->i_fop = &yaffs_file_operations;
647 inode->i_mapping->a_ops = &yaffs_file_address_operations;
649 case S_IFDIR: // directory
650 inode->i_op = &yaffs_dir_inode_operations;
651 inode->i_fop = &yaffs_dir_operations;
653 case S_IFLNK: // symlink
654 inode->i_op = &yaffs_symlink_inode_operations;
659 inode->u.generic_ip = obj;
660 obj->myInode = inode;
665 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
670 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
672 struct inode * inode;
674 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
676 inode = iget(sb,obj->objectId);
678 // NB Side effect: iget calls back to yaffs_read_inode().
679 // iget also increments the inode's i_count
684 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
691 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
693 obj = yaffs_DentryToObject(f->f_dentry);
697 yaffs_GrossLock(dev);
699 inode = f->f_dentry->d_inode;
701 if (*pos < inode->i_size)
703 if (*pos + n > inode->i_size)
705 n = inode->i_size - *pos;
713 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
719 yaffs_GrossUnlock(dev);
723 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
729 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
737 obj = yaffs_DentryToObject(f->f_dentry);
741 yaffs_GrossLock(dev);
743 inode = f->f_dentry->d_inode;
745 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
747 ipos = inode->i_size;
757 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
761 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));
764 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
766 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
771 if(ipos > inode->i_size)
773 inode->i_size = ipos;
774 inode->i_blocks = (ipos + 511)>>9;
776 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
780 yaffs_GrossUnlock(dev);
782 return nWritten != n ? -ENOSPC : nWritten;
786 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
790 struct inode *inode = f->f_dentry->d_inode;
791 unsigned long offset, curoffs;
795 char name[YAFFS_MAX_NAME_LENGTH +1];
797 obj = yaffs_DentryToObject(f->f_dentry);
800 yaffs_GrossLock(dev);
804 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
808 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
809 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
818 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
819 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
829 list_for_each(i,&obj->variant.directoryVariant.children)
832 if(curoffs >= offset)
834 l = list_entry(i, yaffs_Object,siblings);
836 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
837 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
843 yaffs_GetObjectInode(l),
844 yaffs_GetObjectType(l))
858 yaffs_GrossUnlock(dev);
865 * File creation. Allocate an inode, and we're done..
867 //#if defined(CONFIG_KERNEL_2_5)
868 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
869 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
871 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
876 yaffs_Object *obj = NULL;
879 yaffs_Object *parent = yaffs_InodeToObject(dir);
885 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
886 parent->objectId,parent->variantType));
890 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
894 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
895 dentry->d_name.name, mode,rdev));
899 yaffs_GrossLock(dev);
901 switch (mode & S_IFMT)
904 // Special (socket, fifo, device...)
905 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
906 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
908 case S_IFREG: // file
909 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
910 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
912 case S_IFDIR: // directory
913 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
914 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
916 case S_IFLNK: // symlink
917 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
918 obj = NULL; // Do we ever get here?
924 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
925 d_instantiate(dentry, inode);
926 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
931 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
935 yaffs_GrossUnlock(dev);
940 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
943 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
944 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
946 // attempt to fix dir bug - didn't work
955 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
956 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
957 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
959 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
962 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
963 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
967 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
974 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
976 dev = yaffs_InodeToObject(dir)->myDev;
978 yaffs_GrossLock(dev);
981 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
984 yaffs_GrossUnlock(dev);
986 if( retVal == YAFFS_OK)
988 dentry->d_inode->i_nlink--;
989 mark_inode_dirty(dentry->d_inode);
1002 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1004 struct inode *inode = old_dentry->d_inode;
1005 yaffs_Object *obj = NULL;
1006 yaffs_Object *link=NULL;
1009 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1011 obj = yaffs_InodeToObject(inode);
1014 yaffs_GrossLock(dev);
1016 if (!S_ISDIR(inode->i_mode)) // Don't link directories
1018 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1024 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1025 d_instantiate(dentry, old_dentry->d_inode);
1026 atomic_inc(&old_dentry->d_inode->i_count);
1027 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1028 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1032 yaffs_GrossUnlock(dev);
1046 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1051 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1053 dev = yaffs_InodeToObject(dir)->myDev;
1054 yaffs_GrossLock(dev);
1055 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1056 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1058 yaffs_GrossUnlock(dev);
1063 struct inode* inode;
1065 inode = yaffs_get_inode(dir->i_sb, obj->st_mode, 0, obj);
1066 d_instantiate(dentry, inode);
1067 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1072 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1079 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1085 obj = yaffs_DentryToObject(dentry);
1089 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1090 yaffs_GrossLock(dev);
1091 yaffs_FlushFile(obj,1);
1092 yaffs_GrossUnlock(dev);
1097 * The VFS layer already does all the dentry stuff for rename.
1099 * NB: POSIX says you can rename an object over an old object of the same name
1101 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1104 int retVal = YAFFS_FAIL;
1106 yaffs_Object *target;
1108 dev = yaffs_InodeToObject(old_dir)->myDev;
1110 yaffs_GrossLock(dev);
1112 // Check if the target is an existing directory that is not empty.
1113 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1116 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1117 !list_empty(&target->variant.directoryVariant.children))
1119 retVal = YAFFS_FAIL;
1124 // Unlink the target if it exists
1125 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1128 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1129 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1132 yaffs_GrossUnlock(dev);
1134 if(retVal == YAFFS_OK)
1136 if(removed == YAFFS_OK)
1138 new_dentry->d_inode->i_nlink--;
1139 mark_inode_dirty(new_dentry->d_inode);
1152 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1154 struct inode *inode = dentry->d_inode;
1158 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1160 if((error = inode_change_ok(inode,attr)) == 0)
1163 dev = yaffs_InodeToObject(inode)->myDev;
1164 yaffs_GrossLock(dev);
1165 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1173 yaffs_GrossUnlock(dev);
1174 inode_setattr(inode,attr);
1179 //#if defined(CONFIG_KERNEL_2_5) /* Added NCB 185-8-2003 */
1180 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1181 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1183 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1186 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1187 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1189 yaffs_GrossLock(dev);
1191 buf->f_type = YAFFS_MAGIC;
1192 buf->f_bsize = sb->s_blocksize;
1193 buf->f_namelen = 255;
1194 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * YAFFS_CHUNKS_PER_BLOCK/
1195 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1198 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1199 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
1200 buf->f_bavail = buf->f_bfree;
1202 yaffs_GrossUnlock(dev);
1206 static void yaffs_read_inode (struct inode *inode)
1208 // NB This is called as a side effect of other functions and
1209 // thus gross locking should always be in place already.
1212 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1214 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1216 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1218 yaffs_FillInodeFromObject(inode,obj);
1224 static yaffs_Device *yaffs_dev;
1225 static yaffs_Device *yaffsram_dev;
1229 static void yaffs_put_super(struct super_block *sb)
1231 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1233 yaffs_GrossLock(dev);
1234 if(dev->putSuperFunc)
1236 dev->putSuperFunc(sb);
1238 yaffs_Deinitialise(dev);
1239 yaffs_GrossUnlock(dev);
1241 if(dev == yaffs_dev) yaffs_dev = NULL;
1242 if(dev == yaffsram_dev) yaffsram_dev = NULL;
1248 #ifdef CONFIG_YAFFS_MTD_ENABLED
1250 static void yaffs_MTDPutSuper(struct super_block *sb)
1253 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1260 put_mtd_device(mtd);
1266 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
1269 struct inode * inode;
1270 struct dentry * root;
1273 sb->s_magic = YAFFS_MAGIC;
1274 sb->s_op = &yaffs_super_ops;
1277 printk(KERN_INFO"yaffs: sb is NULL\n");
1279 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1280 else if(! kdevname(sb->s_dev))
1281 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1283 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1287 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1288 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1289 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1291 sb->s_blocksize = PAGE_CACHE_SIZE;
1292 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1294 T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1296 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1297 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1305 #ifdef CONFIG_YAFFS_RAM_ENABLED
1306 // Set the yaffs_Device up for ram emulation
1308 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1311 // Deep shit could not allocate device structure
1312 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
1316 memset(dev,0,sizeof(yaffs_Device));
1317 dev->genericDevice = NULL; // Not used for RAM emulation.
1319 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1320 dev->startBlock = 1; // Don't use block 0
1321 dev->endBlock = nBlocks - 1;
1322 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1323 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1324 dev->nReservedBlocks = 5;
1326 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1327 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1328 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1329 dev->initialiseNAND = nandemul_InitialiseNAND;
1338 #ifdef CONFIG_YAFFS_MTD_ENABLED
1339 struct mtd_info *mtd;
1341 printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1342 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev));
1344 // Check it's an mtd device.....
1345 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1347 return NULL; // This isn't an mtd device
1351 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1354 printk(KERN_DEBUG "yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev));
1359 if(mtd->type != MTD_NANDFLASH)
1361 printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);
1365 //printk(KERN_DEBUG" erase %x\n",mtd->erase);
1366 //printk(KERN_DEBUG" read %x\n",mtd->read);
1367 //printk(KERN_DEBUG" write %x\n",mtd->write);
1368 //printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
1369 //printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
1370 //printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
1371 //printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
1377 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1384 printk(KERN_DEBUG "yaffs: MTD device does not support required functions\n");
1388 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1389 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1391 printk(KERN_DEBUG "yaffs: MTD device does not support have the right page sizes\n");
1396 // OK, so if we got here, we have an MTD that's NAND and looks
1397 // like it has the right capabilities
1398 // Set the yaffs_Device up for ram emulation
1400 //#if defined(CONFIG_KERNEL_2_5)
1401 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1402 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1404 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1408 // Deep shit could not allocate device structure
1409 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
1413 memset(dev,0,sizeof(yaffs_Device));
1414 dev->genericDevice = mtd;
1416 // Set up the memory size parameters....
1418 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1419 dev->startBlock = 1; // Don't use block 0
1420 dev->endBlock = nBlocks - 1;
1421 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1422 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1423 dev->nReservedBlocks = 5;
1424 dev->nShortOpCaches = 10; // Enable short op caching
1427 // ... and the functions.
1428 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1429 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1430 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1431 dev->initialiseNAND = nandmtd_InitialiseNAND;
1433 dev->putSuperFunc = yaffs_MTDPutSuper;
1435 #ifdef CONFIG_YAFFS_USE_NANDECC
1436 dev->useNANDECC = 1;
1444 init_MUTEX(&dev->grossLock);
1447 yaffs_GrossLock(dev);
1448 yaffs_GutsInitialise(yaffs_SuperToDevice(sb));
1450 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised\n"));
1452 // Create root inode
1453 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(yaffs_SuperToDevice(sb)));
1455 yaffs_GrossUnlock(dev);
1461 inode->i_op = & yaffs_dir_inode_operations;
1462 inode->i_fop = & yaffs_dir_operations;
1464 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1467 root = d_alloc_root(inode);
1469 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1477 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1481 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1483 return yaffs_internal_read_super(1,sb,data,silent) ? 0 : -1;
1485 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1487 return yaffs_internal_read_super(0,sb,data,silent) ? 0 : -1;
1491 #ifdef CONFIG_YAFFS_MTD_ENABLED
1492 //#if defined(CONFIG_KERNEL_2_5)
1493 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1494 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1497 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1500 /* changes NCB 2.5.70 */
1501 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1502 static struct file_system_type yaffs_fs_type = {
1503 .owner = THIS_MODULE,
1505 .get_sb = yaffs_read_super,
1506 .kill_sb = kill_block_super,
1507 // .kill_sb = kill_litter_super,
1508 .fs_flags = FS_REQUIRES_DEV,
1511 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1513 return yaffs_internal_read_super(0,sb,data,silent);
1516 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1520 #ifdef CONFIG_YAFFS_RAM_ENABLED
1522 //#if defined(CONFIG_KERNEL_2_5)
1523 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1524 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1527 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_ram);
1530 /* changes NCB 2.5.70 */
1531 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1532 static struct file_system_type yaffs_fs_type = {
1533 .owner = THIS_MODULE,
1535 .get_sb = yaffs_ram_read_super,
1536 .kill_sb = kill_block_super,
1537 // .kill_sb = kill_litter_super,
1538 .fs_flags = FS_SINGLE,
1541 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1543 return yaffs_internal_read_super(1,sb,data,silent);
1546 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1548 #endif // CONFIG_YAFFS_RAM_ENABLED
1551 static struct proc_dir_entry *my_proc_entry;
1552 static struct proc_dir_entry *my_proc_ram_write_entry;
1554 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1556 buf +=sprintf(buf,"\nDevice %s\n",name);
1557 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1558 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1559 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1560 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1561 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1562 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1563 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1564 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1565 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1566 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1567 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1568 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1569 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1570 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1571 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1572 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1573 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1574 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1575 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1576 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1577 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1578 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1579 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1580 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1581 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1582 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1583 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1589 static int yaffs_proc_read(
1599 char my_buffer[3000];
1603 if (offset > 0) return 0;
1605 /* Fill the buffer and get its length */
1606 buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1608 if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1609 if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1612 strcpy(page,my_buffer);
1613 return strlen(my_buffer);
1617 static int yaffs_proc_ram_write(
1627 printk(KERN_DEBUG "yaffs write size %d\n",count);
1631 static int __init init_yaffs_fs(void)
1635 yaffs_dev = yaffsram_dev = NULL;
1637 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
1638 #ifdef CONFIG_YAFFS_USE_GENERIC_RW
1639 printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
1641 printk(KERN_DEBUG "yaffs is using direct read/write (uncached)\n");
1645 /* Install the proc_fs entry */
1646 my_proc_entry = create_proc_read_entry("yaffs",
1656 #ifdef CONFIG_YAFFS_RAM_ENABLED
1658 my_proc_ram_write_entry = create_proc_entry("yaffs_ram",
1662 if(!my_proc_ram_write_entry)
1668 my_proc_ram_write_entry->write_proc = yaffs_proc_ram_write;
1672 error = register_filesystem(&yaffs_ram_fs_type);
1677 #endif //CONFIG_YAFFS_RAM_ENABLED
1679 #ifdef CONFIG_YAFFS_MTD_ENABLED
1680 error = register_filesystem(&yaffs_fs_type);
1683 #ifdef CONFIG_YAFFS_RAM_ENABLED
1684 unregister_filesystem(&yaffs_ram_fs_type);
1685 #endif //CONFIG_YAFFS_RAM_ENABLED
1687 #endif // CONFIG_YAFFS_MTD_ENABLED
1692 static void __exit exit_yaffs_fs(void)
1694 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Clean up\n");
1696 remove_proc_entry("yaffs",&proc_root);
1698 #ifdef CONFIG_YAFFS_RAM_ENABLED
1699 unregister_filesystem(&yaffs_ram_fs_type);
1701 #ifdef CONFIG_YAFFS_MTD_ENABLED
1702 unregister_filesystem(&yaffs_fs_type);
1707 module_init(init_yaffs_fs)
1708 module_exit(exit_yaffs_fs)
1710 MODULE_DESCRIPTION("YAFFS - a NAND specific flash file system");
1711 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002");
1712 MODULE_LICENSE("GPL");