2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2009 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * Luc van OostenRyck for numerous patches.
10 * Nick Bane for numerous patches.
11 * Nick Bane for 2.5/2.6 integration.
12 * Andras Toth for mknod rdev issue.
13 * Michael Fischer for finding the problem with inode inconsistency.
14 * Some code bodily lifted from JFFS
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
23 * This is the file system front-end to YAFFS that hooks it up to
27 * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with
29 * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this
31 * >> inode->u.generic_ip points to the associated yaffs_Object.
34 const char *yaffs_fs_c_version =
35 "$Id: yaffs_fs.c,v 1.83 2009-09-23 23:24:55 charles Exp $";
36 extern const char *yaffs_guts_c_version;
38 #include <linux/version.h>
39 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
40 #include <linux/config.h>
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/init.h>
47 #include <linux/proc_fs.h>
48 #include <linux/smp_lock.h>
49 #include <linux/pagemap.h>
50 #include <linux/mtd/mtd.h>
51 #include <linux/interrupt.h>
52 #include <linux/string.h>
53 #include <linux/ctype.h>
55 #include "asm/div64.h"
57 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
59 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
60 #include <linux/statfs.h>
61 #define UnlockPage(p) unlock_page(p)
62 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
64 /* FIXME: use sb->s_id instead ? */
65 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
69 #include <linux/locks.h>
70 #define BDEVNAME_SIZE 0
71 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
73 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0))
74 /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */
80 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
81 #define YPROC_ROOT (&proc_root)
83 #define YPROC_ROOT NULL
86 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
87 #define WRITE_SIZE_STR "writesize"
88 #define WRITE_SIZE(mtd) ((mtd)->writesize)
90 #define WRITE_SIZE_STR "oobblock"
91 #define WRITE_SIZE(mtd) ((mtd)->oobblock)
94 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27))
95 #define YAFFS_USE_WRITE_BEGIN_END 1
97 #define YAFFS_USE_WRITE_BEGIN_END 0
100 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28))
101 static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size)
103 uint64_t result = partition_size;
104 do_div(result, block_size);
105 return (uint32_t)result;
108 #define YCALCBLOCKS(s, b) ((s)/(b))
111 #include <linux/uaccess.h>
113 #include "yportenv.h"
114 #include "yaffs_guts.h"
116 #include <linux/mtd/mtd.h>
117 #include "yaffs_mtdif.h"
118 #include "yaffs_mtdif1.h"
119 #include "yaffs_mtdif2.h"
121 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS;
122 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
123 unsigned int yaffs_auto_checkpoint = 1;
125 /* Module Parameters */
126 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
127 module_param(yaffs_traceMask, uint, 0644);
128 module_param(yaffs_wr_attempts, uint, 0644);
129 module_param(yaffs_auto_checkpoint, uint, 0644);
131 MODULE_PARM(yaffs_traceMask, "i");
132 MODULE_PARM(yaffs_wr_attempts, "i");
133 MODULE_PARM(yaffs_auto_checkpoint, "i");
136 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
137 /* use iget and read_inode */
138 #define Y_IGET(sb, inum) iget((sb), (inum))
139 static void yaffs_read_inode(struct inode *inode);
142 /* Call local equivalent */
143 #define YAFFS_USE_OWN_IGET
144 #define Y_IGET(sb, inum) yaffs_iget((sb), (inum))
146 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
149 /*#define T(x) printk x */
151 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
152 #define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)
154 #define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip)
157 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
158 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
160 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
161 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
163 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
167 #define update_dir_time(dir) do {\
168 (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
171 static void yaffs_put_super(struct super_block *sb);
173 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
175 static ssize_t yaffs_hold_space(struct file *f);
176 static void yaffs_release_space(struct file *f);
178 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
179 static int yaffs_file_flush(struct file *file, fl_owner_t id);
181 static int yaffs_file_flush(struct file *file);
184 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
187 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
189 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
190 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
191 struct nameidata *n);
192 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
193 struct nameidata *n);
195 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
196 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
198 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
199 struct dentry *dentry);
200 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
201 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
202 const char *symname);
203 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
205 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
206 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
209 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
212 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
213 struct inode *new_dir, struct dentry *new_dentry);
214 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
216 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
217 static int yaffs_sync_fs(struct super_block *sb, int wait);
218 static void yaffs_write_super(struct super_block *sb);
220 static int yaffs_sync_fs(struct super_block *sb);
221 static int yaffs_write_super(struct super_block *sb);
224 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
225 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
226 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
227 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
229 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
232 #ifdef YAFFS_HAS_PUT_INODE
233 static void yaffs_put_inode(struct inode *inode);
236 static void yaffs_delete_inode(struct inode *);
237 static void yaffs_clear_inode(struct inode *);
239 static int yaffs_readpage(struct file *file, struct page *page);
240 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
241 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
243 static int yaffs_writepage(struct page *page);
247 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
248 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
249 loff_t pos, unsigned len, unsigned flags,
250 struct page **pagep, void **fsdata);
251 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
252 loff_t pos, unsigned len, unsigned copied,
253 struct page *pg, void *fsdadata);
255 static int yaffs_prepare_write(struct file *f, struct page *pg,
256 unsigned offset, unsigned to);
257 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
262 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
264 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
265 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
267 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
270 static struct address_space_operations yaffs_file_address_operations = {
271 .readpage = yaffs_readpage,
272 .writepage = yaffs_writepage,
273 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
274 .write_begin = yaffs_write_begin,
275 .write_end = yaffs_write_end,
277 .prepare_write = yaffs_prepare_write,
278 .commit_write = yaffs_commit_write,
282 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
283 static const struct file_operations yaffs_file_operations = {
284 .read = do_sync_read,
285 .write = do_sync_write,
286 .aio_read = generic_file_aio_read,
287 .aio_write = generic_file_aio_write,
288 .mmap = generic_file_mmap,
289 .flush = yaffs_file_flush,
290 .fsync = yaffs_sync_object,
291 .splice_read = generic_file_splice_read,
292 .splice_write = generic_file_splice_write,
293 .llseek = generic_file_llseek,
296 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
298 static const struct file_operations yaffs_file_operations = {
299 .read = do_sync_read,
300 .write = do_sync_write,
301 .aio_read = generic_file_aio_read,
302 .aio_write = generic_file_aio_write,
303 .mmap = generic_file_mmap,
304 .flush = yaffs_file_flush,
305 .fsync = yaffs_sync_object,
306 .sendfile = generic_file_sendfile,
311 static const struct file_operations yaffs_file_operations = {
312 .read = generic_file_read,
313 .write = generic_file_write,
314 .mmap = generic_file_mmap,
315 .flush = yaffs_file_flush,
316 .fsync = yaffs_sync_object,
317 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
318 .sendfile = generic_file_sendfile,
323 static const struct inode_operations yaffs_file_inode_operations = {
324 .setattr = yaffs_setattr,
327 static const struct inode_operations yaffs_symlink_inode_operations = {
328 .readlink = yaffs_readlink,
329 .follow_link = yaffs_follow_link,
330 .setattr = yaffs_setattr,
333 static const struct inode_operations yaffs_dir_inode_operations = {
334 .create = yaffs_create,
335 .lookup = yaffs_lookup,
337 .unlink = yaffs_unlink,
338 .symlink = yaffs_symlink,
339 .mkdir = yaffs_mkdir,
340 .rmdir = yaffs_unlink,
341 .mknod = yaffs_mknod,
342 .rename = yaffs_rename,
343 .setattr = yaffs_setattr,
346 static const struct file_operations yaffs_dir_operations = {
347 .read = generic_read_dir,
348 .readdir = yaffs_readdir,
349 .fsync = yaffs_sync_object,
352 static const struct super_operations yaffs_super_ops = {
353 .statfs = yaffs_statfs,
355 #ifndef YAFFS_USE_OWN_IGET
356 .read_inode = yaffs_read_inode,
358 #ifdef YAFFS_HAS_PUT_INODE
359 .put_inode = yaffs_put_inode,
361 .put_super = yaffs_put_super,
362 .delete_inode = yaffs_delete_inode,
363 .clear_inode = yaffs_clear_inode,
364 .sync_fs = yaffs_sync_fs,
365 .write_super = yaffs_write_super,
368 static void yaffs_GrossLock(yaffs_Device *dev)
370 T(YAFFS_TRACE_OS, ("yaffs locking %p\n", current));
371 down(&dev->grossLock);
372 T(YAFFS_TRACE_OS, ("yaffs locked %p\n", current));
375 static void yaffs_GrossUnlock(yaffs_Device *dev)
377 T(YAFFS_TRACE_OS, ("yaffs unlocking %p\n", current));
381 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
384 unsigned char *alias;
387 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
389 yaffs_GrossLock(dev);
391 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
393 yaffs_GrossUnlock(dev);
398 ret = vfs_readlink(dentry, buffer, buflen, alias);
403 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
404 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
406 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
409 unsigned char *alias;
411 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
413 yaffs_GrossLock(dev);
415 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
417 yaffs_GrossUnlock(dev);
424 ret = vfs_follow_link(nd, alias);
427 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
434 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
438 * Lookup is used to find objects in the fs
440 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
442 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
445 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
449 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
451 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
453 yaffs_GrossLock(dev);
456 ("yaffs_lookup for %d:%s\n",
457 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
459 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
460 dentry->d_name.name);
462 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
464 /* Can't hold gross lock when calling yaffs_get_inode() */
465 yaffs_GrossUnlock(dev);
469 ("yaffs_lookup found %d\n", obj->objectId));
471 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
475 ("yaffs_loookup dentry \n"));
476 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
477 * d_add even if NULL inode */
479 /*dget(dentry); // try to solve directory bug */
480 d_add(dentry, inode);
488 T(YAFFS_TRACE_OS, ("yaffs_lookup not found\n"));
492 /* added NCB for 2.5/6 compatability - forces add even if inode is
493 * NULL which creates dentry hash */
494 d_add(dentry, inode);
500 #ifdef YAFFS_HAS_PUT_INODE
502 /* For now put inode is just for debugging
503 * Put inode is called when the inode **structure** is put.
505 static void yaffs_put_inode(struct inode *inode)
508 ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
509 atomic_read(&inode->i_count)));
514 /* clear is called to tell the fs to release any per-inode data it holds */
515 static void yaffs_clear_inode(struct inode *inode)
520 obj = yaffs_InodeToObject(inode);
523 ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
524 atomic_read(&inode->i_count),
525 obj ? "object exists" : "null object"));
529 yaffs_GrossLock(dev);
531 /* Clear the association between the inode and
535 yaffs_InodeToObjectLV(inode) = NULL;
537 /* If the object freeing was deferred, then the real
539 * This should fix the inode inconsistency problem.
542 yaffs_HandleDeferedFree(obj);
544 yaffs_GrossUnlock(dev);
549 /* delete is called when the link count is zero and the inode
550 * is put (ie. nobody wants to know about it anymore, time to
552 * NB Must call clear_inode()
554 static void yaffs_delete_inode(struct inode *inode)
556 yaffs_Object *obj = yaffs_InodeToObject(inode);
560 ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
561 atomic_read(&inode->i_count),
562 obj ? "object exists" : "null object"));
566 yaffs_GrossLock(dev);
567 yaffs_DeleteObject(obj);
568 yaffs_GrossUnlock(dev);
570 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
571 truncate_inode_pages(&inode->i_data, 0);
576 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
577 static int yaffs_file_flush(struct file *file, fl_owner_t id)
579 static int yaffs_file_flush(struct file *file)
582 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
584 yaffs_Device *dev = obj->myDev;
587 ("yaffs_file_flush object %d (%s)\n", obj->objectId,
588 obj->dirty ? "dirty" : "clean"));
590 yaffs_GrossLock(dev);
592 yaffs_FlushFile(obj, 1,0);
594 yaffs_GrossUnlock(dev);
599 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
601 /* Lifted from jffs2 */
604 unsigned char *pg_buf;
609 T(YAFFS_TRACE_OS, ("yaffs_readpage at %08x, size %08x\n",
610 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
611 (unsigned)PAGE_CACHE_SIZE));
613 obj = yaffs_DentryToObject(f->f_dentry);
617 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
618 BUG_ON(!PageLocked(pg));
625 /* FIXME: Can kmap fail? */
627 yaffs_GrossLock(dev);
629 ret = yaffs_ReadDataFromFile(obj, pg_buf,
630 pg->index << PAGE_CACHE_SHIFT,
633 yaffs_GrossUnlock(dev);
639 ClearPageUptodate(pg);
646 flush_dcache_page(pg);
649 T(YAFFS_TRACE_OS, ("yaffs_readpage done\n"));
653 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
655 int ret = yaffs_readpage_nolock(f, pg);
660 static int yaffs_readpage(struct file *f, struct page *pg)
662 return yaffs_readpage_unlock(f, pg);
665 /* writepage inspired by/stolen from smbfs */
667 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
668 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
670 static int yaffs_writepage(struct page *page)
673 struct address_space *mapping = page->mapping;
674 loff_t offset = (loff_t) page->index << PAGE_CACHE_SHIFT;
676 unsigned long end_index;
684 inode = mapping->host;
688 if (offset > inode->i_size) {
690 ("yaffs_writepage at %08x, inode size = %08x!!!\n",
691 (unsigned)(page->index << PAGE_CACHE_SHIFT),
692 (unsigned)inode->i_size));
694 (" -> don't care!!\n"));
699 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
702 if (page->index < end_index)
703 nBytes = PAGE_CACHE_SIZE;
705 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
711 obj = yaffs_InodeToObject(inode);
712 yaffs_GrossLock(obj->myDev);
715 ("yaffs_writepage at %08x, size %08x\n",
716 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
718 ("writepag0: obj = %05x, ino = %05x\n",
719 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
721 nWritten = yaffs_WriteDataToFile(obj, buffer,
722 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
725 ("writepag1: obj = %05x, ino = %05x\n",
726 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
728 yaffs_GrossUnlock(obj->myDev);
731 SetPageUptodate(page);
735 return (nWritten == nBytes) ? 0 : -ENOSPC;
739 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
740 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
741 loff_t pos, unsigned len, unsigned flags,
742 struct page **pagep, void **fsdata)
744 struct page *pg = NULL;
745 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
746 uint32_t offset = pos & (PAGE_CACHE_SIZE - 1);
747 uint32_t to = offset + len;
752 T(YAFFS_TRACE_OS, ("start yaffs_write_begin\n"));
754 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
755 pg = grab_cache_page_write_begin(mapping, index, flags);
757 pg = __grab_cache_page(mapping, index);
766 space_held = yaffs_hold_space(filp);
773 /* Update page if required */
775 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
776 ret = yaffs_readpage_nolock(filp, pg);
781 /* Happy path return */
782 T(YAFFS_TRACE_OS, ("end yaffs_write_begin - ok\n"));
787 T(YAFFS_TRACE_OS, ("end yaffs_write_begin fail returning %d\n", ret));
789 yaffs_release_space(filp);
792 page_cache_release(pg);
799 static int yaffs_prepare_write(struct file *f, struct page *pg,
800 unsigned offset, unsigned to)
802 T(YAFFS_TRACE_OS, ("yaffs_prepair_write\n"));
804 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
805 return yaffs_readpage_nolock(f, pg);
810 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
811 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
812 loff_t pos, unsigned len, unsigned copied,
813 struct page *pg, void *fsdadata)
817 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
820 addr = kva + offset_into_page;
823 ("yaffs_write_end addr %x pos %x nBytes %d\n",
827 ret = yaffs_file_write(filp, addr, copied, &pos);
831 ("yaffs_write_end not same size ret %d copied %d\n",
834 ClearPageUptodate(pg);
841 yaffs_release_space(filp);
843 page_cache_release(pg);
848 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
853 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
854 int nBytes = to - offset;
863 saddr = (unsigned) addr;
866 ("yaffs_commit_write addr %x pos %x nBytes %d\n",
867 saddr, spos, nBytes));
869 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
871 if (nWritten != nBytes) {
873 ("yaffs_commit_write not same size nWritten %d nBytes %d\n",
876 ClearPageUptodate(pg);
884 ("yaffs_commit_write returning %d\n",
885 nWritten == nBytes ? 0 : nWritten));
887 return nWritten == nBytes ? 0 : nWritten;
892 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
897 /* Check mode against the variant type and attempt to repair if broken. */
898 __u32 mode = obj->yst_mode;
899 switch (obj->variantType) {
900 case YAFFS_OBJECT_TYPE_FILE:
901 if (!S_ISREG(mode)) {
902 obj->yst_mode &= ~S_IFMT;
903 obj->yst_mode |= S_IFREG;
907 case YAFFS_OBJECT_TYPE_SYMLINK:
908 if (!S_ISLNK(mode)) {
909 obj->yst_mode &= ~S_IFMT;
910 obj->yst_mode |= S_IFLNK;
914 case YAFFS_OBJECT_TYPE_DIRECTORY:
915 if (!S_ISDIR(mode)) {
916 obj->yst_mode &= ~S_IFMT;
917 obj->yst_mode |= S_IFDIR;
921 case YAFFS_OBJECT_TYPE_UNKNOWN:
922 case YAFFS_OBJECT_TYPE_HARDLINK:
923 case YAFFS_OBJECT_TYPE_SPECIAL:
929 inode->i_flags |= S_NOATIME;
931 inode->i_ino = obj->objectId;
932 inode->i_mode = obj->yst_mode;
933 inode->i_uid = obj->yst_uid;
934 inode->i_gid = obj->yst_gid;
935 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
936 inode->i_blksize = inode->i_sb->s_blocksize;
938 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
940 inode->i_rdev = old_decode_dev(obj->yst_rdev);
941 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
942 inode->i_atime.tv_nsec = 0;
943 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
944 inode->i_mtime.tv_nsec = 0;
945 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
946 inode->i_ctime.tv_nsec = 0;
948 inode->i_rdev = obj->yst_rdev;
949 inode->i_atime = obj->yst_atime;
950 inode->i_mtime = obj->yst_mtime;
951 inode->i_ctime = obj->yst_ctime;
953 inode->i_size = yaffs_GetObjectFileLength(obj);
954 inode->i_blocks = (inode->i_size + 511) >> 9;
956 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
959 ("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
960 inode->i_mode, inode->i_uid, inode->i_gid,
961 (int)inode->i_size, atomic_read(&inode->i_count)));
963 switch (obj->yst_mode & S_IFMT) {
964 default: /* fifo, device or socket */
965 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
966 init_special_inode(inode, obj->yst_mode,
967 old_decode_dev(obj->yst_rdev));
969 init_special_inode(inode, obj->yst_mode,
970 (dev_t) (obj->yst_rdev));
973 case S_IFREG: /* file */
974 inode->i_op = &yaffs_file_inode_operations;
975 inode->i_fop = &yaffs_file_operations;
976 inode->i_mapping->a_ops =
977 &yaffs_file_address_operations;
979 case S_IFDIR: /* directory */
980 inode->i_op = &yaffs_dir_inode_operations;
981 inode->i_fop = &yaffs_dir_operations;
983 case S_IFLNK: /* symlink */
984 inode->i_op = &yaffs_symlink_inode_operations;
988 yaffs_InodeToObjectLV(inode) = obj;
990 obj->myInode = inode;
994 ("yaffs_FileInode invalid parameters\n"));
999 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1002 struct inode *inode;
1006 ("yaffs_get_inode for NULL super_block!!\n"));
1013 ("yaffs_get_inode for NULL object!!\n"));
1019 ("yaffs_get_inode for object %d\n", obj->objectId));
1021 inode = Y_IGET(sb, obj->objectId);
1025 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1026 /* iget also increments the inode's i_count */
1027 /* NB You can't be holding grossLock or deadlock will happen! */
1032 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1037 struct inode *inode;
1040 obj = yaffs_DentryToObject(f->f_dentry);
1044 yaffs_GrossLock(dev);
1046 inode = f->f_dentry->d_inode;
1048 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
1049 ipos = inode->i_size;
1055 ("yaffs_file_write: hey obj is null!\n"));
1058 ("yaffs_file_write about to write writing %zu bytes"
1059 "to object %d at %d\n",
1060 n, obj->objectId, ipos));
1062 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1065 ("yaffs_file_write writing %zu bytes, %d written at %d\n",
1066 n, nWritten, ipos));
1071 if (ipos > inode->i_size) {
1072 inode->i_size = ipos;
1073 inode->i_blocks = (ipos + 511) >> 9;
1076 ("yaffs_file_write size updated to %d bytes, "
1078 ipos, (int)(inode->i_blocks)));
1082 yaffs_GrossUnlock(dev);
1083 return (nWritten == 0) && (n > 0) ? -ENOSPC : nWritten;
1086 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1087 /* For now we just assume few parallel writes and check against a small number. */
1088 /* Todo: need to do this with a counter to handle parallel reads better */
1090 static ssize_t yaffs_hold_space(struct file *f)
1098 obj = yaffs_DentryToObject(f->f_dentry);
1102 yaffs_GrossLock(dev);
1104 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1106 yaffs_GrossUnlock(dev);
1108 return (nFreeChunks > 20) ? 1 : 0;
1111 static void yaffs_release_space(struct file *f)
1117 obj = yaffs_DentryToObject(f->f_dentry);
1121 yaffs_GrossLock(dev);
1124 yaffs_GrossUnlock(dev);
1127 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1131 struct inode *inode = f->f_dentry->d_inode;
1132 unsigned long offset, curoffs;
1133 struct ylist_head *i;
1136 char name[YAFFS_MAX_NAME_LENGTH + 1];
1138 obj = yaffs_DentryToObject(f->f_dentry);
1141 yaffs_GrossLock(dev);
1145 T(YAFFS_TRACE_OS, ("yaffs_readdir: starting at %d\n", (int)offset));
1149 ("yaffs_readdir: entry . ino %d \n",
1150 (int)inode->i_ino));
1151 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1158 ("yaffs_readdir: entry .. ino %d \n",
1159 (int)f->f_dentry->d_parent->d_inode->i_ino));
1160 if (filldir(dirent, "..", 2, offset,
1161 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1169 /* If the directory has changed since the open or last call to
1170 readdir, rewind to after the 2 canned entries. */
1172 if (f->f_version != inode->i_version) {
1175 f->f_version = inode->i_version;
1178 ylist_for_each(i, &obj->variant.directoryVariant.children) {
1180 if (curoffs >= offset) {
1181 l = ylist_entry(i, yaffs_Object, siblings);
1183 yaffs_GetObjectName(l, name,
1184 YAFFS_MAX_NAME_LENGTH + 1);
1186 ("yaffs_readdir: %s inode %d\n", name,
1187 yaffs_GetObjectInode(l)));
1193 yaffs_GetObjectInode(l),
1194 yaffs_GetObjectType(l)) < 0)
1204 yaffs_GrossUnlock(dev);
1210 * File creation. Allocate an inode, and we're done..
1213 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1216 #define YCRED(x) (x->cred)
1219 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1220 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1223 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1227 struct inode *inode;
1229 yaffs_Object *obj = NULL;
1232 yaffs_Object *parent = yaffs_InodeToObject(dir);
1234 int error = -ENOSPC;
1235 uid_t uid = YCRED(current)->fsuid;
1236 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1238 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1243 ("yaffs_mknod: parent object %d type %d\n",
1244 parent->objectId, parent->variantType));
1247 ("yaffs_mknod: could not get parent object\n"));
1251 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
1253 dentry->d_name.name, mode, rdev));
1255 dev = parent->myDev;
1257 yaffs_GrossLock(dev);
1259 switch (mode & S_IFMT) {
1261 /* Special (socket, fifo, device...) */
1262 T(YAFFS_TRACE_OS, ("yaffs_mknod: making special\n"));
1263 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1264 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1265 gid, old_encode_dev(rdev));
1267 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1271 case S_IFREG: /* file */
1272 T(YAFFS_TRACE_OS, ("yaffs_mknod: making file\n"));
1273 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1276 case S_IFDIR: /* directory */
1278 ("yaffs_mknod: making directory\n"));
1279 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1282 case S_IFLNK: /* symlink */
1283 T(YAFFS_TRACE_OS, ("yaffs_mknod: making symlink\n"));
1284 obj = NULL; /* Do we ever get here? */
1288 /* Can not call yaffs_get_inode() with gross lock held */
1289 yaffs_GrossUnlock(dev);
1292 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1293 d_instantiate(dentry, inode);
1294 update_dir_time(dir);
1296 ("yaffs_mknod created object %d count = %d\n",
1297 obj->objectId, atomic_read(&inode->i_count)));
1301 ("yaffs_mknod failed making object\n"));
1308 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1311 T(YAFFS_TRACE_OS, ("yaffs_mkdir\n"));
1312 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1316 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1317 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1318 struct nameidata *n)
1320 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1323 T(YAFFS_TRACE_OS, ("yaffs_create\n"));
1324 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1327 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1334 ("yaffs_unlink %d:%s\n", (int)(dir->i_ino),
1335 dentry->d_name.name));
1337 dev = yaffs_InodeToObject(dir)->myDev;
1339 yaffs_GrossLock(dev);
1341 retVal = yaffs_Unlink(yaffs_InodeToObject(dir), dentry->d_name.name);
1343 if (retVal == YAFFS_OK) {
1344 dentry->d_inode->i_nlink--;
1346 yaffs_GrossUnlock(dev);
1347 mark_inode_dirty(dentry->d_inode);
1348 update_dir_time(dir);
1351 yaffs_GrossUnlock(dev);
1358 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1359 struct dentry *dentry)
1361 struct inode *inode = old_dentry->d_inode;
1362 yaffs_Object *obj = NULL;
1363 yaffs_Object *link = NULL;
1366 T(YAFFS_TRACE_OS, ("yaffs_link\n"));
1368 obj = yaffs_InodeToObject(inode);
1371 yaffs_GrossLock(dev);
1373 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1374 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1378 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1379 d_instantiate(dentry, old_dentry->d_inode);
1380 atomic_inc(&old_dentry->d_inode->i_count);
1382 ("yaffs_link link count %d i_count %d\n",
1383 old_dentry->d_inode->i_nlink,
1384 atomic_read(&old_dentry->d_inode->i_count)));
1387 yaffs_GrossUnlock(dev);
1390 update_dir_time(dir);
1397 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1398 const char *symname)
1402 uid_t uid = YCRED(current)->fsuid;
1403 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1405 T(YAFFS_TRACE_OS, ("yaffs_symlink\n"));
1407 dev = yaffs_InodeToObject(dir)->myDev;
1408 yaffs_GrossLock(dev);
1409 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1410 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1411 yaffs_GrossUnlock(dev);
1414 struct inode *inode;
1416 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1417 d_instantiate(dentry, inode);
1418 update_dir_time(dir);
1419 T(YAFFS_TRACE_OS, ("symlink created OK\n"));
1422 T(YAFFS_TRACE_OS, ("symlink not created\n"));
1428 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1435 obj = yaffs_DentryToObject(dentry);
1439 T(YAFFS_TRACE_OS, ("yaffs_sync_object\n"));
1440 yaffs_GrossLock(dev);
1441 yaffs_FlushFile(obj, 1, datasync);
1442 yaffs_GrossUnlock(dev);
1447 * The VFS layer already does all the dentry stuff for rename.
1449 * NB: POSIX says you can rename an object over an old object of the same name
1451 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1452 struct inode *new_dir, struct dentry *new_dentry)
1455 int retVal = YAFFS_FAIL;
1456 yaffs_Object *target;
1458 T(YAFFS_TRACE_OS, ("yaffs_rename\n"));
1459 dev = yaffs_InodeToObject(old_dir)->myDev;
1461 yaffs_GrossLock(dev);
1463 /* Check if the target is an existing directory that is not empty. */
1464 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1465 new_dentry->d_name.name);
1469 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1470 !ylist_empty(&target->variant.directoryVariant.children)) {
1472 T(YAFFS_TRACE_OS, ("target is non-empty dir\n"));
1474 retVal = YAFFS_FAIL;
1476 /* Now does unlinking internally using shadowing mechanism */
1477 T(YAFFS_TRACE_OS, ("calling yaffs_RenameObject\n"));
1479 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1480 old_dentry->d_name.name,
1481 yaffs_InodeToObject(new_dir),
1482 new_dentry->d_name.name);
1484 yaffs_GrossUnlock(dev);
1486 if (retVal == YAFFS_OK) {
1488 new_dentry->d_inode->i_nlink--;
1489 mark_inode_dirty(new_dentry->d_inode);
1492 update_dir_time(old_dir);
1493 if(old_dir != new_dir)
1494 update_dir_time(new_dir);
1501 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1503 struct inode *inode = dentry->d_inode;
1508 ("yaffs_setattr of object %d\n",
1509 yaffs_InodeToObject(inode)->objectId));
1511 error = inode_change_ok(inode, attr);
1513 dev = yaffs_InodeToObject(inode)->myDev;
1514 yaffs_GrossLock(dev);
1515 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
1521 yaffs_GrossUnlock(dev);
1523 error = inode_setattr(inode, attr);
1528 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1529 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1531 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1532 struct super_block *sb = dentry->d_sb;
1533 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1534 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1536 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1538 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1540 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1543 T(YAFFS_TRACE_OS, ("yaffs_statfs\n"));
1545 yaffs_GrossLock(dev);
1547 buf->f_type = YAFFS_MAGIC;
1548 buf->f_bsize = sb->s_blocksize;
1549 buf->f_namelen = 255;
1551 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
1552 /* Do this if chunk size is not a power of 2 */
1554 uint64_t bytesInDev;
1557 bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock + 1))) *
1558 ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk));
1560 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
1561 buf->f_blocks = bytesInDev;
1563 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
1564 ((uint64_t)(dev->nDataBytesPerChunk));
1566 do_div(bytesFree, sb->s_blocksize);
1568 buf->f_bfree = bytesFree;
1570 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
1573 (dev->endBlock - dev->startBlock + 1) *
1574 dev->nChunksPerBlock /
1575 (sb->s_blocksize / dev->nDataBytesPerChunk);
1577 yaffs_GetNumberOfFreeChunks(dev) /
1578 (sb->s_blocksize / dev->nDataBytesPerChunk);
1581 (dev->endBlock - dev->startBlock + 1) *
1582 dev->nChunksPerBlock *
1583 (dev->nDataBytesPerChunk / sb->s_blocksize);
1586 yaffs_GetNumberOfFreeChunks(dev) *
1587 (dev->nDataBytesPerChunk / sb->s_blocksize);
1592 buf->f_bavail = buf->f_bfree;
1594 yaffs_GrossUnlock(dev);
1600 static void yaffs_flush_sb_inodes(struct super_block *sb)
1605 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
1606 obj = yaffs_InodeToObject(iptr);
1608 T(YAFFS_TRACE_OS, ("flushing obj %d\n",obj->objectId));
1609 yaffs_FlushFile(obj,1,0);
1614 static int yaffs_do_sync_fs(struct super_block *sb)
1617 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1618 T(YAFFS_TRACE_OS, ("yaffs_do_sync_fs\n"));
1621 yaffs_GrossLock(dev);
1624 yaffs_FlushEntireDeviceCache(dev);
1625 yaffs_flush_sb_inodes(sb);
1626 yaffs_CheckpointSave(dev);
1629 yaffs_GrossUnlock(dev);
1637 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1638 static void yaffs_write_super(struct super_block *sb)
1640 static int yaffs_write_super(struct super_block *sb)
1644 T(YAFFS_TRACE_OS, ("yaffs_write_super\n"));
1645 if (yaffs_auto_checkpoint >= 2)
1646 yaffs_do_sync_fs(sb);
1647 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
1653 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1654 static int yaffs_sync_fs(struct super_block *sb, int wait)
1656 static int yaffs_sync_fs(struct super_block *sb)
1659 T(YAFFS_TRACE_OS, ("yaffs_sync_fs\n"));
1661 if (yaffs_auto_checkpoint >= 1)
1662 yaffs_do_sync_fs(sb);
1667 #ifdef YAFFS_USE_OWN_IGET
1669 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
1671 struct inode *inode;
1673 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1676 ("yaffs_iget for %lu\n", ino));
1678 inode = iget_locked(sb, ino);
1680 return ERR_PTR(-ENOMEM);
1681 if (!(inode->i_state & I_NEW))
1684 /* NB This is called as a side effect of other functions, but
1685 * we had to release the lock to prevent deadlocks, so
1686 * need to lock again.
1689 yaffs_GrossLock(dev);
1691 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1693 yaffs_FillInodeFromObject(inode, obj);
1695 yaffs_GrossUnlock(dev);
1697 unlock_new_inode(inode);
1703 static void yaffs_read_inode(struct inode *inode)
1705 /* NB This is called as a side effect of other functions, but
1706 * we had to release the lock to prevent deadlocks, so
1707 * need to lock again.
1711 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
1714 ("yaffs_read_inode for %d\n", (int)inode->i_ino));
1716 yaffs_GrossLock(dev);
1718 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
1720 yaffs_FillInodeFromObject(inode, obj);
1722 yaffs_GrossUnlock(dev);
1727 static YLIST_HEAD(yaffs_dev_list);
1729 #if 0 /* not used */
1730 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
1732 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1734 if (*flags & MS_RDONLY) {
1735 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1738 ("yaffs_remount_fs: %s: RO\n", dev->name));
1740 yaffs_GrossLock(dev);
1742 yaffs_FlushEntireDeviceCache(dev);
1744 yaffs_CheckpointSave(dev);
1749 yaffs_GrossUnlock(dev);
1752 ("yaffs_remount_fs: %s: RW\n", dev->name));
1759 static void yaffs_put_super(struct super_block *sb)
1761 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1763 T(YAFFS_TRACE_OS, ("yaffs_put_super\n"));
1765 yaffs_GrossLock(dev);
1767 yaffs_FlushEntireDeviceCache(dev);
1769 yaffs_CheckpointSave(dev);
1771 if (dev->putSuperFunc)
1772 dev->putSuperFunc(sb);
1774 yaffs_Deinitialise(dev);
1776 yaffs_GrossUnlock(dev);
1778 /* we assume this is protected by lock_kernel() in mount/umount */
1779 ylist_del(&dev->devList);
1781 if (dev->spareBuffer) {
1782 YFREE(dev->spareBuffer);
1783 dev->spareBuffer = NULL;
1790 static void yaffs_MTDPutSuper(struct super_block *sb)
1792 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
1797 put_mtd_device(mtd);
1801 static void yaffs_MarkSuperBlockDirty(void *vsb)
1803 struct super_block *sb = (struct super_block *)vsb;
1805 T(YAFFS_TRACE_OS, ("yaffs_MarkSuperBlockDirty() sb = %p\n", sb));
1812 int skip_checkpoint_read;
1813 int skip_checkpoint_write;
1817 #define MAX_OPT_LEN 20
1818 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
1820 char cur_opt[MAX_OPT_LEN + 1];
1824 /* Parse through the options which is a comma seperated list */
1826 while (options_str && *options_str && !error) {
1827 memset(cur_opt, 0, MAX_OPT_LEN + 1);
1830 while (*options_str && *options_str != ',') {
1831 if (p < MAX_OPT_LEN) {
1832 cur_opt[p] = *options_str;
1838 if (!strcmp(cur_opt, "inband-tags"))
1839 options->inband_tags = 1;
1840 else if (!strcmp(cur_opt, "no-cache"))
1841 options->no_cache = 1;
1842 else if (!strcmp(cur_opt, "no-checkpoint-read"))
1843 options->skip_checkpoint_read = 1;
1844 else if (!strcmp(cur_opt, "no-checkpoint-write"))
1845 options->skip_checkpoint_write = 1;
1846 else if (!strcmp(cur_opt, "no-checkpoint")) {
1847 options->skip_checkpoint_read = 1;
1848 options->skip_checkpoint_write = 1;
1850 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
1859 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
1860 struct super_block *sb,
1861 void *data, int silent)
1864 struct inode *inode = NULL;
1865 struct dentry *root;
1866 yaffs_Device *dev = 0;
1867 char devname_buf[BDEVNAME_SIZE + 1];
1868 struct mtd_info *mtd;
1870 char *data_str = (char *)data;
1872 yaffs_options options;
1874 sb->s_magic = YAFFS_MAGIC;
1875 sb->s_op = &yaffs_super_ops;
1876 sb->s_flags |= MS_NOATIME;
1879 printk(KERN_INFO "yaffs: sb is NULL\n");
1880 else if (!sb->s_dev)
1881 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
1882 else if (!yaffs_devname(sb, devname_buf))
1883 printk(KERN_INFO "yaffs: devname is NULL\n");
1885 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
1887 yaffs_devname(sb, devname_buf));
1892 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
1894 memset(&options, 0, sizeof(options));
1896 if (yaffs_parse_options(&options, data_str)) {
1897 /* Option parsing failed */
1902 sb->s_blocksize = PAGE_CACHE_SIZE;
1903 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
1904 T(YAFFS_TRACE_OS, ("yaffs_read_super: Using yaffs%d\n", yaffsVersion));
1906 ("yaffs_read_super: block size %d\n", (int)(sb->s_blocksize)));
1908 #ifdef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
1910 ("yaffs: Write verification disabled. All guarantees "
1911 "null and void\n"));
1914 T(YAFFS_TRACE_ALWAYS, ("yaffs: Attempting MTD mount on %u.%u, "
1916 MAJOR(sb->s_dev), MINOR(sb->s_dev),
1917 yaffs_devname(sb, devname_buf)));
1919 /* Check it's an mtd device..... */
1920 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
1921 return NULL; /* This isn't an mtd device */
1923 /* Get the device */
1924 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
1926 T(YAFFS_TRACE_ALWAYS,
1927 ("yaffs: MTD device #%u doesn't appear to exist\n",
1931 /* Check it's NAND */
1932 if (mtd->type != MTD_NANDFLASH) {
1933 T(YAFFS_TRACE_ALWAYS,
1934 ("yaffs: MTD device is not NAND it's type %d\n", mtd->type));
1938 T(YAFFS_TRACE_OS, (" erase %p\n", mtd->erase));
1939 T(YAFFS_TRACE_OS, (" read %p\n", mtd->read));
1940 T(YAFFS_TRACE_OS, (" write %p\n", mtd->write));
1941 T(YAFFS_TRACE_OS, (" readoob %p\n", mtd->read_oob));
1942 T(YAFFS_TRACE_OS, (" writeoob %p\n", mtd->write_oob));
1943 T(YAFFS_TRACE_OS, (" block_isbad %p\n", mtd->block_isbad));
1944 T(YAFFS_TRACE_OS, (" block_markbad %p\n", mtd->block_markbad));
1945 T(YAFFS_TRACE_OS, (" %s %d\n", WRITE_SIZE_STR, WRITE_SIZE(mtd)));
1946 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
1947 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
1948 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1949 T(YAFFS_TRACE_OS, (" size %u\n", mtd->size));
1951 T(YAFFS_TRACE_OS, (" size %lld\n", mtd->size));
1954 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
1956 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
1957 T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs2\n"));
1961 /* Added NCB 26/5/2006 for completeness */
1962 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
1963 T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs1\n"));
1969 if (yaffsVersion == 2) {
1970 /* Check for version 2 style functions */
1972 !mtd->block_isbad ||
1973 !mtd->block_markbad ||
1976 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1977 !mtd->read_oob || !mtd->write_oob) {
1980 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
1982 T(YAFFS_TRACE_ALWAYS,
1983 ("yaffs: MTD device does not support required "
1988 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
1989 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
1990 !options.inband_tags) {
1991 T(YAFFS_TRACE_ALWAYS,
1992 ("yaffs: MTD device does not have the "
1993 "right page sizes\n"));
1997 /* Check for V1 style functions */
2001 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2002 !mtd->read_oob || !mtd->write_oob) {
2005 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2007 T(YAFFS_TRACE_ALWAYS,
2008 ("yaffs: MTD device does not support required "
2013 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2014 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2015 T(YAFFS_TRACE_ALWAYS,
2016 ("yaffs: MTD device does not support have the "
2017 "right page sizes\n"));
2022 /* OK, so if we got here, we have an MTD that's NAND and looks
2023 * like it has the right capabilities
2024 * Set the yaffs_Device up for mtd
2027 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2028 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2030 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2033 /* Deep shit could not allocate device structure */
2034 T(YAFFS_TRACE_ALWAYS,
2035 ("yaffs_read_super: Failed trying to allocate "
2036 "yaffs_Device. \n"));
2040 memset(dev, 0, sizeof(yaffs_Device));
2041 dev->genericDevice = mtd;
2042 dev->name = mtd->name;
2044 /* Set up the memory size parameters.... */
2046 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2048 dev->startBlock = 0;
2049 dev->endBlock = nBlocks - 1;
2050 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2051 dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2052 dev->nReservedBlocks = 5;
2053 dev->nShortOpCaches = (options.no_cache) ? 0 : 10;
2054 dev->inbandTags = options.inband_tags;
2056 /* ... and the functions. */
2057 if (yaffsVersion == 2) {
2058 dev->writeChunkWithTagsToNAND =
2059 nandmtd2_WriteChunkWithTagsToNAND;
2060 dev->readChunkWithTagsFromNAND =
2061 nandmtd2_ReadChunkWithTagsFromNAND;
2062 dev->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2063 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
2064 dev->spareBuffer = YMALLOC(mtd->oobsize);
2066 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2067 dev->totalBytesPerChunk = mtd->writesize;
2068 dev->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2070 dev->totalBytesPerChunk = mtd->oobblock;
2071 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2073 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2075 dev->startBlock = 0;
2076 dev->endBlock = nBlocks - 1;
2078 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2079 /* use the MTD interface in yaffs_mtdif1.c */
2080 dev->writeChunkWithTagsToNAND =
2081 nandmtd1_WriteChunkWithTagsToNAND;
2082 dev->readChunkWithTagsFromNAND =
2083 nandmtd1_ReadChunkWithTagsFromNAND;
2084 dev->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2085 dev->queryNANDBlock = nandmtd1_QueryNANDBlock;
2087 dev->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2088 dev->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2092 /* ... and common functions */
2093 dev->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2094 dev->initialiseNAND = nandmtd_InitialiseNAND;
2096 dev->putSuperFunc = yaffs_MTDPutSuper;
2098 dev->superBlock = (void *)sb;
2099 dev->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2102 #ifndef CONFIG_YAFFS_DOES_ECC
2103 dev->useNANDECC = 1;
2106 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2107 dev->wideTnodesDisabled = 1;
2110 dev->skipCheckpointRead = options.skip_checkpoint_read;
2111 dev->skipCheckpointWrite = options.skip_checkpoint_write;
2113 /* we assume this is protected by lock_kernel() in mount/umount */
2114 ylist_add_tail(&dev->devList, &yaffs_dev_list);
2116 init_MUTEX(&dev->grossLock);
2118 yaffs_GrossLock(dev);
2120 err = yaffs_GutsInitialise(dev);
2123 ("yaffs_read_super: guts initialised %s\n",
2124 (err == YAFFS_OK) ? "OK" : "FAILED"));
2126 /* Release lock before yaffs_get_inode() */
2127 yaffs_GrossUnlock(dev);
2129 /* Create root inode */
2130 if (err == YAFFS_OK)
2131 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2137 inode->i_op = &yaffs_dir_inode_operations;
2138 inode->i_fop = &yaffs_dir_operations;
2140 T(YAFFS_TRACE_OS, ("yaffs_read_super: got root inode\n"));
2142 root = d_alloc_root(inode);
2144 T(YAFFS_TRACE_OS, ("yaffs_read_super: d_alloc_root done\n"));
2151 sb->s_dirt = !dev->isCheckpointed;
2152 T(YAFFS_TRACE_ALWAYS,
2153 ("yaffs_read_super: isCheckpointed %d\n", dev->isCheckpointed));
2155 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
2160 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2161 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2164 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2167 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2168 static int yaffs_read_super(struct file_system_type *fs,
2169 int flags, const char *dev_name,
2170 void *data, struct vfsmount *mnt)
2173 return get_sb_bdev(fs, flags, dev_name, data,
2174 yaffs_internal_read_super_mtd, mnt);
2177 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2178 int flags, const char *dev_name,
2182 return get_sb_bdev(fs, flags, dev_name, data,
2183 yaffs_internal_read_super_mtd);
2187 static struct file_system_type yaffs_fs_type = {
2188 .owner = THIS_MODULE,
2190 .get_sb = yaffs_read_super,
2191 .kill_sb = kill_block_super,
2192 .fs_flags = FS_REQUIRES_DEV,
2195 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2198 return yaffs_internal_read_super(1, sb, data, silent);
2201 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2206 #ifdef CONFIG_YAFFS_YAFFS2
2208 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2209 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2212 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2215 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2216 static int yaffs2_read_super(struct file_system_type *fs,
2217 int flags, const char *dev_name, void *data,
2218 struct vfsmount *mnt)
2220 return get_sb_bdev(fs, flags, dev_name, data,
2221 yaffs2_internal_read_super_mtd, mnt);
2224 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2225 int flags, const char *dev_name,
2229 return get_sb_bdev(fs, flags, dev_name, data,
2230 yaffs2_internal_read_super_mtd);
2234 static struct file_system_type yaffs2_fs_type = {
2235 .owner = THIS_MODULE,
2237 .get_sb = yaffs2_read_super,
2238 .kill_sb = kill_block_super,
2239 .fs_flags = FS_REQUIRES_DEV,
2242 static struct super_block *yaffs2_read_super(struct super_block *sb,
2243 void *data, int silent)
2245 return yaffs_internal_read_super(2, sb, data, silent);
2248 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
2252 #endif /* CONFIG_YAFFS_YAFFS2 */
2254 static struct proc_dir_entry *my_proc_entry;
2256 static char *yaffs_dump_dev(char *buf, yaffs_Device * dev)
2258 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
2259 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
2260 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk);
2261 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
2262 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
2263 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
2264 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
2265 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks);
2266 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
2267 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
2268 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
2269 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
2270 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
2271 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
2272 buf += sprintf(buf, "nPageWrites........ %d\n", dev->nPageWrites);
2273 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
2274 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
2275 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
2276 buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
2277 buf += sprintf(buf, "passiveGCs......... %d\n",
2278 dev->passiveGarbageCollections);
2279 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
2280 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches);
2281 buf += sprintf(buf, "nRetireBlocks...... %d\n", dev->nRetiredBlocks);
2282 buf += sprintf(buf, "eccFixed........... %d\n", dev->eccFixed);
2283 buf += sprintf(buf, "eccUnfixed......... %d\n", dev->eccUnfixed);
2284 buf += sprintf(buf, "tagsEccFixed....... %d\n", dev->tagsEccFixed);
2285 buf += sprintf(buf, "tagsEccUnfixed..... %d\n", dev->tagsEccUnfixed);
2286 buf += sprintf(buf, "cacheHits.......... %d\n", dev->cacheHits);
2287 buf += sprintf(buf, "nDeletedFiles...... %d\n", dev->nDeletedFiles);
2288 buf += sprintf(buf, "nUnlinkedFiles..... %d\n", dev->nUnlinkedFiles);
2290 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
2291 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
2292 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
2293 buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags);
2298 static int yaffs_proc_read(char *page,
2300 off_t offset, int count, int *eof, void *data)
2302 struct ylist_head *item;
2307 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
2308 * We use 'offset' (*ppos) to indicate where we are in devList.
2309 * This also assumes the user has posted a read buffer large
2310 * enough to hold the complete output; but that's life in /proc.
2315 /* Print header first */
2317 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__
2318 "\n%s\n%s\n", yaffs_fs_c_version,
2319 yaffs_guts_c_version);
2322 /* hold lock_kernel while traversing yaffs_dev_list */
2325 /* Locate and print the Nth entry. Order N-squared but N is small. */
2326 ylist_for_each(item, &yaffs_dev_list) {
2327 yaffs_Device *dev = ylist_entry(item, yaffs_Device, devList);
2332 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->name);
2333 buf = yaffs_dump_dev(buf, dev);
2338 return buf - page < count ? buf - page : count;
2342 * Set the verbosity of the warnings and error messages.
2344 * Note that the names can only be a..z or _ with the current code.
2349 unsigned mask_bitfield;
2351 {"allocate", YAFFS_TRACE_ALLOCATE},
2352 {"always", YAFFS_TRACE_ALWAYS},
2353 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
2354 {"buffers", YAFFS_TRACE_BUFFERS},
2355 {"bug", YAFFS_TRACE_BUG},
2356 {"checkpt", YAFFS_TRACE_CHECKPOINT},
2357 {"deletion", YAFFS_TRACE_DELETION},
2358 {"erase", YAFFS_TRACE_ERASE},
2359 {"error", YAFFS_TRACE_ERROR},
2360 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
2361 {"gc", YAFFS_TRACE_GC},
2362 {"mtd", YAFFS_TRACE_MTD},
2363 {"nandaccess", YAFFS_TRACE_NANDACCESS},
2364 {"os", YAFFS_TRACE_OS},
2365 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
2366 {"scan", YAFFS_TRACE_SCAN},
2367 {"tracing", YAFFS_TRACE_TRACING},
2369 {"verify", YAFFS_TRACE_VERIFY},
2370 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
2371 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
2372 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
2374 {"write", YAFFS_TRACE_WRITE},
2375 {"all", 0xffffffff},
2380 #define MAX_MASK_NAME_LENGTH 40
2381 static int yaffs_proc_write(struct file *file, const char *buf,
2382 unsigned long count, void *data)
2384 unsigned rg = 0, mask_bitfield;
2388 char substring[MAX_MASK_NAME_LENGTH + 1];
2394 rg = yaffs_traceMask;
2396 while (!done && (pos < count)) {
2398 while ((pos < count) && isspace(buf[pos]))
2415 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
2417 if (end > buf + pos) {
2418 mask_name = "numeral";
2419 len = end - (buf + pos);
2423 for (x = buf + pos, i = 0;
2424 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
2425 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
2427 substring[i] = '\0';
2429 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2430 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
2431 mask_name = mask_flags[i].mask_name;
2432 mask_bitfield = mask_flags[i].mask_bitfield;
2439 if (mask_name != NULL) {
2443 rg &= ~mask_bitfield;
2446 rg |= mask_bitfield;
2452 rg |= mask_bitfield;
2458 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
2460 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
2462 if (rg & YAFFS_TRACE_ALWAYS) {
2463 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
2465 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
2466 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
2473 /* Stuff to handle installation of file systems */
2474 struct file_system_to_install {
2475 struct file_system_type *fst;
2479 static struct file_system_to_install fs_to_install[] = {
2480 {&yaffs_fs_type, 0},
2481 {&yaffs2_fs_type, 0},
2485 static int __init init_yaffs_fs(void)
2488 struct file_system_to_install *fsinst;
2490 T(YAFFS_TRACE_ALWAYS,
2491 ("yaffs " __DATE__ " " __TIME__ " Installing. \n"));
2493 /* Install the proc_fs entry */
2494 my_proc_entry = create_proc_entry("yaffs",
2498 if (my_proc_entry) {
2499 my_proc_entry->write_proc = yaffs_proc_write;
2500 my_proc_entry->read_proc = yaffs_proc_read;
2501 my_proc_entry->data = NULL;
2505 /* Now add the file system entries */
2507 fsinst = fs_to_install;
2509 while (fsinst->fst && !error) {
2510 error = register_filesystem(fsinst->fst);
2512 fsinst->installed = 1;
2516 /* Any errors? uninstall */
2518 fsinst = fs_to_install;
2520 while (fsinst->fst) {
2521 if (fsinst->installed) {
2522 unregister_filesystem(fsinst->fst);
2523 fsinst->installed = 0;
2532 static void __exit exit_yaffs_fs(void)
2535 struct file_system_to_install *fsinst;
2537 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
2540 remove_proc_entry("yaffs", YPROC_ROOT);
2542 fsinst = fs_to_install;
2544 while (fsinst->fst) {
2545 if (fsinst->installed) {
2546 unregister_filesystem(fsinst->fst);
2547 fsinst->installed = 0;
2553 module_init(init_yaffs_fs)
2554 module_exit(exit_yaffs_fs)
2556 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
2557 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2006");
2558 MODULE_LICENSE("GPL");