2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
5 * Copyright (C) 2002 Aleph One Ltd.
6 * for Toby Churchill Ltd and Brightstar Engineering
8 * Created by Charles Manning <charles@aleph1.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This is the file system front-end to YAFFS that hooks it up to
18 * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with this superblock
19 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this superblock
20 * >> inode->u.generic_ip points to the associated yaffs_Object.
24 * * Luc van OostenRyck for numerous patches.
25 * * Nick Bane for numerous patches.
26 * * Nick Bane for 2.5/2.6 integration.
27 * * Andras Toth for mknod rdev issue.
28 * * Michael Fischer for finding the problem with inode inconsistency.
29 * * Some code bodily lifted from JFFS2.
33 const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.24 2005-08-01 20:54:45 luc Exp $";
34 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/smp_lock.h>
47 #include <linux/pagemap.h>
48 #include <linux/mtd/mtd.h>
49 #include <linux/interrupt.h>
50 #include <linux/string.h>
53 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
55 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
56 #include <asm/statfs.h>
57 #define UnlockPage(p) unlock_page(p)
58 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
59 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf) // FIXME: use sb->s_id instead ?
63 #include <linux/locks.h>
64 #define BDEVNAME_SIZE 0
65 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
69 #include <asm/uaccess.h>
72 #include "yaffs_guts.h"
77 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS;
78 //unsigned yaffs_traceMask = 0xFFFFFFFF;
81 #ifdef CONFIG_YAFFS_YAFFS1
82 #include <linux/mtd/mtd.h>
83 #include "yaffs_mtdif.h"
84 #include "yaffs_mtdif2.h"
85 #endif //CONFIG_YAFFS_YAFFS1
87 //#define T(x) printk x
91 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
92 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
94 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
95 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
97 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
101 static void yaffs_put_super(struct super_block *sb);
103 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
105 static int yaffs_file_flush(struct file* file);
107 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
109 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
111 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
112 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
113 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
115 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
116 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
118 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
119 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
120 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
121 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
123 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
124 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
126 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
128 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
129 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
131 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
132 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
134 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
136 static void yaffs_read_inode (struct inode *inode);
138 static void yaffs_put_inode (struct inode *inode);
139 static void yaffs_delete_inode(struct inode *);
140 static void yaffs_clear_inode(struct inode *);
142 static int yaffs_readpage(struct file *file, struct page * page);
143 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
144 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
146 static int yaffs_writepage(struct page *page);
148 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
149 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
151 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen);
152 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
156 static struct address_space_operations yaffs_file_address_operations = {
157 .readpage = yaffs_readpage,
158 .writepage = yaffs_writepage,
159 .prepare_write = yaffs_prepare_write,
160 .commit_write = yaffs_commit_write,
163 static struct file_operations yaffs_file_operations = {
164 .read = generic_file_read,
165 .write = generic_file_write,
166 .mmap = generic_file_mmap,
167 .flush = yaffs_file_flush,
168 .fsync = yaffs_sync_object,
171 static struct inode_operations yaffs_file_inode_operations = {
172 .setattr = yaffs_setattr,
175 static struct inode_operations yaffs_symlink_inode_operations = {
176 .readlink = yaffs_readlink,
177 .follow_link = yaffs_follow_link,
178 .setattr = yaffs_setattr,
181 static struct inode_operations yaffs_dir_inode_operations = {
182 .create = yaffs_create,
183 .lookup = yaffs_lookup,
185 .unlink = yaffs_unlink,
186 .symlink = yaffs_symlink,
187 .mkdir = yaffs_mkdir,
188 .rmdir = yaffs_unlink,
189 .mknod = yaffs_mknod,
190 .rename = yaffs_rename,
191 .setattr = yaffs_setattr,
194 static struct file_operations yaffs_dir_operations = {
195 .read = generic_read_dir,
196 .readdir = yaffs_readdir,
197 .fsync = yaffs_sync_object,
200 static struct super_operations yaffs_super_ops = {
201 .statfs = yaffs_statfs,
202 .read_inode = yaffs_read_inode,
203 .put_inode = yaffs_put_inode,
204 .put_super = yaffs_put_super,
205 .delete_inode = yaffs_delete_inode,
206 .clear_inode = yaffs_clear_inode,
211 static void yaffs_GrossLock(yaffs_Device *dev)
213 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
215 down(&dev->grossLock);
218 static void yaffs_GrossUnlock(yaffs_Device *dev)
220 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
225 static int yaffs_readlink(struct dentry *dentry, char __user *buffer, int buflen)
227 unsigned char *alias;
230 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
233 yaffs_GrossLock(dev);
235 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
237 yaffs_GrossUnlock(dev);
242 ret = vfs_readlink(dentry, buffer, buflen, alias);
247 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
249 unsigned char *alias;
251 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
254 yaffs_GrossLock(dev);
256 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
258 yaffs_GrossUnlock(dev);
263 ret = vfs_follow_link(nd,alias);
269 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
272 * Lookup is used to find objects in the fs
274 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
276 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
278 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
282 struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
284 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
287 yaffs_GrossLock(dev);
290 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
292 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
294 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
300 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
302 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode,0,obj);
306 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
307 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */
309 //dget(dentry); // try to solve directory bug
312 yaffs_GrossUnlock(dev);
322 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
325 yaffs_GrossUnlock(dev);
327 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/
331 // return (ERR_PTR(-EIO));
335 // For now put inode is just for debugging
336 // Put inode is called when the inode **structure** is put.
337 static void yaffs_put_inode(struct inode *inode)
339 T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
343 // clear is called to tell the fs to release any per-inode data it holds
344 static void yaffs_clear_inode(struct inode *inode)
349 obj = yaffs_InodeToObject(inode);
351 T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
352 obj ? "object exists" : "null object"));
357 yaffs_GrossLock(dev);
359 // Clear the association between the inode ant the yaffs_Object.
361 inode->u.generic_ip = NULL;
363 // If the object freeing was deferred, then the real free happens now.
364 // This should fix the inode inconsistency problem.
366 yaffs_HandleDeferedFree(obj);
368 yaffs_GrossUnlock(dev);
374 // delete is called when the link count is zero and the inode
375 // is put (ie. nobody wants to know about it anymore, time to
377 // NB Must call clear_inode()
378 static void yaffs_delete_inode(struct inode *inode)
380 yaffs_Object *obj = yaffs_InodeToObject(inode);
383 T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
384 obj ? "object exists" : "null object"));
389 yaffs_GrossLock(dev);
390 yaffs_DeleteFile(obj);
391 yaffs_GrossUnlock(dev);
397 static int yaffs_file_flush(struct file* file)
399 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
401 yaffs_Device *dev = obj->myDev;
403 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
404 obj->dirty ? "dirty" : "clean"));
406 yaffs_GrossLock(dev);
408 yaffs_FlushFile(obj,1);
410 yaffs_GrossUnlock(dev);
417 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
422 unsigned char *pg_buf;
427 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
428 (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
430 obj = yaffs_DentryToObject(f->f_dentry);
435 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
436 BUG_ON(!PageLocked(pg));
443 /* FIXME: Can kmap fail? */
445 yaffs_GrossLock(dev);
447 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
449 yaffs_GrossUnlock(dev);
451 if(ret >= 0) ret = 0;
454 ClearPageUptodate(pg);
461 flush_dcache_page(pg);
465 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
469 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
471 int ret = yaffs_readpage_nolock(f,pg);
476 static int yaffs_readpage(struct file *f, struct page * pg)
478 return yaffs_readpage_unlock(f,pg);
481 // writepage inspired by/stolen from smbfs
484 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
485 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
487 static int yaffs_writepage(struct page *page)
490 struct address_space *mapping = page->mapping;
492 unsigned long end_index;
500 inode = mapping->host;
504 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
507 if (page->index < end_index)
509 nBytes = PAGE_CACHE_SIZE;
513 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
515 // What's happening here?
516 ///* OK, are we completely out? */
517 //if (page->index >= end_index+1 || !offset)
525 obj = yaffs_InodeToObject(inode);
526 yaffs_GrossLock(obj->myDev);
529 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
531 yaffs_GrossUnlock(obj->myDev);
534 SetPageUptodate(page);
538 return (nWritten == nBytes) ? 0 : -ENOSPC;
543 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
546 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
547 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
548 return yaffs_readpage_nolock(f,pg);
554 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
557 void *addr = page_address(pg) + offset;
558 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
559 int nBytes = to - offset;
563 unsigned saddr = (unsigned)addr;
565 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
567 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
569 if(nWritten != nBytes)
571 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
573 ClearPageUptodate(pg);
580 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
588 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
592 inode->i_ino = obj->objectId;
593 inode->i_mode = obj->yst_mode;
594 inode->i_uid = obj->yst_uid;
595 inode->i_gid = obj->yst_gid;
596 inode->i_blksize = inode->i_sb->s_blocksize;
597 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
599 inode->i_rdev = old_decode_dev(obj->yst_rdev);
600 inode->i_atime.tv_sec = (time_t)(obj->yst_atime);
601 inode->i_atime.tv_nsec = 0;
602 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime;
603 inode->i_mtime.tv_nsec =0;
604 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime;
605 inode->i_ctime.tv_nsec = 0;
607 inode->i_rdev = obj->yst_rdev;
608 inode->i_atime = obj->yst_atime;
609 inode->i_mtime = obj->yst_mtime;
610 inode->i_ctime = obj->yst_ctime;
612 inode->i_size = yaffs_GetObjectFileLength(obj);
613 inode->i_blocks = (inode->i_size + 511) >> 9;
615 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
617 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
618 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
620 switch (obj->yst_mode & S_IFMT)
622 default: // fifo, device or socket
623 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
624 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev));
626 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev));
629 case S_IFREG: // file
630 inode->i_op = &yaffs_file_inode_operations;
631 inode->i_fop = &yaffs_file_operations;
632 inode->i_mapping->a_ops = &yaffs_file_address_operations;
634 case S_IFDIR: // directory
635 inode->i_op = &yaffs_dir_inode_operations;
636 inode->i_fop = &yaffs_dir_operations;
638 case S_IFLNK: // symlink
639 inode->i_op = &yaffs_symlink_inode_operations;
644 inode->u.generic_ip = obj;
645 obj->myInode = inode;
650 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
655 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
657 struct inode * inode;
661 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
668 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
673 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
675 inode = iget(sb,obj->objectId);
677 // NB Side effect: iget calls back to yaffs_read_inode().
678 // iget also increments the inode's i_count
683 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
691 obj = yaffs_DentryToObject(f->f_dentry);
695 yaffs_GrossLock(dev);
697 inode = f->f_dentry->d_inode;
699 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
701 ipos = inode->i_size;
711 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
715 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));
718 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
720 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
725 if(ipos > inode->i_size)
727 inode->i_size = ipos;
728 inode->i_blocks = (ipos + 511)>>9;
730 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
734 yaffs_GrossUnlock(dev);
736 return nWritten != n ? -ENOSPC : nWritten;
741 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
745 struct inode *inode = f->f_dentry->d_inode;
746 unsigned long offset, curoffs;
750 char name[YAFFS_MAX_NAME_LENGTH +1];
752 obj = yaffs_DentryToObject(f->f_dentry);
755 yaffs_GrossLock(dev);
759 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
763 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
764 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
773 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
774 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
784 list_for_each(i,&obj->variant.directoryVariant.children)
787 if(curoffs >= offset)
789 l = list_entry(i, yaffs_Object,siblings);
791 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
792 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
798 yaffs_GetObjectInode(l),
799 yaffs_GetObjectType(l))
813 yaffs_GrossUnlock(dev);
820 * File creation. Allocate an inode, and we're done..
822 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
823 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
825 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
830 yaffs_Object *obj = NULL;
833 yaffs_Object *parent = yaffs_InodeToObject(dir);
836 uid_t uid = current->fsuid;
837 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
841 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
842 parent->objectId,parent->variantType));
846 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
850 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
851 dentry->d_name.name, mode,rdev));
855 yaffs_GrossLock(dev);
857 switch (mode & S_IFMT)
860 // Special (socket, fifo, device...)
861 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
862 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
863 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,old_encode_dev(rdev));
865 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,rdev);
868 case S_IFREG: // file
869 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
870 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,uid, gid);
872 case S_IFDIR: // directory
873 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
874 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,uid, gid);
876 case S_IFLNK: // symlink
877 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
878 obj = NULL; // Do we ever get here?
884 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
885 d_instantiate(dentry, inode);
886 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
891 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
895 yaffs_GrossUnlock(dev);
900 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
903 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
904 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
906 // attempt to fix dir bug - didn't work
915 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
916 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
918 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
921 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
922 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
926 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
933 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
935 dev = yaffs_InodeToObject(dir)->myDev;
937 yaffs_GrossLock(dev);
940 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
943 yaffs_GrossUnlock(dev);
945 if( retVal == YAFFS_OK)
947 dentry->d_inode->i_nlink--;
948 mark_inode_dirty(dentry->d_inode);
961 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
963 struct inode *inode = old_dentry->d_inode;
964 yaffs_Object *obj = NULL;
965 yaffs_Object *link=NULL;
968 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
970 obj = yaffs_InodeToObject(inode);
973 yaffs_GrossLock(dev);
975 if (!S_ISDIR(inode->i_mode)) // Don't link directories
977 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
983 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
984 d_instantiate(dentry, old_dentry->d_inode);
985 atomic_inc(&old_dentry->d_inode->i_count);
986 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
987 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
991 yaffs_GrossUnlock(dev);
1005 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1009 uid_t uid = current->fsuid;
1010 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1012 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1014 dev = yaffs_InodeToObject(dir)->myDev;
1015 yaffs_GrossLock(dev);
1016 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1017 S_IFLNK | S_IRWXUGO, uid, gid,
1019 yaffs_GrossUnlock(dev);
1024 struct inode* inode;
1026 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1027 d_instantiate(dentry, inode);
1028 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1033 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1040 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1046 obj = yaffs_DentryToObject(dentry);
1050 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1051 yaffs_GrossLock(dev);
1052 yaffs_FlushFile(obj,1);
1053 yaffs_GrossUnlock(dev);
1058 * The VFS layer already does all the dentry stuff for rename.
1060 * NB: POSIX says you can rename an object over an old object of the same name
1062 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1065 int retVal = YAFFS_FAIL;
1067 yaffs_Object *target;
1069 dev = yaffs_InodeToObject(old_dir)->myDev;
1071 yaffs_GrossLock(dev);
1073 // Check if the target is an existing directory that is not empty.
1074 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1077 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1078 !list_empty(&target->variant.directoryVariant.children))
1080 retVal = YAFFS_FAIL;
1085 // Unlink the target if it exists
1086 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1089 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1090 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1093 yaffs_GrossUnlock(dev);
1095 if(retVal == YAFFS_OK)
1097 if(removed == YAFFS_OK)
1099 new_dentry->d_inode->i_nlink--;
1100 mark_inode_dirty(new_dentry->d_inode);
1113 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1115 struct inode *inode = dentry->d_inode;
1119 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1121 if((error = inode_change_ok(inode,attr)) == 0)
1124 dev = yaffs_InodeToObject(inode)->myDev;
1125 yaffs_GrossLock(dev);
1126 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1134 yaffs_GrossUnlock(dev);
1136 error = inode_setattr(inode,attr);
1141 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1142 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1144 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1149 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1150 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1152 yaffs_GrossLock(dev);
1155 buf->f_type = YAFFS_MAGIC;
1156 buf->f_bsize = sb->s_blocksize;
1157 buf->f_namelen = 255;
1158 if(sb->s_blocksize > dev->nBytesPerChunk)
1161 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1162 (sb->s_blocksize/dev->nBytesPerChunk);
1163 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1164 (sb->s_blocksize/dev->nBytesPerChunk);
1169 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1170 (dev->nBytesPerChunk/sb->s_blocksize);
1171 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1172 (dev->nBytesPerChunk/sb->s_blocksize);
1176 buf->f_bavail = buf->f_bfree;
1178 yaffs_GrossUnlock(dev);
1182 static void yaffs_read_inode (struct inode *inode)
1184 // NB This is called as a side effect of other functions and
1185 // thus gross locking should always be in place already.
1188 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1190 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1192 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1194 yaffs_FillInodeFromObject(inode,obj);
1198 static LIST_HEAD(yaffs_dev_list);
1200 static void yaffs_put_super(struct super_block *sb)
1202 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1204 yaffs_GrossLock(dev);
1205 if(dev->putSuperFunc)
1207 dev->putSuperFunc(sb);
1209 yaffs_Deinitialise(dev);
1210 yaffs_GrossUnlock(dev);
1212 /* we assume this is protected by lock_kernel() in mount/umount */
1213 list_del(&dev->devList);
1219 #ifdef CONFIG_YAFFS_YAFFS1
1221 static void yaffs_MTDPutSuper(struct super_block *sb)
1224 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1231 put_mtd_device(mtd);
1237 static struct super_block *yaffs_internal_read_super(int yaffsVersion, struct super_block * sb, void * data, int silent)
1240 struct inode * inode = NULL;
1241 struct dentry * root;
1242 yaffs_Device *dev = 0;
1243 char devname_buf[BDEVNAME_SIZE+1];
1246 sb->s_magic = YAFFS_MAGIC;
1247 sb->s_op = &yaffs_super_ops;
1250 printk(KERN_INFO"yaffs: sb is NULL\n");
1252 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1253 else if(!yaffs_devname(sb, devname_buf))
1254 printk(KERN_INFO"yaffs: devname is NULL\n");
1256 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, yaffs_devname(sb, devname_buf));
1260 sb->s_blocksize = PAGE_CACHE_SIZE;
1261 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1262 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1263 T(YAFFS_TRACE_OS,("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1265 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1266 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1272 struct mtd_info *mtd;
1274 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1275 MAJOR(sb->s_dev),MINOR(sb->s_dev), yaffs_devname(sb, devname_buf)));
1277 // Check it's an mtd device.....
1278 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1280 return NULL; // This isn't an mtd device
1284 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1287 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1292 if(mtd->type != MTD_NANDFLASH)
1294 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1298 T(YAFFS_TRACE_OS,(" erase %p\n",mtd->erase));
1299 T(YAFFS_TRACE_OS,(" read %p\n",mtd->read));
1300 T(YAFFS_TRACE_OS,(" write %p\n",mtd->write));
1301 T(YAFFS_TRACE_OS,(" readoob %p\n",mtd->read_oob));
1302 T(YAFFS_TRACE_OS,(" writeoob %p\n",mtd->write_oob));
1303 T(YAFFS_TRACE_OS,(" block_isbad %p\n",mtd->block_isbad));
1304 T(YAFFS_TRACE_OS,(" block_markbad %p\n",mtd->block_markbad));
1305 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1306 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1307 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1308 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1310 if(yaffsVersion == 2)
1312 // Check for version 2 style functions
1314 !mtd->block_isbad ||
1315 !mtd->block_markbad ||
1323 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1327 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1328 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1330 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1335 // Check for V1 style functions
1344 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1348 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1349 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1351 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1357 // OK, so if we got here, we have an MTD that's NAND and looks
1358 // like it has the right capabilities
1359 // Set the yaffs_Device up for mtd
1361 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1362 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1364 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1368 // Deep shit could not allocate device structure
1369 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1373 memset(dev,0,sizeof(yaffs_Device));
1374 dev->genericDevice = mtd;
1375 dev->name = mtd->name;
1377 // Set up the memory size parameters....
1379 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1380 dev->startBlock = 0;
1381 dev->endBlock = nBlocks - 1;
1382 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1383 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1384 dev->nReservedBlocks = 5;
1385 dev->nShortOpCaches = 10; // Enable short op caching
1388 // ... and the functions.
1389 if(yaffsVersion == 2)
1391 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1392 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1393 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1394 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1395 dev->spareBuffer = YMALLOC(mtd->oobsize);
1397 dev->nBytesPerChunk = mtd->oobblock;
1398 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1399 nBlocks = mtd->size / mtd->erasesize;
1400 dev->startBlock = 0;
1401 dev->endBlock = nBlocks - 1;
1405 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1406 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1409 // ... and common functions
1410 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1411 dev->initialiseNAND = nandmtd_InitialiseNAND;
1413 dev->putSuperFunc = yaffs_MTDPutSuper;
1415 #ifdef CONFIG_YAFFS_USE_NANDECC
1416 dev->useNANDECC = 1;
1420 /* we assume this is protected by lock_kernel() in mount/umount */
1421 list_add_tail(&dev->devList, &yaffs_dev_list);
1423 init_MUTEX(&dev->grossLock);
1426 yaffs_GrossLock(dev);
1428 err = yaffs_GutsInitialise(dev);
1430 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1432 // Create root inode
1434 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1436 yaffs_GrossUnlock(dev);
1442 inode->i_op = & yaffs_dir_inode_operations;
1443 inode->i_fop = & yaffs_dir_operations;
1445 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1448 root = d_alloc_root(inode);
1450 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1458 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1464 #ifdef CONFIG_YAFFS_YAFFS1
1466 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1467 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1469 return yaffs_internal_read_super(1,sb,data,silent) ? 0 : -1;
1472 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1475 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1478 static struct file_system_type yaffs_fs_type = {
1479 .owner = THIS_MODULE,
1481 .get_sb = yaffs_read_super,
1482 .kill_sb = kill_block_super,
1483 .fs_flags = FS_REQUIRES_DEV,
1486 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1488 return yaffs_internal_read_super(1,sb,data,silent);
1491 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1494 #endif // CONFIG_YAFFS_YAFFS1
1496 #ifdef CONFIG_YAFFS_YAFFS2
1498 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1499 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1501 return yaffs_internal_read_super(2,sb,data,silent) ? 0 : -1;
1504 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1507 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1510 static struct file_system_type yaffs2_fs_type = {
1511 .owner = THIS_MODULE,
1513 .get_sb = yaffs2_read_super,
1514 .kill_sb = kill_block_super,
1515 .fs_flags = FS_REQUIRES_DEV,
1518 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1520 return yaffs_internal_read_super(2,sb,data,silent);
1523 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1526 #endif // CONFIG_YAFFS_YAFFS2
1531 static struct proc_dir_entry *my_proc_entry;
1533 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev)
1535 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1536 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1537 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1538 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1539 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1540 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1541 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1542 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1543 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1544 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1545 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1546 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1547 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1548 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1549 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1550 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1551 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1552 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1553 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1554 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1555 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1556 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1557 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1558 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1559 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1560 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1561 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1562 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1567 static int yaffs_proc_read(
1576 struct list_head *item;
1581 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1582 * We use 'offset' (*ppos) to indicate where we are in devList.
1583 * This also assumes the user has posted a read buffer large
1584 * enough to hold the complete output; but that's life in /proc.
1589 /* Print header first */
1591 buf += sprintf(buf, "YAFFS built:" __DATE__ " "__TIME__
1592 "\n%s\n%s\n", yaffs_fs_c_version, yaffs_guts_c_version);
1595 /* hold lock_kernel while traversing yaffs_dev_list */
1598 /* Locate and print the Nth entry. Order N-squared but N is small. */
1599 list_for_each(item, &yaffs_dev_list) {
1600 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1605 buf += sprintf(buf,"\nDevice %d \"%s\"\n", n, dev->name);
1606 buf = yaffs_dump_dev(buf, dev);
1611 return buf-page < count ? buf-page : count;
1614 // Stuff to handle installation of file systems
1615 struct file_system_to_install
1617 struct file_system_type *fst;
1621 static struct file_system_to_install fs_to_install[] =
1623 #ifdef CONFIG_YAFFS_YAFFS1
1624 { &yaffs_fs_type,0},
1626 #ifdef CONFIG_YAFFS_YAFFS2
1627 { &yaffs2_fs_type,0},
1632 static int __init init_yaffs_fs(void)
1635 struct file_system_to_install *fsinst;
1637 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1641 /* Install the proc_fs entry */
1642 my_proc_entry = create_proc_read_entry("yaffs",
1654 // Now add the file system entries
1656 fsinst = fs_to_install;
1658 while(fsinst->fst && !error)
1660 error = register_filesystem(fsinst->fst);
1663 fsinst->installed = 1;
1668 // Any errors? uninstall
1671 fsinst = fs_to_install;
1675 if(fsinst->installed)
1677 unregister_filesystem(fsinst->fst);
1678 fsinst->installed = 0;
1687 static void __exit exit_yaffs_fs(void)
1690 struct file_system_to_install *fsinst;
1692 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1694 remove_proc_entry("yaffs",&proc_root);
1696 fsinst = fs_to_install;
1700 if(fsinst->installed)
1702 unregister_filesystem(fsinst->fst);
1703 fsinst->installed = 0;
1710 module_init(init_yaffs_fs)
1711 module_exit(exit_yaffs_fs)
1713 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1714 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1715 MODULE_LICENSE("GPL");