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 #ifdef 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));
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));
449 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
455 obj = yaffs_DentryToObject(f->f_dentry);
456 inode = f->f_dentry->d_inode;
458 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
460 ipos = inode->i_size;
470 T((KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
474 T((KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos));
477 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
479 T((KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
484 if(ipos > inode->i_size)
486 inode->i_size = ipos;
487 inode->i_blocks = (ipos + inode->i_blksize - 1)/ inode->i_blksize;
489 T((KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,inode->i_blocks));
493 return nWritten != n ? -ENOSPC : nWritten;
497 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
500 struct inode *inode = f->f_dentry->d_inode;
501 unsigned long offset, curoffs;
505 char name[YAFFS_MAX_NAME_LENGTH +1];
507 obj = yaffs_DentryToObject(f->f_dentry);
511 T(("yaffs_readdir: starting at %d\n",(int)offset));
515 T((KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
516 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
525 T((KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
526 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
539 list_for_each(i,&obj->variant.directoryVariant.children)
542 if(curoffs >= offset)
544 l = list_entry(i, yaffs_Object,siblings);
546 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
547 T((KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
553 yaffs_GetObjectInode(l),
554 yaffs_GetObjectType(l))
575 * File creation. Allocate an inode, and we're done..
577 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev)
581 yaffs_Object *obj = NULL;
582 yaffs_Object *parent = yaffs_InodeToObject(dir);
588 T((KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
589 parent->objectId,parent->variantType));
593 T((KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
597 T(("yaffs_mknod: making oject for %s, mode %x dev %x\n",
598 dentry->d_name.name, mode,dev));
600 switch (mode & S_IFMT)
603 // Special (socket, fifo, device...)
604 T((KERN_DEBUG"yaffs_mknod: making special\n"));
605 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,dev);
607 case S_IFREG: // file
608 T((KERN_DEBUG"yaffs_mknod: making file\n"));
609 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
611 case S_IFDIR: // directory
612 T((KERN_DEBUG"yaffs_mknod: making directory\n"));
613 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
615 case S_IFLNK: // symlink
616 T((KERN_DEBUG"yaffs_mknod: making file\n"));
617 obj = NULL; // Do we ever get here?
623 inode = yaffs_get_inode(dir->i_sb, mode, dev, obj);
624 d_instantiate(dentry, inode);
625 T((KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
630 T((KERN_DEBUG"yaffs_mknod failed making object\n"));
638 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
641 T((KERN_DEBUG"yaffs_mkdir\n"));
642 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
644 // attempt to fix dir bug - didn't work
653 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
655 T((KERN_DEBUG"yaffs_create\n"));
656 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
660 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
663 T((KERN_DEBUG"yaffs_unlink\n"));
665 if(yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name) == YAFFS_OK)
679 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
681 struct inode *inode = old_dentry->d_inode;
682 yaffs_Object *obj = NULL;
683 yaffs_Object *link=NULL;
685 T((KERN_DEBUG"yaffs_link\n"));
687 obj = yaffs_InodeToObject(inode);
689 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
701 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
705 T((KERN_DEBUG"yaffs_symlink\n"));
707 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
708 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
713 T((KERN_DEBUG"symlink created OK\n"));
718 T((KERN_DEBUG"symlink not created\n"));
725 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
728 T((KERN_DEBUG"yaffs_sync_object\n"));
729 yaffs_FlushFile(yaffs_DentryToObject(dentry));
734 * The VFS layer already does all the dentry stuff for rename.
736 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
740 if( yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
741 yaffs_InodeToObject(new_dir),new_dentry->d_name.name) == YAFFS_OK)
753 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
755 struct inode *inode = dentry->d_inode;
758 T((KERN_DEBUG"yaffs_setattr\n"));
760 if((error = inode_change_ok(inode,attr)) == 0)
763 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
772 inode_setattr(inode,attr);
777 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
779 T((KERN_DEBUG"yaffs_statfs\n"));
781 buf->f_type = YAFFS_MAGIC;
782 buf->f_bsize = sb->s_blocksize;
783 buf->f_namelen = 255;
784 buf->f_blocks = yaffs_SuperToDevice(sb)->nBlocks * YAFFS_CHUNKS_PER_BLOCK/
785 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
788 buf->f_bfree = yaffs_GetNumberOfFreeChunks(yaffs_SuperToDevice(sb))/
789 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
790 buf->f_bavail = buf->f_bfree;
794 static void yaffs_read_inode (struct inode *inode)
799 T((KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
801 obj = yaffs_FindObjectByNumber(yaffs_SuperToDevice(inode->i_sb),inode->i_ino);
803 yaffs_FillInodeFromObject(inode,obj);
807 static void yaffs_put_super(struct super_block *sb)
809 yaffs_Device *dev = yaffs_SuperToDevice(sb);
811 if(dev->putSuperFunc)
813 dev->putSuperFunc(sb);
818 #ifdef YAFFS_MTD_ENABLED
820 static void yaffs_MTDPutSuper(struct super_block *sb)
823 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
835 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
837 struct inode * inode;
838 struct dentry * root;
841 sb->s_magic = YAFFS_MAGIC;
842 sb->s_op = &yaffs_super_ops;
845 printk(KERN_INFO"yaffs: sb is NULL\n");
847 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
848 else if(! kdevname(sb->s_dev))
849 printk(KERN_INFO"yaffs: kdevname is NULL\n");
851 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
855 #if CONFIG_YAFFS_USE_CHUNK_SIZE
856 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
857 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
859 sb->s_blocksize = PAGE_CACHE_SIZE;
860 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
862 T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",sb->s_blocksize));
868 #ifdef YAFFS_RAM_ENABLED
869 // Set the yaffs_Device up for ram emulation
871 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
874 // Deep shit could not allocate device structure
875 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
879 memset(dev,0,sizeof(yaffs_Device));
880 dev->genericDevice = NULL; // Not used for RAM emulation.
882 dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
883 dev->startBlock = 1; // Don't use block 0
884 dev->endBlock = dev->nBlocks - 1;
886 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
887 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
888 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
889 dev->initialiseNAND = nandemul_InitialiseNAND;
896 #ifdef YAFFS_MTD_ENABLED
897 struct mtd_info *mtd;
899 printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
900 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev));
902 // Hope it's a NAND mtd
903 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
906 printk(KERN_DEBUG "yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev));
910 if(mtd->type != MTD_NANDFLASH)
912 printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);
916 printk(KERN_DEBUG" erase %x\n",mtd->erase);
917 printk(KERN_DEBUG" read %x\n",mtd->read);
918 printk(KERN_DEBUG" write %x\n",mtd->write);
919 printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
920 printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
921 printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
922 printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
931 printk(KERN_DEBUG "yaffs: MTD device does not support required functions\n");
935 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
936 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
938 printk(KERN_DEBUG "yaffs: MTD device does not support have the right page sizes\n");
943 // OK, so if we got here, we have an MTD that's NAND and looks
944 // like it has the right capabilities
945 // Set the yaffs_Device up for ram emulation
947 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
950 // Deep shit could not allocate device structure
951 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
955 memset(dev,0,sizeof(yaffs_Device));
956 dev->genericDevice = mtd;
958 // Set up the memory size parameters....
960 // NCB dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
961 dev->nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
962 dev->startBlock = 1; // Don't use block 0
963 dev->endBlock = dev->nBlocks - 1;
965 // ... and the functions.
966 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
967 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
968 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
969 dev->initialiseNAND = nandmtd_InitialiseNAND;
971 dev->putSuperFunc = yaffs_MTDPutSuper;
977 yaffs_GutsInitialise(yaffs_SuperToDevice(sb));
978 T(("yaffs_read_super: guts initialised\n"));
981 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(yaffs_SuperToDevice(sb)));
985 T(("yaffs_read_super: got root inode\n"));
988 root = d_alloc_root(inode);
990 T(("yaffs_read_super: d_alloc_root done\n"));
998 T(("yaffs_read_super: done\n"));
1002 #ifdef YAFFS_MTD_ENABLED
1003 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1005 return yaffs_internal_read_super(0,sb,data,silent);
1008 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1011 #ifdef YAFFS_RAM_ENABLED
1013 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1015 return yaffs_internal_read_super(1,sb,data,silent);
1018 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1019 #endif // YAFFS_RAM_ENABLED
1022 static struct proc_dir_entry *my_proc_entry;
1025 static int yaffs_proc_read(
1035 static char my_buffer[1000];
1037 if (offset > 0) return 0;
1039 /* Fill the buffer and get its length */
1041 "YAFFS built:"__DATE__ " "__TIME__"\n"
1045 strcpy(page,my_buffer);
1046 return strlen(my_buffer);
1049 static int __init init_yaffs_fs(void)
1053 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
1054 #if CONFIG_YAFFS_USE_GENERIC_RW
1055 printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
1057 printk(KERN_DEBUG "yaffs is using direct read/write (uncached)\n");
1061 /* Install the proc_fs entry */
1062 my_proc_entry = create_proc_read_entry("yaffs",
1072 #ifdef YAFFS_RAM_ENABLED
1074 error = register_filesystem(&yaffs_ram_fs_type);
1079 #endif //YAFFS_RAM_ENABLED
1081 #ifdef YAFFS_MTD_ENABLED
1082 error = register_filesystem(&yaffs_fs_type);
1085 #ifdef YAFFS_RAM_ENABLED
1086 unregister_filesystem(&yaffs_ram_fs_type);
1087 #endif //YAFFS_RAM_ENABLED
1089 #endif // YAFFS_MTD_ENABLED
1094 static void __exit exit_yaffs_fs(void)
1096 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Clean up\n");
1098 remove_proc_entry("yaffs",&proc_root);
1100 #ifdef YAFFS_RAM_ENABLED
1101 unregister_filesystem(&yaffs_ram_fs_type);
1103 #ifdef YAFFS_MTD_ENABLED
1104 unregister_filesystem(&yaffs_fs_type);
1109 module_init(init_yaffs_fs)
1110 module_exit(exit_yaffs_fs)
1112 MODULE_DESCRIPTION("YAFFS - a NAND specific flash file system");
1113 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002");
1114 MODULE_LICENSE("GPL");