2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 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 #include <linux/version.h>
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10))
37 #define YAFFS_COMPILE_BACKGROUND
40 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28))
41 #define YAFFS_COMPILE_EXPORTFS
45 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
46 #include <linux/config.h>
49 #include <linux/kernel.h>
50 #include <linux/module.h>
51 #include <linux/slab.h>
52 #include <linux/init.h>
54 #include <linux/proc_fs.h>
55 #include <linux/smp_lock.h>
56 #include <linux/pagemap.h>
57 #include <linux/mtd/mtd.h>
58 #include <linux/interrupt.h>
59 #include <linux/string.h>
60 #include <linux/ctype.h>
62 #ifdef YAFFS_COMPILE_EXPORTFS
63 #include <linux/exportfs.h>
66 #ifdef YAFFS_COMPILE_BACKGROUND
67 #include <linux/kthread.h>
68 #include <linux/delay.h>
69 #include <linux/freezer.h>
72 #include <asm/div64.h>
74 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
76 #include <linux/statfs.h>
78 #define UnlockPage(p) unlock_page(p)
79 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
81 /* FIXME: use sb->s_id instead ? */
82 #define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf)
86 #include <linux/locks.h>
87 #define BDEVNAME_SIZE 0
88 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
90 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0))
91 /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */
97 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
98 #define YPROC_ROOT (&proc_root)
100 #define YPROC_ROOT NULL
103 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
104 #define WRITE_SIZE_STR "writesize"
105 #define WRITE_SIZE(mtd) ((mtd)->writesize)
107 #define WRITE_SIZE_STR "oobblock"
108 #define WRITE_SIZE(mtd) ((mtd)->oobblock)
111 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27))
112 #define YAFFS_USE_WRITE_BEGIN_END 1
114 #define YAFFS_USE_WRITE_BEGIN_END 0
117 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28))
118 static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size)
120 uint64_t result = partition_size;
121 do_div(result, block_size);
122 return (uint32_t)result;
125 #define YCALCBLOCKS(s, b) ((s)/(b))
128 #include <linux/uaccess.h>
129 #include <linux/mtd/mtd.h>
131 #include "yportenv.h"
132 #include "yaffs_trace.h"
133 #include "yaffs_guts.h"
135 #include "yaffs_linux.h"
137 #include "yaffs_mtdif.h"
138 #include "yaffs_mtdif1.h"
139 #include "yaffs_mtdif2.h"
141 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS | YAFFS_TRACE_ALWAYS;
142 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
143 unsigned int yaffs_auto_checkpoint = 1;
144 unsigned int yaffs_gc_control = 1;
146 /* Module Parameters */
147 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
148 module_param(yaffs_traceMask, uint, 0644);
149 module_param(yaffs_wr_attempts, uint, 0644);
150 module_param(yaffs_auto_checkpoint, uint, 0644);
151 module_param(yaffs_gc_control, uint, 0644);
153 MODULE_PARM(yaffs_traceMask, "i");
154 MODULE_PARM(yaffs_wr_attempts, "i");
155 MODULE_PARM(yaffs_auto_checkpoint, "i");
156 MODULE_PARM(yaffs_gc_control, "i");
159 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
160 /* use iget and read_inode */
161 #define Y_IGET(sb, inum) iget((sb), (inum))
162 static void yaffs_read_inode(struct inode *inode);
165 /* Call local equivalent */
166 #define YAFFS_USE_OWN_IGET
167 #define Y_IGET(sb, inum) yaffs_iget((sb), (inum))
169 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
172 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
173 #define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)
175 #define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip)
178 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
179 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
181 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
182 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
184 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
188 #define update_dir_time(dir) do {\
189 (dir)->i_ctime = (dir)->i_mtime = CURRENT_TIME; \
192 static void yaffs_put_super(struct super_block *sb);
194 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
196 static ssize_t yaffs_hold_space(struct file *f);
197 static void yaffs_release_space(struct file *f);
199 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
200 static int yaffs_file_flush(struct file *file, fl_owner_t id);
202 static int yaffs_file_flush(struct file *file);
205 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
208 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
210 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
211 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
212 struct nameidata *n);
213 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
214 struct nameidata *n);
216 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
217 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
219 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
220 struct dentry *dentry);
221 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
222 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
223 const char *symname);
224 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
226 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
227 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
230 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
233 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
234 struct inode *new_dir, struct dentry *new_dentry);
235 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
237 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
238 static int yaffs_sync_fs(struct super_block *sb, int wait);
239 static void yaffs_write_super(struct super_block *sb);
241 static int yaffs_sync_fs(struct super_block *sb);
242 static int yaffs_write_super(struct super_block *sb);
245 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
246 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
247 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
248 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
250 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
253 #ifdef YAFFS_HAS_PUT_INODE
254 static void yaffs_put_inode(struct inode *inode);
257 static void yaffs_delete_inode(struct inode *);
258 static void yaffs_clear_inode(struct inode *);
260 static int yaffs_readpage(struct file *file, struct page *page);
261 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
262 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
264 static int yaffs_writepage(struct page *page);
267 #ifdef CONFIG_YAFFS_XATTR
268 int yaffs_setxattr(struct dentry *dentry, const char *name,
269 const void *value, size_t size, int flags);
270 ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
272 int yaffs_removexattr(struct dentry *dentry, const char *name);
273 ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size);
277 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
278 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
279 loff_t pos, unsigned len, unsigned flags,
280 struct page **pagep, void **fsdata);
281 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
282 loff_t pos, unsigned len, unsigned copied,
283 struct page *pg, void *fsdadata);
285 static int yaffs_prepare_write(struct file *f, struct page *pg,
286 unsigned offset, unsigned to);
287 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
292 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
294 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
295 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
297 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
299 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin);
301 static struct address_space_operations yaffs_file_address_operations = {
302 .readpage = yaffs_readpage,
303 .writepage = yaffs_writepage,
304 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
305 .write_begin = yaffs_write_begin,
306 .write_end = yaffs_write_end,
308 .prepare_write = yaffs_prepare_write,
309 .commit_write = yaffs_commit_write,
313 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
314 static const struct file_operations yaffs_file_operations = {
315 .read = do_sync_read,
316 .write = do_sync_write,
317 .aio_read = generic_file_aio_read,
318 .aio_write = generic_file_aio_write,
319 .mmap = generic_file_mmap,
320 .flush = yaffs_file_flush,
321 .fsync = yaffs_sync_object,
322 .splice_read = generic_file_splice_read,
323 .splice_write = generic_file_splice_write,
324 .llseek = generic_file_llseek,
327 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
329 static const struct file_operations yaffs_file_operations = {
330 .read = do_sync_read,
331 .write = do_sync_write,
332 .aio_read = generic_file_aio_read,
333 .aio_write = generic_file_aio_write,
334 .mmap = generic_file_mmap,
335 .flush = yaffs_file_flush,
336 .fsync = yaffs_sync_object,
337 .sendfile = generic_file_sendfile,
342 static const struct file_operations yaffs_file_operations = {
343 .read = generic_file_read,
344 .write = generic_file_write,
345 .mmap = generic_file_mmap,
346 .flush = yaffs_file_flush,
347 .fsync = yaffs_sync_object,
348 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
349 .sendfile = generic_file_sendfile,
354 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
355 static void zero_user_segment(struct page *page, unsigned start, unsigned end)
357 void * kaddr = kmap_atomic(page, KM_USER0);
358 memset(kaddr + start, 0, end - start);
359 kunmap_atomic(kaddr, KM_USER0);
360 flush_dcache_page(page);
365 static const struct inode_operations yaffs_file_inode_operations = {
366 .setattr = yaffs_setattr,
367 #ifdef CONFIG_YAFFS_XATTR
368 .setxattr = yaffs_setxattr,
369 .getxattr = yaffs_getxattr,
370 .listxattr = yaffs_listxattr,
371 .removexattr = yaffs_removexattr,
375 static const struct inode_operations yaffs_symlink_inode_operations = {
376 .readlink = yaffs_readlink,
377 .follow_link = yaffs_follow_link,
378 .setattr = yaffs_setattr,
379 #ifdef CONFIG_YAFFS_XATTR
380 .setxattr = yaffs_setxattr,
381 .getxattr = yaffs_getxattr,
382 .listxattr = yaffs_listxattr,
383 .removexattr = yaffs_removexattr,
387 static const struct inode_operations yaffs_dir_inode_operations = {
388 .create = yaffs_create,
389 .lookup = yaffs_lookup,
391 .unlink = yaffs_unlink,
392 .symlink = yaffs_symlink,
393 .mkdir = yaffs_mkdir,
394 .rmdir = yaffs_unlink,
395 .mknod = yaffs_mknod,
396 .rename = yaffs_rename,
397 .setattr = yaffs_setattr,
398 #ifdef CONFIG_YAFFS_XATTR
399 .setxattr = yaffs_setxattr,
400 .getxattr = yaffs_getxattr,
401 .listxattr = yaffs_listxattr,
402 .removexattr = yaffs_removexattr,
406 static const struct file_operations yaffs_dir_operations = {
407 .read = generic_read_dir,
408 .readdir = yaffs_readdir,
409 .fsync = yaffs_sync_object,
410 .llseek = yaffs_dir_llseek,
413 static const struct super_operations yaffs_super_ops = {
414 .statfs = yaffs_statfs,
416 #ifndef YAFFS_USE_OWN_IGET
417 .read_inode = yaffs_read_inode,
419 #ifdef YAFFS_HAS_PUT_INODE
420 .put_inode = yaffs_put_inode,
422 .put_super = yaffs_put_super,
423 .delete_inode = yaffs_delete_inode,
424 .clear_inode = yaffs_clear_inode,
425 .sync_fs = yaffs_sync_fs,
426 .write_super = yaffs_write_super,
429 static unsigned yaffs_gc_control_callback(yaffs_Device *dev)
431 return yaffs_gc_control;
434 static void yaffs_GrossLock(yaffs_Device *dev)
436 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
437 down(&(yaffs_DeviceToContext(dev)->grossLock));
438 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locked %p\n"), current));
441 static void yaffs_GrossUnlock(yaffs_Device *dev)
443 T(YAFFS_TRACE_LOCK, (TSTR("yaffs unlocking %p\n"), current));
444 up(&(yaffs_DeviceToContext(dev)->grossLock));
447 #ifdef YAFFS_COMPILE_EXPORTFS
449 static struct inode *
450 yaffs2_nfs_get_inode(struct super_block *sb, uint64_t ino, uint32_t generation)
452 return Y_IGET(sb, ino);
455 static struct dentry *
456 yaffs2_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
458 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode) ;
461 static struct dentry *
462 yaffs2_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
464 return generic_fh_to_parent(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode);
467 struct dentry *yaffs2_get_parent(struct dentry *dentry)
470 struct super_block *sb = dentry->d_inode->i_sb;
471 struct dentry *parent = ERR_PTR(-ENOENT);
473 unsigned long parent_ino;
475 yaffs_Object *parent_obj;
477 d_obj = yaffs_InodeToObject(dentry->d_inode);
480 parent_obj = d_obj->parent;
482 parent_ino = yaffs_GetObjectInode(parent_obj);
483 inode = Y_IGET(sb, parent_ino);
486 parent = ERR_CAST(inode);
488 parent = d_obtain_alias(inode);
489 if (!IS_ERR(parent)) {
490 parent = ERR_PTR(-ENOMEM);
500 /* Just declare a zero structure as a NULL value implies
501 * using the default functions of exportfs.
504 static struct export_operations yaffs_export_ops =
506 .fh_to_dentry = yaffs2_fh_to_dentry,
507 .fh_to_parent = yaffs2_fh_to_parent,
508 .get_parent = yaffs2_get_parent,
513 /*-----------------------------------------------------------------*/
514 /* Directory search context allows us to unlock access to yaffs during
515 * filldir without causing problems with the directory being modified.
516 * This is similar to the tried and tested mechanism used in yaffs direct.
518 * A search context iterates along a doubly linked list of siblings in the
519 * directory. If the iterating object is deleted then this would corrupt
520 * the list iteration, likely causing a crash. The search context avoids
521 * this by using the removeObjectCallback to move the search context to the
522 * next object before the object is deleted.
524 * Many readdirs (and thus seach conexts) may be alive simulateously so
525 * each yaffs_Device has a list of these.
527 * A seach context lives for the duration of a readdir.
529 * All these functions must be called while yaffs is locked.
532 struct yaffs_SearchContext {
534 yaffs_Object *dirObj;
535 yaffs_Object *nextReturn;
536 struct ylist_head others;
540 * yaffs_NewSearch() creates a new search context, initialises it and
541 * adds it to the device's search context list.
543 * Called at start of readdir.
545 static struct yaffs_SearchContext * yaffs_NewSearch(yaffs_Object *dir)
547 yaffs_Device *dev = dir->myDev;
548 struct yaffs_SearchContext *sc = YMALLOC(sizeof(struct yaffs_SearchContext));
552 if( ylist_empty(&sc->dirObj->variant.directoryVariant.children))
553 sc->nextReturn = NULL;
555 sc->nextReturn = ylist_entry(
556 dir->variant.directoryVariant.children.next,
557 yaffs_Object,siblings);
558 YINIT_LIST_HEAD(&sc->others);
559 ylist_add(&sc->others,&(yaffs_DeviceToContext(dev)->searchContexts));
565 * yaffs_EndSearch() disposes of a search context and cleans up.
567 static void yaffs_EndSearch(struct yaffs_SearchContext * sc)
570 ylist_del(&sc->others);
576 * yaffs_SearchAdvance() moves a search context to the next object.
577 * Called when the search iterates or when an object removal causes
578 * the search context to be moved to the next object.
580 static void yaffs_SearchAdvance(struct yaffs_SearchContext *sc)
585 if( sc->nextReturn == NULL ||
586 ylist_empty(&sc->dirObj->variant.directoryVariant.children))
587 sc->nextReturn = NULL;
589 struct ylist_head *next = sc->nextReturn->siblings.next;
591 if( next == &sc->dirObj->variant.directoryVariant.children)
592 sc->nextReturn = NULL; /* end of list */
594 sc->nextReturn = ylist_entry(next,yaffs_Object,siblings);
599 * yaffs_RemoveObjectCallback() is called when an object is unlinked.
600 * We check open search contexts and advance any which are currently
601 * on the object being iterated.
603 static void yaffs_RemoveObjectCallback(yaffs_Object *obj)
606 struct ylist_head *i;
607 struct yaffs_SearchContext *sc;
608 struct ylist_head *search_contexts = &(yaffs_DeviceToContext(obj->myDev)->searchContexts);
611 /* Iterate through the directory search contexts.
612 * If any are currently on the object being removed, then advance
613 * the search context to the next object to prevent a hanging pointer.
615 ylist_for_each(i, search_contexts) {
617 sc = ylist_entry(i, struct yaffs_SearchContext,others);
618 if(sc->nextReturn == obj)
619 yaffs_SearchAdvance(sc);
626 /*-----------------------------------------------------------------*/
628 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
631 unsigned char *alias;
634 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
636 yaffs_GrossLock(dev);
638 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
640 yaffs_GrossUnlock(dev);
645 ret = vfs_readlink(dentry, buffer, buflen, alias);
650 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
651 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
653 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
656 unsigned char *alias;
658 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
660 yaffs_GrossLock(dev);
662 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
664 yaffs_GrossUnlock(dev);
671 ret = vfs_follow_link(nd, alias);
674 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
681 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
685 * Lookup is used to find objects in the fs
687 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
689 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
692 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
696 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
698 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
700 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
701 yaffs_GrossLock(dev);
704 (TSTR("yaffs_lookup for %d:%s\n"),
705 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
707 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
708 dentry->d_name.name);
710 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
712 /* Can't hold gross lock when calling yaffs_get_inode() */
713 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
714 yaffs_GrossUnlock(dev);
718 (TSTR("yaffs_lookup found %d\n"), obj->objectId));
720 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
724 (TSTR("yaffs_loookup dentry \n")));
725 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
726 * d_add even if NULL inode */
728 /*dget(dentry); // try to solve directory bug */
729 d_add(dentry, inode);
737 T(YAFFS_TRACE_OS,(TSTR("yaffs_lookup not found\n")));
741 /* added NCB for 2.5/6 compatability - forces add even if inode is
742 * NULL which creates dentry hash */
743 d_add(dentry, inode);
749 #ifdef YAFFS_HAS_PUT_INODE
751 /* For now put inode is just for debugging
752 * Put inode is called when the inode **structure** is put.
754 static void yaffs_put_inode(struct inode *inode)
757 (TSTR("yaffs_put_inode: ino %d, count %d\n"), (int)inode->i_ino,
758 atomic_read(&inode->i_count)));
763 /* clear is called to tell the fs to release any per-inode data it holds */
764 static void yaffs_clear_inode(struct inode *inode)
769 obj = yaffs_InodeToObject(inode);
772 (TSTR("yaffs_clear_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
773 atomic_read(&inode->i_count),
774 obj ? "object exists" : "null object"));
778 yaffs_GrossLock(dev);
780 /* Clear the association between the inode and
784 yaffs_InodeToObjectLV(inode) = NULL;
786 /* If the object freeing was deferred, then the real
788 * This should fix the inode inconsistency problem.
791 yaffs_HandleDeferedFree(obj);
793 yaffs_GrossUnlock(dev);
798 /* delete is called when the link count is zero and the inode
799 * is put (ie. nobody wants to know about it anymore, time to
801 * NB Must call clear_inode()
803 static void yaffs_delete_inode(struct inode *inode)
805 yaffs_Object *obj = yaffs_InodeToObject(inode);
809 (TSTR("yaffs_delete_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
810 atomic_read(&inode->i_count),
811 obj ? "object exists" : "null object"));
815 yaffs_GrossLock(dev);
816 yaffs_DeleteObject(obj);
817 yaffs_GrossUnlock(dev);
819 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
820 truncate_inode_pages(&inode->i_data, 0);
825 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
826 static int yaffs_file_flush(struct file *file, fl_owner_t id)
828 static int yaffs_file_flush(struct file *file)
831 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
833 yaffs_Device *dev = obj->myDev;
836 (TSTR("yaffs_file_flush object %d (%s)\n"), obj->objectId,
837 obj->dirty ? "dirty" : "clean"));
839 yaffs_GrossLock(dev);
841 yaffs_FlushFile(obj, 1, 0);
843 yaffs_GrossUnlock(dev);
848 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
850 /* Lifted from jffs2 */
853 unsigned char *pg_buf;
859 (TSTR("yaffs_readpage_nolock at %08x, size %08x\n"),
860 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
861 (unsigned)PAGE_CACHE_SIZE));
863 obj = yaffs_DentryToObject(f->f_dentry);
867 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
868 BUG_ON(!PageLocked(pg));
875 /* FIXME: Can kmap fail? */
877 yaffs_GrossLock(dev);
879 ret = yaffs_ReadDataFromFile(obj, pg_buf,
880 pg->index << PAGE_CACHE_SHIFT,
883 yaffs_GrossUnlock(dev);
889 ClearPageUptodate(pg);
896 flush_dcache_page(pg);
899 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage_nolock done\n")));
903 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
905 int ret = yaffs_readpage_nolock(f, pg);
910 static int yaffs_readpage(struct file *f, struct page *pg)
914 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage\n")));
915 ret=yaffs_readpage_unlock(f, pg);
916 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage done\n")));
920 /* writepage inspired by/stolen from smbfs */
922 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
923 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
925 static int yaffs_writepage(struct page *page)
928 struct address_space *mapping = page->mapping;
930 unsigned long end_index;
939 inode = mapping->host;
942 i_size = i_size_read(inode);
944 end_index = i_size >> PAGE_CACHE_SHIFT;
946 if(page->index < end_index)
947 nBytes = PAGE_CACHE_SIZE;
949 nBytes = i_size & (PAGE_CACHE_SIZE -1);
951 if (page->index > end_index || !nBytes) {
953 (TSTR("yaffs_writepage at %08x, inode size = %08x!!!\n"),
954 (unsigned)(page->index << PAGE_CACHE_SHIFT),
955 (unsigned)inode->i_size));
957 (TSTR(" -> don't care!!\n")));
959 zero_user_segment(page,0,PAGE_CACHE_SIZE);
960 set_page_writeback(page);
962 end_page_writeback(page);
967 if(nBytes != PAGE_CACHE_SIZE)
968 zero_user_segment(page,nBytes,PAGE_CACHE_SIZE);
974 obj = yaffs_InodeToObject(inode);
975 yaffs_GrossLock(obj->myDev);
978 (TSTR("yaffs_writepage at %08x, size %08x\n"),
979 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
981 (TSTR("writepag0: obj = %05x, ino = %05x\n"),
982 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
984 nWritten = yaffs_WriteDataToFile(obj, buffer,
985 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
988 (TSTR("writepag1: obj = %05x, ino = %05x\n"),
989 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
991 yaffs_GrossUnlock(obj->myDev);
994 set_page_writeback(page);
996 end_page_writeback(page);
999 return (nWritten == nBytes) ? 0 : -ENOSPC;
1003 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1004 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
1005 loff_t pos, unsigned len, unsigned flags,
1006 struct page **pagep, void **fsdata)
1008 struct page *pg = NULL;
1009 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1015 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
1016 pg = grab_cache_page_write_begin(mapping, index, flags);
1018 pg = __grab_cache_page(mapping, index);
1027 (TSTR("start yaffs_write_begin index %d(%x) uptodate %d\n"),
1028 (int)index,(int)index,Page_Uptodate(pg) ? 1 : 0));
1031 space_held = yaffs_hold_space(filp);
1038 /* Update page if required */
1040 if (!Page_Uptodate(pg))
1041 ret = yaffs_readpage_nolock(filp, pg);
1046 /* Happy path return */
1047 T(YAFFS_TRACE_OS, (TSTR("end yaffs_write_begin - ok\n")));
1053 (TSTR("end yaffs_write_begin fail returning %d\n"), ret));
1055 yaffs_release_space(filp);
1058 page_cache_release(pg);
1065 static int yaffs_prepare_write(struct file *f, struct page *pg,
1066 unsigned offset, unsigned to)
1068 T(YAFFS_TRACE_OS, (TSTR("yaffs_prepair_write\n")));
1070 if (!Page_Uptodate(pg))
1071 return yaffs_readpage_nolock(f, pg);
1076 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1077 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1078 loff_t pos, unsigned len, unsigned copied,
1079 struct page *pg, void *fsdadata)
1083 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
1086 addr = kva + offset_into_page;
1089 ("yaffs_write_end addr %p pos %x nBytes %d\n",
1090 addr,(unsigned)pos, copied));
1092 ret = yaffs_file_write(filp, addr, copied, &pos);
1094 if (ret != copied) {
1096 (TSTR("yaffs_write_end not same size ret %d copied %d\n"),
1105 yaffs_release_space(filp);
1107 page_cache_release(pg);
1112 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1117 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
1118 int nBytes = to - offset;
1121 unsigned spos = pos;
1125 addr = kva + offset;
1127 saddr = (unsigned) addr;
1130 (TSTR("yaffs_commit_write addr %x pos %x nBytes %d\n"),
1131 saddr, spos, nBytes));
1133 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
1135 if (nWritten != nBytes) {
1137 (TSTR("yaffs_commit_write not same size nWritten %d nBytes %d\n"),
1147 (TSTR("yaffs_commit_write returning %d\n"),
1148 nWritten == nBytes ? 0 : nWritten));
1150 return nWritten == nBytes ? 0 : nWritten;
1155 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
1160 /* Check mode against the variant type and attempt to repair if broken. */
1161 __u32 mode = obj->yst_mode;
1162 switch (obj->variantType) {
1163 case YAFFS_OBJECT_TYPE_FILE:
1164 if (!S_ISREG(mode)) {
1165 obj->yst_mode &= ~S_IFMT;
1166 obj->yst_mode |= S_IFREG;
1170 case YAFFS_OBJECT_TYPE_SYMLINK:
1171 if (!S_ISLNK(mode)) {
1172 obj->yst_mode &= ~S_IFMT;
1173 obj->yst_mode |= S_IFLNK;
1177 case YAFFS_OBJECT_TYPE_DIRECTORY:
1178 if (!S_ISDIR(mode)) {
1179 obj->yst_mode &= ~S_IFMT;
1180 obj->yst_mode |= S_IFDIR;
1184 case YAFFS_OBJECT_TYPE_UNKNOWN:
1185 case YAFFS_OBJECT_TYPE_HARDLINK:
1186 case YAFFS_OBJECT_TYPE_SPECIAL:
1192 inode->i_flags |= S_NOATIME;
1194 inode->i_ino = obj->objectId;
1195 inode->i_mode = obj->yst_mode;
1196 inode->i_uid = obj->yst_uid;
1197 inode->i_gid = obj->yst_gid;
1198 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1199 inode->i_blksize = inode->i_sb->s_blocksize;
1201 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1203 inode->i_rdev = old_decode_dev(obj->yst_rdev);
1204 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
1205 inode->i_atime.tv_nsec = 0;
1206 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
1207 inode->i_mtime.tv_nsec = 0;
1208 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
1209 inode->i_ctime.tv_nsec = 0;
1211 inode->i_rdev = obj->yst_rdev;
1212 inode->i_atime = obj->yst_atime;
1213 inode->i_mtime = obj->yst_mtime;
1214 inode->i_ctime = obj->yst_ctime;
1216 inode->i_size = yaffs_GetObjectFileLength(obj);
1217 inode->i_blocks = (inode->i_size + 511) >> 9;
1219 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1222 (TSTR("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n"),
1223 inode->i_mode, inode->i_uid, inode->i_gid,
1224 (int)inode->i_size, atomic_read(&inode->i_count)));
1226 switch (obj->yst_mode & S_IFMT) {
1227 default: /* fifo, device or socket */
1228 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1229 init_special_inode(inode, obj->yst_mode,
1230 old_decode_dev(obj->yst_rdev));
1232 init_special_inode(inode, obj->yst_mode,
1233 (dev_t) (obj->yst_rdev));
1236 case S_IFREG: /* file */
1237 inode->i_op = &yaffs_file_inode_operations;
1238 inode->i_fop = &yaffs_file_operations;
1239 inode->i_mapping->a_ops =
1240 &yaffs_file_address_operations;
1242 case S_IFDIR: /* directory */
1243 inode->i_op = &yaffs_dir_inode_operations;
1244 inode->i_fop = &yaffs_dir_operations;
1246 case S_IFLNK: /* symlink */
1247 inode->i_op = &yaffs_symlink_inode_operations;
1251 yaffs_InodeToObjectLV(inode) = obj;
1253 obj->myInode = inode;
1257 (TSTR("yaffs_FileInode invalid parameters\n")));
1262 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1265 struct inode *inode;
1269 (TSTR("yaffs_get_inode for NULL super_block!!\n")));
1276 (TSTR("yaffs_get_inode for NULL object!!\n")));
1282 (TSTR("yaffs_get_inode for object %d\n"), obj->objectId));
1284 inode = Y_IGET(sb, obj->objectId);
1288 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1289 /* iget also increments the inode's i_count */
1290 /* NB You can't be holding grossLock or deadlock will happen! */
1295 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1300 struct inode *inode;
1303 obj = yaffs_DentryToObject(f->f_dentry);
1307 yaffs_GrossLock(dev);
1309 inode = f->f_dentry->d_inode;
1311 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
1312 ipos = inode->i_size;
1318 (TSTR("yaffs_file_write: hey obj is null!\n")));
1321 (TSTR("yaffs_file_write about to write writing %u(%x) bytes"
1322 "to object %d at %d(%x)\n"),
1323 (unsigned) n, (unsigned) n, obj->objectId, ipos,ipos));
1325 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1328 (TSTR("yaffs_file_write: %d(%x) bytes written\n"),
1329 (unsigned )n,(unsigned)n));
1334 if (ipos > inode->i_size) {
1335 inode->i_size = ipos;
1336 inode->i_blocks = (ipos + 511) >> 9;
1339 (TSTR("yaffs_file_write size updated to %d bytes, "
1341 ipos, (int)(inode->i_blocks)));
1345 yaffs_GrossUnlock(dev);
1346 return (nWritten == 0) && (n > 0) ? -ENOSPC : nWritten;
1349 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1350 /* For now we just assume few parallel writes and check against a small number. */
1351 /* Todo: need to do this with a counter to handle parallel reads better */
1353 static ssize_t yaffs_hold_space(struct file *f)
1361 obj = yaffs_DentryToObject(f->f_dentry);
1365 yaffs_GrossLock(dev);
1367 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1369 yaffs_GrossUnlock(dev);
1371 return (nFreeChunks > 20) ? 1 : 0;
1374 static void yaffs_release_space(struct file *f)
1380 obj = yaffs_DentryToObject(f->f_dentry);
1384 yaffs_GrossLock(dev);
1387 yaffs_GrossUnlock(dev);
1391 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin)
1399 offset += i_size_read(file->f_path.dentry->d_inode);
1402 offset += file->f_pos;
1407 if (offset != file->f_pos)
1408 file->f_pos = offset;
1417 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1421 struct yaffs_SearchContext *sc;
1422 struct inode *inode = f->f_dentry->d_inode;
1423 unsigned long offset, curoffs;
1427 char name[YAFFS_MAX_NAME_LENGTH + 1];
1429 obj = yaffs_DentryToObject(f->f_dentry);
1432 yaffs_GrossLock(dev);
1434 yaffs_DeviceToContext(dev)->readdirProcess = current;
1438 sc = yaffs_NewSearch(obj);
1444 T(YAFFS_TRACE_OS, (TSTR("yaffs_readdir: starting at %d\n"), (int)offset));
1448 (TSTR("yaffs_readdir: entry . ino %d \n"),
1449 (int)inode->i_ino));
1450 yaffs_GrossUnlock(dev);
1451 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1453 yaffs_GrossLock(dev);
1459 (TSTR("yaffs_readdir: entry .. ino %d \n"),
1460 (int)f->f_dentry->d_parent->d_inode->i_ino));
1461 yaffs_GrossUnlock(dev);
1462 if (filldir(dirent, "..", 2, offset,
1463 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1465 yaffs_GrossLock(dev);
1472 /* If the directory has changed since the open or last call to
1473 readdir, rewind to after the 2 canned entries. */
1474 if (f->f_version != inode->i_version) {
1477 f->f_version = inode->i_version;
1480 while(sc->nextReturn){
1483 if (curoffs >= offset) {
1484 int this_inode = yaffs_GetObjectInode(l);
1485 int this_type = yaffs_GetObjectType(l);
1487 yaffs_GetObjectName(l, name,
1488 YAFFS_MAX_NAME_LENGTH + 1);
1490 (TSTR("yaffs_readdir: %s inode %d\n"),
1491 name, yaffs_GetObjectInode(l)));
1493 yaffs_GrossUnlock(dev);
1503 yaffs_GrossLock(dev);
1508 yaffs_SearchAdvance(sc);
1512 yaffs_DeviceToContext(dev)->readdirProcess = NULL;
1514 yaffs_GrossUnlock(dev);
1516 yaffs_EndSearch(sc);
1524 * File creation. Allocate an inode, and we're done..
1527 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1530 #define YCRED(x) (x->cred)
1533 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1534 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1537 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1541 struct inode *inode;
1543 yaffs_Object *obj = NULL;
1546 yaffs_Object *parent = yaffs_InodeToObject(dir);
1548 int error = -ENOSPC;
1549 uid_t uid = YCRED(current)->fsuid;
1550 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1552 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1557 (TSTR("yaffs_mknod: parent object %d type %d\n"),
1558 parent->objectId, parent->variantType));
1561 (TSTR("yaffs_mknod: could not get parent object\n")));
1565 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
1566 "mode %x dev %x\n"),
1567 dentry->d_name.name, mode, rdev));
1569 dev = parent->myDev;
1571 yaffs_GrossLock(dev);
1573 switch (mode & S_IFMT) {
1575 /* Special (socket, fifo, device...) */
1576 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making special\n")));
1577 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1578 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1579 gid, old_encode_dev(rdev));
1581 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1585 case S_IFREG: /* file */
1586 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making file\n")));
1587 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1590 case S_IFDIR: /* directory */
1592 (TSTR("yaffs_mknod: making directory\n")));
1593 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1596 case S_IFLNK: /* symlink */
1597 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making symlink\n")));
1598 obj = NULL; /* Do we ever get here? */
1602 /* Can not call yaffs_get_inode() with gross lock held */
1603 yaffs_GrossUnlock(dev);
1606 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1607 d_instantiate(dentry, inode);
1608 update_dir_time(dir);
1610 (TSTR("yaffs_mknod created object %d count = %d\n"),
1611 obj->objectId, atomic_read(&inode->i_count)));
1613 yaffs_FillInodeFromObject(dir,parent);
1616 (TSTR("yaffs_mknod failed making object\n")));
1623 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1626 T(YAFFS_TRACE_OS, (TSTR("yaffs_mkdir\n")));
1627 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1631 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1632 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1633 struct nameidata *n)
1635 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1638 T(YAFFS_TRACE_OS,(TSTR("yaffs_create\n")));
1639 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1642 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1650 (TSTR("yaffs_unlink %d:%s\n"),
1652 dentry->d_name.name));
1653 obj = yaffs_InodeToObject(dir);
1656 yaffs_GrossLock(dev);
1658 retVal = yaffs_Unlink(obj, dentry->d_name.name);
1660 if (retVal == YAFFS_OK) {
1661 dentry->d_inode->i_nlink--;
1663 yaffs_GrossUnlock(dev);
1664 mark_inode_dirty(dentry->d_inode);
1665 update_dir_time(dir);
1668 yaffs_GrossUnlock(dev);
1675 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1676 struct dentry *dentry)
1678 struct inode *inode = old_dentry->d_inode;
1679 yaffs_Object *obj = NULL;
1680 yaffs_Object *link = NULL;
1683 T(YAFFS_TRACE_OS, (TSTR("yaffs_link\n")));
1685 obj = yaffs_InodeToObject(inode);
1688 yaffs_GrossLock(dev);
1690 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1691 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1695 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1696 d_instantiate(dentry, old_dentry->d_inode);
1697 atomic_inc(&old_dentry->d_inode->i_count);
1699 (TSTR("yaffs_link link count %d i_count %d\n"),
1700 old_dentry->d_inode->i_nlink,
1701 atomic_read(&old_dentry->d_inode->i_count)));
1704 yaffs_GrossUnlock(dev);
1707 update_dir_time(dir);
1714 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1715 const char *symname)
1719 uid_t uid = YCRED(current)->fsuid;
1720 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1722 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
1724 dev = yaffs_InodeToObject(dir)->myDev;
1725 yaffs_GrossLock(dev);
1726 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1727 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1728 yaffs_GrossUnlock(dev);
1731 struct inode *inode;
1733 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1734 d_instantiate(dentry, inode);
1735 update_dir_time(dir);
1736 T(YAFFS_TRACE_OS, (TSTR("symlink created OK\n")));
1739 T(YAFFS_TRACE_OS, (TSTR("symlink not created\n")));
1745 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1752 obj = yaffs_DentryToObject(dentry);
1756 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
1757 (TSTR("yaffs_sync_object\n")));
1758 yaffs_GrossLock(dev);
1759 yaffs_FlushFile(obj, 1, datasync);
1760 yaffs_GrossUnlock(dev);
1765 * The VFS layer already does all the dentry stuff for rename.
1767 * NB: POSIX says you can rename an object over an old object of the same name
1769 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1770 struct inode *new_dir, struct dentry *new_dentry)
1773 int retVal = YAFFS_FAIL;
1774 yaffs_Object *target;
1776 T(YAFFS_TRACE_OS, (TSTR("yaffs_rename\n")));
1777 dev = yaffs_InodeToObject(old_dir)->myDev;
1779 yaffs_GrossLock(dev);
1781 /* Check if the target is an existing directory that is not empty. */
1782 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1783 new_dentry->d_name.name);
1787 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1788 !ylist_empty(&target->variant.directoryVariant.children)) {
1790 T(YAFFS_TRACE_OS, (TSTR("target is non-empty dir\n")));
1792 retVal = YAFFS_FAIL;
1794 /* Now does unlinking internally using shadowing mechanism */
1795 T(YAFFS_TRACE_OS, (TSTR("calling yaffs_RenameObject\n")));
1797 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1798 old_dentry->d_name.name,
1799 yaffs_InodeToObject(new_dir),
1800 new_dentry->d_name.name);
1802 yaffs_GrossUnlock(dev);
1804 if (retVal == YAFFS_OK) {
1806 new_dentry->d_inode->i_nlink--;
1807 mark_inode_dirty(new_dentry->d_inode);
1810 update_dir_time(old_dir);
1811 if(old_dir != new_dir)
1812 update_dir_time(new_dir);
1819 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1821 struct inode *inode = dentry->d_inode;
1826 (TSTR("yaffs_setattr of object %d\n"),
1827 yaffs_InodeToObject(inode)->objectId));
1829 /* Fail if a requested resize >= 2GB */
1830 if (attr->ia_valid & ATTR_SIZE &&
1831 (attr->ia_size >> 31))
1835 error = inode_change_ok(inode, attr);
1839 error = inode_setattr(inode, attr);
1840 T(YAFFS_TRACE_OS,(TSTR("inode_setattr called\n")));
1841 if (attr->ia_valid & ATTR_SIZE)
1842 truncate_inode_pages(&inode->i_data,attr->ia_size);
1844 dev = yaffs_InodeToObject(inode)->myDev;
1845 if (attr->ia_valid & ATTR_SIZE){
1846 T(YAFFS_TRACE_OS,(TSTR("resize to %d(%x)\n"),
1847 (int)(attr->ia_size),(int)(attr->ia_size)));
1849 yaffs_GrossLock(dev);
1850 result = yaffs_SetAttributes(yaffs_InodeToObject(inode), attr);
1851 if(result == YAFFS_OK) {
1856 yaffs_GrossUnlock(dev);
1861 (TSTR("yaffs_setattr done returning %d\n"),error));
1866 #ifdef CONFIG_YAFFS_XATTR
1867 int yaffs_setxattr(struct dentry *dentry, const char *name,
1868 const void *value, size_t size, int flags)
1870 struct inode *inode = dentry->d_inode;
1873 yaffs_Object *obj = yaffs_InodeToObject(inode);
1876 (TSTR("yaffs_setxattr of object %d\n"),
1883 yaffs_GrossLock(dev);
1884 result = yaffs_SetXAttribute(obj, name, value, size, flags);
1885 if(result == YAFFS_OK)
1889 yaffs_GrossUnlock(dev);
1893 (TSTR("yaffs_setxattr done returning %d\n"),error));
1899 ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
1902 struct inode *inode = dentry->d_inode;
1905 yaffs_Object *obj = yaffs_InodeToObject(inode);
1908 (TSTR("yaffs_getxattr of object %d\n"),
1914 yaffs_GrossLock(dev);
1915 error = yaffs_GetXAttribute(obj, name, buff, size);
1916 yaffs_GrossUnlock(dev);
1920 (TSTR("yaffs_getxattr done returning %d\n"),error));
1925 int yaffs_removexattr(struct dentry *dentry, const char *name)
1927 struct inode *inode = dentry->d_inode;
1930 yaffs_Object *obj = yaffs_InodeToObject(inode);
1933 (TSTR("yaffs_removexattr of object %d\n"),
1940 yaffs_GrossLock(dev);
1941 result = yaffs_RemoveXAttribute(obj, name);
1942 if(result == YAFFS_OK)
1946 yaffs_GrossUnlock(dev);
1950 (TSTR("yaffs_removexattr done returning %d\n"),error));
1955 ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size)
1957 struct inode *inode = dentry->d_inode;
1960 yaffs_Object *obj = yaffs_InodeToObject(inode);
1963 (TSTR("yaffs_listxattr of object %d\n"),
1970 yaffs_GrossLock(dev);
1971 error = yaffs_ListXAttributes(obj, buff, size);
1972 yaffs_GrossUnlock(dev);
1976 (TSTR("yaffs_listxattr done returning %d\n"),error));
1984 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1985 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1987 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1988 struct super_block *sb = dentry->d_sb;
1989 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1990 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
1992 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1994 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
1996 yaffs_Device *dev = yaffs_SuperToDevice(sb);
1999 T(YAFFS_TRACE_OS, (TSTR("yaffs_statfs\n")));
2001 yaffs_GrossLock(dev);
2003 buf->f_type = YAFFS_MAGIC;
2004 buf->f_bsize = sb->s_blocksize;
2005 buf->f_namelen = 255;
2007 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
2008 /* Do this if chunk size is not a power of 2 */
2010 uint64_t bytesInDev;
2013 bytesInDev = ((uint64_t)((dev->param.endBlock - dev->param.startBlock + 1))) *
2014 ((uint64_t)(dev->param.nChunksPerBlock * dev->nDataBytesPerChunk));
2016 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
2017 buf->f_blocks = bytesInDev;
2019 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
2020 ((uint64_t)(dev->nDataBytesPerChunk));
2022 do_div(bytesFree, sb->s_blocksize);
2024 buf->f_bfree = bytesFree;
2026 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
2029 (dev->param.endBlock - dev->param.startBlock + 1) *
2030 dev->param.nChunksPerBlock /
2031 (sb->s_blocksize / dev->nDataBytesPerChunk);
2033 yaffs_GetNumberOfFreeChunks(dev) /
2034 (sb->s_blocksize / dev->nDataBytesPerChunk);
2037 (dev->param.endBlock - dev->param.startBlock + 1) *
2038 dev->param.nChunksPerBlock *
2039 (dev->nDataBytesPerChunk / sb->s_blocksize);
2042 yaffs_GetNumberOfFreeChunks(dev) *
2043 (dev->nDataBytesPerChunk / sb->s_blocksize);
2048 buf->f_bavail = buf->f_bfree;
2050 yaffs_GrossUnlock(dev);
2056 static void yaffs_FlushInodes(struct super_block *sb)
2061 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
2062 obj = yaffs_InodeToObject(iptr);
2064 T(YAFFS_TRACE_OS, (TSTR("flushing obj %d\n"),
2066 yaffs_FlushFile(obj,1,0);
2072 static void yaffs_FlushSuperBlock(struct super_block *sb, int do_checkpoint)
2074 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2078 yaffs_FlushInodes(sb);
2079 yaffs_UpdateDirtyDirectories(dev);
2080 yaffs_FlushEntireDeviceCache(dev);
2082 yaffs_CheckpointSave(dev);
2086 static unsigned yaffs_bg_gc_urgency(yaffs_Device *dev)
2088 unsigned erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
2089 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2090 unsigned scatteredFree = 0; /* Free chunks not in an erased block */
2092 if(erasedChunks < dev->nFreeChunks)
2093 scatteredFree = (dev->nFreeChunks - erasedChunks);
2095 if(!context->bgRunning)
2097 else if(scatteredFree < (dev->param.nChunksPerBlock * 2))
2099 else if(erasedChunks > dev->nFreeChunks/2)
2101 else if(erasedChunks > dev->nFreeChunks/4)
2107 static int yaffs_do_sync_fs(struct super_block *sb,
2108 int request_checkpoint)
2111 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2112 unsigned int oneshot_checkpoint = (yaffs_auto_checkpoint & 4);
2113 unsigned gc_urgent = yaffs_bg_gc_urgency(dev);
2116 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2117 (TSTR("yaffs_do_sync_fs: gc-urgency %d %s %s%s\n"),
2119 sb->s_dirt ? "dirty" : "clean",
2120 request_checkpoint ? "checkpoint requested" : "no checkpoint",
2121 oneshot_checkpoint ? " one-shot" : "" ));
2123 yaffs_GrossLock(dev);
2124 do_checkpoint = ((request_checkpoint && !gc_urgent) ||
2125 oneshot_checkpoint) &&
2126 !dev->isCheckpointed;
2128 if (sb->s_dirt || do_checkpoint) {
2129 yaffs_FlushSuperBlock(sb, !dev->isCheckpointed && do_checkpoint);
2131 if(oneshot_checkpoint)
2132 yaffs_auto_checkpoint &= ~4;
2134 yaffs_GrossUnlock(dev);
2140 * yaffs background thread functions .
2141 * yaffs_BackgroundThread() the thread function
2142 * yaffs_BackgroundStart() launches the background thread.
2143 * yaffs_BackgroundStop() cleans up the background thread.
2146 * The thread should only run after the yaffs is initialised
2147 * The thread should be stopped before yaffs is unmounted.
2148 * The thread should not do any writing while the fs is in read only.
2151 #ifdef YAFFS_COMPILE_BACKGROUND
2153 void yaffs_background_waker(unsigned long data)
2155 wake_up_process((struct task_struct *)data);
2158 static int yaffs_BackgroundThread(void *data)
2160 yaffs_Device *dev = (yaffs_Device *)data;
2161 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2162 unsigned long now = jiffies;
2163 unsigned long next_dir_update = now;
2164 unsigned long next_gc = now;
2165 unsigned long expires;
2166 unsigned int urgency;
2169 struct timer_list timer;
2171 T(YAFFS_TRACE_BACKGROUND,
2172 (TSTR("yaffs_background starting for dev %p\n"),
2177 while(context->bgRunning){
2178 T(YAFFS_TRACE_BACKGROUND,
2179 (TSTR("yaffs_background\n")));
2181 if(kthread_should_stop())
2187 yaffs_GrossLock(dev);
2191 if(time_after(now, next_dir_update)){
2192 yaffs_UpdateDirtyDirectories(dev);
2193 next_dir_update = now + HZ;
2196 if(time_after(now,next_gc)){
2197 if(!dev->isCheckpointed){
2198 urgency = yaffs_bg_gc_urgency(dev);
2199 gcResult = yaffs_BackgroundGarbageCollect(dev, urgency);
2201 next_gc = now + HZ/20+1;
2202 else if(urgency > 0)
2203 next_gc = now + HZ/10+1;
2205 next_gc = now + HZ * 2;
2207 * gc not running so set to next_dir_update
2208 * to cut down on wake ups
2210 next_gc = next_dir_update;
2212 yaffs_GrossUnlock(dev);
2214 expires = next_dir_update;
2215 if (time_before(next_gc,expires))
2217 if(time_before(expires,now))
2221 timer.expires = expires+1;
2222 timer.data = (unsigned long) current;
2223 timer.function = yaffs_background_waker;
2225 set_current_state(TASK_INTERRUPTIBLE);
2228 del_timer_sync(&timer);
2237 static int yaffs_BackgroundStart(yaffs_Device *dev)
2240 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2242 context->bgRunning = 1;
2244 context->bgThread = kthread_run(yaffs_BackgroundThread,
2245 (void *)dev,"yaffs-bg");
2247 if(IS_ERR(context->bgThread)){
2248 retval = PTR_ERR(context->bgThread);
2249 context->bgThread = NULL;
2250 context->bgRunning = 0;
2255 static void yaffs_BackgroundStop(yaffs_Device *dev)
2257 struct yaffs_LinuxContext *ctxt = yaffs_DeviceToContext(dev);
2259 ctxt->bgRunning = 0;
2261 if( ctxt->bgThread){
2262 kthread_stop(ctxt->bgThread);
2263 ctxt->bgThread = NULL;
2267 static int yaffs_BackgroundThread(void *data)
2272 static int yaffs_BackgroundStart(yaffs_Device *dev)
2277 static void yaffs_BackgroundStop(yaffs_Device *dev)
2283 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2284 static void yaffs_write_super(struct super_block *sb)
2286 static int yaffs_write_super(struct super_block *sb)
2289 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 2);
2291 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2292 (TSTR("yaffs_write_super%s\n"),
2293 request_checkpoint ? " checkpt" : ""));
2295 yaffs_do_sync_fs(sb, request_checkpoint);
2297 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2303 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2304 static int yaffs_sync_fs(struct super_block *sb, int wait)
2306 static int yaffs_sync_fs(struct super_block *sb)
2309 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 1);
2311 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
2312 (TSTR("yaffs_sync_fs%s\n"),
2313 request_checkpoint ? " checkpt" : ""));
2315 yaffs_do_sync_fs(sb, request_checkpoint);
2320 #ifdef YAFFS_USE_OWN_IGET
2322 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2324 struct inode *inode;
2326 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2329 (TSTR("yaffs_iget for %lu\n"), ino));
2331 inode = iget_locked(sb, ino);
2333 return ERR_PTR(-ENOMEM);
2334 if (!(inode->i_state & I_NEW))
2337 /* NB This is called as a side effect of other functions, but
2338 * we had to release the lock to prevent deadlocks, so
2339 * need to lock again.
2342 yaffs_GrossLock(dev);
2344 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2346 yaffs_FillInodeFromObject(inode, obj);
2348 yaffs_GrossUnlock(dev);
2350 unlock_new_inode(inode);
2356 static void yaffs_read_inode(struct inode *inode)
2358 /* NB This is called as a side effect of other functions, but
2359 * we had to release the lock to prevent deadlocks, so
2360 * need to lock again.
2364 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2367 (TSTR("yaffs_read_inode for %d\n"), (int)inode->i_ino));
2369 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2370 yaffs_GrossLock(dev);
2372 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2374 yaffs_FillInodeFromObject(inode, obj);
2376 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2377 yaffs_GrossUnlock(dev);
2382 static YLIST_HEAD(yaffs_context_list);
2383 struct semaphore yaffs_context_lock;
2385 #if 0 /* not used */
2386 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2388 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2390 if (*flags & MS_RDONLY) {
2391 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2394 (TSTR("yaffs_remount_fs: %s: RO\n"), dev->name));
2396 yaffs_GrossLock(dev);
2398 yaffs_FlushSuperBlock(sb,1);
2403 yaffs_GrossUnlock(dev);
2406 (TSTR("yaffs_remount_fs: %s: RW\n"), dev->name));
2413 static void yaffs_put_super(struct super_block *sb)
2415 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2417 T(YAFFS_TRACE_OS, (TSTR("yaffs_put_super\n")));
2419 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2420 (TSTR("Shutting down yaffs background thread\n")));
2421 yaffs_BackgroundStop(dev);
2422 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2423 (TSTR("yaffs background thread shut down\n")));
2425 yaffs_GrossLock(dev);
2427 yaffs_FlushSuperBlock(sb,1);
2429 if (yaffs_DeviceToContext(dev)->putSuperFunc)
2430 yaffs_DeviceToContext(dev)->putSuperFunc(sb);
2433 yaffs_Deinitialise(dev);
2435 yaffs_GrossUnlock(dev);
2437 down(&yaffs_context_lock);
2438 ylist_del_init(&(yaffs_DeviceToContext(dev)->contextList));
2439 up(&yaffs_context_lock);
2441 if (yaffs_DeviceToContext(dev)->spareBuffer) {
2442 YFREE(yaffs_DeviceToContext(dev)->spareBuffer);
2443 yaffs_DeviceToContext(dev)->spareBuffer = NULL;
2450 static void yaffs_MTDPutSuper(struct super_block *sb)
2452 struct mtd_info *mtd = yaffs_DeviceToContext(yaffs_SuperToDevice(sb))->mtd;
2457 put_mtd_device(mtd);
2461 static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev)
2463 struct super_block *sb = yaffs_DeviceToContext(dev)->superBlock;
2465 T(YAFFS_TRACE_OS, (TSTR("yaffs_MarkSuperBlockDirty() sb = %p\n"), sb));
2472 int skip_checkpoint_read;
2473 int skip_checkpoint_write;
2476 int tags_ecc_overridden;
2477 int lazy_loading_enabled;
2478 int lazy_loading_overridden;
2479 int empty_lost_and_found;
2480 int empty_lost_and_found_overridden;
2483 #define MAX_OPT_LEN 30
2484 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2486 char cur_opt[MAX_OPT_LEN + 1];
2490 /* Parse through the options which is a comma seperated list */
2492 while (options_str && *options_str && !error) {
2493 memset(cur_opt, 0, MAX_OPT_LEN + 1);
2496 while(*options_str == ',')
2499 while (*options_str && *options_str != ',') {
2500 if (p < MAX_OPT_LEN) {
2501 cur_opt[p] = *options_str;
2507 if (!strcmp(cur_opt, "inband-tags"))
2508 options->inband_tags = 1;
2509 else if (!strcmp(cur_opt, "tags-ecc-off")){
2510 options->tags_ecc_on = 0;
2511 options->tags_ecc_overridden=1;
2512 } else if (!strcmp(cur_opt, "tags-ecc-on")){
2513 options->tags_ecc_on = 1;
2514 options->tags_ecc_overridden = 1;
2515 } else if (!strcmp(cur_opt, "lazy-loading-off")){
2516 options->lazy_loading_enabled = 0;
2517 options->lazy_loading_overridden=1;
2518 } else if (!strcmp(cur_opt, "lazy-loading-on")){
2519 options->lazy_loading_enabled = 1;
2520 options->lazy_loading_overridden = 1;
2521 } else if (!strcmp(cur_opt, "empty-lost-and-found-off")){
2522 options->empty_lost_and_found = 0;
2523 options->empty_lost_and_found_overridden=1;
2524 } else if (!strcmp(cur_opt, "empty-lost-and-found-on")){
2525 options->empty_lost_and_found = 1;
2526 options->empty_lost_and_found_overridden=1;
2527 } else if (!strcmp(cur_opt, "no-cache"))
2528 options->no_cache = 1;
2529 else if (!strcmp(cur_opt, "no-checkpoint-read"))
2530 options->skip_checkpoint_read = 1;
2531 else if (!strcmp(cur_opt, "no-checkpoint-write"))
2532 options->skip_checkpoint_write = 1;
2533 else if (!strcmp(cur_opt, "no-checkpoint")) {
2534 options->skip_checkpoint_read = 1;
2535 options->skip_checkpoint_write = 1;
2537 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2546 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2547 struct super_block *sb,
2548 void *data, int silent)
2551 struct inode *inode = NULL;
2552 struct dentry *root;
2553 yaffs_Device *dev = 0;
2554 char devname_buf[BDEVNAME_SIZE + 1];
2555 struct mtd_info *mtd;
2557 char *data_str = (char *)data;
2558 struct yaffs_LinuxContext *context = NULL;
2559 yaffs_DeviceParam *param;
2561 yaffs_options options;
2563 sb->s_magic = YAFFS_MAGIC;
2564 sb->s_op = &yaffs_super_ops;
2565 sb->s_flags |= MS_NOATIME;
2567 #ifdef YAFFS_COMPILE_EXPORTFS
2568 sb->s_export_op = &yaffs_export_ops;
2572 printk(KERN_INFO "yaffs: sb is NULL\n");
2573 else if (!sb->s_dev)
2574 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
2575 else if (!yaffs_devname(sb, devname_buf))
2576 printk(KERN_INFO "yaffs: devname is NULL\n");
2578 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
2580 yaffs_devname(sb, devname_buf));
2585 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2587 memset(&options, 0, sizeof(options));
2589 if (yaffs_parse_options(&options, data_str)) {
2590 /* Option parsing failed */
2595 sb->s_blocksize = PAGE_CACHE_SIZE;
2596 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
2599 (TSTR("yaffs_read_super: Using yaffs%d\n"), yaffsVersion));
2601 (TSTR("yaffs_read_super: block size %d\n"),
2602 (int)(sb->s_blocksize)));
2604 T(YAFFS_TRACE_ALWAYS,
2605 (TSTR("yaffs: Attempting MTD mount of %u.%u,\"%s\"\n"),
2606 MAJOR(sb->s_dev), MINOR(sb->s_dev),
2607 yaffs_devname(sb, devname_buf)));
2609 /* Check it's an mtd device..... */
2610 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2611 return NULL; /* This isn't an mtd device */
2613 /* Get the device */
2614 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2616 T(YAFFS_TRACE_ALWAYS,
2617 (TSTR("yaffs: MTD device #%u doesn't appear to exist\n"),
2621 /* Check it's NAND */
2622 if (mtd->type != MTD_NANDFLASH) {
2623 T(YAFFS_TRACE_ALWAYS,
2624 (TSTR("yaffs: MTD device is not NAND it's type %d\n"),
2629 T(YAFFS_TRACE_OS, (TSTR(" erase %p\n"), mtd->erase));
2630 T(YAFFS_TRACE_OS, (TSTR(" read %p\n"), mtd->read));
2631 T(YAFFS_TRACE_OS, (TSTR(" write %p\n"), mtd->write));
2632 T(YAFFS_TRACE_OS, (TSTR(" readoob %p\n"), mtd->read_oob));
2633 T(YAFFS_TRACE_OS, (TSTR(" writeoob %p\n"), mtd->write_oob));
2634 T(YAFFS_TRACE_OS, (TSTR(" block_isbad %p\n"), mtd->block_isbad));
2635 T(YAFFS_TRACE_OS, (TSTR(" block_markbad %p\n"), mtd->block_markbad));
2636 T(YAFFS_TRACE_OS, (TSTR(" %s %d\n"), WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2637 T(YAFFS_TRACE_OS, (TSTR(" oobsize %d\n"), mtd->oobsize));
2638 T(YAFFS_TRACE_OS, (TSTR(" erasesize %d\n"), mtd->erasesize));
2639 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2640 T(YAFFS_TRACE_OS, (TSTR(" size %u\n"), mtd->size));
2642 T(YAFFS_TRACE_OS, (TSTR(" size %lld\n"), mtd->size));
2645 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2647 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2648 T(YAFFS_TRACE_ALWAYS,
2649 (TSTR("yaffs: auto selecting yaffs2\n")));
2653 /* Added NCB 26/5/2006 for completeness */
2654 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2655 T(YAFFS_TRACE_ALWAYS,
2656 (TSTR("yaffs: auto selecting yaffs1\n")));
2662 if (yaffsVersion == 2) {
2663 /* Check for version 2 style functions */
2665 !mtd->block_isbad ||
2666 !mtd->block_markbad ||
2669 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2670 !mtd->read_oob || !mtd->write_oob) {
2673 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2675 T(YAFFS_TRACE_ALWAYS,
2676 (TSTR("yaffs: MTD device does not support required "
2681 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
2682 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
2683 !options.inband_tags) {
2684 T(YAFFS_TRACE_ALWAYS,
2685 (TSTR("yaffs: MTD device does not have the "
2686 "right page sizes\n")));
2690 /* Check for V1 style functions */
2694 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2695 !mtd->read_oob || !mtd->write_oob) {
2698 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2700 T(YAFFS_TRACE_ALWAYS,
2701 (TSTR("yaffs: MTD device does not support required "
2706 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2707 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2708 T(YAFFS_TRACE_ALWAYS,
2709 (TSTR("yaffs: MTD device does not support have the "
2710 "right page sizes\n")));
2715 /* OK, so if we got here, we have an MTD that's NAND and looks
2716 * like it has the right capabilities
2717 * Set the yaffs_Device up for mtd
2720 dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2721 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
2723 if(!dev || !context ){
2733 /* Deep shit could not allocate device structure */
2734 T(YAFFS_TRACE_ALWAYS,
2735 (TSTR("yaffs_read_super: Failed trying to allocate "
2736 "yaffs_Device. \n")));
2739 memset(dev, 0, sizeof(yaffs_Device));
2740 param = &(dev->param);
2742 memset(context,0,sizeof(struct yaffs_LinuxContext));
2743 dev->context = context;
2744 YINIT_LIST_HEAD(&(context->contextList));
2746 context->superBlock = sb;
2750 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2751 sb->s_fs_info = dev;
2753 sb->u.generic_sbp = dev;
2756 yaffs_DeviceToContext(dev)->mtd = mtd;
2757 param->name = mtd->name;
2759 /* Set up the memory size parameters.... */
2761 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2763 param->startBlock = 0;
2764 param->endBlock = nBlocks - 1;
2765 param->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2766 param->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2767 param->nReservedBlocks = 5;
2768 param->nShortOpCaches = (options.no_cache) ? 0 : 10;
2769 param->inbandTags = options.inband_tags;
2771 #ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
2772 param->disableLazyLoad = 1;
2774 #ifdef CONFIG_YAFFS_XATTR
2775 param->enableXattr = 1;
2777 if(options.lazy_loading_overridden)
2778 param->disableLazyLoad = !options.lazy_loading_enabled;
2780 #ifdef CONFIG_YAFFS_DISABLE_TAGS_ECC
2781 param->noTagsECC = 1;
2784 #ifdef CONFIG_YAFFS_DISABLE_BACKGROUND
2786 param->deferDirectoryUpdate = 1;
2789 if(options.tags_ecc_overridden)
2790 param->noTagsECC = !options.tags_ecc_on;
2792 #ifdef CONFIG_YAFFS_EMPTY_LOST_AND_FOUND
2793 param->emptyLostAndFound = 1;
2796 #ifdef CONFIG_YAFFS_DISABLE_BLOCK_REFRESHING
2797 param->refreshPeriod = 0;
2799 param->refreshPeriod = 500;
2802 if(options.empty_lost_and_found_overridden)
2803 param->emptyLostAndFound = options.empty_lost_and_found;
2805 /* ... and the functions. */
2806 if (yaffsVersion == 2) {
2807 param->writeChunkWithTagsToNAND =
2808 nandmtd2_WriteChunkWithTagsToNAND;
2809 param->readChunkWithTagsFromNAND =
2810 nandmtd2_ReadChunkWithTagsFromNAND;
2811 param->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2812 param->queryNANDBlock = nandmtd2_QueryNANDBlock;
2813 yaffs_DeviceToContext(dev)->spareBuffer = YMALLOC(mtd->oobsize);
2814 param->isYaffs2 = 1;
2815 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2816 param->totalBytesPerChunk = mtd->writesize;
2817 param->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2819 param->totalBytesPerChunk = mtd->oobblock;
2820 param->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2822 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2824 param->startBlock = 0;
2825 param->endBlock = nBlocks - 1;
2827 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2828 /* use the MTD interface in yaffs_mtdif1.c */
2829 param->writeChunkWithTagsToNAND =
2830 nandmtd1_WriteChunkWithTagsToNAND;
2831 param->readChunkWithTagsFromNAND =
2832 nandmtd1_ReadChunkWithTagsFromNAND;
2833 param->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2834 param->queryNANDBlock = nandmtd1_QueryNANDBlock;
2836 param->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2837 param->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2839 param->isYaffs2 = 0;
2841 /* ... and common functions */
2842 param->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2843 param->initialiseNAND = nandmtd_InitialiseNAND;
2845 yaffs_DeviceToContext(dev)->putSuperFunc = yaffs_MTDPutSuper;
2847 param->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2848 param->gcControl = yaffs_gc_control_callback;
2850 yaffs_DeviceToContext(dev)->superBlock= sb;
2853 #ifndef CONFIG_YAFFS_DOES_ECC
2854 param->useNANDECC = 1;
2857 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2858 param->wideTnodesDisabled = 1;
2861 param->skipCheckpointRead = options.skip_checkpoint_read;
2862 param->skipCheckpointWrite = options.skip_checkpoint_write;
2864 /* we assume this is protected by lock_kernel() in mount/umount */
2865 down(&yaffs_context_lock);
2866 ylist_add_tail(&(yaffs_DeviceToContext(dev)->contextList), &yaffs_context_list);
2867 up(&yaffs_context_lock);
2869 /* Directory search handling...*/
2870 YINIT_LIST_HEAD(&(yaffs_DeviceToContext(dev)->searchContexts));
2871 param->removeObjectCallback = yaffs_RemoveObjectCallback;
2873 init_MUTEX(&(yaffs_DeviceToContext(dev)->grossLock));
2875 yaffs_GrossLock(dev);
2877 err = yaffs_GutsInitialise(dev);
2880 (TSTR("yaffs_read_super: guts initialised %s\n"),
2881 (err == YAFFS_OK) ? "OK" : "FAILED"));
2884 yaffs_BackgroundStart(dev);
2886 if(!context->bgThread)
2887 param->deferDirectoryUpdate = 0;
2890 /* Release lock before yaffs_get_inode() */
2891 yaffs_GrossUnlock(dev);
2893 /* Create root inode */
2894 if (err == YAFFS_OK)
2895 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2901 inode->i_op = &yaffs_dir_inode_operations;
2902 inode->i_fop = &yaffs_dir_operations;
2904 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: got root inode\n")));
2906 root = d_alloc_root(inode);
2908 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: d_alloc_root done\n")));
2915 sb->s_dirt = !dev->isCheckpointed;
2916 T(YAFFS_TRACE_ALWAYS,
2917 (TSTR("yaffs_read_super: isCheckpointed %d\n"),
2918 dev->isCheckpointed));
2920 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: done\n")));
2925 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2926 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2929 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2932 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2933 static int yaffs_read_super(struct file_system_type *fs,
2934 int flags, const char *dev_name,
2935 void *data, struct vfsmount *mnt)
2938 return get_sb_bdev(fs, flags, dev_name, data,
2939 yaffs_internal_read_super_mtd, mnt);
2942 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2943 int flags, const char *dev_name,
2947 return get_sb_bdev(fs, flags, dev_name, data,
2948 yaffs_internal_read_super_mtd);
2952 static struct file_system_type yaffs_fs_type = {
2953 .owner = THIS_MODULE,
2955 .get_sb = yaffs_read_super,
2956 .kill_sb = kill_block_super,
2957 .fs_flags = FS_REQUIRES_DEV,
2960 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2963 return yaffs_internal_read_super(1, sb, data, silent);
2966 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2971 #ifdef CONFIG_YAFFS_YAFFS2
2973 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2974 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2977 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2980 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2981 static int yaffs2_read_super(struct file_system_type *fs,
2982 int flags, const char *dev_name, void *data,
2983 struct vfsmount *mnt)
2985 return get_sb_bdev(fs, flags, dev_name, data,
2986 yaffs2_internal_read_super_mtd, mnt);
2989 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
2990 int flags, const char *dev_name,
2994 return get_sb_bdev(fs, flags, dev_name, data,
2995 yaffs2_internal_read_super_mtd);
2999 static struct file_system_type yaffs2_fs_type = {
3000 .owner = THIS_MODULE,
3002 .get_sb = yaffs2_read_super,
3003 .kill_sb = kill_block_super,
3004 .fs_flags = FS_REQUIRES_DEV,
3007 static struct super_block *yaffs2_read_super(struct super_block *sb,
3008 void *data, int silent)
3010 return yaffs_internal_read_super(2, sb, data, silent);
3013 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
3017 #endif /* CONFIG_YAFFS_YAFFS2 */
3019 static struct proc_dir_entry *my_proc_entry;
3020 static struct proc_dir_entry *debug_proc_entry;
3022 static char *yaffs_dump_dev_part0(char *buf, yaffs_Device * dev)
3024 buf += sprintf(buf, "startBlock......... %d\n", dev->param.startBlock);
3025 buf += sprintf(buf, "endBlock........... %d\n", dev->param.endBlock);
3026 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->param.totalBytesPerChunk);
3027 buf += sprintf(buf, "useNANDECC......... %d\n", dev->param.useNANDECC);
3028 buf += sprintf(buf, "noTagsECC.......... %d\n", dev->param.noTagsECC);
3029 buf += sprintf(buf, "isYaffs2........... %d\n", dev->param.isYaffs2);
3030 buf += sprintf(buf, "inbandTags......... %d\n", dev->param.inbandTags);
3031 buf += sprintf(buf, "emptyLostAndFound.. %d\n", dev->param.emptyLostAndFound);
3032 buf += sprintf(buf, "disableLazyLoad.... %d\n", dev->param.disableLazyLoad);
3033 buf += sprintf(buf, "refreshPeriod...... %d\n", dev->param.refreshPeriod);
3034 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->param.nShortOpCaches);
3035 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->param.nReservedBlocks);
3037 buf += sprintf(buf, "\n");
3043 static char *yaffs_dump_dev_part1(char *buf, yaffs_Device * dev)
3045 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
3046 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
3047 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
3048 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
3049 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
3050 buf += sprintf(buf, "\n");
3051 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
3052 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
3053 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
3054 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
3055 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
3056 buf += sprintf(buf, "\n");
3057 buf += sprintf(buf, "nPageWrites........ %u\n", dev->nPageWrites);
3058 buf += sprintf(buf, "nPageReads......... %u\n", dev->nPageReads);
3059 buf += sprintf(buf, "nBlockErasures..... %u\n", dev->nBlockErasures);
3060 buf += sprintf(buf, "nGCCopies.......... %u\n", dev->nGCCopies);
3061 buf += sprintf(buf, "allGCs............. %u\n", dev->allGCs);
3062 buf += sprintf(buf, "passiveGCs......... %u\n", dev->passiveGCs);
3063 buf += sprintf(buf, "oldestDirtyGCs..... %u\n", dev->oldestDirtyGCs);
3064 buf += sprintf(buf, "backgroundGCs...... %u\n", dev->backgroundGCs);
3065 buf += sprintf(buf, "nRetriedWrites..... %u\n", dev->nRetriedWrites);
3066 buf += sprintf(buf, "nRetireBlocks...... %u\n", dev->nRetiredBlocks);
3067 buf += sprintf(buf, "eccFixed........... %u\n", dev->eccFixed);
3068 buf += sprintf(buf, "eccUnfixed......... %u\n", dev->eccUnfixed);
3069 buf += sprintf(buf, "tagsEccFixed....... %u\n", dev->tagsEccFixed);
3070 buf += sprintf(buf, "tagsEccUnfixed..... %u\n", dev->tagsEccUnfixed);
3071 buf += sprintf(buf, "cacheHits.......... %u\n", dev->cacheHits);
3072 buf += sprintf(buf, "nDeletedFiles...... %u\n", dev->nDeletedFiles);
3073 buf += sprintf(buf, "nUnlinkedFiles..... %u\n", dev->nUnlinkedFiles);
3074 buf += sprintf(buf, "refreshCount....... %u\n", dev->refreshCount);
3076 sprintf(buf, "nBackgroudDeletions %u\n", dev->nBackgroundDeletions);
3081 static int yaffs_proc_read(char *page,
3083 off_t offset, int count, int *eof, void *data)
3085 struct ylist_head *item;
3090 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
3091 * We use 'offset' (*ppos) to indicate where we are in devList.
3092 * This also assumes the user has posted a read buffer large
3093 * enough to hold the complete output; but that's life in /proc.
3098 /* Print header first */
3100 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__"\n");
3102 buf += sprintf(buf,"\n");
3106 down(&yaffs_context_lock);
3108 /* Locate and print the Nth entry. Order N-squared but N is small. */
3109 ylist_for_each(item, &yaffs_context_list) {
3110 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3111 yaffs_Device *dev = dc->dev;
3113 if (n < (step & ~1)) {
3118 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->param.name);
3119 buf = yaffs_dump_dev_part0(buf, dev);
3121 buf = yaffs_dump_dev_part1(buf, dev);
3125 up(&yaffs_context_lock);
3128 return buf - page < count ? buf - page : count;
3131 static int yaffs_stats_proc_read(char *page,
3133 off_t offset, int count, int *eof, void *data)
3135 struct ylist_head *item;
3139 down(&yaffs_context_lock);
3141 /* Locate and print the Nth entry. Order N-squared but N is small. */
3142 ylist_for_each(item, &yaffs_context_list) {
3143 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3144 yaffs_Device *dev = dc->dev;
3150 erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
3151 nObjects = dev->nObjectsCreated -dev->nFreeObjects;
3152 nTnodes = dev->nTnodesCreated - dev->nFreeTnodes;
3155 buf += sprintf(buf,"%d, %d, %d, %u, %u, %d, %d\n",
3156 n, dev->nFreeChunks, erasedChunks,
3157 dev->backgroundGCs, dev->oldestDirtyGCs,
3160 up(&yaffs_context_lock);
3163 return buf - page < count ? buf - page : count;
3167 * Set the verbosity of the warnings and error messages.
3169 * Note that the names can only be a..z or _ with the current code.
3174 unsigned mask_bitfield;
3176 {"allocate", YAFFS_TRACE_ALLOCATE},
3177 {"always", YAFFS_TRACE_ALWAYS},
3178 {"background", YAFFS_TRACE_BACKGROUND},
3179 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
3180 {"buffers", YAFFS_TRACE_BUFFERS},
3181 {"bug", YAFFS_TRACE_BUG},
3182 {"checkpt", YAFFS_TRACE_CHECKPOINT},
3183 {"deletion", YAFFS_TRACE_DELETION},
3184 {"erase", YAFFS_TRACE_ERASE},
3185 {"error", YAFFS_TRACE_ERROR},
3186 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
3187 {"gc", YAFFS_TRACE_GC},
3188 {"lock", YAFFS_TRACE_LOCK},
3189 {"mtd", YAFFS_TRACE_MTD},
3190 {"nandaccess", YAFFS_TRACE_NANDACCESS},
3191 {"os", YAFFS_TRACE_OS},
3192 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
3193 {"scan", YAFFS_TRACE_SCAN},
3194 {"tracing", YAFFS_TRACE_TRACING},
3195 {"sync", YAFFS_TRACE_SYNC},
3196 {"write", YAFFS_TRACE_WRITE},
3198 {"verify", YAFFS_TRACE_VERIFY},
3199 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
3200 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
3201 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
3203 {"all", 0xffffffff},
3208 #define MAX_MASK_NAME_LENGTH 40
3209 static int yaffs_proc_write_trace_options(struct file *file, const char *buf,
3210 unsigned long count, void *data)
3212 unsigned rg = 0, mask_bitfield;
3216 char substring[MAX_MASK_NAME_LENGTH + 1];
3222 rg = yaffs_traceMask;
3224 while (!done && (pos < count)) {
3226 while ((pos < count) && isspace(buf[pos]))
3243 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3245 if (end > buf + pos) {
3246 mask_name = "numeral";
3247 len = end - (buf + pos);
3251 for (x = buf + pos, i = 0;
3252 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3253 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3255 substring[i] = '\0';
3257 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3258 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3259 mask_name = mask_flags[i].mask_name;
3260 mask_bitfield = mask_flags[i].mask_bitfield;
3267 if (mask_name != NULL) {
3271 rg &= ~mask_bitfield;
3274 rg |= mask_bitfield;
3280 rg |= mask_bitfield;
3286 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3288 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3290 if (rg & YAFFS_TRACE_ALWAYS) {
3291 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3293 flag = ((rg & mask_flags[i].mask_bitfield) ==
3294 mask_flags[i].mask_bitfield) ? '+' : '-';
3295 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3303 static int yaffs_proc_write(struct file *file, const char *buf,
3304 unsigned long count, void *data)
3306 return yaffs_proc_write_trace_options(file, buf, count, data);
3309 /* Stuff to handle installation of file systems */
3310 struct file_system_to_install {
3311 struct file_system_type *fst;
3315 static struct file_system_to_install fs_to_install[] = {
3316 {&yaffs_fs_type, 0},
3317 {&yaffs2_fs_type, 0},
3321 static int __init init_yaffs_fs(void)
3324 struct file_system_to_install *fsinst;
3326 T(YAFFS_TRACE_ALWAYS,
3327 (TSTR("yaffs built " __DATE__ " " __TIME__ " Installing. \n")));
3329 #ifdef CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED
3330 T(YAFFS_TRACE_ALWAYS,
3331 (TSTR(" \n\n\n\nYAFFS-WARNING CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED selected.\n\n\n\n")));
3337 init_MUTEX(&yaffs_context_lock);
3339 /* Install the proc_fs entries */
3340 my_proc_entry = create_proc_entry("yaffs",
3344 if (my_proc_entry) {
3345 my_proc_entry->write_proc = yaffs_proc_write;
3346 my_proc_entry->read_proc = yaffs_proc_read;
3347 my_proc_entry->data = NULL;
3351 debug_proc_entry = create_proc_entry("yaffs_stats",
3355 if (debug_proc_entry) {
3356 debug_proc_entry->write_proc = NULL;
3357 debug_proc_entry->read_proc = yaffs_stats_proc_read;
3358 debug_proc_entry->data = NULL;
3362 /* Now add the file system entries */
3364 fsinst = fs_to_install;
3366 while (fsinst->fst && !error) {
3367 error = register_filesystem(fsinst->fst);
3369 fsinst->installed = 1;
3373 /* Any errors? uninstall */
3375 fsinst = fs_to_install;
3377 while (fsinst->fst) {
3378 if (fsinst->installed) {
3379 unregister_filesystem(fsinst->fst);
3380 fsinst->installed = 0;
3389 static void __exit exit_yaffs_fs(void)
3392 struct file_system_to_install *fsinst;
3394 T(YAFFS_TRACE_ALWAYS,
3395 (TSTR("yaffs built " __DATE__ " " __TIME__ " removing. \n")));
3397 remove_proc_entry("yaffs", YPROC_ROOT);
3398 remove_proc_entry("yaffs_stats", YPROC_ROOT);
3400 fsinst = fs_to_install;
3402 while (fsinst->fst) {
3403 if (fsinst->installed) {
3404 unregister_filesystem(fsinst->fst);
3405 fsinst->installed = 0;
3411 module_init(init_yaffs_fs)
3412 module_exit(exit_yaffs_fs)
3414 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
3415 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
3416 MODULE_LICENSE("GPL");