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 O_APPEND patch.
24 * * Nick Bane for patches marked NCB.
25 * * Some code bodily lifted from JFFS2.
29 #include <linux/config.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/list.h>
37 #include <linux/proc_fs.h>
38 #include <linux/pagemap.h>
39 #include <linux/mtd/mtd.h>
40 #include <linux/interrupt.h>
41 #include <linux/string.h>
42 #include <linux/locks.h>
44 #include <asm/uaccess.h>
46 #include "yaffs_guts.h"
48 #ifdef YAFFS_RAM_ENABLED
49 #include "yaffs_nandemul.h"
50 // 2 MB of RAM for emulation
51 #define YAFFS_RAM_EMULATION_SIZE 0x200000
52 #endif //YAFFS_RAM_ENABLED
54 #ifdef YAFFS_MTD_ENABLED
55 #include <linux/mtd/mtd.h>
56 #include "yaffs_mtdif.h"
57 #endif //YAFFS_MTD_ENABLED
63 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
64 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
65 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
69 static void yaffs_put_super(struct super_block *sb);
71 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
72 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
74 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
76 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
78 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
79 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
80 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
81 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
82 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
83 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
84 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
85 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
86 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
88 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
89 static void yaffs_read_inode (struct inode *inode);
90 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
91 static void yaffs_put_inode (struct inode *inode);
92 static int yaffs_readpage(struct file *file, struct page * page);
94 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
95 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
97 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
98 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
104 static struct address_space_operations yaffs_file_address_operations = {
105 readpage: yaffs_readpage,
106 prepare_write: yaffs_prepare_write,
107 commit_write: yaffs_commit_write
111 static struct file_operations yaffs_file_operations = {
112 #if CONFIG_YAFFS_USE_GENERIC_RW
113 read: generic_file_read,
114 write: generic_file_write,
116 read: yaffs_file_read,
117 write: yaffs_file_write,
119 mmap: generic_file_mmap,
120 fsync: yaffs_sync_object,
124 static struct inode_operations yaffs_file_inode_operations = {
125 setattr: yaffs_setattr,
129 struct inode_operations yaffs_symlink_inode_operations =
131 readlink: yaffs_readlink,
132 follow_link: yaffs_follow_link,
133 setattr: yaffs_setattr
136 static struct inode_operations yaffs_dir_inode_operations = {
137 create: yaffs_create,
138 lookup: yaffs_lookup,
140 unlink: yaffs_unlink,
141 symlink: yaffs_symlink,
145 rename: yaffs_rename,
146 setattr: yaffs_setattr,
149 static struct file_operations yaffs_dir_operations = {
150 read: generic_read_dir,
151 readdir: yaffs_readdir,
152 fsync: yaffs_sync_object,
156 static struct super_operations yaffs_super_ops = {
157 statfs: yaffs_statfs,
158 read_inode: yaffs_read_inode,
159 put_inode: yaffs_put_inode,
160 put_super: yaffs_put_super,
170 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
172 unsigned char *alias;
175 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
180 ret = vfs_readlink(dentry, buffer, buflen, alias);
185 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
187 unsigned char *alias;
189 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
194 ret = vfs_follow_link(nd,alias);
200 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
203 * Lookup is used to find objects in the fs
205 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
211 T((KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
213 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
215 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
219 T((KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
221 inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj);
225 T((KERN_DEBUG"yaffs_loookup looks good\n"));
226 dget(dentry); // try to solve directory bug
234 T((KERN_DEBUG"yaffs_lookup not found\n"));
241 // For now put inode is just for debugging
242 static void yaffs_put_inode(struct inode *inode)
244 T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
246 yaffs_FlushFile(yaffs_InodeToObject(inode));
252 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
257 unsigned char *pg_buf;
260 T((KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
261 pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE));
263 obj = yaffs_DentryToObject(f->f_dentry);
271 /* FIXME: Can kmap fail? */
273 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
275 if(ret >= 0) ret = 0;
278 ClearPageUptodate(pg);
285 flush_dcache_page(pg);
292 T((KERN_DEBUG"yaffs_readpage done\n"));
296 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
298 int ret = yaffs_readpage_nolock(f,pg);
303 static int yaffs_readpage(struct file *f, struct page * pg)
305 return yaffs_readpage_unlock(f,pg);
309 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
312 T((KERN_DEBUG"yaffs_prepair_write\n"));
313 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
314 return yaffs_readpage_nolock(f,pg);
320 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
323 void *addr = page_address(pg) + offset;
324 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
325 int nBytes = to - offset;
329 unsigned saddr = addr;
331 T((KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
333 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
335 if(nWritten != nBytes)
337 T((KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
339 ClearPageUptodate(pg);
342 T((KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
344 return nWritten /* != nBytes ? -ENOMEM : 0 */ ;
350 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
354 inode->i_ino = obj->objectId;
355 inode->i_mode = obj->st_mode;
356 inode->i_uid = obj->st_uid;
357 inode->i_gid = obj->st_gid;
358 inode->i_blksize = inode->i_sb->s_blocksize;
360 inode->i_rdev = obj->st_rdev;;
361 inode->i_atime = obj->st_atime;
362 inode->i_mtime = obj->st_mtime;
363 inode->i_ctime = obj->st_ctime;
364 inode->i_size = yaffs_GetObjectFileLength(obj);
365 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
367 T((KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
368 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
370 switch (obj->st_mode & S_IFMT)
372 default: // fifo, device or socket
373 init_special_inode(inode, obj->st_mode, obj->st_rdev);
375 case S_IFREG: // file
376 inode->i_op = &yaffs_file_inode_operations;
377 inode->i_fop = &yaffs_file_operations;
378 inode->i_mapping->a_ops = &yaffs_file_address_operations;
380 case S_IFDIR: // directory
381 inode->i_op = &yaffs_dir_inode_operations;
382 inode->i_fop = &yaffs_dir_operations;
384 case S_IFLNK: // symlink
385 inode->i_op = &yaffs_symlink_inode_operations;
390 inode->u.generic_ip = obj;
395 T((KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
400 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
402 struct inode * inode;
404 T((KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
406 inode = iget(sb,obj->objectId);
408 // No need to call this since iget calls it via the read_inode callback
409 // yaffs_FillInodeFromObject(inode,obj);
414 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
420 T((KERN_DEBUG"yaffs_file_read\n"));
422 obj = yaffs_DentryToObject(f->f_dentry);
423 inode = f->f_dentry->d_inode;
425 if (*pos < inode->i_size)
427 if (*pos + n > inode->i_size)
429 n = inode->i_size - *pos;
437 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
443 T((KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
448 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
454 obj = yaffs_DentryToObject(f->f_dentry);
455 inode = f->f_dentry->d_inode;
457 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
459 ipos = inode->i_size;
469 T((KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
473 T((KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos));
476 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
478 T((KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
483 if(ipos > inode->i_size)
485 inode->i_size = ipos;
486 inode->i_blocks = (ipos + inode->i_blksize - 1)/ inode->i_blksize;
488 T((KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,inode->i_blocks));
496 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
499 struct inode *inode = f->f_dentry->d_inode;
500 unsigned long offset, curoffs;
504 char name[YAFFS_MAX_NAME_LENGTH +1];
506 obj = yaffs_DentryToObject(f->f_dentry);
510 T(("yaffs_readdir: starting at %d\n",(int)offset));
514 T((KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
515 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
524 T((KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
525 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
538 list_for_each(i,&obj->variant.directoryVariant.children)
541 if(curoffs >= offset)
543 l = list_entry(i, yaffs_Object,siblings);
545 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
546 T((KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
552 yaffs_GetObjectInode(l),
553 yaffs_GetObjectType(l))
574 * File creation. Allocate an inode, and we're done..
576 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev)
580 yaffs_Object *obj = NULL;
581 yaffs_Object *parent = yaffs_InodeToObject(dir);
587 T((KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
588 parent->objectId,parent->variantType));
592 T((KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
596 T(("yaffs_mknod: making oject for %s, mode %x dev %x\n",
597 dentry->d_name.name, mode,dev));
599 switch (mode & S_IFMT)
602 // Special (socket, fifo, device...)
603 T((KERN_DEBUG"yaffs_mknod: making special\n"));
604 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,dev);
606 case S_IFREG: // file
607 T((KERN_DEBUG"yaffs_mknod: making file\n"));
608 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
610 case S_IFDIR: // directory
611 T((KERN_DEBUG"yaffs_mknod: making directory\n"));
612 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
614 case S_IFLNK: // symlink
615 T((KERN_DEBUG"yaffs_mknod: making file\n"));
616 obj = NULL; // Do we ever get here?
622 inode = yaffs_get_inode(dir->i_sb, mode, dev, obj);
623 d_instantiate(dentry, inode);
624 T((KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
629 T((KERN_DEBUG"yaffs_mknod failed making object\n"));
637 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
640 T((KERN_DEBUG"yaffs_mkdir\n"));
641 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
643 // attempt to fix dir bug - didn't work
652 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
654 T((KERN_DEBUG"yaffs_create\n"));
655 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
659 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
662 T((KERN_DEBUG"yaffs_unlink\n"));
664 if(yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name) == YAFFS_OK)
678 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
680 struct inode *inode = old_dentry->d_inode;
681 yaffs_Object *obj = NULL;
682 yaffs_Object *link=NULL;
684 T((KERN_DEBUG"yaffs_link\n"));
686 obj = yaffs_InodeToObject(inode);
688 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
700 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
704 T((KERN_DEBUG"yaffs_symlink\n"));
706 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
707 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
712 T((KERN_DEBUG"symlink created OK\n"));
717 T((KERN_DEBUG"symlink not created\n"));
724 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
727 T((KERN_DEBUG"yaffs_sync_object\n"));
728 yaffs_FlushFile(yaffs_DentryToObject(dentry));
733 * The VFS layer already does all the dentry stuff for rename.
735 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
739 if( yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
740 yaffs_InodeToObject(new_dir),new_dentry->d_name.name) == YAFFS_OK)
752 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
754 struct inode *inode = dentry->d_inode;
757 T((KERN_DEBUG"yaffs_setattr\n"));
759 if((error = inode_change_ok(inode,attr)) == 0)
762 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
771 inode_setattr(inode,attr);
776 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
778 T((KERN_DEBUG"yaffs_statfs\n"));
780 buf->f_type = YAFFS_MAGIC;
781 buf->f_bsize = sb->s_blocksize;
782 buf->f_namelen = 255;
783 buf->f_blocks = yaffs_SuperToDevice(sb)->nBlocks * YAFFS_CHUNKS_PER_BLOCK/
784 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
787 buf->f_bfree = yaffs_GetNumberOfFreeChunks(yaffs_SuperToDevice(sb))/
788 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
789 buf->f_bavail = buf->f_bfree;
793 static void yaffs_read_inode (struct inode *inode)
798 T((KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
800 obj = yaffs_FindObjectByNumber(yaffs_SuperToDevice(inode->i_sb),inode->i_ino);
802 yaffs_FillInodeFromObject(inode,obj);
806 static void yaffs_put_super(struct super_block *sb)
808 yaffs_Device *dev = yaffs_SuperToDevice(sb);
810 if(dev->putSuperFunc)
812 dev->putSuperFunc(sb);
817 #ifdef YAFFS_MTD_ENABLED
819 static void yaffs_MTDPutSuper(struct super_block *sb)
822 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
834 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
836 struct inode * inode;
837 struct dentry * root;
840 sb->s_magic = YAFFS_MAGIC;
841 sb->s_op = &yaffs_super_ops;
844 printk(KERN_INFO"yaffs: sb is NULL\n");
846 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
847 else if(! kdevname(sb->s_dev))
848 printk(KERN_INFO"yaffs: kdevname is NULL\n");
850 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
854 #if CONFIG_YAFFS_USE_CHUNK_SIZE
855 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
856 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
858 sb->s_blocksize = PAGE_CACHE_SIZE;
859 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
861 T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",sb->s_blocksize));
867 #ifdef YAFFS_RAM_ENABLED
868 // Set the yaffs_Device up for ram emulation
870 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
873 // Deep shit could not allocate device structure
874 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
878 memset(dev,0,sizeof(yaffs_Device));
879 dev->genericDevice = NULL; // Not used for RAM emulation.
881 dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
882 dev->startBlock = 1; // Don't use block 0
883 dev->endBlock = dev->nBlocks - 1;
885 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
886 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
887 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
888 dev->initialiseNAND = nandemul_InitialiseNAND;
895 #ifdef YAFFS_MTD_ENABLED
896 struct mtd_info *mtd;
898 printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
899 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev));
901 // Hope it's a NAND mtd
902 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
905 printk(KERN_DEBUG "yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev));
909 if(mtd->type != MTD_NANDFLASH)
911 printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);
915 printk(KERN_DEBUG" erase %x\n",mtd->erase);
916 printk(KERN_DEBUG" read %x\n",mtd->read);
917 printk(KERN_DEBUG" write %x\n",mtd->write);
918 printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
919 printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
920 printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
921 printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
930 printk(KERN_DEBUG "yaffs: MTD device does not support required functions\n");
934 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
935 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
937 printk(KERN_DEBUG "yaffs: MTD device does not support have the right page sizes\n");
942 // OK, so if we got here, we have an MTD that's NAND and looks
943 // like it has the right capabilities
944 // Set the yaffs_Device up for ram emulation
946 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
949 // Deep shit could not allocate device structure
950 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
954 memset(dev,0,sizeof(yaffs_Device));
955 dev->genericDevice = mtd;
957 // Set up the memory size parameters....
959 // NCB dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
960 dev->nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
961 dev->startBlock = 1; // Don't use block 0
962 dev->endBlock = dev->nBlocks - 1;
964 // ... and the functions.
965 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
966 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
967 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
968 dev->initialiseNAND = nandmtd_InitialiseNAND;
970 dev->putSuperFunc = yaffs_MTDPutSuper;
976 yaffs_GutsInitialise(yaffs_SuperToDevice(sb));
977 T(("yaffs_read_super: guts initialised\n"));
980 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(yaffs_SuperToDevice(sb)));
984 T(("yaffs_read_super: got root inode\n"));
987 root = d_alloc_root(inode);
989 T(("yaffs_read_super: d_alloc_root done\n"));
997 T(("yaffs_read_super: done\n"));
1001 #ifdef YAFFS_MTD_ENABLED
1002 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1004 return yaffs_internal_read_super(0,sb,data,silent);
1007 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1010 #ifdef YAFFS_RAM_ENABLED
1012 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1014 return yaffs_internal_read_super(1,sb,data,silent);
1017 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1018 #endif // YAFFS_RAM_ENABLED
1021 static struct proc_dir_entry *my_proc_entry;
1024 static int yaffs_proc_read(
1034 static char my_buffer[1000];
1036 if (offset > 0) return 0;
1038 /* Fill the buffer and get its length */
1040 "YAFFS built:"__DATE__ " "__TIME__"\n"
1044 strcpy(page,my_buffer);
1045 return strlen(my_buffer);
1048 static int __init init_yaffs_fs(void)
1052 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
1053 #if CONFIG_YAFFS_USE_GENERIC_RW
1054 printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
1056 printk(KERN_DEBUG "yaffs is using direct read/write (uncached)\n");
1060 /* Install the proc_fs entry */
1061 my_proc_entry = create_proc_read_entry("yaffs",
1071 #ifdef YAFFS_RAM_ENABLED
1073 error = register_filesystem(&yaffs_ram_fs_type);
1078 #endif //YAFFS_RAM_ENABLED
1080 #ifdef YAFFS_MTD_ENABLED
1081 error = register_filesystem(&yaffs_fs_type);
1084 #ifdef YAFFS_RAM_ENABLED
1085 unregister_filesystem(&yaffs_ram_fs_type);
1086 #endif //YAFFS_RAM_ENABLED
1088 #endif // YAFFS_MTD_ENABLED
1093 static void __exit exit_yaffs_fs(void)
1095 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Clean up\n");
1097 remove_proc_entry("yaffs",&proc_root);
1099 #ifdef YAFFS_RAM_ENABLED
1100 unregister_filesystem(&yaffs_ram_fs_type);
1102 #ifdef YAFFS_MTD_ENABLED
1103 unregister_filesystem(&yaffs_fs_type);
1108 module_init(init_yaffs_fs)
1109 module_exit(exit_yaffs_fs)
1111 MODULE_DESCRIPTION("YAFFS - a NAND specific flash file system");
1112 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002");
1113 MODULE_LICENSE("GPL");