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.40 2006-01-25 01:21:08 tpoynor 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,
174 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
175 .sendfile = generic_file_sendfile,
180 static struct inode_operations yaffs_file_inode_operations = {
181 .setattr = yaffs_setattr,
184 static struct inode_operations yaffs_symlink_inode_operations = {
185 .readlink = yaffs_readlink,
186 .follow_link = yaffs_follow_link,
187 .setattr = yaffs_setattr,
190 static struct inode_operations yaffs_dir_inode_operations = {
191 .create = yaffs_create,
192 .lookup = yaffs_lookup,
194 .unlink = yaffs_unlink,
195 .symlink = yaffs_symlink,
196 .mkdir = yaffs_mkdir,
197 .rmdir = yaffs_unlink,
198 .mknod = yaffs_mknod,
199 .rename = yaffs_rename,
200 .setattr = yaffs_setattr,
203 static struct file_operations yaffs_dir_operations = {
204 .read = generic_read_dir,
205 .readdir = yaffs_readdir,
206 .fsync = yaffs_sync_object,
209 static struct super_operations yaffs_super_ops = {
210 .statfs = yaffs_statfs,
211 .read_inode = yaffs_read_inode,
212 .put_inode = yaffs_put_inode,
213 .put_super = yaffs_put_super,
214 .delete_inode = yaffs_delete_inode,
215 .clear_inode = yaffs_clear_inode,
218 static void yaffs_GrossLock(yaffs_Device * dev)
220 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
222 down(&dev->grossLock);
225 static void yaffs_GrossUnlock(yaffs_Device * dev)
227 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
232 static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
235 unsigned char *alias;
238 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
240 yaffs_GrossLock(dev);
242 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
244 yaffs_GrossUnlock(dev);
249 ret = vfs_readlink(dentry, buffer, buflen, alias);
254 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
255 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
257 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
260 unsigned char *alias;
262 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
264 yaffs_GrossLock(dev);
266 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
268 yaffs_GrossUnlock(dev);
276 ret = vfs_follow_link(nd, alias);
279 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
280 return ERR_PTR (ret);
286 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
290 * Lookup is used to find objects in the fs
292 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
294 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
297 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
301 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
303 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
305 yaffs_GrossLock(dev);
308 (KERN_DEBUG "yaffs_lookup for %d:%s\n",
309 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
312 yaffs_FindObjectByName(yaffs_InodeToObject(dir),
313 dentry->d_name.name);
315 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
317 /* Can't hold gross lock when calling yaffs_get_inode() */
318 yaffs_GrossUnlock(dev);
322 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
324 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
328 (KERN_DEBUG "yaffs_loookup dentry \n"));
329 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
330 * d_add even if NULL inode */
332 /*dget(dentry); // try to solve directory bug */
333 d_add(dentry, inode);
341 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
345 /* added NCB for 2.5/6 compatability - forces add even if inode is
346 * NULL which creates dentry hash */
347 d_add(dentry, inode);
350 /* return (ERR_PTR(-EIO)); */
354 /* For now put inode is just for debugging
355 * Put inode is called when the inode **structure** is put.
357 static void yaffs_put_inode(struct inode *inode)
360 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
361 atomic_read(&inode->i_count)));
365 /* clear is called to tell the fs to release any per-inode data it holds */
366 static void yaffs_clear_inode(struct inode *inode)
371 obj = yaffs_InodeToObject(inode);
374 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
375 atomic_read(&inode->i_count),
376 obj ? "object exists" : "null object"));
380 yaffs_GrossLock(dev);
382 /* Clear the association between the inode and
386 inode->u.generic_ip = NULL;
388 /* If the object freeing was deferred, then the real
390 * This should fix the inode inconsistency problem.
393 yaffs_HandleDeferedFree(obj);
395 yaffs_GrossUnlock(dev);
400 /* delete is called when the link count is zero and the inode
401 * is put (ie. nobody wants to know about it anymore, time to
403 * NB Must call clear_inode()
405 static void yaffs_delete_inode(struct inode *inode)
407 yaffs_Object *obj = yaffs_InodeToObject(inode);
411 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
412 atomic_read(&inode->i_count),
413 obj ? "object exists" : "null object"));
417 yaffs_GrossLock(dev);
418 yaffs_DeleteFile(obj);
419 yaffs_GrossUnlock(dev);
421 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
422 truncate_inode_pages (&inode->i_data, 0);
427 static int yaffs_file_flush(struct file *file)
429 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
431 yaffs_Device *dev = obj->myDev;
434 (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
435 obj->dirty ? "dirty" : "clean"));
437 yaffs_GrossLock(dev);
439 yaffs_FlushFile(obj, 1);
441 yaffs_GrossUnlock(dev);
446 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
448 /* Lifted from jffs2 */
451 unsigned char *pg_buf;
456 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
457 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
458 (unsigned)PAGE_CACHE_SIZE));
460 obj = yaffs_DentryToObject(f->f_dentry);
464 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
465 BUG_ON(!PageLocked(pg));
472 /* FIXME: Can kmap fail? */
474 yaffs_GrossLock(dev);
477 yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
480 yaffs_GrossUnlock(dev);
486 ClearPageUptodate(pg);
493 flush_dcache_page(pg);
496 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
500 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
502 int ret = yaffs_readpage_nolock(f, pg);
507 static int yaffs_readpage(struct file *f, struct page *pg)
509 return yaffs_readpage_unlock(f, pg);
512 /* writepage inspired by/stolen from smbfs */
514 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
515 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
517 static int yaffs_writepage(struct page *page)
520 struct address_space *mapping = page->mapping;
521 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
523 unsigned long end_index;
531 inode = mapping->host;
535 if (offset > inode->i_size) {
538 "yaffs_writepage at %08x, inode size = %08x!!!\n",
539 (unsigned)(page->index << PAGE_CACHE_SHIFT),
540 (unsigned)inode->i_size));
542 (KERN_DEBUG " -> don't care!!\n"));
547 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
550 if (page->index < end_index) {
551 nBytes = PAGE_CACHE_SIZE;
553 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
560 obj = yaffs_InodeToObject(inode);
561 yaffs_GrossLock(obj->myDev);
564 (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
565 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
567 (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
568 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
571 yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
575 (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
576 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
578 yaffs_GrossUnlock(obj->myDev);
581 SetPageUptodate(page);
585 return (nWritten == nBytes) ? 0 : -ENOSPC;
588 static int yaffs_prepare_write(struct file *f, struct page *pg,
589 unsigned offset, unsigned to)
592 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
593 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
594 return yaffs_readpage_nolock(f, pg);
600 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
604 void *addr = page_address(pg) + offset;
605 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
606 int nBytes = to - offset;
610 unsigned saddr = (unsigned)addr;
613 (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
616 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
618 if (nWritten != nBytes) {
621 "yaffs_commit_write not same size nWritten %d nBytes %d\n",
624 ClearPageUptodate(pg);
630 (KERN_DEBUG "yaffs_commit_write returning %d\n",
631 nWritten == nBytes ? 0 : nWritten));
633 return nWritten == nBytes ? 0 : nWritten;
637 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
640 inode->i_ino = obj->objectId;
641 inode->i_mode = obj->yst_mode;
642 inode->i_uid = obj->yst_uid;
643 inode->i_gid = obj->yst_gid;
644 inode->i_blksize = inode->i_sb->s_blocksize;
645 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
647 inode->i_rdev = old_decode_dev(obj->yst_rdev);
648 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
649 inode->i_atime.tv_nsec = 0;
650 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
651 inode->i_mtime.tv_nsec = 0;
652 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
653 inode->i_ctime.tv_nsec = 0;
655 inode->i_rdev = obj->yst_rdev;
656 inode->i_atime = obj->yst_atime;
657 inode->i_mtime = obj->yst_mtime;
658 inode->i_ctime = obj->yst_ctime;
660 inode->i_size = yaffs_GetObjectFileLength(obj);
661 inode->i_blocks = (inode->i_size + 511) >> 9;
663 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
667 "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
668 inode->i_mode, inode->i_uid, inode->i_gid,
669 (int)inode->i_size, atomic_read(&inode->i_count)));
671 switch (obj->yst_mode & S_IFMT) {
672 default: /* fifo, device or socket */
673 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
674 init_special_inode(inode, obj->yst_mode,
675 old_decode_dev(obj->yst_rdev));
677 init_special_inode(inode, obj->yst_mode,
678 (dev_t) (obj->yst_rdev));
681 case S_IFREG: /* file */
682 inode->i_op = &yaffs_file_inode_operations;
683 inode->i_fop = &yaffs_file_operations;
684 inode->i_mapping->a_ops =
685 &yaffs_file_address_operations;
687 case S_IFDIR: /* directory */
688 inode->i_op = &yaffs_dir_inode_operations;
689 inode->i_fop = &yaffs_dir_operations;
691 case S_IFLNK: /* symlink */
692 inode->i_op = &yaffs_symlink_inode_operations;
696 inode->u.generic_ip = obj;
697 obj->myInode = inode;
701 (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
706 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
713 (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
720 (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
726 (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
728 inode = iget(sb, obj->objectId);
730 /* NB Side effect: iget calls back to yaffs_read_inode(). */
731 /* iget also increments the inode's i_count */
732 /* NB You can't be holding grossLock or deadlock will happen! */
737 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
745 obj = yaffs_DentryToObject(f->f_dentry);
749 yaffs_GrossLock(dev);
751 inode = f->f_dentry->d_inode;
753 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
754 ipos = inode->i_size;
761 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
765 "yaffs_file_write about to write writing %d bytes"
766 "to object %d at %d\n",
767 n, obj->objectId, ipos));
770 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
773 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
778 if (ipos > inode->i_size) {
779 inode->i_size = ipos;
780 inode->i_blocks = (ipos + 511) >> 9;
784 "yaffs_file_write size updated to %d bytes, "
786 ipos, (int)(inode->i_blocks)));
790 yaffs_GrossUnlock(dev);
791 return nWritten == 0 ? -ENOSPC : nWritten;
794 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
798 struct inode *inode = f->f_dentry->d_inode;
799 unsigned long offset, curoffs;
803 char name[YAFFS_MAX_NAME_LENGTH + 1];
805 obj = yaffs_DentryToObject(f->f_dentry);
808 yaffs_GrossLock(dev);
812 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
816 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
818 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
827 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
828 (int)f->f_dentry->d_parent->d_inode->i_ino));
830 (dirent, "..", 2, offset,
831 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
840 list_for_each(i, &obj->variant.directoryVariant.children) {
842 if (curoffs >= offset) {
843 l = list_entry(i, yaffs_Object, siblings);
845 yaffs_GetObjectName(l, name,
846 YAFFS_MAX_NAME_LENGTH + 1);
848 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
849 yaffs_GetObjectInode(l)));
855 yaffs_GetObjectInode(l),
856 yaffs_GetObjectType(l))
869 yaffs_GrossUnlock(dev);
875 * File creation. Allocate an inode, and we're done..
877 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
878 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
881 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
887 yaffs_Object *obj = NULL;
890 yaffs_Object *parent = yaffs_InodeToObject(dir);
893 uid_t uid = current->fsuid;
894 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
898 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
899 parent->objectId, parent->variantType));
902 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
906 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
908 dentry->d_name.name, mode, rdev));
912 yaffs_GrossLock(dev);
914 switch (mode & S_IFMT) {
916 /* Special (socket, fifo, device...) */
917 T(YAFFS_TRACE_OS, (KERN_DEBUG
918 "yaffs_mknod: making special\n"));
919 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
921 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
922 gid, old_encode_dev(rdev));
925 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
929 case S_IFREG: /* file */
930 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
932 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
935 case S_IFDIR: /* directory */
937 (KERN_DEBUG "yaffs_mknod: making directory\n"));
939 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
942 case S_IFLNK: /* symlink */
943 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
944 obj = NULL; /* Do we ever get here? */
948 /* Can not call yaffs_get_inode() with gross lock held */
949 yaffs_GrossUnlock(dev);
952 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
953 d_instantiate(dentry, inode);
955 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
956 obj->objectId, atomic_read(&inode->i_count)));
960 (KERN_DEBUG "yaffs_mknod failed making object\n"));
967 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
970 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
971 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
973 /* attempt to fix dir bug - didn't work */
981 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
982 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
985 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
988 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
989 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
992 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
999 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1000 dentry->d_name.name));
1002 dev = yaffs_InodeToObject(dir)->myDev;
1004 yaffs_GrossLock(dev);
1006 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1008 yaffs_GrossUnlock(dev);
1010 if (retVal == YAFFS_OK) {
1011 dentry->d_inode->i_nlink--;
1012 mark_inode_dirty(dentry->d_inode);
1022 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1023 struct dentry *dentry)
1025 struct inode *inode = old_dentry->d_inode;
1026 yaffs_Object *obj = NULL;
1027 yaffs_Object *link = NULL;
1030 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1032 obj = yaffs_InodeToObject(inode);
1035 yaffs_GrossLock(dev);
1037 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1040 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1045 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1046 d_instantiate(dentry, old_dentry->d_inode);
1047 atomic_inc(&old_dentry->d_inode->i_count);
1049 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1050 old_dentry->d_inode->i_nlink,
1051 atomic_read(&old_dentry->d_inode->i_count)));
1055 yaffs_GrossUnlock(dev);
1065 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1066 const char *symname)
1070 uid_t uid = current->fsuid;
1071 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1073 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1075 dev = yaffs_InodeToObject(dir)->myDev;
1076 yaffs_GrossLock(dev);
1077 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1078 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1079 yaffs_GrossUnlock(dev);
1083 struct inode *inode;
1085 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1086 d_instantiate(dentry, inode);
1087 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1090 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1097 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1104 obj = yaffs_DentryToObject(dentry);
1108 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1109 yaffs_GrossLock(dev);
1110 yaffs_FlushFile(obj, 1);
1111 yaffs_GrossUnlock(dev);
1116 * The VFS layer already does all the dentry stuff for rename.
1118 * NB: POSIX says you can rename an object over an old object of the same name
1120 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1121 struct inode *new_dir, struct dentry *new_dentry)
1124 int retVal = YAFFS_FAIL;
1125 yaffs_Object *target;
1127 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1128 dev = yaffs_InodeToObject(old_dir)->myDev;
1130 yaffs_GrossLock(dev);
1132 /* Check if the target is an existing directory that is not empty. */
1134 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1135 new_dentry->d_name.name);
1140 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1141 !list_empty(&target->variant.directoryVariant.children)) {
1143 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1145 retVal = YAFFS_FAIL;
1148 /* Now does unlinking internally using shadowing mechanism */
1149 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1152 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1153 old_dentry->d_name.name,
1154 yaffs_InodeToObject(new_dir),
1155 new_dentry->d_name.name);
1158 yaffs_GrossUnlock(dev);
1160 if (retVal == YAFFS_OK) {
1162 new_dentry->d_inode->i_nlink--;
1163 mark_inode_dirty(new_dentry->d_inode);
1173 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1175 struct inode *inode = dentry->d_inode;
1180 (KERN_DEBUG "yaffs_setattr of object %d\n",
1181 yaffs_InodeToObject(inode)->objectId));
1183 if ((error = inode_change_ok(inode, attr)) == 0) {
1185 dev = yaffs_InodeToObject(inode)->myDev;
1186 yaffs_GrossLock(dev);
1187 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1193 yaffs_GrossUnlock(dev);
1195 error = inode_setattr(inode, attr);
1200 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1201 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1203 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1207 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1208 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1210 yaffs_GrossLock(dev);
1212 buf->f_type = YAFFS_MAGIC;
1213 buf->f_bsize = sb->s_blocksize;
1214 buf->f_namelen = 255;
1215 if (sb->s_blocksize > dev->nBytesPerChunk) {
1218 (dev->endBlock - dev->startBlock +
1219 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1220 dev->nBytesPerChunk);
1222 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1223 dev->nBytesPerChunk);
1227 (dev->endBlock - dev->startBlock +
1228 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1231 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1236 buf->f_bavail = buf->f_bfree;
1238 yaffs_GrossUnlock(dev);
1242 static void yaffs_read_inode(struct inode *inode)
1244 /* NB This is called as a side effect of other functions, but
1245 * we had to release the lock to prevent deadlocks, so
1246 * need to lock again.
1250 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1253 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1255 yaffs_GrossLock(dev);
1257 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1259 yaffs_FillInodeFromObject(inode, obj);
1261 yaffs_GrossUnlock(dev);
1264 static LIST_HEAD(yaffs_dev_list);
1266 static void yaffs_put_super(struct super_block *sb)
1268 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1270 yaffs_GrossLock(dev);
1271 if (dev->putSuperFunc) {
1272 dev->putSuperFunc(sb);
1274 yaffs_Deinitialise(dev);
1275 yaffs_GrossUnlock(dev);
1277 /* we assume this is protected by lock_kernel() in mount/umount */
1278 list_del(&dev->devList);
1284 static void yaffs_MTDPutSuper(struct super_block *sb)
1287 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1293 put_mtd_device(mtd);
1297 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1298 struct super_block *sb,
1299 void *data, int silent)
1302 struct inode *inode = NULL;
1303 struct dentry *root;
1304 yaffs_Device *dev = 0;
1305 char devname_buf[BDEVNAME_SIZE + 1];
1306 struct mtd_info *mtd;
1309 sb->s_magic = YAFFS_MAGIC;
1310 sb->s_op = &yaffs_super_ops;
1313 printk(KERN_INFO "yaffs: sb is NULL\n");
1314 else if (!sb->s_dev)
1315 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1316 else if (!yaffs_devname(sb, devname_buf))
1317 printk(KERN_INFO "yaffs: devname is NULL\n");
1319 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1321 yaffs_devname(sb, devname_buf));
1323 sb->s_blocksize = PAGE_CACHE_SIZE;
1324 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1325 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1327 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1329 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1331 ("yaffs: Write verification disabled. All guarantees "
1332 "null and void\n"));
1335 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1337 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1338 yaffs_devname(sb, devname_buf)));
1340 /* Check it's an mtd device..... */
1341 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1342 return NULL; /* This isn't an mtd device */
1344 /* Get the device */
1345 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1347 T(YAFFS_TRACE_ALWAYS,
1348 ("yaffs: MTD device #%u doesn't appear to exist\n",
1352 /* Check it's NAND */
1353 if (mtd->type != MTD_NANDFLASH) {
1354 T(YAFFS_TRACE_ALWAYS,
1355 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1359 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1360 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1361 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1362 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1363 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1364 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1365 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1366 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1367 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1368 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1369 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1371 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1373 if (yaffsVersion == 1 &&
1374 mtd->oobblock >= 2048) {
1375 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1380 if (yaffsVersion == 2) {
1381 /* Check for version 2 style functions */
1383 !mtd->block_isbad ||
1384 !mtd->block_markbad ||
1388 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1389 T(YAFFS_TRACE_ALWAYS,
1390 ("yaffs: MTD device does not support required "
1395 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1396 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1397 T(YAFFS_TRACE_ALWAYS,
1398 ("yaffs: MTD device does not support have the "
1399 "right page sizes\n"));
1403 /* Check for V1 style functions */
1408 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1409 T(YAFFS_TRACE_ALWAYS,
1410 ("yaffs: MTD device does not support required "
1415 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1416 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1417 T(YAFFS_TRACE_ALWAYS,
1418 ("yaffs: MTD device does not support have the "
1419 "right page sizes\n"));
1424 /* OK, so if we got here, we have an MTD that's NAND and looks
1425 * like it has the right capabilities
1426 * Set the yaffs_Device up for mtd
1429 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1430 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1432 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1435 /* Deep shit could not allocate device structure */
1436 T(YAFFS_TRACE_ALWAYS,
1437 ("yaffs_read_super: Failed trying to allocate "
1438 "yaffs_Device. \n"));
1442 memset(dev, 0, sizeof(yaffs_Device));
1443 dev->genericDevice = mtd;
1444 dev->name = mtd->name;
1446 /* Set up the memory size parameters.... */
1448 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1449 dev->startBlock = 0;
1450 dev->endBlock = nBlocks - 1;
1451 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1452 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1453 dev->nReservedBlocks = 5;
1454 dev->nShortOpCaches = 10; /* Enable short op caching */
1456 /* ... and the functions. */
1457 if (yaffsVersion == 2) {
1458 dev->writeChunkWithTagsToNAND =
1459 nandmtd2_WriteChunkWithTagsToNAND;
1460 dev->readChunkWithTagsFromNAND =
1461 nandmtd2_ReadChunkWithTagsFromNAND;
1462 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1463 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1464 dev->spareBuffer = YMALLOC(mtd->oobsize);
1466 dev->nBytesPerChunk = mtd->oobblock;
1467 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1468 nBlocks = mtd->size / mtd->erasesize;
1469 dev->startBlock = 0;
1470 dev->endBlock = nBlocks - 1;
1472 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1473 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1476 /* ... and common functions */
1477 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1478 dev->initialiseNAND = nandmtd_InitialiseNAND;
1480 dev->putSuperFunc = yaffs_MTDPutSuper;
1482 #ifndef CONFIG_YAFFS_DOES_ECC
1483 dev->useNANDECC = 1;
1486 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
1487 dev->wideTnodesDisabled = 1;
1490 /* we assume this is protected by lock_kernel() in mount/umount */
1491 list_add_tail(&dev->devList, &yaffs_dev_list);
1493 init_MUTEX(&dev->grossLock);
1495 yaffs_GrossLock(dev);
1497 err = yaffs_GutsInitialise(dev);
1500 ("yaffs_read_super: guts initialised %s\n",
1501 (err == YAFFS_OK) ? "OK" : "FAILED"));
1503 /* Release lock before yaffs_get_inode() */
1504 yaffs_GrossUnlock(dev);
1506 /* Create root inode */
1507 if (err == YAFFS_OK)
1508 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1514 inode->i_op = &yaffs_dir_inode_operations;
1515 inode->i_fop = &yaffs_dir_operations;
1517 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1519 root = d_alloc_root(inode);
1521 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1529 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1534 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1535 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1538 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1541 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1542 int flags, const char *dev_name,
1546 return get_sb_bdev(fs, flags, dev_name, data,
1547 yaffs_internal_read_super_mtd);
1550 static struct file_system_type yaffs_fs_type = {
1551 .owner = THIS_MODULE,
1553 .get_sb = yaffs_read_super,
1554 .kill_sb = kill_block_super,
1555 .fs_flags = FS_REQUIRES_DEV,
1558 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1561 return yaffs_internal_read_super(1, sb, data, silent);
1564 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1569 #ifdef CONFIG_YAFFS_YAFFS2
1571 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1572 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1575 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1578 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1579 int flags, const char *dev_name,
1583 return get_sb_bdev(fs, flags, dev_name, data,
1584 yaffs2_internal_read_super_mtd);
1587 static struct file_system_type yaffs2_fs_type = {
1588 .owner = THIS_MODULE,
1590 .get_sb = yaffs2_read_super,
1591 .kill_sb = kill_block_super,
1592 .fs_flags = FS_REQUIRES_DEV,
1595 static struct super_block *yaffs2_read_super(struct super_block *sb,
1596 void *data, int silent)
1598 return yaffs_internal_read_super(2, sb, data, silent);
1601 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1605 #endif /* CONFIG_YAFFS_YAFFS2 */
1607 static struct proc_dir_entry *my_proc_entry;
1609 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1611 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1612 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1613 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1614 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1615 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1616 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1617 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1618 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1619 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1620 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1621 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1622 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1623 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1624 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1626 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1628 sprintf(buf, "passiveGCs......... %d\n",
1629 dev->passiveGarbageCollections);
1630 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1631 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1632 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1633 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1634 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1635 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1636 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1637 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1638 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1640 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1641 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1642 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1647 static int yaffs_proc_read(char *page,
1649 off_t offset, int count, int *eof, void *data)
1651 struct list_head *item;
1656 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1657 * We use 'offset' (*ppos) to indicate where we are in devList.
1658 * This also assumes the user has posted a read buffer large
1659 * enough to hold the complete output; but that's life in /proc.
1664 /* Print header first */
1666 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1667 "\n%s\n%s\n", yaffs_fs_c_version,
1668 yaffs_guts_c_version);
1671 /* hold lock_kernel while traversing yaffs_dev_list */
1674 /* Locate and print the Nth entry. Order N-squared but N is small. */
1675 list_for_each(item, &yaffs_dev_list) {
1676 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1681 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1682 buf = yaffs_dump_dev(buf, dev);
1687 return buf - page < count ? buf - page : count;
1690 /* Stuff to handle installation of file systems */
1691 struct file_system_to_install {
1692 struct file_system_type *fst;
1696 static struct file_system_to_install fs_to_install[] = {
1697 //#ifdef CONFIG_YAFFS_YAFFS1
1698 {&yaffs_fs_type, 0},
1700 //#ifdef CONFIG_YAFFS_YAFFS2
1701 {&yaffs2_fs_type, 0},
1706 static int __init init_yaffs_fs(void)
1709 struct file_system_to_install *fsinst;
1711 T(YAFFS_TRACE_ALWAYS,
1712 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1714 /* Install the proc_fs entry */
1715 my_proc_entry = create_proc_read_entry("yaffs",
1718 yaffs_proc_read, NULL);
1719 if (!my_proc_entry) {
1723 /* Now add the file system entries */
1725 fsinst = fs_to_install;
1727 while (fsinst->fst && !error) {
1728 error = register_filesystem(fsinst->fst);
1730 fsinst->installed = 1;
1735 /* Any errors? uninstall */
1737 fsinst = fs_to_install;
1739 while (fsinst->fst) {
1740 if (fsinst->installed) {
1741 unregister_filesystem(fsinst->fst);
1742 fsinst->installed = 0;
1751 static void __exit exit_yaffs_fs(void)
1754 struct file_system_to_install *fsinst;
1756 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1759 remove_proc_entry("yaffs", &proc_root);
1761 fsinst = fs_to_install;
1763 while (fsinst->fst) {
1764 if (fsinst->installed) {
1765 unregister_filesystem(fsinst->fst);
1766 fsinst->installed = 0;
1773 module_init(init_yaffs_fs)
1774 module_exit(exit_yaffs_fs)
1776 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1777 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1778 MODULE_LICENSE("GPL");