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 CONFIG_YAFFS_RAM_ENABLED
49 #include "yaffs_nandemul.h"
50 // 2 MB of RAM for emulation
51 #define YAFFS_RAM_EMULATION_SIZE 0x200000
52 #endif //CONFIG_YAFFS_RAM_ENABLED
54 #ifdef CONFIG_YAFFS_MTD_ENABLED
55 #include <linux/mtd/mtd.h>
56 #include "yaffs_mtdif.h"
57 #endif //CONFIG_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);
73 static int yaffs_file_flush(struct file* file);
75 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
77 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
79 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
80 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
81 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
82 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
83 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
84 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
85 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
86 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
87 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
89 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
90 static void yaffs_read_inode (struct inode *inode);
91 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
92 static void yaffs_put_inode (struct inode *inode);
93 static int yaffs_readpage(struct file *file, struct page * page);
95 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
96 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
98 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
99 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
105 static struct address_space_operations yaffs_file_address_operations = {
106 readpage: yaffs_readpage,
107 prepare_write: yaffs_prepare_write,
108 commit_write: yaffs_commit_write
112 static struct file_operations yaffs_file_operations = {
113 #ifdef CONFIG_YAFFS_USE_GENERIC_RW
114 read: generic_file_read,
115 write: generic_file_write,
117 read: yaffs_file_read,
118 write: yaffs_file_write,
120 mmap: generic_file_mmap,
121 flush: yaffs_file_flush,
122 fsync: yaffs_sync_object,
126 static struct inode_operations yaffs_file_inode_operations = {
127 setattr: yaffs_setattr,
131 struct inode_operations yaffs_symlink_inode_operations =
133 readlink: yaffs_readlink,
134 follow_link: yaffs_follow_link,
135 setattr: yaffs_setattr
138 static struct inode_operations yaffs_dir_inode_operations = {
139 create: yaffs_create,
140 lookup: yaffs_lookup,
142 unlink: yaffs_unlink,
143 symlink: yaffs_symlink,
147 rename: yaffs_rename,
148 setattr: yaffs_setattr,
151 static struct file_operations yaffs_dir_operations = {
152 read: generic_read_dir,
153 readdir: yaffs_readdir,
154 fsync: yaffs_sync_object,
158 static struct super_operations yaffs_super_ops = {
159 statfs: yaffs_statfs,
160 read_inode: yaffs_read_inode,
161 put_inode: yaffs_put_inode,
162 put_super: yaffs_put_super,
172 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
174 unsigned char *alias;
177 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
182 ret = vfs_readlink(dentry, buffer, buflen, alias);
187 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
189 unsigned char *alias;
191 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
196 ret = vfs_follow_link(nd,alias);
202 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
205 * Lookup is used to find objects in the fs
207 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
213 T((KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
215 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
217 obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
221 T((KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
223 inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj);
227 T((KERN_DEBUG"yaffs_loookup looks good\n"));
228 dget(dentry); // try to solve directory bug
236 T((KERN_DEBUG"yaffs_lookup not found\n"));
243 // For now put inode is just for debugging
244 static void yaffs_put_inode(struct inode *inode)
246 T(("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
248 // yaffs_FlushFile(yaffs_InodeToObject(inode));
253 static int yaffs_file_flush(struct file* file)
255 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
257 T((KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
258 obj->dirty ? "dirty" : "clean"));
260 yaffs_FlushFile(obj);
267 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
272 unsigned char *pg_buf;
275 T((KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
276 pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE));
278 obj = yaffs_DentryToObject(f->f_dentry);
286 /* FIXME: Can kmap fail? */
288 ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
290 if(ret >= 0) ret = 0;
293 ClearPageUptodate(pg);
300 flush_dcache_page(pg);
307 T((KERN_DEBUG"yaffs_readpage done\n"));
311 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
313 int ret = yaffs_readpage_nolock(f,pg);
318 static int yaffs_readpage(struct file *f, struct page * pg)
320 return yaffs_readpage_unlock(f,pg);
324 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
327 T((KERN_DEBUG"yaffs_prepair_write\n"));
328 if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
329 return yaffs_readpage_nolock(f,pg);
335 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
338 void *addr = page_address(pg) + offset;
339 loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
340 int nBytes = to - offset;
344 unsigned saddr = addr;
346 T((KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
348 nWritten = yaffs_file_write(f,addr, nBytes, &pos);
350 if(nWritten != nBytes)
352 T((KERN_DEBUG"yaffs_commit_write not same size nWritten %d nBytes %d\n",nWritten,nBytes));
354 ClearPageUptodate(pg);
361 T((KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
369 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
373 inode->i_ino = obj->objectId;
374 inode->i_mode = obj->st_mode;
375 inode->i_uid = obj->st_uid;
376 inode->i_gid = obj->st_gid;
377 inode->i_blksize = inode->i_sb->s_blocksize;
379 inode->i_rdev = obj->st_rdev;;
380 inode->i_atime = obj->st_atime;
381 inode->i_mtime = obj->st_mtime;
382 inode->i_ctime = obj->st_ctime;
383 inode->i_size = yaffs_GetObjectFileLength(obj);
384 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
386 T((KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
387 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
389 switch (obj->st_mode & S_IFMT)
391 default: // fifo, device or socket
392 init_special_inode(inode, obj->st_mode, obj->st_rdev);
394 case S_IFREG: // file
395 inode->i_op = &yaffs_file_inode_operations;
396 inode->i_fop = &yaffs_file_operations;
397 inode->i_mapping->a_ops = &yaffs_file_address_operations;
399 case S_IFDIR: // directory
400 inode->i_op = &yaffs_dir_inode_operations;
401 inode->i_fop = &yaffs_dir_operations;
403 case S_IFLNK: // symlink
404 inode->i_op = &yaffs_symlink_inode_operations;
409 inode->u.generic_ip = obj;
414 T((KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
419 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
421 struct inode * inode;
423 T((KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
425 inode = iget(sb,obj->objectId);
427 // No need to call this since iget calls it via the read_inode callback
428 // yaffs_FillInodeFromObject(inode,obj);
433 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
439 T((KERN_DEBUG"yaffs_file_read\n"));
441 obj = yaffs_DentryToObject(f->f_dentry);
442 inode = f->f_dentry->d_inode;
444 if (*pos < inode->i_size)
446 if (*pos + n > inode->i_size)
448 n = inode->i_size - *pos;
456 nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
462 T((KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
468 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
474 obj = yaffs_DentryToObject(f->f_dentry);
475 inode = f->f_dentry->d_inode;
477 if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
479 ipos = inode->i_size;
489 T((KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
493 T((KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos));
496 nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n);
498 T((KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
503 if(ipos > inode->i_size)
505 inode->i_size = ipos;
506 inode->i_blocks = (ipos + inode->i_blksize - 1)/ inode->i_blksize;
508 T((KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,inode->i_blocks));
512 return nWritten != n ? -ENOSPC : nWritten;
516 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
519 struct inode *inode = f->f_dentry->d_inode;
520 unsigned long offset, curoffs;
524 char name[YAFFS_MAX_NAME_LENGTH +1];
526 obj = yaffs_DentryToObject(f->f_dentry);
530 T(("yaffs_readdir: starting at %d\n",(int)offset));
534 T((KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
535 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
544 T((KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
545 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
558 list_for_each(i,&obj->variant.directoryVariant.children)
561 if(curoffs >= offset)
563 l = list_entry(i, yaffs_Object,siblings);
565 yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1);
566 T((KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
572 yaffs_GetObjectInode(l),
573 yaffs_GetObjectType(l))
594 * File creation. Allocate an inode, and we're done..
596 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev)
600 yaffs_Object *obj = NULL;
601 yaffs_Object *parent = yaffs_InodeToObject(dir);
607 T((KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
608 parent->objectId,parent->variantType));
612 T((KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
616 T(("yaffs_mknod: making oject for %s, mode %x dev %x\n",
617 dentry->d_name.name, mode,dev));
619 switch (mode & S_IFMT)
622 // Special (socket, fifo, device...)
623 T((KERN_DEBUG"yaffs_mknod: making special\n"));
624 obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,dev);
626 case S_IFREG: // file
627 T((KERN_DEBUG"yaffs_mknod: making file\n"));
628 obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
630 case S_IFDIR: // directory
631 T((KERN_DEBUG"yaffs_mknod: making directory\n"));
632 obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
634 case S_IFLNK: // symlink
635 T((KERN_DEBUG"yaffs_mknod: making file\n"));
636 obj = NULL; // Do we ever get here?
642 inode = yaffs_get_inode(dir->i_sb, mode, dev, obj);
643 d_instantiate(dentry, inode);
644 T((KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
649 T((KERN_DEBUG"yaffs_mknod failed making object\n"));
657 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
660 T((KERN_DEBUG"yaffs_mkdir\n"));
661 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
663 // attempt to fix dir bug - didn't work
672 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
674 T((KERN_DEBUG"yaffs_create\n"));
675 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
679 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
682 T((KERN_DEBUG"yaffs_unlink %d:%s\n",dir->i_ino,dentry->d_name.name));
684 if(yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name) == YAFFS_OK)
698 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
700 struct inode *inode = old_dentry->d_inode;
701 yaffs_Object *obj = NULL;
702 yaffs_Object *link=NULL;
704 T((KERN_DEBUG"yaffs_link\n"));
706 obj = yaffs_InodeToObject(inode);
708 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
720 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
724 T((KERN_DEBUG"yaffs_symlink\n"));
726 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
727 S_IFLNK | S_IRWXUGO, current->uid, current->gid,
732 T((KERN_DEBUG"symlink created OK\n"));
737 T((KERN_DEBUG"symlink not created\n"));
744 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
747 T((KERN_DEBUG"yaffs_sync_object\n"));
748 yaffs_FlushFile(yaffs_DentryToObject(dentry));
753 * The VFS layer already does all the dentry stuff for rename.
755 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
759 if( yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
760 yaffs_InodeToObject(new_dir),new_dentry->d_name.name) == YAFFS_OK)
772 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
774 struct inode *inode = dentry->d_inode;
777 T((KERN_DEBUG"yaffs_setattr\n"));
779 if((error = inode_change_ok(inode,attr)) == 0)
782 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
791 inode_setattr(inode,attr);
796 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
798 T((KERN_DEBUG"yaffs_statfs\n"));
800 buf->f_type = YAFFS_MAGIC;
801 buf->f_bsize = sb->s_blocksize;
802 buf->f_namelen = 255;
803 buf->f_blocks = yaffs_SuperToDevice(sb)->nBlocks * YAFFS_CHUNKS_PER_BLOCK/
804 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
807 buf->f_bfree = yaffs_GetNumberOfFreeChunks(yaffs_SuperToDevice(sb))/
808 (sb->s_blocksize/YAFFS_BYTES_PER_CHUNK);
809 buf->f_bavail = buf->f_bfree;
813 static void yaffs_read_inode (struct inode *inode)
818 T((KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
820 obj = yaffs_FindObjectByNumber(yaffs_SuperToDevice(inode->i_sb),inode->i_ino);
822 yaffs_FillInodeFromObject(inode,obj);
826 static void yaffs_put_super(struct super_block *sb)
828 yaffs_Device *dev = yaffs_SuperToDevice(sb);
830 if(dev->putSuperFunc)
832 dev->putSuperFunc(sb);
837 #ifdef CONFIG_YAFFS_MTD_ENABLED
839 static void yaffs_MTDPutSuper(struct super_block *sb)
842 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
854 static struct super_block *yaffs_internal_read_super(int useRam, struct super_block * sb, void * data, int silent)
856 struct inode * inode;
857 struct dentry * root;
860 sb->s_magic = YAFFS_MAGIC;
861 sb->s_op = &yaffs_super_ops;
864 printk(KERN_INFO"yaffs: sb is NULL\n");
866 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
867 else if(! kdevname(sb->s_dev))
868 printk(KERN_INFO"yaffs: kdevname is NULL\n");
870 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
874 #if CONFIG_YAFFS_USE_CHUNK_SIZE
875 sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
876 sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
878 sb->s_blocksize = PAGE_CACHE_SIZE;
879 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
881 T(("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",sb->s_blocksize));
887 #ifdef CONFIG_YAFFS_RAM_ENABLED
888 // Set the yaffs_Device up for ram emulation
890 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
893 // Deep shit could not allocate device structure
894 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
898 memset(dev,0,sizeof(yaffs_Device));
899 dev->genericDevice = NULL; // Not used for RAM emulation.
901 dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
902 dev->startBlock = 1; // Don't use block 0
903 dev->endBlock = dev->nBlocks - 1;
905 dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
906 dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
907 dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
908 dev->initialiseNAND = nandemul_InitialiseNAND;
915 #ifdef CONFIG_YAFFS_MTD_ENABLED
916 struct mtd_info *mtd;
918 printk(KERN_DEBUG "yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
919 MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev));
921 // Hope it's a NAND mtd
922 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
925 printk(KERN_DEBUG "yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev));
929 if(mtd->type != MTD_NANDFLASH)
931 printk(KERN_DEBUG "yaffs: MTD device is not NAND it's type %d\n", mtd->type);
935 printk(KERN_DEBUG" erase %x\n",mtd->erase);
936 printk(KERN_DEBUG" read %x\n",mtd->read);
937 printk(KERN_DEBUG" write %x\n",mtd->write);
938 printk(KERN_DEBUG" readoob %x\n",mtd->read_oob);
939 printk(KERN_DEBUG" writeoob %x\n",mtd->write_oob);
940 printk(KERN_DEBUG" oobblock %x\n",mtd->oobblock);
941 printk(KERN_DEBUG" oobsize %x\n",mtd->oobsize);
950 printk(KERN_DEBUG "yaffs: MTD device does not support required functions\n");
954 if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
955 mtd->oobsize != YAFFS_BYTES_PER_SPARE)
957 printk(KERN_DEBUG "yaffs: MTD device does not support have the right page sizes\n");
962 // OK, so if we got here, we have an MTD that's NAND and looks
963 // like it has the right capabilities
964 // Set the yaffs_Device up for ram emulation
966 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
969 // Deep shit could not allocate device structure
970 printk(KERN_DEBUG"yaffs_read_super: Failed trying to allocate yaffs_Device. Terminating debug.\n");
974 memset(dev,0,sizeof(yaffs_Device));
975 dev->genericDevice = mtd;
977 // Set up the memory size parameters....
979 // NCB dev->nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
980 dev->nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
981 dev->startBlock = 1; // Don't use block 0
982 dev->endBlock = dev->nBlocks - 1;
984 // ... and the functions.
985 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
986 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
987 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
988 dev->initialiseNAND = nandmtd_InitialiseNAND;
990 dev->putSuperFunc = yaffs_MTDPutSuper;
996 yaffs_GutsInitialise(yaffs_SuperToDevice(sb));
997 T(("yaffs_read_super: guts initialised\n"));
1000 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(yaffs_SuperToDevice(sb)));
1004 T(("yaffs_read_super: got root inode\n"));
1007 root = d_alloc_root(inode);
1009 T(("yaffs_read_super: d_alloc_root done\n"));
1017 T(("yaffs_read_super: done\n"));
1021 #ifdef CONFIG_YAFFS_MTD_ENABLED
1022 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1024 return yaffs_internal_read_super(0,sb,data,silent);
1027 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1030 #ifdef CONFIG_YAFFS_RAM_ENABLED
1032 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1034 return yaffs_internal_read_super(1,sb,data,silent);
1037 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1038 #endif // CONFIG_YAFFS_RAM_ENABLED
1041 static struct proc_dir_entry *my_proc_entry;
1044 static int yaffs_proc_read(
1054 static char my_buffer[1000];
1056 if (offset > 0) return 0;
1058 /* Fill the buffer and get its length */
1060 "YAFFS built:"__DATE__ " "__TIME__"\n"
1064 strcpy(page,my_buffer);
1065 return strlen(my_buffer);
1068 static int __init init_yaffs_fs(void)
1072 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Initialisation\n");
1073 #if CONFIG_YAFFS_USE_GENERIC_RW
1074 printk(KERN_DEBUG "yaffs is using generic read/write (caching)\n");
1076 printk(KERN_DEBUG "yaffs is using direct read/write (uncached)\n");
1080 /* Install the proc_fs entry */
1081 my_proc_entry = create_proc_read_entry("yaffs",
1091 #ifdef CONFIG_YAFFS_RAM_ENABLED
1093 error = register_filesystem(&yaffs_ram_fs_type);
1098 #endif //CONFIG_YAFFS_RAM_ENABLED
1100 #ifdef CONFIG_YAFFS_MTD_ENABLED
1101 error = register_filesystem(&yaffs_fs_type);
1104 #ifdef CONFIG_YAFFS_RAM_ENABLED
1105 unregister_filesystem(&yaffs_ram_fs_type);
1106 #endif //CONFIG_YAFFS_RAM_ENABLED
1108 #endif // CONFIG_YAFFS_MTD_ENABLED
1113 static void __exit exit_yaffs_fs(void)
1115 printk(KERN_DEBUG "yaffs " __DATE__ " " __TIME__ " Clean up\n");
1117 remove_proc_entry("yaffs",&proc_root);
1119 #ifdef CONFIG_YAFFS_RAM_ENABLED
1120 unregister_filesystem(&yaffs_ram_fs_type);
1122 #ifdef CONFIG_YAFFS_MTD_ENABLED
1123 unregister_filesystem(&yaffs_fs_type);
1128 module_init(init_yaffs_fs)
1129 module_exit(exit_yaffs_fs)
1131 MODULE_DESCRIPTION("YAFFS - a NAND specific flash file system");
1132 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002");
1133 MODULE_LICENSE("GPL");