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.38 2005-12-15 20:27:56 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 */
313 /* Can't hold gross lock when calling yaffs_get_inode() */
314 yaffs_GrossUnlock(dev);
318 (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
320 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
324 (KERN_DEBUG "yaffs_loookup dentry \n"));
325 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
326 * d_add even if NULL inode */
328 /*dget(dentry); // try to solve directory bug */
329 d_add(dentry, inode);
337 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
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 */
728 /* NB You can't be holding grossLock or deadlock will happen! */
733 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
741 obj = yaffs_DentryToObject(f->f_dentry);
745 yaffs_GrossLock(dev);
747 inode = f->f_dentry->d_inode;
749 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
750 ipos = inode->i_size;
757 (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
761 "yaffs_file_write about to write writing %d bytes"
762 "to object %d at %d\n",
763 n, obj->objectId, ipos));
766 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
769 (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
774 if (ipos > inode->i_size) {
775 inode->i_size = ipos;
776 inode->i_blocks = (ipos + 511) >> 9;
780 "yaffs_file_write size updated to %d bytes, "
782 ipos, (int)(inode->i_blocks)));
786 yaffs_GrossUnlock(dev);
788 return nWritten != n ? -ENOSPC : nWritten;
791 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
795 struct inode *inode = f->f_dentry->d_inode;
796 unsigned long offset, curoffs;
800 char name[YAFFS_MAX_NAME_LENGTH + 1];
802 obj = yaffs_DentryToObject(f->f_dentry);
805 yaffs_GrossLock(dev);
809 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
813 (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
815 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
824 (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
825 (int)f->f_dentry->d_parent->d_inode->i_ino));
827 (dirent, "..", 2, offset,
828 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
837 list_for_each(i, &obj->variant.directoryVariant.children) {
839 if (curoffs >= offset) {
840 l = list_entry(i, yaffs_Object, siblings);
842 yaffs_GetObjectName(l, name,
843 YAFFS_MAX_NAME_LENGTH + 1);
845 (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
846 yaffs_GetObjectInode(l)));
852 yaffs_GetObjectInode(l),
853 yaffs_GetObjectType(l))
866 yaffs_GrossUnlock(dev);
872 * File creation. Allocate an inode, and we're done..
874 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
875 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
878 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
884 yaffs_Object *obj = NULL;
887 yaffs_Object *parent = yaffs_InodeToObject(dir);
890 uid_t uid = current->fsuid;
891 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
895 (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
896 parent->objectId, parent->variantType));
899 (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
903 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
905 dentry->d_name.name, mode, rdev));
909 yaffs_GrossLock(dev);
911 switch (mode & S_IFMT) {
913 /* Special (socket, fifo, device...) */
914 T(YAFFS_TRACE_OS, (KERN_DEBUG
915 "yaffs_mknod: making special\n"));
916 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
918 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
919 gid, old_encode_dev(rdev));
922 yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
926 case S_IFREG: /* file */
927 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
929 yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
932 case S_IFDIR: /* directory */
934 (KERN_DEBUG "yaffs_mknod: making directory\n"));
936 yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
939 case S_IFLNK: /* symlink */
940 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
941 obj = NULL; /* Do we ever get here? */
945 /* Can not call yaffs_get_inode() with gross lock held */
946 yaffs_GrossUnlock(dev);
949 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
950 d_instantiate(dentry, inode);
952 (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
953 obj->objectId, atomic_read(&inode->i_count)));
957 (KERN_DEBUG "yaffs_mknod failed making object\n"));
964 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
967 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
968 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
970 /* attempt to fix dir bug - didn't work */
978 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
979 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
982 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
985 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
986 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
989 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
996 (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
997 dentry->d_name.name));
999 dev = yaffs_InodeToObject(dir)->myDev;
1001 yaffs_GrossLock(dev);
1003 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1005 yaffs_GrossUnlock(dev);
1007 if (retVal == YAFFS_OK) {
1008 dentry->d_inode->i_nlink--;
1009 mark_inode_dirty(dentry->d_inode);
1019 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1020 struct dentry *dentry)
1022 struct inode *inode = old_dentry->d_inode;
1023 yaffs_Object *obj = NULL;
1024 yaffs_Object *link = NULL;
1027 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
1029 obj = yaffs_InodeToObject(inode);
1032 yaffs_GrossLock(dev);
1034 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1037 yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1042 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1043 d_instantiate(dentry, old_dentry->d_inode);
1044 atomic_inc(&old_dentry->d_inode->i_count);
1046 (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
1047 old_dentry->d_inode->i_nlink,
1048 atomic_read(&old_dentry->d_inode->i_count)));
1052 yaffs_GrossUnlock(dev);
1062 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1063 const char *symname)
1067 uid_t uid = current->fsuid;
1068 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
1070 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
1072 dev = yaffs_InodeToObject(dir)->myDev;
1073 yaffs_GrossLock(dev);
1074 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1075 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1076 yaffs_GrossUnlock(dev);
1080 struct inode *inode;
1082 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1083 d_instantiate(dentry, inode);
1084 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
1087 T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
1094 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1101 obj = yaffs_DentryToObject(dentry);
1105 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
1106 yaffs_GrossLock(dev);
1107 yaffs_FlushFile(obj, 1);
1108 yaffs_GrossUnlock(dev);
1113 * The VFS layer already does all the dentry stuff for rename.
1115 * NB: POSIX says you can rename an object over an old object of the same name
1117 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1118 struct inode *new_dir, struct dentry *new_dentry)
1121 int retVal = YAFFS_FAIL;
1122 yaffs_Object *target;
1124 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
1125 dev = yaffs_InodeToObject(old_dir)->myDev;
1127 yaffs_GrossLock(dev);
1129 /* Check if the target is an existing directory that is not empty. */
1131 yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1132 new_dentry->d_name.name);
1137 target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1138 !list_empty(&target->variant.directoryVariant.children)) {
1140 T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
1142 retVal = YAFFS_FAIL;
1145 /* Now does unlinking internally using shadowing mechanism */
1146 T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
1149 yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1150 old_dentry->d_name.name,
1151 yaffs_InodeToObject(new_dir),
1152 new_dentry->d_name.name);
1155 yaffs_GrossUnlock(dev);
1157 if (retVal == YAFFS_OK) {
1159 new_dentry->d_inode->i_nlink--;
1160 mark_inode_dirty(new_dentry->d_inode);
1170 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1172 struct inode *inode = dentry->d_inode;
1177 (KERN_DEBUG "yaffs_setattr of object %d\n",
1178 yaffs_InodeToObject(inode)->objectId));
1180 if ((error = inode_change_ok(inode, attr)) == 0) {
1182 dev = yaffs_InodeToObject(inode)->myDev;
1183 yaffs_GrossLock(dev);
1184 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1190 yaffs_GrossUnlock(dev);
1192 error = inode_setattr(inode, attr);
1197 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1198 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1200 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1204 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1205 T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
1207 yaffs_GrossLock(dev);
1209 buf->f_type = YAFFS_MAGIC;
1210 buf->f_bsize = sb->s_blocksize;
1211 buf->f_namelen = 255;
1212 if (sb->s_blocksize > dev->nBytesPerChunk) {
1215 (dev->endBlock - dev->startBlock +
1216 1) * dev->nChunksPerBlock / (sb->s_blocksize /
1217 dev->nBytesPerChunk);
1219 yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
1220 dev->nBytesPerChunk);
1224 (dev->endBlock - dev->startBlock +
1225 1) * dev->nChunksPerBlock * (dev->nBytesPerChunk /
1228 yaffs_GetNumberOfFreeChunks(dev) * (dev->nBytesPerChunk /
1233 buf->f_bavail = buf->f_bfree;
1235 yaffs_GrossUnlock(dev);
1239 static void yaffs_read_inode(struct inode *inode)
1241 /* NB This is called as a side effect of other functions, but
1242 * we had to release the lock to prevent deadlocks, so
1243 * need to lock again.
1247 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1250 (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
1252 yaffs_GrossLock(dev);
1254 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1256 yaffs_FillInodeFromObject(inode, obj);
1258 yaffs_GrossUnlock(dev);
1261 static LIST_HEAD(yaffs_dev_list);
1263 static void yaffs_put_super(struct super_block *sb)
1265 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1267 yaffs_GrossLock(dev);
1268 if (dev->putSuperFunc) {
1269 dev->putSuperFunc(sb);
1271 yaffs_Deinitialise(dev);
1272 yaffs_GrossUnlock(dev);
1274 /* we assume this is protected by lock_kernel() in mount/umount */
1275 list_del(&dev->devList);
1281 static void yaffs_MTDPutSuper(struct super_block *sb)
1284 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1290 put_mtd_device(mtd);
1294 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1295 struct super_block *sb,
1296 void *data, int silent)
1299 struct inode *inode = NULL;
1300 struct dentry *root;
1301 yaffs_Device *dev = 0;
1302 char devname_buf[BDEVNAME_SIZE + 1];
1303 struct mtd_info *mtd;
1306 sb->s_magic = YAFFS_MAGIC;
1307 sb->s_op = &yaffs_super_ops;
1310 printk(KERN_INFO "yaffs: sb is NULL\n");
1311 else if (!sb->s_dev)
1312 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1313 else if (!yaffs_devname(sb, devname_buf))
1314 printk(KERN_INFO "yaffs: devname is NULL\n");
1316 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1318 yaffs_devname(sb, devname_buf));
1320 sb->s_blocksize = PAGE_CACHE_SIZE;
1321 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1322 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1324 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1326 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1328 ("yaffs: Write verification disabled. All guarantees "
1329 "null and void\n"));
1332 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1334 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1335 yaffs_devname(sb, devname_buf)));
1337 /* Check it's an mtd device..... */
1338 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
1339 return NULL; /* This isn't an mtd device */
1341 /* Get the device */
1342 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1344 T(YAFFS_TRACE_ALWAYS,
1345 ("yaffs: MTD device #%u doesn't appear to exist\n",
1349 /* Check it's NAND */
1350 if (mtd->type != MTD_NANDFLASH) {
1351 T(YAFFS_TRACE_ALWAYS,
1352 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1356 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1357 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1358 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1359 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1360 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1361 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1362 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1363 T(YAFFS_TRACE_OS, (" oobblock %d\n", mtd->oobblock));
1364 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1365 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1366 T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
1368 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1370 if (yaffsVersion == 1 &&
1371 mtd->oobblock >= 2048) {
1372 T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
1377 if (yaffsVersion == 2) {
1378 /* Check for version 2 style functions */
1380 !mtd->block_isbad ||
1381 !mtd->block_markbad ||
1385 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1386 T(YAFFS_TRACE_ALWAYS,
1387 ("yaffs: MTD device does not support required "
1392 if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1393 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
1394 T(YAFFS_TRACE_ALWAYS,
1395 ("yaffs: MTD device does not support have the "
1396 "right page sizes\n"));
1400 /* Check for V1 style functions */
1405 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1406 T(YAFFS_TRACE_ALWAYS,
1407 ("yaffs: MTD device does not support required "
1412 if (mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1413 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
1414 T(YAFFS_TRACE_ALWAYS,
1415 ("yaffs: MTD device does not support have the "
1416 "right page sizes\n"));
1421 /* OK, so if we got here, we have an MTD that's NAND and looks
1422 * like it has the right capabilities
1423 * Set the yaffs_Device up for mtd
1426 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1427 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1429 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
1432 /* Deep shit could not allocate device structure */
1433 T(YAFFS_TRACE_ALWAYS,
1434 ("yaffs_read_super: Failed trying to allocate "
1435 "yaffs_Device. \n"));
1439 memset(dev, 0, sizeof(yaffs_Device));
1440 dev->genericDevice = mtd;
1441 dev->name = mtd->name;
1443 /* Set up the memory size parameters.... */
1445 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1446 dev->startBlock = 0;
1447 dev->endBlock = nBlocks - 1;
1448 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1449 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1450 dev->nReservedBlocks = 5;
1451 dev->nShortOpCaches = 10; /* Enable short op caching */
1453 /* ... and the functions. */
1454 if (yaffsVersion == 2) {
1455 dev->writeChunkWithTagsToNAND =
1456 nandmtd2_WriteChunkWithTagsToNAND;
1457 dev->readChunkWithTagsFromNAND =
1458 nandmtd2_ReadChunkWithTagsFromNAND;
1459 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1460 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1461 dev->spareBuffer = YMALLOC(mtd->oobsize);
1463 dev->nBytesPerChunk = mtd->oobblock;
1464 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1465 nBlocks = mtd->size / mtd->erasesize;
1466 dev->startBlock = 0;
1467 dev->endBlock = nBlocks - 1;
1469 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1470 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1473 /* ... and common functions */
1474 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1475 dev->initialiseNAND = nandmtd_InitialiseNAND;
1477 dev->putSuperFunc = yaffs_MTDPutSuper;
1479 #ifndef CONFIG_YAFFS_DOES_ECC
1480 dev->useNANDECC = 1;
1483 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
1484 dev->wideTnodesDisabled = 1;
1487 /* we assume this is protected by lock_kernel() in mount/umount */
1488 list_add_tail(&dev->devList, &yaffs_dev_list);
1490 init_MUTEX(&dev->grossLock);
1492 yaffs_GrossLock(dev);
1494 err = yaffs_GutsInitialise(dev);
1497 ("yaffs_read_super: guts initialised %s\n",
1498 (err == YAFFS_OK) ? "OK" : "FAILED"));
1500 /* Release lock before yaffs_get_inode() */
1501 yaffs_GrossUnlock(dev);
1503 /* Create root inode */
1504 if (err == YAFFS_OK)
1505 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
1511 inode->i_op = &yaffs_dir_inode_operations;
1512 inode->i_fop = &yaffs_dir_operations;
1514 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
1516 root = d_alloc_root(inode);
1518 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
1526 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
1531 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1532 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
1535 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
1538 static struct super_block *yaffs_read_super(struct file_system_type *fs,
1539 int flags, const char *dev_name,
1543 return get_sb_bdev(fs, flags, dev_name, data,
1544 yaffs_internal_read_super_mtd);
1547 static struct file_system_type yaffs_fs_type = {
1548 .owner = THIS_MODULE,
1550 .get_sb = yaffs_read_super,
1551 .kill_sb = kill_block_super,
1552 .fs_flags = FS_REQUIRES_DEV,
1555 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
1558 return yaffs_internal_read_super(1, sb, data, silent);
1561 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
1566 #ifdef CONFIG_YAFFS_YAFFS2
1568 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1569 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
1572 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
1575 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
1576 int flags, const char *dev_name,
1580 return get_sb_bdev(fs, flags, dev_name, data,
1581 yaffs2_internal_read_super_mtd);
1584 static struct file_system_type yaffs2_fs_type = {
1585 .owner = THIS_MODULE,
1587 .get_sb = yaffs2_read_super,
1588 .kill_sb = kill_block_super,
1589 .fs_flags = FS_REQUIRES_DEV,
1592 static struct super_block *yaffs2_read_super(struct super_block *sb,
1593 void *data, int silent)
1595 return yaffs_internal_read_super(2, sb, data, silent);
1598 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
1602 #endif /* CONFIG_YAFFS_YAFFS2 */
1604 static struct proc_dir_entry *my_proc_entry;
1606 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
1608 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
1609 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
1610 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
1611 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
1612 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
1613 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
1614 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
1615 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
1616 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
1617 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
1618 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
1619 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
1620 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
1621 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
1623 sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
1625 sprintf(buf, "passiveGCs......... %d\n",
1626 dev->passiveGarbageCollections);
1627 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
1628 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
1629 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
1630 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
1631 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
1632 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
1633 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
1634 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
1635 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
1637 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
1638 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
1639 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
1644 static int yaffs_proc_read(char *page,
1646 off_t offset, int count, int *eof, void *data)
1648 struct list_head *item;
1653 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
1654 * We use 'offset' (*ppos) to indicate where we are in devList.
1655 * This also assumes the user has posted a read buffer large
1656 * enough to hold the complete output; but that's life in /proc.
1661 /* Print header first */
1663 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
1664 "\n%s\n%s\n", yaffs_fs_c_version,
1665 yaffs_guts_c_version);
1668 /* hold lock_kernel while traversing yaffs_dev_list */
1671 /* Locate and print the Nth entry. Order N-squared but N is small. */
1672 list_for_each(item, &yaffs_dev_list) {
1673 yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
1678 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
1679 buf = yaffs_dump_dev(buf, dev);
1684 return buf - page < count ? buf - page : count;
1687 /* Stuff to handle installation of file systems */
1688 struct file_system_to_install {
1689 struct file_system_type *fst;
1693 static struct file_system_to_install fs_to_install[] = {
1694 //#ifdef CONFIG_YAFFS_YAFFS1
1695 {&yaffs_fs_type, 0},
1697 //#ifdef CONFIG_YAFFS_YAFFS2
1698 {&yaffs2_fs_type, 0},
1703 static int __init init_yaffs_fs(void)
1706 struct file_system_to_install *fsinst;
1708 T(YAFFS_TRACE_ALWAYS,
1709 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1711 /* Install the proc_fs entry */
1712 my_proc_entry = create_proc_read_entry("yaffs",
1715 yaffs_proc_read, NULL);
1716 if (!my_proc_entry) {
1720 /* Now add the file system entries */
1722 fsinst = fs_to_install;
1724 while (fsinst->fst && !error) {
1725 error = register_filesystem(fsinst->fst);
1727 fsinst->installed = 1;
1732 /* Any errors? uninstall */
1734 fsinst = fs_to_install;
1736 while (fsinst->fst) {
1737 if (fsinst->installed) {
1738 unregister_filesystem(fsinst->fst);
1739 fsinst->installed = 0;
1748 static void __exit exit_yaffs_fs(void)
1751 struct file_system_to_install *fsinst;
1753 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
1756 remove_proc_entry("yaffs", &proc_root);
1758 fsinst = fs_to_install;
1760 while (fsinst->fst) {
1761 if (fsinst->installed) {
1762 unregister_filesystem(fsinst->fst);
1763 fsinst->installed = 0;
1770 module_init(init_yaffs_fs)
1771 module_exit(exit_yaffs_fs)
1773 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1774 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1775 MODULE_LICENSE("GPL");