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.28 2005-08-09 03:52:23 charles 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;
491 loff_t offset = (loff_t)page->index << PAGE_CACHE_SHIFT;
493 unsigned long end_index;
501 inode = mapping->host;
505 if (offset > inode->i_size)
507 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_writepage at %08x, inode size = %08x!!!\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), (unsigned) inode->i_size));
508 T(YAFFS_TRACE_OS,(KERN_DEBUG" -> don't care!!\n"));
513 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
516 if (page->index < end_index)
518 nBytes = PAGE_CACHE_SIZE;
522 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
524 // What's happening here?
525 ///* OK, are we completely out? */
526 //if (page->index >= end_index+1 || !offset)
534 obj = yaffs_InodeToObject(inode);
535 yaffs_GrossLock(obj->myDev);
537 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_writepage at %08x, size %08x\n", (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
538 T(YAFFS_TRACE_OS,(KERN_DEBUG"writepag0: obj = %05x, ino = %05x\n", (int) obj->variant.fileVariant.fileSize, (int) inode->i_size));
540 nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
542 T(YAFFS_TRACE_OS,(KERN_DEBUG"writepag1: obj = %05x, ino = %05x\n", (int) obj->variant.fileVariant.fileSize, (int) inode->i_size));
544 yaffs_GrossUnlock(obj->myDev);
547 SetPageUptodate(page);
551 return (nWritten == nBytes) ? 0 : -ENOSPC;
556 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
559 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
560 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
561 return yaffs_readpage_nolock(f,pg);
567 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
570 void *addr = page_address(pg) + offset;
571 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
572 int nBytes = to - offset;
576 unsigned saddr = (unsigned)addr;
578 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
580 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
582 if(nWritten != nBytes)
584 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
586 ClearPageUptodate(pg);
593 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
601 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
605 inode->i_ino = obj->objectId;
606 inode->i_mode = obj->yst_mode;
607 inode->i_uid = obj->yst_uid;
608 inode->i_gid = obj->yst_gid;
609 inode->i_blksize = inode->i_sb->s_blocksize;
610 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
612 inode->i_rdev = old_decode_dev(obj->yst_rdev);
613 inode->i_atime.tv_sec = (time_t)(obj->yst_atime);
614 inode->i_atime.tv_nsec = 0;
615 inode->i_mtime.tv_sec = (time_t)obj->yst_mtime;
616 inode->i_mtime.tv_nsec =0;
617 inode->i_ctime.tv_sec = (time_t)obj->yst_ctime;
618 inode->i_ctime.tv_nsec = 0;
620 inode->i_rdev = obj->yst_rdev;
621 inode->i_atime = obj->yst_atime;
622 inode->i_mtime = obj->yst_mtime;
623 inode->i_ctime = obj->yst_ctime;
625 inode->i_size = yaffs_GetObjectFileLength(obj);
626 inode->i_blocks = (inode->i_size + 511) >> 9;
628 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
630 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
631 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
633 switch (obj->yst_mode & S_IFMT)
635 default: // fifo, device or socket
636 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
637 init_special_inode(inode, obj->yst_mode,old_decode_dev(obj->yst_rdev));
639 init_special_inode(inode, obj->yst_mode,(dev_t)(obj->yst_rdev));
642 case S_IFREG: // file
643 inode->i_op = &yaffs_file_inode_operations;
644 inode->i_fop = &yaffs_file_operations;
645 inode->i_mapping->a_ops = &yaffs_file_address_operations;
647 case S_IFDIR: // directory
648 inode->i_op = &yaffs_dir_inode_operations;
649 inode->i_fop = &yaffs_dir_operations;
651 case S_IFLNK: // symlink
652 inode->i_op = &yaffs_symlink_inode_operations;
657 inode->u.generic_ip = obj;
658 obj->myInode = inode;
663 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
668 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
670 struct inode * inode;
674 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
681 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
686 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
688 inode = iget(sb,obj->objectId);
690 // NB Side effect: iget calls back to yaffs_read_inode().
691 // iget also increments the inode's i_count
696 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
704 obj = yaffs_DentryToObject(f->f_dentry);
708 yaffs_GrossLock(dev);
710 inode = f->f_dentry->d_inode;
712 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
714 ipos = inode->i_size;
724 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
728 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));
731 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
733 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
738 if(ipos > inode->i_size)
740 inode->i_size = ipos;
741 inode->i_blocks = (ipos + 511)>>9;
743 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
747 yaffs_GrossUnlock(dev);
749 return nWritten != n ? -ENOSPC : nWritten;
754 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
758 struct inode *inode = f->f_dentry->d_inode;
759 unsigned long offset, curoffs;
763 char name[YAFFS_MAX_NAME_LENGTH +1];
765 obj = yaffs_DentryToObject(f->f_dentry);
768 yaffs_GrossLock(dev);
772 T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
776 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
777 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
786 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
787 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
797 list_for_each(i,&obj->variant.directoryVariant.children)
800 if(curoffs >= offset)
802 l = list_entry(i, yaffs_Object,siblings);
804 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
805 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
811 yaffs_GetObjectInode(l),
812 yaffs_GetObjectType(l))
826 yaffs_GrossUnlock(dev);
833 * File creation. Allocate an inode, and we're done..
835 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
836 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
838 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
843 yaffs_Object *obj = NULL;
846 yaffs_Object *parent = yaffs_InodeToObject(dir);
849 uid_t uid = current->fsuid;
850 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
854 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
855 parent->objectId,parent->variantType));
859 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
863 T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
864 dentry->d_name.name, mode,rdev));
868 yaffs_GrossLock(dev);
870 switch (mode & S_IFMT)
873 // Special (socket, fifo, device...)
874 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
875 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
876 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,old_encode_dev(rdev));
878 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,uid, gid,rdev);
881 case S_IFREG: // file
882 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
883 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,uid, gid);
885 case S_IFDIR: // directory
886 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
887 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,uid, gid);
889 case S_IFLNK: // symlink
890 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
891 obj = NULL; // Do we ever get here?
897 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
898 d_instantiate(dentry, inode);
899 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
904 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
908 yaffs_GrossUnlock(dev);
913 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
916 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
917 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
919 // attempt to fix dir bug - didn't work
928 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
929 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
931 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
934 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
935 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
939 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
946 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
948 dev = yaffs_InodeToObject(dir)->myDev;
950 yaffs_GrossLock(dev);
953 retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
956 yaffs_GrossUnlock(dev);
958 if( retVal == YAFFS_OK)
960 dentry->d_inode->i_nlink--;
961 mark_inode_dirty(dentry->d_inode);
974 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
976 struct inode *inode = old_dentry->d_inode;
977 yaffs_Object *obj = NULL;
978 yaffs_Object *link=NULL;
981 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
983 obj = yaffs_InodeToObject(inode);
986 yaffs_GrossLock(dev);
988 if (!S_ISDIR(inode->i_mode)) // Don't link directories
990 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
996 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
997 d_instantiate(dentry, old_dentry->d_inode);
998 atomic_inc(&old_dentry->d_inode->i_count);
999 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",
1000 old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1004 yaffs_GrossUnlock(dev);
1018 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1022 uid_t uid = current->fsuid;
1023 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1025 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1027 dev = yaffs_InodeToObject(dir)->myDev;
1028 yaffs_GrossLock(dev);
1029 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1030 S_IFLNK | S_IRWXUGO, uid, gid,
1032 yaffs_GrossUnlock(dev);
1037 struct inode* inode;
1039 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1040 d_instantiate(dentry, inode);
1041 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1046 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1053 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1059 obj = yaffs_DentryToObject(dentry);
1063 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1064 yaffs_GrossLock(dev);
1065 yaffs_FlushFile(obj,1);
1066 yaffs_GrossUnlock(dev);
1071 * The VFS layer already does all the dentry stuff for rename.
1073 * NB: POSIX says you can rename an object over an old object of the same name
1075 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1078 int retVal = YAFFS_FAIL;
1080 yaffs_Object *target;
1082 dev = yaffs_InodeToObject(old_dir)->myDev;
1084 yaffs_GrossLock(dev);
1086 // Check if the target is an existing directory that is not empty.
1087 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1090 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1091 !list_empty(&target->variant.directoryVariant.children))
1093 retVal = YAFFS_FAIL;
1098 // Now does unlinking internally using shadowing mechanism
1100 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1101 yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1104 yaffs_GrossUnlock(dev);
1106 if(retVal == YAFFS_OK)
1108 if(removed == YAFFS_OK)
1110 new_dentry->d_inode->i_nlink--;
1111 mark_inode_dirty(new_dentry->d_inode);
1124 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1126 struct inode *inode = dentry->d_inode;
1130 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1132 if((error = inode_change_ok(inode,attr)) == 0)
1135 dev = yaffs_InodeToObject(inode)->myDev;
1136 yaffs_GrossLock(dev);
1137 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1145 yaffs_GrossUnlock(dev);
1147 error = inode_setattr(inode,attr);
1152 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1153 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1155 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1160 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1161 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1163 yaffs_GrossLock(dev);
1166 buf->f_type = YAFFS_MAGIC;
1167 buf->f_bsize = sb->s_blocksize;
1168 buf->f_namelen = 255;
1169 if(sb->s_blocksize > dev->nBytesPerChunk)
1172 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1173 (sb->s_blocksize/dev->nBytesPerChunk);
1174 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1175 (sb->s_blocksize/dev->nBytesPerChunk);
1180 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1181 (dev->nBytesPerChunk/sb->s_blocksize);
1182 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1183 (dev->nBytesPerChunk/sb->s_blocksize);
1187 buf->f_bavail = buf->f_bfree;
1189 yaffs_GrossUnlock(dev);
1193 static void yaffs_read_inode (struct inode *inode)
1195 // NB This is called as a side effect of other functions and
1196 // thus gross locking should always be in place already.
1199 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1201 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1203 obj = yaffs_FindObjectByNumber(dev,inode->i_ino);
1205 yaffs_FillInodeFromObject(inode,obj);
1209 static LIST_HEAD(yaffs_dev_list);
1211 static void yaffs_put_super(struct super_block *sb)
1213 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1215 yaffs_GrossLock(dev);
1216 if(dev->putSuperFunc)
1218 dev->putSuperFunc(sb);
1220 yaffs_Deinitialise(dev);
1221 yaffs_GrossUnlock(dev);
1223 /* we assume this is protected by lock_kernel() in mount/umount */
1224 list_del(&dev->devList);
1230 #ifdef CONFIG_YAFFS_YAFFS1
1232 static void yaffs_MTDPutSuper(struct super_block *sb)
1235 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1242 put_mtd_device(mtd);
1248 static struct super_block *yaffs_internal_read_super(int yaffsVersion, struct super_block * sb, void * data, int silent)
1251 struct inode * inode = NULL;
1252 struct dentry * root;
1253 yaffs_Device *dev = 0;
1254 char devname_buf[BDEVNAME_SIZE+1];
1255 struct mtd_info *mtd;
1258 sb->s_magic = YAFFS_MAGIC;
1259 sb->s_op = &yaffs_super_ops;
1262 printk(KERN_INFO"yaffs: sb is NULL\n");
1264 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1265 else if(!yaffs_devname(sb, devname_buf))
1266 printk(KERN_INFO"yaffs: devname is NULL\n");
1268 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, yaffs_devname(sb, devname_buf));
1272 sb->s_blocksize = PAGE_CACHE_SIZE;
1273 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1274 T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1275 T(YAFFS_TRACE_OS,("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1277 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1278 T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1282 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1283 MAJOR(sb->s_dev),MINOR(sb->s_dev), yaffs_devname(sb, devname_buf)));
1285 // Check it's an mtd device.....
1286 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1288 return NULL; // This isn't an mtd device
1292 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1295 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1300 if(mtd->type != MTD_NANDFLASH)
1302 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1306 T(YAFFS_TRACE_OS,(" erase %p\n",mtd->erase));
1307 T(YAFFS_TRACE_OS,(" read %p\n",mtd->read));
1308 T(YAFFS_TRACE_OS,(" write %p\n",mtd->write));
1309 T(YAFFS_TRACE_OS,(" readoob %p\n",mtd->read_oob));
1310 T(YAFFS_TRACE_OS,(" writeoob %p\n",mtd->write_oob));
1311 T(YAFFS_TRACE_OS,(" block_isbad %p\n",mtd->block_isbad));
1312 T(YAFFS_TRACE_OS,(" block_markbad %p\n",mtd->block_markbad));
1313 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1314 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1315 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1316 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1318 if(yaffsVersion == 2)
1320 // Check for version 2 style functions
1322 !mtd->block_isbad ||
1323 !mtd->block_markbad ||
1331 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1335 if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1336 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1338 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1343 // Check for V1 style functions
1352 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1356 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1357 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1359 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1365 // OK, so if we got here, we have an MTD that's NAND and looks
1366 // like it has the right capabilities
1367 // Set the yaffs_Device up for mtd
1369 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1370 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1372 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1376 // Deep shit could not allocate device structure
1377 T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1381 memset(dev,0,sizeof(yaffs_Device));
1382 dev->genericDevice = mtd;
1383 dev->name = mtd->name;
1385 // Set up the memory size parameters....
1387 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1388 dev->startBlock = 0;
1389 dev->endBlock = nBlocks - 1;
1390 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1391 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1392 dev->nReservedBlocks = 5;
1393 dev->nShortOpCaches = 10; // Enable short op caching
1396 // ... and the functions.
1397 if(yaffsVersion == 2)
1399 dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1400 dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1401 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1402 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1403 dev->spareBuffer = YMALLOC(mtd->oobsize);
1405 dev->nBytesPerChunk = mtd->oobblock;
1406 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1407 nBlocks = mtd->size / mtd->erasesize;
1408 dev->startBlock = 0;
1409 dev->endBlock = nBlocks - 1;
1413 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1414 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1417 // ... and common functions
1418 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1419 dev->initialiseNAND = nandmtd_InitialiseNAND;
1421 dev->putSuperFunc = yaffs_MTDPutSuper;
1423 #ifndef CONFIG_YAFFS_DOES_ECC
1424 dev->useNANDECC = 1;
1427 /* we assume this is protected by lock_kernel() in mount/umount */
1428 list_add_tail(&dev->devList, &yaffs_dev_list);
1430 init_MUTEX(&dev->grossLock);
1433 yaffs_GrossLock(dev);
1435 err = yaffs_GutsInitialise(dev);
1437 T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1439 // Create root inode
1441 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1443 yaffs_GrossUnlock(dev);
1449 inode->i_op = & yaffs_dir_inode_operations;
1450 inode->i_fop = & yaffs_dir_operations;
1452 T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1455 root = d_alloc_root(inode);
1457 T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1465 T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1471 #ifdef CONFIG_YAFFS_YAFFS1
1473 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1474 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1476 return yaffs_internal_read_super(1,sb,data,silent) ? 0 : -1;
1479 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1482 return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1485 static struct file_system_type yaffs_fs_type = {
1486 .owner = THIS_MODULE,
1488 .get_sb = yaffs_read_super,
1489 .kill_sb = kill_block_super,
1490 .fs_flags = FS_REQUIRES_DEV,
1493 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1495 return yaffs_internal_read_super(1,sb,data,silent);
1498 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1501 #endif // CONFIG_YAFFS_YAFFS1
1503 #ifdef CONFIG_YAFFS_YAFFS2
1505 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1506 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1508 return yaffs_internal_read_super(2,sb,data,silent) ? 0 : -1;
1511 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1514 return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1517 static struct file_system_type yaffs2_fs_type = {
1518 .owner = THIS_MODULE,
1520 .get_sb = yaffs2_read_super,
1521 .kill_sb = kill_block_super,
1522 .fs_flags = FS_REQUIRES_DEV,
1525 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1527 return yaffs_internal_read_super(2,sb,data,silent);
1530 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1533 #endif // CONFIG_YAFFS_YAFFS2
1538 static struct proc_dir_entry *my_proc_entry;
1540 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev)
1542 buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1543 buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1544 buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1545 buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1546 buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1547 buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1548 buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1549 buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1550 buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1551 buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1552 buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1553 buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1554 buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1555 buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1556 buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1557 buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1558 buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1559 buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1560 buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1561 buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1562 buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1563 buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1564 buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1565 buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1566 buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1567 buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1568 buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1569 buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1574 static int yaffs_proc_read(
1583 struct list_head *item;
1588 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1589 * We use 'offset' (*ppos) to indicate where we are in devList.
1590 * This also assumes the user has posted a read buffer large
1591 * enough to hold the complete output; but that's life in /proc.
1596 /* Print header first */
1598 buf += sprintf(buf, "YAFFS built:" __DATE__ " "__TIME__
1599 "\n%s\n%s\n", yaffs_fs_c_version, yaffs_guts_c_version);
1602 /* hold lock_kernel while traversing yaffs_dev_list */
1605 /* Locate and print the Nth entry. Order N-squared but N is small. */
1606 list_for_each(item, &yaffs_dev_list) {
1607 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1612 buf += sprintf(buf,"\nDevice %d \"%s\"\n", n, dev->name);
1613 buf = yaffs_dump_dev(buf, dev);
1618 return buf-page < count ? buf-page : count;
1621 // Stuff to handle installation of file systems
1622 struct file_system_to_install
1624 struct file_system_type *fst;
1628 static struct file_system_to_install fs_to_install[] =
1630 #ifdef CONFIG_YAFFS_YAFFS1
1631 { &yaffs_fs_type,0},
1633 #ifdef CONFIG_YAFFS_YAFFS2
1634 { &yaffs2_fs_type,0},
1639 static int __init init_yaffs_fs(void)
1642 struct file_system_to_install *fsinst;
1644 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1648 /* Install the proc_fs entry */
1649 my_proc_entry = create_proc_read_entry("yaffs",
1661 // Now add the file system entries
1663 fsinst = fs_to_install;
1665 while(fsinst->fst && !error)
1667 error = register_filesystem(fsinst->fst);
1670 fsinst->installed = 1;
1675 // Any errors? uninstall
1678 fsinst = fs_to_install;
1682 if(fsinst->installed)
1684 unregister_filesystem(fsinst->fst);
1685 fsinst->installed = 0;
1694 static void __exit exit_yaffs_fs(void)
1697 struct file_system_to_install *fsinst;
1699 T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1701 remove_proc_entry("yaffs",&proc_root);
1703 fsinst = fs_to_install;
1707 if(fsinst->installed)
1709 unregister_filesystem(fsinst->fst);
1710 fsinst->installed = 0;
1717 module_init(init_yaffs_fs)
1718 module_exit(exit_yaffs_fs)
1720 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1721 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1722 MODULE_LICENSE("GPL");