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
20 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this
22 * >> inode->u.generic_ip points to the associated yaffs_Object.
25 * * Luc van OostenRyck for numerous patches.
26 * * Nick Bane for numerous patches.
27 * * Nick Bane for 2.5/2.6 integration.
28 * * Andras Toth for mknod rdev issue.
29 * * Michael Fischer for finding the problem with inode inconsistency.
30 * * Some code bodily lifted from JFFS2.
33 const char *yaffs_fs_c_version =
34 "$Id: yaffs_fs.c,v 1.34 2005-11-14 21:00:54 charles Exp $";
35 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>
52 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
54 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
55 #include <asm/statfs.h>
56 #define UnlockPage(p) unlock_page(p)
57 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
59 /* FIXME: use sb->s_id instead ? */
60 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
64 #include <linux/locks.h>
65 #define BDEVNAME_SIZE 0
66 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
70 #include <asm/uaccess.h>
73 #include "yaffs_guts.h"
75 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS /* | 0xFFFFFFFF */;
77 #include <linux/mtd/mtd.h>
78 #include "yaffs_mtdif.h"
79 #include "yaffs_mtdif2.h"
81 /*#define T(x) printk x */
83 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
84 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
86 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
87 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
89 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
92 static void yaffs_put_super(struct super_block *sb);
94 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
97 static int yaffs_file_flush(struct file *file);
99 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
102 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
104 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
105 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
106 struct nameidata *n);
107 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
108 struct nameidata *n);
110 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
111 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
113 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
114 struct dentry *dentry);
115 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
116 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
117 const char *symname);
118 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
120 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
121 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
124 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
127 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
128 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,
149 unsigned offset, unsigned to);
150 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
153 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
155 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
156 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
158 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
161 static struct address_space_operations yaffs_file_address_operations = {
162 .readpage = yaffs_readpage,
163 .writepage = yaffs_writepage,
164 .prepare_write = yaffs_prepare_write,
165 .commit_write = yaffs_commit_write,
168 static struct file_operations yaffs_file_operations = {
169 .read = generic_file_read,
170 .write = generic_file_write,
171 .mmap = generic_file_mmap,
172 .flush = yaffs_file_flush,
173 .fsync = yaffs_sync_object,
176 static struct inode_operations yaffs_file_inode_operations = {
177 .setattr = yaffs_setattr,
180 static struct inode_operations yaffs_symlink_inode_operations = {
181 .readlink = yaffs_readlink,
182 .follow_link = yaffs_follow_link,
183 .setattr = yaffs_setattr,
186 static struct inode_operations yaffs_dir_inode_operations = {
187 .create = yaffs_create,
188 .lookup = yaffs_lookup,
190 .unlink = yaffs_unlink,
191 .symlink = yaffs_symlink,
192 .mkdir = yaffs_mkdir,
193 .rmdir = yaffs_unlink,
194 .mknod = yaffs_mknod,
195 .rename = yaffs_rename,
196 .setattr = yaffs_setattr,
199 static struct file_operations yaffs_dir_operations = {
200 .read = generic_read_dir,
201 .readdir = yaffs_readdir,
202 .fsync = yaffs_sync_object,
205 static struct super_operations yaffs_super_ops = {
206 .statfs = yaffs_statfs,
207 .read_inode = yaffs_read_inode,
208 .put_inode = yaffs_put_inode,
209 .put_super = yaffs_put_super,
210 .delete_inode = yaffs_delete_inode,
211 .clear_inode = yaffs_clear_inode,
214 static void yaffs_GrossLock(yaffs_Device * dev)
216 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
218 down(&dev->grossLock);
221 static void yaffs_GrossUnlock(yaffs_Device * dev)
223 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
228 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
231 unsigned char *alias;
234 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
236 yaffs_GrossLock(dev);
238 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
240 yaffs_GrossUnlock(dev);
245 ret = vfs_readlink(dentry, buffer, buflen, alias);
250 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
251 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
253 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
256 unsigned char *alias;
258 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
260 yaffs_GrossLock(dev);
262 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
264 yaffs_GrossUnlock(dev);
272 ret = vfs_follow_link(nd, alias);
275 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
276 return ERR_PTR (ret);
282 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
286 * Lookup is used to find objects in the fs
288 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
290 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
293 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
297 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
299 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
301 yaffs_GrossLock(dev);
304 (KERN_DEBUG "yaffs_lookup for %d:%s\n",
305 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
308 yaffs_FindObjectByName(yaffs_InodeToObject(dir),
309 dentry->d_name.name);
311 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
315 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
317 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
321 (KERN_DEBUG "yaffs_loookup dentry \n"));
322 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
323 * d_add even if NULL inode */
325 /*dget(dentry); // try to solve directory bug */
326 d_add(dentry, inode);
328 yaffs_GrossUnlock(dev);
336 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
339 yaffs_GrossUnlock(dev);
341 /* added NCB for 2.5/6 compatability - forces add even if inode is
342 * NULL which creates dentry hash */
343 d_add(dentry, inode);
346 /* return (ERR_PTR(-EIO)); */
350 /* For now put inode is just for debugging
351 * Put inode is called when the inode **structure** is put.
353 static void yaffs_put_inode(struct inode *inode)
356 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
357 atomic_read(&inode->i_count)));
361 /* clear is called to tell the fs to release any per-inode data it holds */
362 static void yaffs_clear_inode(struct inode *inode)
367 obj = yaffs_InodeToObject(inode);
370 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
371 atomic_read(&inode->i_count),
372 obj ? "object exists" : "null object"));
376 yaffs_GrossLock(dev);
378 /* Clear the association between the inode and
382 inode->u.generic_ip = NULL;
384 /* If the object freeing was deferred, then the real
386 * This should fix the inode inconsistency problem.
389 yaffs_HandleDeferedFree(obj);
391 yaffs_GrossUnlock(dev);
396 /* delete is called when the link count is zero and the inode
397 * is put (ie. nobody wants to know about it anymore, time to
399 * NB Must call clear_inode()
401 static void yaffs_delete_inode(struct inode *inode)
403 yaffs_Object *obj = yaffs_InodeToObject(inode);
407 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
408 atomic_read(&inode->i_count),
409 obj ? "object exists" : "null object"));
413 yaffs_GrossLock(dev);
414 yaffs_DeleteFile(obj);
415 yaffs_GrossUnlock(dev);
417 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
418 truncate_inode_pages (&inode->i_data, 0);
423 static int yaffs_file_flush(struct file *file)
425 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
427 yaffs_Device *dev = obj->myDev;
430 (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
431 obj->dirty ? "dirty" : "clean"));
433 yaffs_GrossLock(dev);
435 yaffs_FlushFile(obj, 1);
437 yaffs_GrossUnlock(dev);
442 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
444 /* Lifted from jffs2 */
447 unsigned char *pg_buf;
452 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
453 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
454 (unsigned)PAGE_CACHE_SIZE));
456 obj = yaffs_DentryToObject(f->f_dentry);
460 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
461 BUG_ON(!PageLocked(pg));
468 /* FIXME: Can kmap fail? */
470 yaffs_GrossLock(dev);
473 yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
476 yaffs_GrossUnlock(dev);
482 ClearPageUptodate(pg);
489 flush_dcache_page(pg);
492 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
496 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
498 int ret = yaffs_readpage_nolock(f, pg);
503 static int yaffs_readpage(struct file *f, struct page *pg)
505 return yaffs_readpage_unlock(f, pg);
508 /* writepage inspired by/stolen from smbfs */
510 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
511 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
513 static int yaffs_writepage(struct page *page)
516 struct address_space *mapping = page->mapping;
517 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
519 unsigned long end_index;
527 inode = mapping->host;
531 if (offset > inode->i_size) {
534 "yaffs_writepage at %08x, inode size = %08x!!!\n",
535 (unsigned)(page->index << PAGE_CACHE_SHIFT),
536 (unsigned)inode->i_size));
538 (KERN_DEBUG " -> don't care!!\n"));
543 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
546 if (page->index < end_index) {
547 nBytes = PAGE_CACHE_SIZE;
549 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
556 obj = yaffs_InodeToObject(inode);
557 yaffs_GrossLock(obj->myDev);
560 (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
561 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
563 (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
564 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
567 yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
571 (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
572 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
574 yaffs_GrossUnlock(obj->myDev);
577 SetPageUptodate(page);
581 return (nWritten == nBytes) ? 0 : -ENOSPC;
584 static int yaffs_prepare_write(struct file *f, struct page *pg,
585 unsigned offset, unsigned to)
588 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
589 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
590 return yaffs_readpage_nolock(f, pg);
596 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
600 void *addr = page_address(pg) + offset;
601 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
602 int nBytes = to - offset;
606 unsigned saddr = (unsigned)addr;
609 (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
612 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
614 if (nWritten != nBytes) {
617 "yaffs_commit_write not same size nWritten %d nBytes %d\n",
620 ClearPageUptodate(pg);
626 (KERN_DEBUG "yaffs_commit_write returning %d\n",
627 nWritten == nBytes ? 0 : -1));
629 return nWritten == nBytes ? 0 : -1;
633 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
636 inode->i_ino = obj->objectId;
637 inode->i_mode = obj->yst_mode;
638 inode->i_uid = obj->yst_uid;
639 inode->i_gid = obj->yst_gid;
640 inode->i_blksize = inode->i_sb->s_blocksize;
641 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
643 inode->i_rdev = old_decode_dev(obj->yst_rdev);
644 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
645 inode->i_atime.tv_nsec = 0;
646 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
647 inode->i_mtime.tv_nsec = 0;
648 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
649 inode->i_ctime.tv_nsec = 0;
651 inode->i_rdev = obj->yst_rdev;
652 inode->i_atime = obj->yst_atime;
653 inode->i_mtime = obj->yst_mtime;
654 inode->i_ctime = obj->yst_ctime;
656 inode->i_size = yaffs_GetObjectFileLength(obj);
657 inode->i_blocks = (inode->i_size + 511) >> 9;
659 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
663 "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
664 inode->i_mode, inode->i_uid, inode->i_gid,
665 (int)inode->i_size, atomic_read(&inode->i_count)));
667 switch (obj->yst_mode & S_IFMT) {
668 default: /* fifo, device or socket */
669 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
670 init_special_inode(inode, obj->yst_mode,
671 old_decode_dev(obj->yst_rdev));
673 init_special_inode(inode, obj->yst_mode,
674 (dev_t) (obj->yst_rdev));
677 case S_IFREG: /* file */
678 inode->i_op = &yaffs_file_inode_operations;
679 inode->i_fop = &yaffs_file_operations;
680 inode->i_mapping->a_ops =
681 &yaffs_file_address_operations;
683 case S_IFDIR: /* directory */
684 inode->i_op = &yaffs_dir_inode_operations;
685 inode->i_fop = &yaffs_dir_operations;
687 case S_IFLNK: /* symlink */
688 inode->i_op = &yaffs_symlink_inode_operations;
692 inode->u.generic_ip = obj;
693 obj->myInode = inode;
697 (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
702 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
709 (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
716 (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
722 (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
724 inode = iget(sb, obj->objectId);
726 /* NB Side effect: iget calls back to yaffs_read_inode(). */
727 /* iget also increments the inode's i_count */
732 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
740 obj = yaffs_DentryToObject(f->f_dentry);
744 yaffs_GrossLock(dev);
746 inode = f->f_dentry->d_inode;
748 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
749 ipos = inode->i_size;
756 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
760 "yaffs_file_write about to write writing %d bytes"
761 "to object %d at %d\n",
762 n, obj->objectId, ipos));
765 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
768 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
773 if (ipos > inode->i_size) {
774 inode->i_size = ipos;
775 inode->i_blocks = (ipos + 511) >> 9;
779 "yaffs_file_write size updated to %d bytes, "
781 ipos, (int)(inode->i_blocks)));
785 yaffs_GrossUnlock(dev);
787 return nWritten != n ? -ENOSPC : nWritten;
790 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
794 struct inode *inode = f->f_dentry->d_inode;
795 unsigned long offset, curoffs;
799 char name[YAFFS_MAX_NAME_LENGTH + 1];
801 obj = yaffs_DentryToObject(f->f_dentry);
804 yaffs_GrossLock(dev);
808 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
812 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
814 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
823 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
824 (int)f->f_dentry->d_parent->d_inode->i_ino));
826 (dirent, "..", 2, offset,
827 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
836 list_for_each(i, &obj->variant.directoryVariant.children) {
838 if (curoffs >= offset) {
839 l = list_entry(i, yaffs_Object, siblings);
841 yaffs_GetObjectName(l, name,
842 YAFFS_MAX_NAME_LENGTH + 1);
844 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
845 yaffs_GetObjectInode(l)));
851 yaffs_GetObjectInode(l),
852 yaffs_GetObjectType(l))
865 yaffs_GrossUnlock(dev);
871 * File creation. Allocate an inode, and we're done..
873 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
874 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
877 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
883 yaffs_Object *obj = NULL;
886 yaffs_Object *parent = yaffs_InodeToObject(dir);
889 uid_t uid = current->fsuid;
890 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
894 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
895 parent->objectId, parent->variantType));
898 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
902 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
904 dentry->d_name.name, mode, rdev));
908 yaffs_GrossLock(dev);
910 switch (mode & S_IFMT) {
912 /* Special (socket, fifo, device...) */
913 T(YAFFS_TRACE_OS, (KERN_DEBUG
914 "yaffs_mknod: making special\n"));
915 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
917 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
918 gid, old_encode_dev(rdev));
921 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
925 case S_IFREG: /* file */
926 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
928 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
931 case S_IFDIR: /* directory */
933 (KERN_DEBUG "yaffs_mknod: making directory\n"));
935 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
938 case S_IFLNK: /* symlink */
939 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
940 obj = NULL; /* Do we ever get here? */
945 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
946 d_instantiate(dentry, inode);
948 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
949 obj->objectId, atomic_read(&inode->i_count)));
953 (KERN_DEBUG "yaffs_mknod failed making object\n"));
957 yaffs_GrossUnlock(dev);
962 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
965 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
966 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
968 /* attempt to fix dir bug - didn't work */
976 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
977 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
980 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
983 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
984 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
987 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
994 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
995 dentry->d_name.name));
997 dev = yaffs_InodeToObject(dir)->myDev;
999 yaffs_GrossLock(dev);
1001 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1003 yaffs_GrossUnlock(dev);
1005 if (retVal == YAFFS_OK) {
1006 dentry->d_inode->i_nlink--;
1007 mark_inode_dirty(dentry->d_inode);
1017 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1018 struct dentry *dentry)
1020 struct inode *inode = old_dentry->d_inode;
1021 yaffs_Object *obj = NULL;
1022 yaffs_Object *link = NULL;
1025 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1027 obj = yaffs_InodeToObject(inode);
1030 yaffs_GrossLock(dev);
1032 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1035 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1040 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1041 d_instantiate(dentry, old_dentry->d_inode);
1042 atomic_inc(&old_dentry->d_inode->i_count);
1044 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1045 old_dentry->d_inode->i_nlink,
1046 atomic_read(&old_dentry->d_inode->i_count)));
1050 yaffs_GrossUnlock(dev);
1060 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1061 const char *symname)
1065 uid_t uid = current->fsuid;
1066 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1068 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1070 dev = yaffs_InodeToObject(dir)->myDev;
1071 yaffs_GrossLock(dev);
1072 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1073 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1074 yaffs_GrossUnlock(dev);
1078 struct inode *inode;
1080 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1081 d_instantiate(dentry, inode);
1082 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1085 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1092 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1099 obj = yaffs_DentryToObject(dentry);
1103 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1104 yaffs_GrossLock(dev);
1105 yaffs_FlushFile(obj, 1);
1106 yaffs_GrossUnlock(dev);
1111 * The VFS layer already does all the dentry stuff for rename.
1113 * NB: POSIX says you can rename an object over an old object of the same name
1115 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1116 struct inode *new_dir, struct dentry *new_dentry)
1119 int retVal = YAFFS_FAIL;
1120 yaffs_Object *target;
1122 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1123 dev = yaffs_InodeToObject(old_dir)->myDev;
1125 yaffs_GrossLock(dev);
1127 /* Check if the target is an existing directory that is not empty. */
1129 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1130 new_dentry->d_name.name);
1135 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1136 !list_empty(&target->variant.directoryVariant.children)) {
1138 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1140 retVal = YAFFS_FAIL;
1143 /* Now does unlinking internally using shadowing mechanism */
1144 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1147 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1148 old_dentry->d_name.name,
1149 yaffs_InodeToObject(new_dir),
1150 new_dentry->d_name.name);
1153 yaffs_GrossUnlock(dev);
1155 if (retVal == YAFFS_OK) {
1157 new_dentry->d_inode->i_nlink--;
1158 mark_inode_dirty(new_dentry->d_inode);
1168 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1170 struct inode *inode = dentry->d_inode;
1175 (KERN_DEBUG "yaffs_setattr of object %d\n",
1176 yaffs_InodeToObject(inode)->objectId));
1178 if ((error = inode_change_ok(inode, attr)) == 0) {
1180 dev = yaffs_InodeToObject(inode)->myDev;
1181 yaffs_GrossLock(dev);
1182 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1188 yaffs_GrossUnlock(dev);
1190 error = inode_setattr(inode, attr);
1195 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1196 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1198 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1202 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1203 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1205 yaffs_GrossLock(dev);
1207 buf->f_type = YAFFS_MAGIC;
1208 buf->f_bsize = sb->s_blocksize;
1209 buf->f_namelen = 255;
1210 if (sb->s_blocksize > dev->nBytesPerChunk) {
1213 (dev->endBlock - dev->startBlock +
1214 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1215 dev->nBytesPerChunk);
1217 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1218 dev->nBytesPerChunk);
1222 (dev->endBlock - dev->startBlock +
1223 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1226 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1231 buf->f_bavail = buf->f_bfree;
1233 yaffs_GrossUnlock(dev);
1237 static void yaffs_read_inode(struct inode *inode)
1239 /* NB This is called as a side effect of other functions and
1240 * thus gross locking should always be in place already.
1244 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1247 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1249 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1251 yaffs_FillInodeFromObject(inode, obj);
1255 static LIST_HEAD(yaffs_dev_list);
1257 static void yaffs_put_super(struct super_block *sb)
1259 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1261 yaffs_GrossLock(dev);
1262 if (dev->putSuperFunc) {
1263 dev->putSuperFunc(sb);
1265 yaffs_Deinitialise(dev);
1266 yaffs_GrossUnlock(dev);
1268 /* we assume this is protected by lock_kernel() in mount/umount */
1269 list_del(&dev->devList);
1275 static void yaffs_MTDPutSuper(struct super_block *sb)
1278 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1284 put_mtd_device(mtd);
1288 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1289 struct super_block *sb,
1290 void *data, int silent)
1293 struct inode *inode = NULL;
1294 struct dentry *root;
1295 yaffs_Device *dev = 0;
1296 char devname_buf[BDEVNAME_SIZE + 1];
1297 struct mtd_info *mtd;
1300 sb->s_magic = YAFFS_MAGIC;
1301 sb->s_op = &yaffs_super_ops;
1304 printk(KERN_INFO "yaffs: sb is NULL\n");
1305 else if (!sb->s_dev)
1306 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1307 else if (!yaffs_devname(sb, devname_buf))
1308 printk(KERN_INFO "yaffs: devname is NULL\n");
1310 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1312 yaffs_devname(sb, devname_buf));
1314 sb->s_blocksize = PAGE_CACHE_SIZE;
1315 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1316 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1318 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1320 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1322 ("yaffs: Write verification disabled. All guarantees "
1323 "null and void\n"));
1326 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1328 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1329 yaffs_devname(sb, devname_buf)));
1331 /* Check it's an mtd device..... */
1332 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1333 return NULL; /* This isn't an mtd device */
1335 /* Get the device */
1336 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1338 T(YAFFS_TRACE_ALWAYS,
1339 ("yaffs: MTD device #%u doesn't appear to exist\n",
1343 /* Check it's NAND */
1344 if (mtd->type != MTD_NANDFLASH) {
1345 T(YAFFS_TRACE_ALWAYS,
1346 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1350 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1351 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1352 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1353 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1354 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1355 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1356 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1357 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1358 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1359 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1360 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1362 if (yaffsVersion == 2) {
1363 /* Check for version 2 style functions */
1365 !mtd->block_isbad ||
1366 !mtd->block_markbad ||
1370 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1371 T(YAFFS_TRACE_ALWAYS,
1372 ("yaffs: MTD device does not support required "
1377 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1378 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1379 T(YAFFS_TRACE_ALWAYS,
1380 ("yaffs: MTD device does not support have the "
1381 "right page sizes\n"));
1385 /* Check for V1 style functions */
1390 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1391 T(YAFFS_TRACE_ALWAYS,
1392 ("yaffs: MTD device does not support required "
1397 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1398 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1399 T(YAFFS_TRACE_ALWAYS,
1400 ("yaffs: MTD device does not support have the "
1401 "right page sizes\n"));
1406 /* OK, so if we got here, we have an MTD that's NAND and looks
1407 * like it has the right capabilities
1408 * Set the yaffs_Device up for mtd
1411 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1412 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1414 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1417 /* Deep shit could not allocate device structure */
1418 T(YAFFS_TRACE_ALWAYS,
1419 ("yaffs_read_super: Failed trying to allocate "
1420 "yaffs_Device. \n"));
1424 memset(dev, 0, sizeof(yaffs_Device));
1425 dev->genericDevice = mtd;
1426 dev->name = mtd->name;
1428 /* Set up the memory size parameters.... */
1430 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1431 dev->startBlock = 0;
1432 dev->endBlock = nBlocks - 1;
1433 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1434 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1435 dev->nReservedBlocks = 5;
1436 dev->nShortOpCaches = 10; /* Enable short op caching */
1438 /* ... and the functions. */
1439 if (yaffsVersion == 2) {
1440 dev->writeChunkWithTagsToNAND =
1441 nandmtd2_WriteChunkWithTagsToNAND;
1442 dev->readChunkWithTagsFromNAND =
1443 nandmtd2_ReadChunkWithTagsFromNAND;
1444 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1445 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1446 dev->spareBuffer = YMALLOC(mtd->oobsize);
1448 dev->nBytesPerChunk = mtd->oobblock;
1449 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1450 nBlocks = mtd->size / mtd->erasesize;
1451 dev->startBlock = 0;
1452 dev->endBlock = nBlocks - 1;
1454 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1455 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1458 /* ... and common functions */
1459 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1460 dev->initialiseNAND = nandmtd_InitialiseNAND;
1462 dev->putSuperFunc = yaffs_MTDPutSuper;
1464 #ifndef CONFIG_YAFFS_DOES_ECC
1465 dev->useNANDECC = 1;
1468 /* we assume this is protected by lock_kernel() in mount/umount */
1469 list_add_tail(&dev->devList, &yaffs_dev_list);
1471 init_MUTEX(&dev->grossLock);
1473 yaffs_GrossLock(dev);
1475 err = yaffs_GutsInitialise(dev);
1478 ("yaffs_read_super: guts initialised %s\n",
1479 (err == YAFFS_OK) ? "OK" : "FAILED"));
1481 /* Create root inode */
1482 if (err == YAFFS_OK)
1483 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1486 yaffs_GrossUnlock(dev);
1491 inode->i_op = &yaffs_dir_inode_operations;
1492 inode->i_fop = &yaffs_dir_operations;
1494 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1496 root = d_alloc_root(inode);
1498 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1506 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1511 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1512 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1515 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1518 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1519 int flags, const char *dev_name,
1523 return get_sb_bdev(fs, flags, dev_name, data,
1524 yaffs_internal_read_super_mtd);
1527 static struct file_system_type yaffs_fs_type = {
1528 .owner = THIS_MODULE,
1530 .get_sb = yaffs_read_super,
1531 .kill_sb = kill_block_super,
1532 .fs_flags = FS_REQUIRES_DEV,
1535 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1538 return yaffs_internal_read_super(1, sb, data, silent);
1541 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1546 #ifdef CONFIG_YAFFS_YAFFS2
1548 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1549 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1552 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1555 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1556 int flags, const char *dev_name,
1560 return get_sb_bdev(fs, flags, dev_name, data,
1561 yaffs2_internal_read_super_mtd);
1564 static struct file_system_type yaffs2_fs_type = {
1565 .owner = THIS_MODULE,
1567 .get_sb = yaffs2_read_super,
1568 .kill_sb = kill_block_super,
1569 .fs_flags = FS_REQUIRES_DEV,
1572 static struct super_block *yaffs2_read_super(struct super_block *sb,
1573 void *data, int silent)
1575 return yaffs_internal_read_super(2, sb, data, silent);
1578 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1582 #endif /* CONFIG_YAFFS_YAFFS2 */
1584 static struct proc_dir_entry *my_proc_entry;
1586 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1588 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1589 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1590 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1591 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1592 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1593 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1594 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1595 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1596 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1597 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1598 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1599 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1600 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1601 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1603 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1605 sprintf(buf, "passiveGCs......... %d\n",
1606 dev->passiveGarbageCollections);
1607 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1608 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1609 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1610 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1611 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1612 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1613 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1614 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1615 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1617 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1618 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1619 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1624 static int yaffs_proc_read(char *page,
1626 off_t offset, int count, int *eof, void *data)
1628 struct list_head *item;
1633 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1634 * We use 'offset' (*ppos) to indicate where we are in devList.
1635 * This also assumes the user has posted a read buffer large
1636 * enough to hold the complete output; but that's life in /proc.
1641 /* Print header first */
1643 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1644 "\n%s\n%s\n", yaffs_fs_c_version,
1645 yaffs_guts_c_version);
1648 /* hold lock_kernel while traversing yaffs_dev_list */
1651 /* Locate and print the Nth entry. Order N-squared but N is small. */
1652 list_for_each(item, &yaffs_dev_list) {
1653 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1658 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1659 buf = yaffs_dump_dev(buf, dev);
1664 return buf - page < count ? buf - page : count;
1667 /* Stuff to handle installation of file systems */
1668 struct file_system_to_install {
1669 struct file_system_type *fst;
1673 static struct file_system_to_install fs_to_install[] = {
1674 //#ifdef CONFIG_YAFFS_YAFFS1
1675 {&yaffs_fs_type, 0},
1677 //#ifdef CONFIG_YAFFS_YAFFS2
1678 {&yaffs2_fs_type, 0},
1683 static int __init init_yaffs_fs(void)
1686 struct file_system_to_install *fsinst;
1688 T(YAFFS_TRACE_ALWAYS,
1689 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1691 /* Install the proc_fs entry */
1692 my_proc_entry = create_proc_read_entry("yaffs",
1695 yaffs_proc_read, NULL);
1696 if (!my_proc_entry) {
1700 /* Now add the file system entries */
1702 fsinst = fs_to_install;
1704 while (fsinst->fst && !error) {
1705 error = register_filesystem(fsinst->fst);
1707 fsinst->installed = 1;
1712 /* Any errors? uninstall */
1714 fsinst = fs_to_install;
1716 while (fsinst->fst) {
1717 if (fsinst->installed) {
1718 unregister_filesystem(fsinst->fst);
1719 fsinst->installed = 0;
1728 static void __exit exit_yaffs_fs(void)
1731 struct file_system_to_install *fsinst;
1733 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1736 remove_proc_entry("yaffs", &proc_root);
1738 fsinst = fs_to_install;
1740 while (fsinst->fst) {
1741 if (fsinst->installed) {
1742 unregister_filesystem(fsinst->fst);
1743 fsinst->installed = 0;
1750 module_init(init_yaffs_fs)
1751 module_exit(exit_yaffs_fs)
1753 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1754 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1755 MODULE_LICENSE("GPL");