Add cache write through and some benign fixes
[yaffs2.git] / yaffs_fs.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  * yaffs_fs.c
4  *
5  * Copyright (C) 2002 Aleph One Ltd.
6  *   for Toby Churchill Ltd and Brightstar Engineering
7  *
8  * Created by Charles Manning <charles@aleph1.co.uk>
9  *
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.
13  *
14  * This is the file system front-end to YAFFS that hooks it up to
15  * the VFS.
16  *
17  * Special notes: 
18  * >> sb->u.generic_sbp points to the yaffs_Device associated with this superblock
19  * >> inode->u.generic_ip points to the associated yaffs_Object.
20  *
21  *
22  * Acknowledgements:
23  * * Luc van OostenRyck for numerous patches.
24  * * Nick Bane for numerous patches.
25  * * Nick Bane for 2.5/2.6 integration.
26  * * Andras Toth for mknod rdev issue.
27  * * Michael Fischer for finding the problem with inode inconsistency.
28  * * Some code bodily lifted from JFFS2.
29  */
30
31
32 const char *yaffs_fs_c_version = "$Id: yaffs_fs.c,v 1.6 2005-07-03 10:32:40 charles Exp $";
33 extern const char *yaffs_guts_c_version;
34
35
36
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>
44 #include <linux/fs.h>
45 #include <linux/proc_fs.h>
46 #include <linux/pagemap.h>
47 #include <linux/mtd/mtd.h>
48 #include <linux/interrupt.h>
49 #include <linux/string.h>
50
51
52 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
53
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)
58 //#define kdevname(x) cdevname(to_kdev_t(x))
59 #define kdevname(x) "(unavailable)"     // temporary fix
60
61 #else
62
63 #include <linux/locks.h>
64
65 #endif
66
67 #include <asm/uaccess.h>
68
69 #include "yportenv.h"
70 #include "yaffs_guts.h"
71
72
73
74
75 unsigned yaffs_traceMask = YAFFS_TRACE_ALWAYS | YAFFS_TRACE_BAD_BLOCKS;
76 //unsigned yaffs_traceMask = 0xFFFFFFFF;
77
78
79 #ifdef CONFIG_YAFFS_RAM_ENABLED
80 #include "yaffs_nandemul.h" 
81 // 2 MB of RAM for emulation
82 #define YAFFS_RAM_EMULATION_SIZE  0x200000
83 #endif //CONFIG_YAFFS_RAM_ENABLED
84
85 #if CONFIG_YAFFS2_RAM_ENABLED
86 #include "yaffs_nandemul2k.h"
87 #endif
88
89 #ifdef CONFIG_YAFFS_MTD_ENABLED
90 #include <linux/mtd/mtd.h>
91 #include "yaffs_mtdif.h"
92 #include "yaffs_mtdif2.h"
93 #endif //CONFIG_YAFFS_MTD_ENABLED
94
95 //#define T(x) printk x
96
97
98
99 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)((iptr)->u.generic_ip))
100 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
101 //NCB #define yaffs_SuperToDevice(sb)   ((yaffs_Device *)sb->u.generic_sbp)
102
103 //#if defined(CONFIG_KERNEL_2_5)
104 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
105 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
106 #else
107 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
108 #endif
109
110
111 static void yaffs_put_super(struct super_block *sb);
112
113 #if 0
114 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos);
115 #endif
116
117 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos);
118
119 static int yaffs_file_flush(struct file* file);
120
121 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync);
122
123 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
124
125 //#if defined(CONFIG_KERNEL_2_5)        /* Added NCB 185-8-2003 */
126 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
127 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n);
128 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n);
129 #else
130 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
131 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry);
132 #endif
133 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry);
134 static int yaffs_unlink(struct inode * dir, struct dentry *dentry);
135 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname);
136 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode);
137
138 //#if defined(CONFIG_KERNEL_2_5)
139 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
140 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev);
141 #else
142 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int dev);
143 #endif
144 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry);
145 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
146
147 //#if defined(CONFIG_KERNEL_2_5)        /* Added NCB 185-8-2003 */
148 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
149 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
150 #else
151 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
152 #endif
153 static void yaffs_read_inode (struct inode *inode);
154
155 //#if defined(CONFIG_KERNEL_2_5)
156 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
157 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data);
158 #else
159 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent);
160 #endif
161
162 static void yaffs_put_inode (struct inode *inode);
163 static void yaffs_delete_inode(struct inode *);
164 static void yaffs_clear_inode(struct inode *);
165
166 static int yaffs_readpage(struct file *file, struct page * page);
167 static int yaffs_writepage(struct page *page);
168 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
169 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to);
170
171 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen);
172 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
173
174
175
176
177 static struct address_space_operations yaffs_file_address_operations = {
178         readpage:               yaffs_readpage,
179         writepage:              yaffs_writepage,
180         prepare_write:  yaffs_prepare_write,
181         commit_write:   yaffs_commit_write
182 };
183
184
185 static struct file_operations yaffs_file_operations = {
186
187         read:           generic_file_read,
188         write:          generic_file_write,
189
190         mmap:           generic_file_mmap,
191         flush:          yaffs_file_flush,
192         fsync:          yaffs_sync_object,
193 };
194
195
196 static struct inode_operations yaffs_file_inode_operations = {
197         setattr:        yaffs_setattr,
198 };
199
200
201 struct inode_operations yaffs_symlink_inode_operations =
202 {       
203         readlink:       yaffs_readlink,
204         follow_link:    yaffs_follow_link,
205         setattr:        yaffs_setattr
206 };
207
208 static struct inode_operations yaffs_dir_inode_operations = {
209         create:         yaffs_create,
210         lookup:         yaffs_lookup,
211         link:           yaffs_link,
212         unlink:         yaffs_unlink,   
213         symlink:        yaffs_symlink,
214         mkdir:          yaffs_mkdir,
215         rmdir:          yaffs_unlink,
216         mknod:          yaffs_mknod,
217         rename:         yaffs_rename,
218         setattr:        yaffs_setattr,
219 };
220
221 static struct file_operations yaffs_dir_operations = {
222         read:           generic_read_dir,
223         readdir:        yaffs_readdir,
224         fsync:          yaffs_sync_object,
225 };
226
227
228 static struct super_operations yaffs_super_ops = {
229         statfs:                 yaffs_statfs,
230         read_inode:             yaffs_read_inode,
231         put_inode:              yaffs_put_inode,
232         put_super:              yaffs_put_super,
233 //      remount_fs:
234         delete_inode:           yaffs_delete_inode,
235         clear_inode:            yaffs_clear_inode,
236 };
237
238
239
240 static void yaffs_GrossLock(yaffs_Device *dev)
241 {
242         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs locking\n"));
243
244         down(&dev->grossLock);
245 }
246
247 static void yaffs_GrossUnlock(yaffs_Device *dev)
248 {
249         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs unlocking\n"));
250         up(&dev->grossLock);
251
252 }
253
254 static int yaffs_readlink(struct dentry *dentry, char *buffer, int buflen)
255 {
256         unsigned char *alias;
257         int ret;
258
259         yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
260
261
262         yaffs_GrossLock(dev);
263         
264         alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
265         
266         yaffs_GrossUnlock(dev);
267         
268         if(!alias)
269                 return -ENOMEM;
270
271         ret = vfs_readlink(dentry, buffer, buflen, alias);
272         kfree(alias);
273         return ret;
274 }
275
276 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
277 {
278         unsigned char *alias;
279         int ret;
280         yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
281
282
283         yaffs_GrossLock(dev);
284
285         alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
286         
287         yaffs_GrossUnlock(dev);
288         
289         if(!alias)
290                 return -ENOMEM;
291
292         ret = vfs_follow_link(nd,alias);
293         kfree(alias);
294         return ret;
295 }
296
297
298 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj);
299
300 /*
301  * Lookup is used to find objects in the fs
302  */
303 //#if defined(CONFIG_KERNEL_2_5)        /* Added NCB 185-8-2003 */
304 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
305
306 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *n)
307 #else
308 static struct dentry * yaffs_lookup(struct inode *dir, struct dentry *dentry)
309 #endif
310 {
311         yaffs_Object *obj;
312         struct inode *inode = NULL; // NCB 2.5/2.6 needs NULL here
313         
314         yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
315
316
317         yaffs_GrossLock(dev);
318
319         
320         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup for %d:%s\n",yaffs_InodeToObject(dir)->objectId,dentry->d_name.name));
321         
322         obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),dentry->d_name.name);
323         
324         obj = yaffs_GetEquivalentObject(obj); // in case it was a hardlink
325         
326
327         
328         if(obj)
329         {
330                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup found %d\n",obj->objectId));
331                 
332                 inode = yaffs_get_inode(dir->i_sb, obj->st_mode,0,obj);
333                 
334                 if(inode)
335                 {
336                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_loookup dentry \n"));
337 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to d_add even if NULL inode */ 
338 #if 0
339                         //dget(dentry); // try to solve directory bug
340                         d_add(dentry,inode);
341                         
342                         yaffs_GrossUnlock(dev);
343
344                         // return dentry;
345                         return NULL;
346 #endif
347                 }
348
349         }
350         else
351         {
352                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_lookup not found\n"));
353                 
354         }
355         yaffs_GrossUnlock(dev);
356
357 /* added NCB for 2.5/6 compatability - forces add even if inode is NULL which creates dentry hash*/     
358         d_add(dentry,inode);
359         
360         return NULL;
361         //      return (ERR_PTR(-EIO));
362         
363 }
364
365 // For now put inode is just for debugging
366 // Put inode is called when the inode **structure** is put.
367 static void yaffs_put_inode(struct inode *inode)
368 {
369         T(YAFFS_TRACE_OS,("yaffs_put_inode: ino %d, count %d\n",(int)inode->i_ino, atomic_read(&inode->i_count)));
370         
371 }
372
373 // clear is called to tell the fs to release any per-inode data it holds
374 static void yaffs_clear_inode(struct inode *inode)
375 {
376         yaffs_Object *obj;
377         yaffs_Device *dev;
378         
379         obj = yaffs_InodeToObject(inode);
380         
381         T(YAFFS_TRACE_OS,("yaffs_clear_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
382                 obj ? "object exists" : "null object"));        
383
384         if(obj)
385         {
386                 dev = obj->myDev;
387                 yaffs_GrossLock(dev);
388                 
389                 // Clear the association between the inode ant the yaffs_Object.
390                 obj->myInode = NULL;
391                 inode->u.generic_ip = NULL;
392                 
393                 // If the object freeing was deferred, then the real free happens now.
394                 // This should fix the inode inconsistency problem.
395                 
396                 yaffs_HandleDeferedFree(obj);
397                 
398                 yaffs_GrossUnlock(dev);
399         }
400         
401         
402 }
403
404 // delete is called when the link count is zero and the inode
405 // is put (ie. nobody wants to know about it anymore, time to
406 // delete the file).
407 // NB Must call clear_inode()
408 static void yaffs_delete_inode(struct inode *inode)
409 {
410         yaffs_Object *obj = yaffs_InodeToObject(inode);
411         yaffs_Device *dev;
412
413         T(YAFFS_TRACE_OS,("yaffs_delete_inode: ino %d, count %d %s\n",(int)inode->i_ino, atomic_read(&inode->i_count),
414                 obj ? "object exists" : "null object"));
415         
416         if(obj)
417         {
418                 dev = obj->myDev;
419                 yaffs_GrossLock(dev);
420                 yaffs_DeleteFile(obj);
421                 yaffs_GrossUnlock(dev);
422         }
423         clear_inode(inode);
424 }
425
426
427 static int yaffs_file_flush(struct file* file)
428 {
429         yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
430         
431         yaffs_Device *dev = obj->myDev;
432         
433         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_flush object %d (%s)\n",obj->objectId,
434                                 obj->dirty ? "dirty" : "clean"));
435
436         yaffs_GrossLock(dev);
437         
438     yaffs_FlushFile(obj,1);
439
440         yaffs_GrossUnlock(dev);
441
442     return 0;
443 }
444
445
446
447 static int yaffs_readpage_nolock(struct file *f, struct page * pg)
448 {
449         // Lifted from jffs2
450         
451         yaffs_Object *obj;
452         unsigned char *pg_buf;
453         int ret;
454
455         yaffs_Device *dev;
456
457         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage at %08x, size %08x\n",
458                       (unsigned)(pg->index << PAGE_CACHE_SHIFT), (unsigned)PAGE_CACHE_SIZE));
459
460         obj  = yaffs_DentryToObject(f->f_dentry);
461
462         dev = obj->myDev;
463         
464         
465         if (!PageLocked(pg))
466                 PAGE_BUG(pg);
467
468         pg_buf = kmap(pg);
469         /* FIXME: Can kmap fail? */
470
471         yaffs_GrossLock(dev);
472         
473         ret = yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT, PAGE_CACHE_SIZE);
474
475         yaffs_GrossUnlock(dev);
476         
477         if(ret >= 0) ret = 0;
478
479         if (ret) {
480                 ClearPageUptodate(pg);
481                 SetPageError(pg);
482         } else {
483                 SetPageUptodate(pg);
484                 ClearPageError(pg);
485         }
486
487         flush_dcache_page(pg);
488         kunmap(pg);
489
490
491         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readpage done\n"));
492         return ret;
493 }
494
495 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
496 {
497         int ret = yaffs_readpage_nolock(f,pg);
498         UnlockPage(pg);
499         return ret;
500 }
501
502 static int yaffs_readpage(struct file *f, struct page * pg)
503 {
504         return yaffs_readpage_unlock(f,pg);
505 }
506
507 // writepage inspired by/stolen from smbfs
508 //
509
510 static int yaffs_writepage(struct page *page)
511 {
512         struct address_space *mapping = page->mapping;
513         struct inode *inode;
514         unsigned long end_index;
515         char *buffer;
516         yaffs_Object *obj;
517         int nWritten = 0;
518         unsigned nBytes;
519
520         if (!mapping)
521                 BUG();
522         inode = mapping->host;
523         if (!inode)
524                 BUG();
525
526         end_index = inode->i_size >> PAGE_CACHE_SHIFT;
527
528         /* easy case */
529         if (page->index < end_index)
530         {
531                 nBytes = PAGE_CACHE_SIZE;
532         }
533         else
534         {
535                 nBytes = inode->i_size & (PAGE_CACHE_SIZE-1);
536         }
537         //  What's happening here?
538         ///* OK, are we completely out? */
539         //if (page->index >= end_index+1 || !offset)
540         //      return -EIO;
541
542         get_page(page);
543
544
545         buffer = kmap(page);
546
547         obj = yaffs_InodeToObject(inode);
548         yaffs_GrossLock(obj->myDev);
549
550
551         nWritten = yaffs_WriteDataToFile(obj,buffer,page->index << PAGE_CACHE_SHIFT,nBytes,0);
552
553         yaffs_GrossUnlock(obj->myDev);
554         
555         kunmap(page);
556         SetPageUptodate(page);
557         UnlockPage(page);
558         put_page(page);
559
560         return (nWritten == nBytes) ? 0  : -ENOSPC;
561 }
562
563
564
565 static int yaffs_prepare_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
566 {
567
568         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_prepair_write\n"));
569         if(!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
570                 return  yaffs_readpage_nolock(f,pg);    
571
572         return 0;
573         
574 }
575
576 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset, unsigned to)
577 {
578
579         void *addr = page_address(pg) + offset;
580         loff_t pos = (((loff_t)pg->index) << PAGE_CACHE_SHIFT) + offset;
581         int nBytes = to - offset;
582         int nWritten;
583         
584         unsigned spos = pos;
585         unsigned saddr = (unsigned)addr;
586
587         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write addr %x pos %x nBytes %d\n",saddr,spos,nBytes));
588         
589         nWritten = yaffs_file_write(f,addr, nBytes, &pos);
590         
591         if(nWritten != nBytes)
592         {
593                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write not same size nWritten %d  nBytes %d\n",nWritten,nBytes));
594                 SetPageError(pg);
595                 ClearPageUptodate(pg);
596         }
597         else
598         {
599                 SetPageUptodate(pg);
600         }
601
602         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_commit_write returning %d\n",nWritten));
603         
604         return nWritten;
605
606 }
607
608
609
610 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
611 {
612         if (inode && obj) 
613         {
614                 inode->i_ino = obj->objectId;
615                 inode->i_mode = obj->st_mode;
616                 inode->i_uid = obj->st_uid;
617                 inode->i_gid = obj->st_gid;
618                 inode->i_blksize = inode->i_sb->s_blocksize;
619 //#if defined(CONFIG_KERNEL_2_5)
620 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
621
622                 inode->i_rdev = old_decode_dev(obj->st_rdev);
623                 inode->i_atime.tv_sec = (time_t)(obj->st_atime);
624                 inode->i_atime.tv_nsec = 0;
625                 inode->i_mtime.tv_sec = (time_t)obj->st_mtime;
626                 inode->i_mtime.tv_nsec =0;
627                 inode->i_ctime.tv_sec = (time_t)obj->st_ctime;
628                 inode->i_ctime.tv_nsec = 0;
629 #else
630                 inode->i_rdev = obj->st_rdev;
631                 inode->i_atime = obj->st_atime;
632                 inode->i_mtime = obj->st_mtime;
633                 inode->i_ctime = obj->st_ctime;
634 #endif
635                 inode->i_size = yaffs_GetObjectFileLength(obj);
636                 inode->i_blocks = (inode->i_size + 511) >> 9;
637
638                 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
639                 
640                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
641                                 inode->i_mode, inode->i_uid, inode->i_gid, (int)inode->i_size, atomic_read(&inode->i_count)));
642                 
643                 switch (obj->st_mode & S_IFMT) 
644                 {
645                         default: // fifo, device or socket
646 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
647                                init_special_inode(inode, obj->st_mode,old_decode_dev(obj->st_rdev));
648 #else
649                                  init_special_inode(inode, obj->st_mode,(dev_t)(obj->st_rdev));
650 #endif                          break;
651                         case S_IFREG:   // file         
652                                 inode->i_op = &yaffs_file_inode_operations;
653                                 inode->i_fop = &yaffs_file_operations;
654                                 inode->i_mapping->a_ops = &yaffs_file_address_operations;
655                                 break;
656                         case S_IFDIR:   // directory
657                                 inode->i_op = &yaffs_dir_inode_operations;
658                                 inode->i_fop = &yaffs_dir_operations;
659                                 break;
660                         case S_IFLNK:   // symlink
661                                 inode->i_op = &yaffs_symlink_inode_operations;
662                                 break;
663                 }
664                 
665                 
666                 inode->u.generic_ip = obj;
667                 obj->myInode = inode;
668                 
669         }
670         else
671         {
672                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_FileInode invalid parameters\n"));
673         }
674
675 }
676
677 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,yaffs_Object *obj)
678 {
679         struct inode * inode;
680         
681         if(!sb)
682         {
683           T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL super_block!!\n"));
684           return NULL;
685           
686         }
687         
688         if(!obj)
689         {
690           T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for NULL object!!\n"));
691           return NULL;
692           
693         }
694         
695         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_get_inode for object %d\n",obj->objectId));
696
697         inode = iget(sb,obj->objectId);
698
699         // NB Side effect: iget calls back to yaffs_read_inode().
700         // iget also increments the inode's i_count
701         
702         return inode;
703 }
704
705 #if 0
706
707 // No longer used because we use generic rw */
708 static ssize_t yaffs_file_read(struct file *f, char *buf, size_t n, loff_t *pos)
709 {
710         yaffs_Object *obj;
711         int nRead,ipos;
712         struct inode *inode;
713         yaffs_Device *dev;
714         
715         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read\n"));
716
717         obj  = yaffs_DentryToObject(f->f_dentry);
718         
719         dev = obj->myDev;
720         
721         yaffs_GrossLock(dev);
722         
723         inode = f->f_dentry->d_inode;
724         
725         if (*pos < inode->i_size) 
726         {
727                         if (*pos + n > inode->i_size)
728                         {
729                                 n = inode->i_size - *pos;
730                         }
731         }
732         else
733         {
734                 n = 0;
735         }
736         
737         nRead = yaffs_ReadDataFromFile(obj,buf,*pos,n);
738         if(nRead > 0)
739         {
740                 f->f_pos += nRead;
741         }
742         
743         yaffs_GrossUnlock(dev);
744         
745         ipos = *pos;
746         
747         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_read read %d bytes, %d read at %d\n",n,nRead,ipos));
748         return nRead;
749         
750 }
751
752 #endif
753
754 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n, loff_t *pos)
755 {
756         yaffs_Object *obj;
757         int nWritten,ipos;
758         struct inode *inode;
759         yaffs_Device *dev;
760         
761         
762         obj  = yaffs_DentryToObject(f->f_dentry);
763         
764         dev = obj->myDev;
765         
766         yaffs_GrossLock(dev);
767
768         inode = f->f_dentry->d_inode;
769
770         if(!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
771         {
772                 ipos = inode->i_size;
773         }
774         else
775         {
776                 ipos = *pos;
777         }
778         
779         
780         if(!obj)
781         {
782                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write: hey obj is null!\n"));
783         }
784         else
785         {
786                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write about to write writing %d bytes to object %d at %d\n",n,obj->objectId,ipos));
787         }
788
789         nWritten = yaffs_WriteDataToFile(obj,buf,ipos,n,0);
790
791         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write writing %d bytes, %d written at %d\n",n,nWritten,ipos));
792         if(nWritten > 0)
793         {
794                 ipos += nWritten;
795                 *pos = ipos;
796                 if(ipos > inode->i_size)
797                 {
798                         inode->i_size = ipos;
799                         inode->i_blocks = (ipos + 511)>>9;
800                         
801                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_file_write size updated to %d bytes, %d blocks\n",ipos,(int)(inode->i_blocks)));
802                 }
803                 
804         }
805         yaffs_GrossUnlock(dev);
806         
807         return nWritten != n ? -ENOSPC : nWritten;
808 }
809
810
811
812 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
813 {
814         yaffs_Object *obj;
815         yaffs_Device *dev;
816         struct inode *inode = f->f_dentry->d_inode;
817         unsigned long offset, curoffs;
818         struct list_head *i;    
819         yaffs_Object *l;
820         
821         char name[YAFFS_MAX_NAME_LENGTH +1];
822                 
823         obj =  yaffs_DentryToObject(f->f_dentry);
824         dev = obj->myDev;
825         
826         yaffs_GrossLock(dev);
827         
828         offset = f->f_pos;
829         
830         T(YAFFS_TRACE_OS,("yaffs_readdir: starting at %d\n",(int)offset));
831         
832         if(offset == 0)
833         {
834         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry . ino %d \n",(int)inode->i_ino));
835                 if(filldir(dirent,".",1,offset,inode->i_ino,DT_DIR) < 0)
836                 {
837                         goto out;
838                 }
839                 offset++;
840                 f->f_pos++;
841         }
842         if(offset == 1)
843         {
844                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: entry .. ino %d \n",(int)f->f_dentry->d_parent->d_inode->i_ino));
845                 if(filldir(dirent,"..",2,offset,f->f_dentry->d_parent->d_inode->i_ino,DT_DIR) < 0)
846                 {
847                         goto out;
848                 }
849                 offset++;
850                 f->f_pos++;
851         }
852         
853         curoffs = 1;
854         
855         list_for_each(i,&obj->variant.directoryVariant.children)
856         {
857                 curoffs++;
858                 if(curoffs >= offset)
859                 {               
860                         l = list_entry(i, yaffs_Object,siblings);
861                         
862                         yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1); 
863                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_readdir: %s inode %d\n",name,yaffs_GetObjectInode(l)));
864                         
865                         if(filldir(dirent,
866                                            name,
867                                            strlen(name),
868                                            offset,
869                                            yaffs_GetObjectInode(l),
870                                            yaffs_GetObjectType(l))
871                                            < 0)
872                         {
873                                 goto up_and_out;
874                         }
875                         
876                         offset++;
877                         f->f_pos++;        
878                 }
879         }
880
881   up_and_out:
882   out:
883   
884     yaffs_GrossUnlock(dev);
885     
886         return 0;
887 }
888
889
890 /*
891  * File creation. Allocate an inode, and we're done..
892  */
893 //#if defined(CONFIG_KERNEL_2_5)
894 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
895 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
896 #else
897 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode, int rdev)
898 #endif
899 {
900         struct inode *inode;
901         
902         yaffs_Object *obj = NULL;
903         yaffs_Device *dev;
904         
905         yaffs_Object *parent = yaffs_InodeToObject(dir);
906         
907         int error = -ENOSPC;
908
909         if(parent)
910         {
911                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: parent object %d type %d\n",
912                                          parent->objectId,parent->variantType));
913         }
914         else
915         {
916                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: could not get parent object\n"));
917                 return -EPERM;
918         }
919         
920         T(YAFFS_TRACE_OS,("yaffs_mknod: making oject for %s, mode %x dev %x\n",
921                                         dentry->d_name.name, mode,rdev));
922
923         dev = parent->myDev;
924         
925         yaffs_GrossLock(dev);
926
927         switch (mode & S_IFMT) 
928         {
929                 default:
930                         // Special (socket, fifo, device...)
931                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making special\n"));
932 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
933                         obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,old_encode_dev(rdev));
934 #else
935                         obj = yaffs_MknodSpecial(parent,dentry->d_name.name,mode,current->uid, current->gid,rdev);
936 #endif                  break;
937                 case S_IFREG:   // file         
938                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
939                         obj = yaffs_MknodFile(parent,dentry->d_name.name,mode,current->uid, current->gid);
940                         break;
941                 case S_IFDIR:   // directory
942                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making directory\n"));
943                         obj = yaffs_MknodDirectory(parent,dentry->d_name.name,mode,current->uid, current->gid);
944                         break;
945                 case S_IFLNK:   // symlink
946                         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod: making file\n"));
947                         obj = NULL; // Do we ever get here?
948                         break;
949         }
950         
951         if(obj)
952         {
953                 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
954                 d_instantiate(dentry, inode);
955                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod created object %d count = %d\n",obj->objectId,atomic_read(&inode->i_count)));
956                 error = 0;
957         }
958         else
959         {
960                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mknod failed making object\n"));
961                 error = -ENOMEM;
962         }
963
964         yaffs_GrossUnlock(dev);
965
966         return error;
967 }
968
969 static int yaffs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
970 {
971         int retVal;
972         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_mkdir\n"));
973         retVal =  yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
974 #if 0
975  // attempt to fix dir bug - didn't work
976         if(!retVal)
977         {
978                 dget(dentry);
979         }
980 #endif
981         return retVal;
982 }
983
984 //#if defined(CONFIG_KERNEL_2_5)        /* Added NCB 185-8-2003 */
985 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
986 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *n)
987 #else
988 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
989 #endif
990 {
991         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_create\n"));
992         return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
993 }
994
995
996 static int yaffs_unlink(struct inode * dir, struct dentry *dentry)
997 {
998         int retVal;
999         
1000         yaffs_Device *dev;
1001         
1002         
1003         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_unlink %d:%s\n",(int)(dir->i_ino),dentry->d_name.name));
1004         
1005         dev = yaffs_InodeToObject(dir)->myDev;
1006         
1007         yaffs_GrossLock(dev);
1008         
1009         
1010         retVal = yaffs_Unlink(yaffs_InodeToObject(dir),dentry->d_name.name);
1011         
1012         
1013         yaffs_GrossUnlock(dev);
1014         
1015         if( retVal == YAFFS_OK)
1016         {
1017                 dentry->d_inode->i_nlink--;
1018                 mark_inode_dirty(dentry->d_inode);
1019                 return 0;
1020         }
1021         else
1022         {
1023                 return -ENOTEMPTY;
1024         }
1025 }
1026
1027
1028 /*
1029  * Create a link...
1030  */
1031 static int yaffs_link(struct dentry *old_dentry, struct inode * dir, struct dentry * dentry)
1032 {
1033         struct inode *inode = old_dentry->d_inode;
1034         yaffs_Object *obj = NULL;
1035         yaffs_Object *link=NULL;
1036         yaffs_Device *dev;
1037         
1038         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link\n"));
1039         
1040         obj = yaffs_InodeToObject(inode);
1041         dev = obj->myDev;
1042         
1043         yaffs_GrossLock(dev);
1044
1045         if (!S_ISDIR(inode->i_mode))    // Don't link directories
1046         {
1047                 link = yaffs_Link(yaffs_InodeToObject(dir),dentry->d_name.name,obj);
1048         }
1049         
1050
1051         if(link)
1052         {
1053                 old_dentry->d_inode->i_nlink =  yaffs_GetObjectLinkCount(obj);
1054                 d_instantiate(dentry, old_dentry->d_inode);
1055                 atomic_inc(&old_dentry->d_inode->i_count);
1056                 T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_link link count %d i_count %d\n",    
1057                         old_dentry->d_inode->i_nlink,atomic_read(&old_dentry->d_inode->i_count)));
1058         
1059         }
1060         
1061         yaffs_GrossUnlock(dev);
1062         
1063
1064         if(link)
1065         {
1066         
1067                 return 0;
1068         }
1069         
1070         
1071         return -EPERM; 
1072 }
1073
1074
1075 static int yaffs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
1076 {
1077         yaffs_Object *obj;
1078         yaffs_Device *dev;
1079         
1080         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_symlink\n"));
1081         
1082         dev = yaffs_InodeToObject(dir)->myDev;
1083         yaffs_GrossLock(dev);
1084         obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name, 
1085                                                          S_IFLNK | S_IRWXUGO, current->uid, current->gid,
1086                                                          symname);
1087         yaffs_GrossUnlock(dev);
1088
1089         if(obj)
1090         {
1091
1092                 struct inode* inode;
1093         
1094                 inode = yaffs_get_inode(dir->i_sb, obj->st_mode, 0, obj);
1095                 d_instantiate(dentry, inode);
1096                 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink created OK\n"));
1097                 return 0;
1098         }
1099         else
1100         {
1101                 T(YAFFS_TRACE_OS,(KERN_DEBUG"symlink not created\n"));
1102
1103         }
1104         
1105         return -ENOMEM;
1106 }
1107
1108 static int yaffs_sync_object(struct file * file, struct dentry *dentry, int datasync)
1109 {
1110
1111         yaffs_Object *obj;
1112         yaffs_Device *dev;
1113         
1114         obj = yaffs_DentryToObject(dentry);
1115
1116         dev = obj->myDev;
1117         
1118         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_sync_object\n"));
1119         yaffs_GrossLock(dev);
1120         yaffs_FlushFile(obj,1);
1121         yaffs_GrossUnlock(dev);
1122         return 0;
1123 }
1124
1125 /*
1126  * The VFS layer already does all the dentry stuff for rename.
1127  *
1128  * NB: POSIX says you can rename an object over an old object of the same name
1129  */
1130 static int yaffs_rename(struct inode * old_dir, struct dentry *old_dentry, struct inode * new_dir,struct dentry *new_dentry)
1131 {
1132         yaffs_Device *dev;
1133         int retVal = YAFFS_FAIL;
1134         int removed = 0;
1135         yaffs_Object *target;
1136         
1137         dev = yaffs_InodeToObject(old_dir)->myDev;
1138
1139         yaffs_GrossLock(dev);
1140         
1141         // Check if the target is an existing directory that is not empty.
1142         target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1143         
1144         if(target &&
1145            target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1146            !list_empty(&target->variant.directoryVariant.children))
1147         {
1148                 retVal = YAFFS_FAIL;
1149         }
1150         else
1151         {
1152            
1153                 // Unlink the target if it exists
1154                 removed = yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1155
1156         
1157                 retVal =  yaffs_RenameObject(yaffs_InodeToObject(old_dir),old_dentry->d_name.name,
1158                                                                         yaffs_InodeToObject(new_dir),new_dentry->d_name.name);
1159                                                                         
1160         }
1161         yaffs_GrossUnlock(dev);
1162         
1163         if(retVal == YAFFS_OK)
1164         {
1165                 if(removed == YAFFS_OK)
1166                 {
1167                         new_dentry->d_inode->i_nlink--;
1168                         mark_inode_dirty(new_dentry->d_inode);
1169                 }
1170                 
1171                 return 0;
1172         }
1173         else
1174         {
1175                 return -ENOTEMPTY;
1176         }
1177         
1178
1179 }
1180
1181 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1182 {
1183         struct inode *inode = dentry->d_inode;
1184         int error;
1185         yaffs_Device *dev;
1186         
1187         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_setattr of object %d\n",yaffs_InodeToObject(inode)->objectId));
1188         
1189         if((error = inode_change_ok(inode,attr)) == 0)
1190         {
1191         
1192                 dev = yaffs_InodeToObject(inode)->myDev;
1193                 yaffs_GrossLock(dev);
1194                 if(yaffs_SetAttributes(yaffs_InodeToObject(inode),attr) == YAFFS_OK)
1195                 {
1196                         error = 0;
1197                 }
1198                 else
1199                 {
1200                         error = -EPERM;
1201                 }
1202                 yaffs_GrossUnlock(dev);
1203                 inode_setattr(inode,attr);
1204         }
1205         return error;
1206 }
1207
1208 //#if defined(CONFIG_KERNEL_2_5)        /* Added NCB 185-8-2003 */
1209 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1210 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1211 #else
1212 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1213 #endif
1214 {
1215
1216         
1217         yaffs_Device *dev = yaffs_SuperToDevice(sb);
1218         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_statfs\n"));
1219
1220         yaffs_GrossLock(dev);
1221         
1222         
1223         buf->f_type = YAFFS_MAGIC;
1224         buf->f_bsize = sb->s_blocksize;
1225         buf->f_namelen = 255;
1226         if(sb->s_blocksize > dev->nBytesPerChunk)
1227         {
1228                 
1229                 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock/
1230                                                 (sb->s_blocksize/dev->nBytesPerChunk);
1231                 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev)/
1232                                                 (sb->s_blocksize/dev->nBytesPerChunk);
1233         }
1234         else
1235         {
1236                 
1237                 buf->f_blocks = (dev->endBlock - dev->startBlock + 1) * dev->nChunksPerBlock *
1238                                                 (dev->nBytesPerChunk/sb->s_blocksize);
1239                 buf->f_bfree = yaffs_GetNumberOfFreeChunks(dev) *
1240                                                 (dev->nBytesPerChunk/sb->s_blocksize);
1241         }
1242         buf->f_files = 0;
1243         buf->f_ffree = 0;
1244         buf->f_bavail =  buf->f_bfree;
1245         
1246         yaffs_GrossUnlock(dev);
1247         return 0;
1248 }
1249
1250 static void yaffs_read_inode (struct inode *inode)
1251 {
1252         // NB This is called as a side effect of other functions and
1253         // thus gross locking should always be in place already.
1254         
1255         yaffs_Object *obj ; 
1256         yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1257         
1258         T(YAFFS_TRACE_OS,(KERN_DEBUG"yaffs_read_inode for %d\n",(int)inode->i_ino));
1259
1260         obj  = yaffs_FindObjectByNumber(dev,inode->i_ino);
1261         
1262         yaffs_FillInodeFromObject(inode,obj);
1263
1264 }
1265
1266
1267
1268 // Todo
1269 // Currently we only can report a single partition. Need to use lists here
1270 static yaffs_Device *yaffs_dev;
1271 static yaffs_Device *yaffsram_dev;
1272
1273
1274
1275 static void yaffs_put_super(struct super_block *sb)
1276 {
1277         yaffs_Device *dev = yaffs_SuperToDevice(sb);
1278         
1279         yaffs_GrossLock(dev);
1280         if(dev->putSuperFunc)
1281         {
1282                  dev->putSuperFunc(sb);
1283         }
1284         yaffs_Deinitialise(dev);
1285         yaffs_GrossUnlock(dev);
1286
1287         if(dev == yaffs_dev) yaffs_dev = NULL;
1288         if(dev == yaffsram_dev) yaffsram_dev = NULL;
1289                 
1290         kfree(dev);
1291 }
1292
1293
1294 #ifdef CONFIG_YAFFS_MTD_ENABLED
1295
1296 static void  yaffs_MTDPutSuper(struct super_block *sb)
1297 {
1298         
1299         struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1300         
1301         if(mtd->sync)
1302         {
1303                 mtd->sync(mtd);
1304         }
1305         
1306         put_mtd_device(mtd);
1307 }
1308
1309 #endif
1310
1311
1312 static struct super_block *yaffs_internal_read_super(int yaffsVersion,int useRam, struct super_block * sb, void * data, int silent)
1313 {
1314         int nBlocks;
1315         struct inode * inode = NULL;
1316         struct dentry * root;
1317         yaffs_Device *dev;
1318         int err;
1319         
1320         sb->s_magic = YAFFS_MAGIC;
1321         sb->s_op = &yaffs_super_ops;
1322         
1323         if(!sb)
1324                 printk(KERN_INFO"yaffs: sb is NULL\n");
1325         else if(!sb->s_dev)
1326                 printk(KERN_INFO"yaffs: sb->s_dev is NULL\n");
1327         else if(! kdevname(sb->s_dev))
1328                 printk(KERN_INFO"yaffs: kdevname is NULL\n");
1329         else
1330                 printk(KERN_INFO"yaffs: dev is %d name is \"%s\"\n", sb->s_dev, kdevname(sb->s_dev));
1331
1332         
1333
1334 #ifdef CONFIG_YAFFS_USE_CHUNK_SIZE
1335         sb->s_blocksize = YAFFS_BYTES_PER_CHUNK;
1336         sb->s_blocksize_bits = YAFFS_CHUNK_SIZE_SHIFT;
1337 #else
1338         sb->s_blocksize = PAGE_CACHE_SIZE;
1339         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1340 #endif
1341         T(YAFFS_TRACE_OS,("yaffs_read_super: Using yaffs%d\n",yaffsVersion));
1342         T(YAFFS_TRACE_OS,("yaffs_read_super: %s block size %d\n", useRam ? "RAM" : "MTD",(int)(sb->s_blocksize)));
1343
1344 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1345         T(YAFFS_TRACE_OS,("yaffs: Write verification disabled. All guarantees null and void\n"));
1346 #endif
1347
1348
1349         
1350         if(useRam)
1351         {
1352
1353 #ifdef CONFIG_YAFFS_RAM_ENABLED
1354                 // Set the yaffs_Device up for ram emulation
1355
1356                 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1357                 if(!dev)
1358                 {
1359                         // Deep shit could not allocate device structure
1360                         T(YAFFS_TRACE_OS,("yaffs_read_super: Failed trying to allocate yaffs_Device.\n"));
1361                         return NULL;
1362                 }
1363
1364                 memset(dev,0,sizeof(yaffs_Device));
1365                 dev->genericDevice = NULL; // Not used for RAM emulation.
1366
1367                 nBlocks = YAFFS_RAM_EMULATION_SIZE / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1368                 dev->startBlock = 1;  // Don't use block 0
1369                 dev->endBlock = nBlocks - 1;
1370                 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1371                 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1372                 dev->nReservedBlocks = 5;
1373                 
1374                 if(yaffsVersion == 2)
1375                 {
1376                         dev->writeChunkWithTagsToNAND  = nandemul2k_WriteChunkWithTagsToNAND;
1377                         dev->readChunkWithTagsFromNAND = nandemul2k_ReadChunkWithTagsFromNAND;
1378                         dev->markNANDBlockBad          = nandemul2k_MarkNANDBlockBad;
1379                         dev->queryNANDBlock            = nandemul2k_QueryNANDBlock;
1380                         dev->eraseBlockInNAND          = nandemul2k_EraseBlockInNAND;
1381                         dev->initialiseNAND            = nandemul2k_InitialiseNAND;
1382                         dev->isYaffs2 = 1;
1383                         dev->nChunksPerBlock = nandemul2k_GetChunksPerBlock();
1384                         dev->nBytesPerChunk =  nandemul2k_GetBytesPerChunk();;
1385                         nBlocks = nandemul2k_GetNumberOfBlocks();
1386                         dev->startBlock = 1;  // Don't use block 0
1387                         dev->endBlock = nBlocks - 1;
1388                 }
1389                 else
1390                 {
1391                         dev->writeChunkToNAND = nandemul_WriteChunkToNAND;
1392                         dev->readChunkFromNAND = nandemul_ReadChunkFromNAND;
1393                         dev->eraseBlockInNAND = nandemul_EraseBlockInNAND;
1394                         dev->initialiseNAND = nandemul_InitialiseNAND;
1395                         dev->isYaffs2 = 0;
1396                 }
1397                 
1398                 yaffsram_dev = dev;
1399                 
1400 #endif
1401
1402         }
1403         else
1404         {       
1405 #ifdef CONFIG_YAFFS_MTD_ENABLED
1406                 struct mtd_info *mtd;
1407                 
1408                 T(YAFFS_TRACE_ALWAYS,("yaffs: Attempting MTD mount on %u.%u, \"%s\"\n",
1409                  MAJOR(sb->s_dev),MINOR(sb->s_dev),kdevname(sb->s_dev)));
1410                         
1411                 // Check it's an mtd device.....
1412                 if(MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1413                 {
1414                         return NULL; // This isn't an mtd device
1415                 } 
1416                 
1417                 // Get the device
1418                 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1419                 if (!mtd) 
1420                 {
1421                         T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device #%u doesn't appear to exist\n", MINOR(sb->s_dev)));
1422                         return NULL;
1423                 }
1424                 
1425                 // Check it's NAND
1426                 if(mtd->type != MTD_NANDFLASH)
1427                 {
1428                         T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1429                         return NULL;
1430                 }
1431
1432                 T(YAFFS_TRACE_OS,(" erase %x\n",mtd->erase));
1433                 T(YAFFS_TRACE_OS,(" read %x\n",mtd->read));
1434                 T(YAFFS_TRACE_OS,(" write %x\n",mtd->write));
1435                 T(YAFFS_TRACE_OS,(" readoob %x\n",mtd->read_oob));
1436                 T(YAFFS_TRACE_OS,(" writeoob %x\n",mtd->write_oob));
1437                 T(YAFFS_TRACE_OS,(" block_isbad %x\n",mtd->block_isbad));
1438                 T(YAFFS_TRACE_OS,(" block_markbad %x\n",mtd->block_markbad));
1439                 T(YAFFS_TRACE_OS,(" oobblock %d\n",mtd->oobblock));
1440                 T(YAFFS_TRACE_OS,(" oobsize %d\n",mtd->oobsize));
1441                 T(YAFFS_TRACE_OS,(" erasesize %d\n",mtd->erasesize));
1442                 T(YAFFS_TRACE_OS,(" size %d\n",mtd->size));
1443
1444                 if(yaffsVersion == 2)
1445                 {
1446                         // Check for version 2 style functions
1447                         if(!mtd->erase ||
1448                            !mtd->block_isbad ||
1449                            !mtd->block_markbad ||
1450                            !mtd->read  ||
1451                            !mtd->write ||
1452 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1453                            !mtd->write_ecc ||
1454                            !mtd->read_ecc ||
1455 #endif
1456                            !mtd->read_oob ||
1457                            !mtd->write_oob )
1458                         {
1459                                 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1460                                 return NULL;
1461                         }
1462                 
1463                         if(mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1464                            mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE)
1465                         {
1466                                 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1467                                 return NULL;
1468                         }               }
1469                 else
1470                 {
1471                         // Check for V1 style functions
1472                         if(!mtd->erase ||
1473                            !mtd->read  ||
1474                            !mtd->write ||
1475 #ifndef CONFIG_YAFFS_USE_OLD_MTD
1476                            !mtd->write_ecc ||
1477                            !mtd->read_ecc ||
1478 #endif
1479                            !mtd->read_oob ||
1480                            !mtd->write_oob )
1481                         {
1482                                 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support required functions\n"));;
1483                                 return NULL;
1484                         }
1485                 
1486                         if(mtd->oobblock != YAFFS_BYTES_PER_CHUNK ||
1487                            mtd->oobsize != YAFFS_BYTES_PER_SPARE)
1488                         {
1489                                 T(YAFFS_TRACE_ALWAYS,("yaffs: MTD device does not support have the right page sizes\n"));
1490                                 return NULL;
1491                         }
1492                 }
1493                    
1494
1495                         // OK, so if we got here, we have an MTD that's NAND and looks 
1496                         // like it has the right capabilities
1497                         // Set the yaffs_Device up for mtd
1498
1499 //#if defined(CONFIG_KERNEL_2_5)
1500 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1501                 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1502 #else
1503                 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device),GFP_KERNEL);
1504 #endif
1505                 if(!dev)
1506                 {
1507                         // Deep shit could not allocate device structure
1508                         T(YAFFS_TRACE_ALWAYS,("yaffs_read_super: Failed trying to allocate yaffs_Device. \n"));
1509                         return NULL;
1510                 }
1511
1512                 memset(dev,0,sizeof(yaffs_Device));
1513                 dev->genericDevice = mtd; 
1514
1515                 // Set up the memory size parameters....
1516                 
1517                 nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
1518                 dev->startBlock = 1;  // Don't use block 0
1519                 dev->endBlock = nBlocks - 1;
1520                 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
1521                 dev->nBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
1522                 dev->nReservedBlocks = 5;
1523                 dev->nShortOpCaches = 10; // Enable short op caching
1524                 
1525
1526                 // ... and the functions.
1527                 if(yaffsVersion == 2)
1528                 {
1529                         dev->writeChunkWithTagsToNAND = nandmtd2_WriteChunkWithTagsToNAND;
1530                         dev->readChunkWithTagsFromNAND = nandmtd2_ReadChunkWithTagsFromNAND;
1531                         dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
1532                         dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
1533                         dev->spareBuffer = YMALLOC(mtd->oobsize);
1534                         dev->isYaffs2 = 1;
1535                         dev->nBytesPerChunk = mtd->oobblock;
1536                         dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
1537                         nBlocks = mtd->size / mtd->erasesize;
1538                         dev->startBlock = 1;  // Don't use block 0
1539                         dev->endBlock = nBlocks - 1;
1540                 }
1541                 else
1542                 {
1543                         dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
1544                         dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
1545                         dev->isYaffs2 = 0;
1546                 }
1547                 // ... and common functions
1548                 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
1549                 dev->initialiseNAND = nandmtd_InitialiseNAND;
1550                 
1551                 dev->putSuperFunc = yaffs_MTDPutSuper;
1552                 
1553 #ifdef CONFIG_YAFFS_USE_NANDECC
1554                 dev->useNANDECC = 1;
1555 #endif
1556
1557                 yaffs_dev = dev;
1558                 
1559 #endif
1560         }
1561
1562         init_MUTEX(&dev->grossLock);
1563         
1564         
1565         yaffs_GrossLock(dev);
1566         
1567         err = yaffs_GutsInitialise(dev);
1568
1569         T(YAFFS_TRACE_OS,("yaffs_read_super: guts initialised %s\n", (err == YAFFS_OK) ? "OK" : "FAILED"));
1570
1571         // Create root inode
1572         if(err == YAFFS_OK)
1573           inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,yaffs_Root(dev));
1574
1575         yaffs_GrossUnlock(dev);
1576
1577         if (!inode)
1578                 return NULL;
1579                 
1580 // added NCB
1581         inode->i_op = & yaffs_dir_inode_operations;
1582         inode->i_fop = & yaffs_dir_operations;
1583
1584         T(YAFFS_TRACE_OS,("yaffs_read_super: got root inode\n"));
1585                 
1586
1587         root = d_alloc_root(inode);
1588
1589         T(YAFFS_TRACE_OS,("yaffs_read_super: d_alloc_root done\n"));
1590
1591         if (!root) {
1592                 iput(inode);
1593                 return NULL;
1594         }
1595         sb->s_root = root;
1596
1597         T(YAFFS_TRACE_OS,("yaffs_read_super: done\n"));
1598         return sb;
1599 }
1600
1601
1602 static int yaffs_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1603 {
1604          return yaffs_internal_read_super(1,1,sb,data,silent) ? 0 : -1;
1605 }
1606 static int yaffs_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1607 {
1608          return yaffs_internal_read_super(1,0,sb,data,silent) ? 0 : -1;
1609 }
1610
1611 static int yaffs2_internal_read_super_ram(struct super_block * sb, void * data, int silent)
1612 {
1613          return yaffs_internal_read_super(2,1,sb,data,silent) ? 0 : -1;
1614 }
1615 static int yaffs2_internal_read_super_mtd(struct super_block * sb, void * data, int silent)
1616 {
1617          return yaffs_internal_read_super(2,0,sb,data,silent) ? 0 : -1;
1618 }
1619
1620
1621
1622 #ifdef CONFIG_YAFFS_MTD_ENABLED
1623 //#if defined(CONFIG_KERNEL_2_5)
1624 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1625 static struct super_block *yaffs_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1626 {
1627
1628     return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_mtd);
1629 }
1630
1631 /* changes NCB 2.5.70 */
1632 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1633 static struct file_system_type yaffs_fs_type = {
1634         .owner          = THIS_MODULE,
1635         .name           = "yaffs",
1636         .get_sb         = yaffs_read_super,
1637         .kill_sb        = kill_block_super,
1638 //      .kill_sb        = kill_litter_super,
1639         .fs_flags       = FS_REQUIRES_DEV,
1640 };
1641 #else
1642 static struct super_block *yaffs_read_super(struct super_block * sb, void * data, int silent)
1643 {
1644         return yaffs_internal_read_super(1,0,sb,data,silent);
1645 }
1646
1647 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1648 #endif
1649
1650 #endif // CONFIG_YAFFS_MTD_ENABLED
1651
1652 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1653
1654 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1655 static struct super_block *yaffs2_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1656 {
1657
1658     return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_mtd);
1659 }
1660
1661 /* changes NCB 2.5.70 */
1662 //static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super, FS_REQUIRES_DEV);
1663 static struct file_system_type yaffs2_fs_type = {
1664         .owner          = THIS_MODULE,
1665         .name           = "yaffs2",
1666         .get_sb         = yaffs2_read_super,
1667         .kill_sb        = kill_block_super,
1668 //      .kill_sb        = kill_litter_super,
1669         .fs_flags       = FS_REQUIRES_DEV,
1670 };
1671 #else
1672 static struct super_block *yaffs2_read_super(struct super_block * sb, void * data, int silent)
1673 {
1674         return yaffs_internal_read_super(2,0,sb,data,silent);
1675 }
1676
1677 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super, FS_REQUIRES_DEV);
1678 #endif
1679
1680 #endif // CONFIG_YAFFS2_MTD_ENABLED
1681
1682
1683 #ifdef CONFIG_YAFFS_RAM_ENABLED
1684
1685 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1686 static struct super_block *yaffs_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1687 {
1688
1689     return get_sb_bdev(fs, flags, dev_name, data, yaffs_internal_read_super_ram);
1690 }
1691
1692
1693 static struct file_system_type yaffs_ram_fs_type = {
1694         .owner          = THIS_MODULE,
1695         .name           = "yaffsram",
1696         .get_sb         = yaffs_ram_read_super,
1697         .kill_sb        = kill_block_super,
1698 //      .kill_sb        = kill_litter_super,
1699         .fs_flags       = FS_SINGLE,
1700 };
1701 #else
1702 static struct super_block *yaffs_ram_read_super(struct super_block * sb, void * data, int silent)
1703 {
1704         return yaffs_internal_read_super(1,1,sb,data,silent);
1705 }
1706
1707 static DECLARE_FSTYPE(yaffs_ram_fs_type, "yaffsram", yaffs_ram_read_super, FS_SINGLE);
1708 #endif
1709
1710 #endif // CONFIG_YAFFS_RAM_ENABLED
1711
1712 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1713
1714 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1715 static struct super_block *yaffs2_ram_read_super(struct file_system_type * fs, int flags, const char *dev_name, void *data)
1716 {
1717
1718     return get_sb_bdev(fs, flags, dev_name, data, yaffs2_internal_read_super_ram);
1719 }
1720
1721
1722 static struct file_system_type yaffs2_ram_fs_type = {
1723         .owner          = THIS_MODULE,
1724         .name           = "yaffs2ram",
1725         .get_sb         = yaffs2_ram_read_super,
1726         .kill_sb        = kill_block_super,
1727 //      .kill_sb        = kill_litter_super,
1728         .fs_flags       = FS_SINGLE,
1729 };
1730 #else
1731 static struct super_block *yaffs2_ram_read_super(struct super_block * sb, void * data, int silent)
1732 {
1733         return yaffs_internal_read_super(2,1,sb,data,silent);
1734 }
1735
1736 static DECLARE_FSTYPE(yaffs2_ram_fs_type, "yaffs2ram", yaffs2_ram_read_super, FS_SINGLE);
1737 #endif
1738
1739 #endif // CONFIG_YAFFS2_RAM_ENABLED
1740
1741
1742
1743 static struct proc_dir_entry *my_proc_entry;
1744 static struct proc_dir_entry *my_proc_ram_write_entry;
1745
1746 static char * yaffs_dump_dev(char *buf,yaffs_Device *dev,char *name)
1747 {
1748         buf +=sprintf(buf,"\nDevice %s\n",name);
1749         buf +=sprintf(buf,"startBlock......... %d\n",dev->startBlock);
1750         buf +=sprintf(buf,"endBlock........... %d\n",dev->endBlock);
1751         buf +=sprintf(buf,"chunkGroupBits..... %d\n",dev->chunkGroupBits);
1752         buf +=sprintf(buf,"chunkGroupSize..... %d\n",dev->chunkGroupSize);
1753         buf +=sprintf(buf,"nErasedBlocks...... %d\n",dev->nErasedBlocks);
1754         buf +=sprintf(buf,"nTnodesCreated..... %d\n",dev->nTnodesCreated);
1755         buf +=sprintf(buf,"nFreeTnodes........ %d\n",dev->nFreeTnodes);
1756         buf +=sprintf(buf,"nObjectsCreated.... %d\n",dev->nObjectsCreated);
1757         buf +=sprintf(buf,"nFreeObjects....... %d\n",dev->nFreeObjects);
1758         buf +=sprintf(buf,"nFreeChunks........ %d\n",dev->nFreeChunks);
1759         buf +=sprintf(buf,"nPageWrites........ %d\n",dev->nPageWrites);
1760         buf +=sprintf(buf,"nPageReads......... %d\n",dev->nPageReads);
1761         buf +=sprintf(buf,"nBlockErasures..... %d\n",dev->nBlockErasures);
1762         buf +=sprintf(buf,"nGCCopies.......... %d\n",dev->nGCCopies);
1763         buf +=sprintf(buf,"garbageCollections. %d\n",dev->garbageCollections);
1764         buf +=sprintf(buf,"passiveGCs......... %d\n",dev->passiveGarbageCollections);
1765         buf +=sprintf(buf,"nRetriedWrites..... %d\n",dev->nRetriedWrites);
1766         buf +=sprintf(buf,"nRetireBlocks...... %d\n",dev->nRetiredBlocks);
1767         buf +=sprintf(buf,"eccFixed........... %d\n",dev->eccFixed);
1768         buf +=sprintf(buf,"eccUnfixed......... %d\n",dev->eccUnfixed);
1769         buf +=sprintf(buf,"tagsEccFixed....... %d\n",dev->tagsEccFixed);
1770         buf +=sprintf(buf,"tagsEccUnfixed..... %d\n",dev->tagsEccUnfixed);
1771         buf +=sprintf(buf,"cacheHits.......... %d\n",dev->cacheHits);
1772         buf +=sprintf(buf,"nDeletedFiles...... %d\n",dev->nDeletedFiles);
1773         buf +=sprintf(buf,"nUnlinkedFiles..... %d\n",dev->nUnlinkedFiles);
1774         buf +=sprintf(buf,"nBackgroudDeletions %d\n",dev->nBackgroundDeletions);
1775         buf +=sprintf(buf,"useNANDECC......... %d\n",dev->useNANDECC);
1776         buf +=sprintf(buf,"isYaffs2........... %d\n",dev->isYaffs2);
1777
1778         
1779         return buf;     
1780 }
1781
1782 static int  yaffs_proc_read(
1783         char *page,
1784         char **start,
1785         off_t offset,
1786         int count,
1787         int *eof,
1788         void *data
1789         )
1790 {
1791
1792         char my_buffer[3000];
1793         char *buf;
1794         buf = my_buffer;
1795
1796         if (offset > 0) return 0;
1797
1798         /* Fill the buffer and get its length */
1799         buf +=sprintf(buf,"YAFFS built:"__DATE__ " "__TIME__"\n%s\n%s\n", yaffs_fs_c_version,yaffs_guts_c_version);
1800         
1801         if(yaffs_dev) buf = yaffs_dump_dev(buf,yaffs_dev,"yaffs");
1802         if(yaffsram_dev) buf = yaffs_dump_dev(buf,yaffsram_dev,"yaffsram");
1803         
1804
1805         strcpy(page,my_buffer);
1806         return strlen(my_buffer);
1807 }
1808
1809
1810 static int  yaffs_proc_ram_write(
1811         char *page,
1812         char **start,
1813         off_t offset,
1814         int count,
1815         int *eof,
1816         void *data
1817         )
1818 {
1819
1820         printk(KERN_DEBUG "yaffs write size %d\n",count);
1821         return count;
1822 }
1823
1824
1825
1826 // Stuff to handle installation of file systems
1827 struct file_system_to_install
1828 {
1829    struct file_system_type *fst;
1830    int installed;
1831 };
1832
1833 static struct file_system_to_install fs_to_install[] =
1834 {
1835 #ifdef CONFIG_YAFFS_RAM_ENABLED
1836      { &yaffs_ram_fs_type, 0},
1837 #endif
1838 #ifdef CONFIG_YAFFS2_RAM_ENABLED
1839      { &yaffs2_ram_fs_type,0},
1840 #endif
1841 #ifdef CONFIG_YAFFS_MTD_ENABLED
1842      { &yaffs_fs_type,0},
1843 #endif
1844 #ifdef CONFIG_YAFFS2_MTD_ENABLED
1845      { &yaffs2_fs_type,0},
1846 #endif
1847      { NULL,0}
1848 };
1849
1850 static int __init init_yaffs_fs(void)
1851 {
1852         int error = 0;
1853         struct file_system_to_install *fsinst;  
1854         
1855         yaffs_dev = yaffsram_dev = NULL;
1856         
1857    T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
1858
1859
1860
1861     /* Install the proc_fs entry */
1862     my_proc_entry = create_proc_read_entry("yaffs",
1863                                            S_IRUGO | S_IFREG,
1864                                            &proc_root,
1865                                            yaffs_proc_read,
1866                                            NULL);
1867     if(!my_proc_entry)
1868     {
1869        return -ENOMEM;
1870     }
1871     
1872     
1873
1874     // Now add the file system entries
1875     
1876     fsinst = fs_to_install;
1877     
1878     while(fsinst->fst && !error)
1879     {
1880       error = register_filesystem(fsinst->fst);
1881       if(!error)
1882       {
1883           fsinst->installed = 1;
1884       }
1885       fsinst++;
1886     }
1887    
1888     // Any errors? uninstall 
1889     if(error)
1890     {
1891             fsinst = fs_to_install;
1892             
1893             while(fsinst->fst)
1894             {
1895               if(fsinst->installed)
1896               {
1897                 unregister_filesystem(fsinst->fst);
1898                 fsinst->installed = 0;
1899               }
1900               fsinst++;
1901             }
1902     }
1903     
1904     return error;
1905 }
1906
1907 static void __exit exit_yaffs_fs(void)
1908 {
1909
1910    struct file_system_to_install *fsinst;
1911    
1912    T(YAFFS_TRACE_ALWAYS,("yaffs " __DATE__ " " __TIME__ " removing. \n"));
1913
1914    remove_proc_entry("yaffs",&proc_root);
1915     
1916     fsinst = fs_to_install;
1917     
1918     while(fsinst->fst)
1919     {
1920       if(fsinst->installed)
1921       {
1922         unregister_filesystem(fsinst->fst);
1923         fsinst->installed = 0;
1924       }
1925       fsinst++;
1926     }
1927
1928 }
1929
1930 module_init(init_yaffs_fs)
1931 module_exit(exit_yaffs_fs)
1932
1933 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
1934 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002,2003,2004");
1935 MODULE_LICENSE("GPL");
1936
1937