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 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
206 static int yaffs_sync_object(struct file *file, int datasync);
208 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
212 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
214 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
215 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
216 struct nameidata *n);
217 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
218 struct nameidata *n);
220 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
221 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
223 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
224 struct dentry *dentry);
225 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
226 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
227 const char *symname);
228 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
230 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
231 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
234 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
237 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
238 struct inode *new_dir, struct dentry *new_dentry);
239 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
241 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
242 static int yaffs_sync_fs(struct super_block *sb, int wait);
243 static void yaffs_write_super(struct super_block *sb);
245 static int yaffs_sync_fs(struct super_block *sb);
246 static int yaffs_write_super(struct super_block *sb);
249 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
250 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
251 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
252 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
254 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
257 #ifdef YAFFS_HAS_PUT_INODE
258 static void yaffs_put_inode(struct inode *inode);
261 static void yaffs_delete_inode(struct inode *);
262 static void yaffs_clear_inode(struct inode *);
264 static int yaffs_readpage(struct file *file, struct page *page);
265 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
266 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
268 static int yaffs_writepage(struct page *page);
271 #ifdef CONFIG_YAFFS_XATTR
272 int yaffs_setxattr(struct dentry *dentry, const char *name,
273 const void *value, size_t size, int flags);
274 ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
276 int yaffs_removexattr(struct dentry *dentry, const char *name);
277 ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size);
281 #if (YAFFS_USE_WRITE_BEGIN_END != 0)
282 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
283 loff_t pos, unsigned len, unsigned flags,
284 struct page **pagep, void **fsdata);
285 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
286 loff_t pos, unsigned len, unsigned copied,
287 struct page *pg, void *fsdadata);
289 static int yaffs_prepare_write(struct file *f, struct page *pg,
290 unsigned offset, unsigned to);
291 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
296 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
298 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
299 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
301 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
303 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin);
305 static struct address_space_operations yaffs_file_address_operations = {
306 .readpage = yaffs_readpage,
307 .writepage = yaffs_writepage,
308 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
309 .write_begin = yaffs_write_begin,
310 .write_end = yaffs_write_end,
312 .prepare_write = yaffs_prepare_write,
313 .commit_write = yaffs_commit_write,
317 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
318 static const struct file_operations yaffs_file_operations = {
319 .read = do_sync_read,
320 .write = do_sync_write,
321 .aio_read = generic_file_aio_read,
322 .aio_write = generic_file_aio_write,
323 .mmap = generic_file_mmap,
324 .flush = yaffs_file_flush,
325 .fsync = yaffs_sync_object,
326 .splice_read = generic_file_splice_read,
327 .splice_write = generic_file_splice_write,
328 .llseek = generic_file_llseek,
331 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
333 static const struct file_operations yaffs_file_operations = {
334 .read = do_sync_read,
335 .write = do_sync_write,
336 .aio_read = generic_file_aio_read,
337 .aio_write = generic_file_aio_write,
338 .mmap = generic_file_mmap,
339 .flush = yaffs_file_flush,
340 .fsync = yaffs_sync_object,
341 .sendfile = generic_file_sendfile,
346 static const struct file_operations yaffs_file_operations = {
347 .read = generic_file_read,
348 .write = generic_file_write,
349 .mmap = generic_file_mmap,
350 .flush = yaffs_file_flush,
351 .fsync = yaffs_sync_object,
352 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
353 .sendfile = generic_file_sendfile,
358 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25))
359 static void zero_user_segment(struct page *page, unsigned start, unsigned end)
361 void * kaddr = kmap_atomic(page, KM_USER0);
362 memset(kaddr + start, 0, end - start);
363 kunmap_atomic(kaddr, KM_USER0);
364 flush_dcache_page(page);
369 static const struct inode_operations yaffs_file_inode_operations = {
370 .setattr = yaffs_setattr,
371 #ifdef CONFIG_YAFFS_XATTR
372 .setxattr = yaffs_setxattr,
373 .getxattr = yaffs_getxattr,
374 .listxattr = yaffs_listxattr,
375 .removexattr = yaffs_removexattr,
379 static const struct inode_operations yaffs_symlink_inode_operations = {
380 .readlink = yaffs_readlink,
381 .follow_link = yaffs_follow_link,
382 .setattr = yaffs_setattr,
383 #ifdef CONFIG_YAFFS_XATTR
384 .setxattr = yaffs_setxattr,
385 .getxattr = yaffs_getxattr,
386 .listxattr = yaffs_listxattr,
387 .removexattr = yaffs_removexattr,
391 static const struct inode_operations yaffs_dir_inode_operations = {
392 .create = yaffs_create,
393 .lookup = yaffs_lookup,
395 .unlink = yaffs_unlink,
396 .symlink = yaffs_symlink,
397 .mkdir = yaffs_mkdir,
398 .rmdir = yaffs_unlink,
399 .mknod = yaffs_mknod,
400 .rename = yaffs_rename,
401 .setattr = yaffs_setattr,
402 #ifdef CONFIG_YAFFS_XATTR
403 .setxattr = yaffs_setxattr,
404 .getxattr = yaffs_getxattr,
405 .listxattr = yaffs_listxattr,
406 .removexattr = yaffs_removexattr,
410 static const struct file_operations yaffs_dir_operations = {
411 .read = generic_read_dir,
412 .readdir = yaffs_readdir,
413 .fsync = yaffs_sync_object,
414 .llseek = yaffs_dir_llseek,
417 static const struct super_operations yaffs_super_ops = {
418 .statfs = yaffs_statfs,
420 #ifndef YAFFS_USE_OWN_IGET
421 .read_inode = yaffs_read_inode,
423 #ifdef YAFFS_HAS_PUT_INODE
424 .put_inode = yaffs_put_inode,
426 .put_super = yaffs_put_super,
427 .delete_inode = yaffs_delete_inode,
428 .clear_inode = yaffs_clear_inode,
429 .sync_fs = yaffs_sync_fs,
430 .write_super = yaffs_write_super,
433 static unsigned yaffs_gc_control_callback(yaffs_Device *dev)
435 return yaffs_gc_control;
438 static void yaffs_GrossLock(yaffs_Device *dev)
440 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locking %p\n"), current));
441 down(&(yaffs_DeviceToContext(dev)->grossLock));
442 T(YAFFS_TRACE_LOCK, (TSTR("yaffs locked %p\n"), current));
445 static void yaffs_GrossUnlock(yaffs_Device *dev)
447 T(YAFFS_TRACE_LOCK, (TSTR("yaffs unlocking %p\n"), current));
448 up(&(yaffs_DeviceToContext(dev)->grossLock));
451 #ifdef YAFFS_COMPILE_EXPORTFS
453 static struct inode *
454 yaffs2_nfs_get_inode(struct super_block *sb, uint64_t ino, uint32_t generation)
456 return Y_IGET(sb, ino);
459 static struct dentry *
460 yaffs2_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
462 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode) ;
465 static struct dentry *
466 yaffs2_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type)
468 return generic_fh_to_parent(sb, fid, fh_len, fh_type, yaffs2_nfs_get_inode);
471 struct dentry *yaffs2_get_parent(struct dentry *dentry)
474 struct super_block *sb = dentry->d_inode->i_sb;
475 struct dentry *parent = ERR_PTR(-ENOENT);
477 unsigned long parent_ino;
479 yaffs_Object *parent_obj;
481 d_obj = yaffs_InodeToObject(dentry->d_inode);
484 parent_obj = d_obj->parent;
486 parent_ino = yaffs_GetObjectInode(parent_obj);
487 inode = Y_IGET(sb, parent_ino);
490 parent = ERR_CAST(inode);
492 parent = d_obtain_alias(inode);
493 if (!IS_ERR(parent)) {
494 parent = ERR_PTR(-ENOMEM);
504 /* Just declare a zero structure as a NULL value implies
505 * using the default functions of exportfs.
508 static struct export_operations yaffs_export_ops =
510 .fh_to_dentry = yaffs2_fh_to_dentry,
511 .fh_to_parent = yaffs2_fh_to_parent,
512 .get_parent = yaffs2_get_parent,
517 /*-----------------------------------------------------------------*/
518 /* Directory search context allows us to unlock access to yaffs during
519 * filldir without causing problems with the directory being modified.
520 * This is similar to the tried and tested mechanism used in yaffs direct.
522 * A search context iterates along a doubly linked list of siblings in the
523 * directory. If the iterating object is deleted then this would corrupt
524 * the list iteration, likely causing a crash. The search context avoids
525 * this by using the removeObjectCallback to move the search context to the
526 * next object before the object is deleted.
528 * Many readdirs (and thus seach conexts) may be alive simulateously so
529 * each yaffs_Device has a list of these.
531 * A seach context lives for the duration of a readdir.
533 * All these functions must be called while yaffs is locked.
536 struct yaffs_SearchContext {
538 yaffs_Object *dirObj;
539 yaffs_Object *nextReturn;
540 struct ylist_head others;
544 * yaffs_NewSearch() creates a new search context, initialises it and
545 * adds it to the device's search context list.
547 * Called at start of readdir.
549 static struct yaffs_SearchContext * yaffs_NewSearch(yaffs_Object *dir)
551 yaffs_Device *dev = dir->myDev;
552 struct yaffs_SearchContext *sc = YMALLOC(sizeof(struct yaffs_SearchContext));
556 if( ylist_empty(&sc->dirObj->variant.directoryVariant.children))
557 sc->nextReturn = NULL;
559 sc->nextReturn = ylist_entry(
560 dir->variant.directoryVariant.children.next,
561 yaffs_Object,siblings);
562 YINIT_LIST_HEAD(&sc->others);
563 ylist_add(&sc->others,&(yaffs_DeviceToContext(dev)->searchContexts));
569 * yaffs_EndSearch() disposes of a search context and cleans up.
571 static void yaffs_EndSearch(struct yaffs_SearchContext * sc)
574 ylist_del(&sc->others);
580 * yaffs_SearchAdvance() moves a search context to the next object.
581 * Called when the search iterates or when an object removal causes
582 * the search context to be moved to the next object.
584 static void yaffs_SearchAdvance(struct yaffs_SearchContext *sc)
589 if( sc->nextReturn == NULL ||
590 ylist_empty(&sc->dirObj->variant.directoryVariant.children))
591 sc->nextReturn = NULL;
593 struct ylist_head *next = sc->nextReturn->siblings.next;
595 if( next == &sc->dirObj->variant.directoryVariant.children)
596 sc->nextReturn = NULL; /* end of list */
598 sc->nextReturn = ylist_entry(next,yaffs_Object,siblings);
603 * yaffs_RemoveObjectCallback() is called when an object is unlinked.
604 * We check open search contexts and advance any which are currently
605 * on the object being iterated.
607 static void yaffs_RemoveObjectCallback(yaffs_Object *obj)
610 struct ylist_head *i;
611 struct yaffs_SearchContext *sc;
612 struct ylist_head *search_contexts = &(yaffs_DeviceToContext(obj->myDev)->searchContexts);
615 /* Iterate through the directory search contexts.
616 * If any are currently on the object being removed, then advance
617 * the search context to the next object to prevent a hanging pointer.
619 ylist_for_each(i, search_contexts) {
621 sc = ylist_entry(i, struct yaffs_SearchContext,others);
622 if(sc->nextReturn == obj)
623 yaffs_SearchAdvance(sc);
630 /*-----------------------------------------------------------------*/
632 static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
635 unsigned char *alias;
638 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
640 yaffs_GrossLock(dev);
642 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
644 yaffs_GrossUnlock(dev);
649 ret = vfs_readlink(dentry, buffer, buflen, alias);
654 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
655 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
657 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
660 unsigned char *alias;
662 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
664 yaffs_GrossLock(dev);
666 alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
668 yaffs_GrossUnlock(dev);
675 ret = vfs_follow_link(nd, alias);
678 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
685 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
689 * Lookup is used to find objects in the fs
691 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
693 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
696 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
700 struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
702 yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
704 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
705 yaffs_GrossLock(dev);
708 (TSTR("yaffs_lookup for %d:%s\n"),
709 yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
711 obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
712 dentry->d_name.name);
714 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
716 /* Can't hold gross lock when calling yaffs_get_inode() */
717 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
718 yaffs_GrossUnlock(dev);
722 (TSTR("yaffs_lookup found %d\n"), obj->objectId));
724 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
728 (TSTR("yaffs_loookup dentry \n")));
729 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
730 * d_add even if NULL inode */
732 /*dget(dentry); // try to solve directory bug */
733 d_add(dentry, inode);
741 T(YAFFS_TRACE_OS,(TSTR("yaffs_lookup not found\n")));
745 /* added NCB for 2.5/6 compatability - forces add even if inode is
746 * NULL which creates dentry hash */
747 d_add(dentry, inode);
753 #ifdef YAFFS_HAS_PUT_INODE
755 /* For now put inode is just for debugging
756 * Put inode is called when the inode **structure** is put.
758 static void yaffs_put_inode(struct inode *inode)
761 (TSTR("yaffs_put_inode: ino %d, count %d\n"), (int)inode->i_ino,
762 atomic_read(&inode->i_count)));
767 /* clear is called to tell the fs to release any per-inode data it holds */
768 static void yaffs_clear_inode(struct inode *inode)
773 obj = yaffs_InodeToObject(inode);
776 (TSTR("yaffs_clear_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
777 atomic_read(&inode->i_count),
778 obj ? "object exists" : "null object"));
782 yaffs_GrossLock(dev);
784 /* Clear the association between the inode and
788 yaffs_InodeToObjectLV(inode) = NULL;
790 /* If the object freeing was deferred, then the real
792 * This should fix the inode inconsistency problem.
795 yaffs_HandleDeferedFree(obj);
797 yaffs_GrossUnlock(dev);
802 /* delete is called when the link count is zero and the inode
803 * is put (ie. nobody wants to know about it anymore, time to
805 * NB Must call clear_inode()
807 static void yaffs_delete_inode(struct inode *inode)
809 yaffs_Object *obj = yaffs_InodeToObject(inode);
813 (TSTR("yaffs_delete_inode: ino %d, count %d %s\n"), (int)inode->i_ino,
814 atomic_read(&inode->i_count),
815 obj ? "object exists" : "null object"));
819 yaffs_GrossLock(dev);
820 yaffs_DeleteObject(obj);
821 yaffs_GrossUnlock(dev);
823 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
824 truncate_inode_pages(&inode->i_data, 0);
829 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
830 static int yaffs_file_flush(struct file *file, fl_owner_t id)
832 static int yaffs_file_flush(struct file *file)
835 yaffs_Object *obj = yaffs_DentryToObject(file->f_dentry);
837 yaffs_Device *dev = obj->myDev;
840 (TSTR("yaffs_file_flush object %d (%s)\n"), obj->objectId,
841 obj->dirty ? "dirty" : "clean"));
843 yaffs_GrossLock(dev);
845 yaffs_FlushFile(obj, 1, 0);
847 yaffs_GrossUnlock(dev);
852 static int yaffs_readpage_nolock(struct file *f, struct page *pg)
854 /* Lifted from jffs2 */
857 unsigned char *pg_buf;
863 (TSTR("yaffs_readpage_nolock at %08x, size %08x\n"),
864 (unsigned)(pg->index << PAGE_CACHE_SHIFT),
865 (unsigned)PAGE_CACHE_SIZE));
867 obj = yaffs_DentryToObject(f->f_dentry);
871 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
872 BUG_ON(!PageLocked(pg));
879 /* FIXME: Can kmap fail? */
881 yaffs_GrossLock(dev);
883 ret = yaffs_ReadDataFromFile(obj, pg_buf,
884 pg->index << PAGE_CACHE_SHIFT,
887 yaffs_GrossUnlock(dev);
893 ClearPageUptodate(pg);
900 flush_dcache_page(pg);
903 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage_nolock done\n")));
907 static int yaffs_readpage_unlock(struct file *f, struct page *pg)
909 int ret = yaffs_readpage_nolock(f, pg);
914 static int yaffs_readpage(struct file *f, struct page *pg)
918 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage\n")));
919 ret=yaffs_readpage_unlock(f, pg);
920 T(YAFFS_TRACE_OS, (TSTR("yaffs_readpage done\n")));
924 /* writepage inspired by/stolen from smbfs */
926 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
927 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
929 static int yaffs_writepage(struct page *page)
932 struct address_space *mapping = page->mapping;
934 unsigned long end_index;
943 inode = mapping->host;
946 i_size = i_size_read(inode);
948 end_index = i_size >> PAGE_CACHE_SHIFT;
950 if(page->index < end_index)
951 nBytes = PAGE_CACHE_SIZE;
953 nBytes = i_size & (PAGE_CACHE_SIZE -1);
955 if (page->index > end_index || !nBytes) {
957 (TSTR("yaffs_writepage at %08x, inode size = %08x!!!\n"),
958 (unsigned)(page->index << PAGE_CACHE_SHIFT),
959 (unsigned)inode->i_size));
961 (TSTR(" -> don't care!!\n")));
963 zero_user_segment(page,0,PAGE_CACHE_SIZE);
964 set_page_writeback(page);
966 end_page_writeback(page);
971 if(nBytes != PAGE_CACHE_SIZE)
972 zero_user_segment(page,nBytes,PAGE_CACHE_SIZE);
978 obj = yaffs_InodeToObject(inode);
979 yaffs_GrossLock(obj->myDev);
982 (TSTR("yaffs_writepage at %08x, size %08x\n"),
983 (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
985 (TSTR("writepag0: obj = %05x, ino = %05x\n"),
986 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
988 nWritten = yaffs_WriteDataToFile(obj, buffer,
989 page->index << PAGE_CACHE_SHIFT, nBytes, 0);
992 (TSTR("writepag1: obj = %05x, ino = %05x\n"),
993 (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
995 yaffs_GrossUnlock(obj->myDev);
998 set_page_writeback(page);
1000 end_page_writeback(page);
1003 return (nWritten == nBytes) ? 0 : -ENOSPC;
1007 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1008 static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
1009 loff_t pos, unsigned len, unsigned flags,
1010 struct page **pagep, void **fsdata)
1012 struct page *pg = NULL;
1013 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1019 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28)
1020 pg = grab_cache_page_write_begin(mapping, index, flags);
1022 pg = __grab_cache_page(mapping, index);
1031 (TSTR("start yaffs_write_begin index %d(%x) uptodate %d\n"),
1032 (int)index,(int)index,Page_Uptodate(pg) ? 1 : 0));
1035 space_held = yaffs_hold_space(filp);
1042 /* Update page if required */
1044 if (!Page_Uptodate(pg))
1045 ret = yaffs_readpage_nolock(filp, pg);
1050 /* Happy path return */
1051 T(YAFFS_TRACE_OS, (TSTR("end yaffs_write_begin - ok\n")));
1057 (TSTR("end yaffs_write_begin fail returning %d\n"), ret));
1059 yaffs_release_space(filp);
1062 page_cache_release(pg);
1069 static int yaffs_prepare_write(struct file *f, struct page *pg,
1070 unsigned offset, unsigned to)
1072 T(YAFFS_TRACE_OS, (TSTR("yaffs_prepair_write\n")));
1074 if (!Page_Uptodate(pg))
1075 return yaffs_readpage_nolock(f, pg);
1080 #if (YAFFS_USE_WRITE_BEGIN_END > 0)
1081 static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1082 loff_t pos, unsigned len, unsigned copied,
1083 struct page *pg, void *fsdadata)
1087 uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
1090 addr = kva + offset_into_page;
1093 ("yaffs_write_end addr %p pos %x nBytes %d\n",
1094 addr,(unsigned)pos, copied));
1096 ret = yaffs_file_write(filp, addr, copied, &pos);
1098 if (ret != copied) {
1100 (TSTR("yaffs_write_end not same size ret %d copied %d\n"),
1109 yaffs_release_space(filp);
1111 page_cache_release(pg);
1116 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1121 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
1122 int nBytes = to - offset;
1125 unsigned spos = pos;
1129 addr = kva + offset;
1131 saddr = (unsigned) addr;
1134 (TSTR("yaffs_commit_write addr %x pos %x nBytes %d\n"),
1135 saddr, spos, nBytes));
1137 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
1139 if (nWritten != nBytes) {
1141 (TSTR("yaffs_commit_write not same size nWritten %d nBytes %d\n"),
1151 (TSTR("yaffs_commit_write returning %d\n"),
1152 nWritten == nBytes ? 0 : nWritten));
1154 return nWritten == nBytes ? 0 : nWritten;
1159 static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
1164 /* Check mode against the variant type and attempt to repair if broken. */
1165 __u32 mode = obj->yst_mode;
1166 switch (obj->variantType) {
1167 case YAFFS_OBJECT_TYPE_FILE:
1168 if (!S_ISREG(mode)) {
1169 obj->yst_mode &= ~S_IFMT;
1170 obj->yst_mode |= S_IFREG;
1174 case YAFFS_OBJECT_TYPE_SYMLINK:
1175 if (!S_ISLNK(mode)) {
1176 obj->yst_mode &= ~S_IFMT;
1177 obj->yst_mode |= S_IFLNK;
1181 case YAFFS_OBJECT_TYPE_DIRECTORY:
1182 if (!S_ISDIR(mode)) {
1183 obj->yst_mode &= ~S_IFMT;
1184 obj->yst_mode |= S_IFDIR;
1188 case YAFFS_OBJECT_TYPE_UNKNOWN:
1189 case YAFFS_OBJECT_TYPE_HARDLINK:
1190 case YAFFS_OBJECT_TYPE_SPECIAL:
1196 inode->i_flags |= S_NOATIME;
1198 inode->i_ino = obj->objectId;
1199 inode->i_mode = obj->yst_mode;
1200 inode->i_uid = obj->yst_uid;
1201 inode->i_gid = obj->yst_gid;
1202 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1203 inode->i_blksize = inode->i_sb->s_blocksize;
1205 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1207 inode->i_rdev = old_decode_dev(obj->yst_rdev);
1208 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
1209 inode->i_atime.tv_nsec = 0;
1210 inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
1211 inode->i_mtime.tv_nsec = 0;
1212 inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
1213 inode->i_ctime.tv_nsec = 0;
1215 inode->i_rdev = obj->yst_rdev;
1216 inode->i_atime = obj->yst_atime;
1217 inode->i_mtime = obj->yst_mtime;
1218 inode->i_ctime = obj->yst_ctime;
1220 inode->i_size = yaffs_GetObjectFileLength(obj);
1221 inode->i_blocks = (inode->i_size + 511) >> 9;
1223 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1226 (TSTR("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n"),
1227 inode->i_mode, inode->i_uid, inode->i_gid,
1228 (int)inode->i_size, atomic_read(&inode->i_count)));
1230 switch (obj->yst_mode & S_IFMT) {
1231 default: /* fifo, device or socket */
1232 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1233 init_special_inode(inode, obj->yst_mode,
1234 old_decode_dev(obj->yst_rdev));
1236 init_special_inode(inode, obj->yst_mode,
1237 (dev_t) (obj->yst_rdev));
1240 case S_IFREG: /* file */
1241 inode->i_op = &yaffs_file_inode_operations;
1242 inode->i_fop = &yaffs_file_operations;
1243 inode->i_mapping->a_ops =
1244 &yaffs_file_address_operations;
1246 case S_IFDIR: /* directory */
1247 inode->i_op = &yaffs_dir_inode_operations;
1248 inode->i_fop = &yaffs_dir_operations;
1250 case S_IFLNK: /* symlink */
1251 inode->i_op = &yaffs_symlink_inode_operations;
1255 yaffs_InodeToObjectLV(inode) = obj;
1257 obj->myInode = inode;
1261 (TSTR("yaffs_FileInode invalid parameters\n")));
1266 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1269 struct inode *inode;
1273 (TSTR("yaffs_get_inode for NULL super_block!!\n")));
1280 (TSTR("yaffs_get_inode for NULL object!!\n")));
1286 (TSTR("yaffs_get_inode for object %d\n"), obj->objectId));
1288 inode = Y_IGET(sb, obj->objectId);
1292 /* NB Side effect: iget calls back to yaffs_read_inode(). */
1293 /* iget also increments the inode's i_count */
1294 /* NB You can't be holding grossLock or deadlock will happen! */
1299 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1304 struct inode *inode;
1307 obj = yaffs_DentryToObject(f->f_dentry);
1311 yaffs_GrossLock(dev);
1313 inode = f->f_dentry->d_inode;
1315 if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
1316 ipos = inode->i_size;
1322 (TSTR("yaffs_file_write: hey obj is null!\n")));
1325 (TSTR("yaffs_file_write about to write writing %u(%x) bytes"
1326 "to object %d at %d(%x)\n"),
1327 (unsigned) n, (unsigned) n, obj->objectId, ipos,ipos));
1329 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
1332 (TSTR("yaffs_file_write: %d(%x) bytes written\n"),
1333 (unsigned )n,(unsigned)n));
1338 if (ipos > inode->i_size) {
1339 inode->i_size = ipos;
1340 inode->i_blocks = (ipos + 511) >> 9;
1343 (TSTR("yaffs_file_write size updated to %d bytes, "
1345 ipos, (int)(inode->i_blocks)));
1349 yaffs_GrossUnlock(dev);
1350 return (nWritten == 0) && (n > 0) ? -ENOSPC : nWritten;
1353 /* Space holding and freeing is done to ensure we have space available for write_begin/end */
1354 /* For now we just assume few parallel writes and check against a small number. */
1355 /* Todo: need to do this with a counter to handle parallel reads better */
1357 static ssize_t yaffs_hold_space(struct file *f)
1365 obj = yaffs_DentryToObject(f->f_dentry);
1369 yaffs_GrossLock(dev);
1371 nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
1373 yaffs_GrossUnlock(dev);
1375 return (nFreeChunks > 20) ? 1 : 0;
1378 static void yaffs_release_space(struct file *f)
1384 obj = yaffs_DentryToObject(f->f_dentry);
1388 yaffs_GrossLock(dev);
1391 yaffs_GrossUnlock(dev);
1395 static loff_t yaffs_dir_llseek(struct file *file, loff_t offset, int origin)
1403 offset += i_size_read(file->f_path.dentry->d_inode);
1406 offset += file->f_pos;
1411 if (offset != file->f_pos)
1412 file->f_pos = offset;
1421 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
1425 struct yaffs_SearchContext *sc;
1426 struct inode *inode = f->f_dentry->d_inode;
1427 unsigned long offset, curoffs;
1431 char name[YAFFS_MAX_NAME_LENGTH + 1];
1433 obj = yaffs_DentryToObject(f->f_dentry);
1436 yaffs_GrossLock(dev);
1438 yaffs_DeviceToContext(dev)->readdirProcess = current;
1442 sc = yaffs_NewSearch(obj);
1448 T(YAFFS_TRACE_OS, (TSTR("yaffs_readdir: starting at %d\n"), (int)offset));
1452 (TSTR("yaffs_readdir: entry . ino %d \n"),
1453 (int)inode->i_ino));
1454 yaffs_GrossUnlock(dev);
1455 if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
1457 yaffs_GrossLock(dev);
1463 (TSTR("yaffs_readdir: entry .. ino %d \n"),
1464 (int)f->f_dentry->d_parent->d_inode->i_ino));
1465 yaffs_GrossUnlock(dev);
1466 if (filldir(dirent, "..", 2, offset,
1467 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
1469 yaffs_GrossLock(dev);
1476 /* If the directory has changed since the open or last call to
1477 readdir, rewind to after the 2 canned entries. */
1478 if (f->f_version != inode->i_version) {
1481 f->f_version = inode->i_version;
1484 while(sc->nextReturn){
1487 if (curoffs >= offset) {
1488 int this_inode = yaffs_GetObjectInode(l);
1489 int this_type = yaffs_GetObjectType(l);
1491 yaffs_GetObjectName(l, name,
1492 YAFFS_MAX_NAME_LENGTH + 1);
1494 (TSTR("yaffs_readdir: %s inode %d\n"),
1495 name, yaffs_GetObjectInode(l)));
1497 yaffs_GrossUnlock(dev);
1507 yaffs_GrossLock(dev);
1512 yaffs_SearchAdvance(sc);
1516 yaffs_DeviceToContext(dev)->readdirProcess = NULL;
1518 yaffs_GrossUnlock(dev);
1520 yaffs_EndSearch(sc);
1528 * File creation. Allocate an inode, and we're done..
1531 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1534 #define YCRED(x) (x->cred)
1537 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1538 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1541 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1545 struct inode *inode;
1547 yaffs_Object *obj = NULL;
1550 yaffs_Object *parent = yaffs_InodeToObject(dir);
1552 int error = -ENOSPC;
1553 uid_t uid = YCRED(current)->fsuid;
1554 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1556 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1561 (TSTR("yaffs_mknod: parent object %d type %d\n"),
1562 parent->objectId, parent->variantType));
1565 (TSTR("yaffs_mknod: could not get parent object\n")));
1569 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
1570 "mode %x dev %x\n"),
1571 dentry->d_name.name, mode, rdev));
1573 dev = parent->myDev;
1575 yaffs_GrossLock(dev);
1577 switch (mode & S_IFMT) {
1579 /* Special (socket, fifo, device...) */
1580 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making special\n")));
1581 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1582 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1583 gid, old_encode_dev(rdev));
1585 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1589 case S_IFREG: /* file */
1590 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making file\n")));
1591 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1594 case S_IFDIR: /* directory */
1596 (TSTR("yaffs_mknod: making directory\n")));
1597 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1600 case S_IFLNK: /* symlink */
1601 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making symlink\n")));
1602 obj = NULL; /* Do we ever get here? */
1606 /* Can not call yaffs_get_inode() with gross lock held */
1607 yaffs_GrossUnlock(dev);
1610 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1611 d_instantiate(dentry, inode);
1612 update_dir_time(dir);
1614 (TSTR("yaffs_mknod created object %d count = %d\n"),
1615 obj->objectId, atomic_read(&inode->i_count)));
1617 yaffs_FillInodeFromObject(dir,parent);
1620 (TSTR("yaffs_mknod failed making object\n")));
1627 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1630 T(YAFFS_TRACE_OS, (TSTR("yaffs_mkdir\n")));
1631 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1635 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1636 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1637 struct nameidata *n)
1639 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1642 T(YAFFS_TRACE_OS,(TSTR("yaffs_create\n")));
1643 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1646 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1654 (TSTR("yaffs_unlink %d:%s\n"),
1656 dentry->d_name.name));
1657 obj = yaffs_InodeToObject(dir);
1660 yaffs_GrossLock(dev);
1662 retVal = yaffs_Unlink(obj, dentry->d_name.name);
1664 if (retVal == YAFFS_OK) {
1665 dentry->d_inode->i_nlink--;
1667 yaffs_GrossUnlock(dev);
1668 mark_inode_dirty(dentry->d_inode);
1669 update_dir_time(dir);
1672 yaffs_GrossUnlock(dev);
1679 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1680 struct dentry *dentry)
1682 struct inode *inode = old_dentry->d_inode;
1683 yaffs_Object *obj = NULL;
1684 yaffs_Object *link = NULL;
1687 T(YAFFS_TRACE_OS, (TSTR("yaffs_link\n")));
1689 obj = yaffs_InodeToObject(inode);
1692 yaffs_GrossLock(dev);
1694 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1695 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1699 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1700 d_instantiate(dentry, old_dentry->d_inode);
1701 atomic_inc(&old_dentry->d_inode->i_count);
1703 (TSTR("yaffs_link link count %d i_count %d\n"),
1704 old_dentry->d_inode->i_nlink,
1705 atomic_read(&old_dentry->d_inode->i_count)));
1708 yaffs_GrossUnlock(dev);
1711 update_dir_time(dir);
1718 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1719 const char *symname)
1723 uid_t uid = YCRED(current)->fsuid;
1724 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1726 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
1728 dev = yaffs_InodeToObject(dir)->myDev;
1729 yaffs_GrossLock(dev);
1730 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1731 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1732 yaffs_GrossUnlock(dev);
1735 struct inode *inode;
1737 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1738 d_instantiate(dentry, inode);
1739 update_dir_time(dir);
1740 T(YAFFS_TRACE_OS, (TSTR("symlink created OK\n")));
1743 T(YAFFS_TRACE_OS, (TSTR("symlink not created\n")));
1749 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1750 static int yaffs_sync_object(struct file *file, int datasync)
1752 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1759 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1760 struct dentry *dentry = file->f_path.dentry;
1763 obj = yaffs_DentryToObject(dentry);
1767 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
1768 (TSTR("yaffs_sync_object\n")));
1769 yaffs_GrossLock(dev);
1770 yaffs_FlushFile(obj, 1, datasync);
1771 yaffs_GrossUnlock(dev);
1776 * The VFS layer already does all the dentry stuff for rename.
1778 * NB: POSIX says you can rename an object over an old object of the same name
1780 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1781 struct inode *new_dir, struct dentry *new_dentry)
1784 int retVal = YAFFS_FAIL;
1785 yaffs_Object *target;
1787 T(YAFFS_TRACE_OS, (TSTR("yaffs_rename\n")));
1788 dev = yaffs_InodeToObject(old_dir)->myDev;
1790 yaffs_GrossLock(dev);
1792 /* Check if the target is an existing directory that is not empty. */
1793 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1794 new_dentry->d_name.name);
1798 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1799 !ylist_empty(&target->variant.directoryVariant.children)) {
1801 T(YAFFS_TRACE_OS, (TSTR("target is non-empty dir\n")));
1803 retVal = YAFFS_FAIL;
1805 /* Now does unlinking internally using shadowing mechanism */
1806 T(YAFFS_TRACE_OS, (TSTR("calling yaffs_RenameObject\n")));
1808 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1809 old_dentry->d_name.name,
1810 yaffs_InodeToObject(new_dir),
1811 new_dentry->d_name.name);
1813 yaffs_GrossUnlock(dev);
1815 if (retVal == YAFFS_OK) {
1817 new_dentry->d_inode->i_nlink--;
1818 mark_inode_dirty(new_dentry->d_inode);
1821 update_dir_time(old_dir);
1822 if(old_dir != new_dir)
1823 update_dir_time(new_dir);
1830 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1832 struct inode *inode = dentry->d_inode;
1837 (TSTR("yaffs_setattr of object %d\n"),
1838 yaffs_InodeToObject(inode)->objectId));
1840 /* Fail if a requested resize >= 2GB */
1841 if (attr->ia_valid & ATTR_SIZE &&
1842 (attr->ia_size >> 31))
1846 error = inode_change_ok(inode, attr);
1850 error = inode_setattr(inode, attr);
1851 T(YAFFS_TRACE_OS,(TSTR("inode_setattr called\n")));
1852 if (attr->ia_valid & ATTR_SIZE)
1853 truncate_inode_pages(&inode->i_data,attr->ia_size);
1855 dev = yaffs_InodeToObject(inode)->myDev;
1856 if (attr->ia_valid & ATTR_SIZE){
1857 T(YAFFS_TRACE_OS,(TSTR("resize to %d(%x)\n"),
1858 (int)(attr->ia_size),(int)(attr->ia_size)));
1860 yaffs_GrossLock(dev);
1861 result = yaffs_SetAttributes(yaffs_InodeToObject(inode), attr);
1862 if(result == YAFFS_OK) {
1867 yaffs_GrossUnlock(dev);
1872 (TSTR("yaffs_setattr done returning %d\n"),error));
1877 #ifdef CONFIG_YAFFS_XATTR
1878 int yaffs_setxattr(struct dentry *dentry, const char *name,
1879 const void *value, size_t size, int flags)
1881 struct inode *inode = dentry->d_inode;
1884 yaffs_Object *obj = yaffs_InodeToObject(inode);
1887 (TSTR("yaffs_setxattr of object %d\n"),
1894 yaffs_GrossLock(dev);
1895 result = yaffs_SetXAttribute(obj, name, value, size, flags);
1896 if(result == YAFFS_OK)
1900 yaffs_GrossUnlock(dev);
1904 (TSTR("yaffs_setxattr done returning %d\n"),error));
1910 ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
1913 struct inode *inode = dentry->d_inode;
1916 yaffs_Object *obj = yaffs_InodeToObject(inode);
1919 (TSTR("yaffs_getxattr of object %d\n"),
1925 yaffs_GrossLock(dev);
1926 error = yaffs_GetXAttribute(obj, name, buff, size);
1927 yaffs_GrossUnlock(dev);
1931 (TSTR("yaffs_getxattr done returning %d\n"),error));
1936 int yaffs_removexattr(struct dentry *dentry, const char *name)
1938 struct inode *inode = dentry->d_inode;
1941 yaffs_Object *obj = yaffs_InodeToObject(inode);
1944 (TSTR("yaffs_removexattr of object %d\n"),
1951 yaffs_GrossLock(dev);
1952 result = yaffs_RemoveXAttribute(obj, name);
1953 if(result == YAFFS_OK)
1957 yaffs_GrossUnlock(dev);
1961 (TSTR("yaffs_removexattr done returning %d\n"),error));
1966 ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size)
1968 struct inode *inode = dentry->d_inode;
1971 yaffs_Object *obj = yaffs_InodeToObject(inode);
1974 (TSTR("yaffs_listxattr of object %d\n"),
1981 yaffs_GrossLock(dev);
1982 error = yaffs_ListXAttributes(obj, buff, size);
1983 yaffs_GrossUnlock(dev);
1987 (TSTR("yaffs_listxattr done returning %d\n"),error));
1995 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1996 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
1998 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
1999 struct super_block *sb = dentry->d_sb;
2000 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2001 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
2003 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2005 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
2007 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2010 T(YAFFS_TRACE_OS, (TSTR("yaffs_statfs\n")));
2012 yaffs_GrossLock(dev);
2014 buf->f_type = YAFFS_MAGIC;
2015 buf->f_bsize = sb->s_blocksize;
2016 buf->f_namelen = 255;
2018 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
2019 /* Do this if chunk size is not a power of 2 */
2021 uint64_t bytesInDev;
2024 bytesInDev = ((uint64_t)((dev->param.endBlock - dev->param.startBlock + 1))) *
2025 ((uint64_t)(dev->param.nChunksPerBlock * dev->nDataBytesPerChunk));
2027 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
2028 buf->f_blocks = bytesInDev;
2030 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
2031 ((uint64_t)(dev->nDataBytesPerChunk));
2033 do_div(bytesFree, sb->s_blocksize);
2035 buf->f_bfree = bytesFree;
2037 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
2040 (dev->param.endBlock - dev->param.startBlock + 1) *
2041 dev->param.nChunksPerBlock /
2042 (sb->s_blocksize / dev->nDataBytesPerChunk);
2044 yaffs_GetNumberOfFreeChunks(dev) /
2045 (sb->s_blocksize / dev->nDataBytesPerChunk);
2048 (dev->param.endBlock - dev->param.startBlock + 1) *
2049 dev->param.nChunksPerBlock *
2050 (dev->nDataBytesPerChunk / sb->s_blocksize);
2053 yaffs_GetNumberOfFreeChunks(dev) *
2054 (dev->nDataBytesPerChunk / sb->s_blocksize);
2059 buf->f_bavail = buf->f_bfree;
2061 yaffs_GrossUnlock(dev);
2067 static void yaffs_FlushInodes(struct super_block *sb)
2072 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
2073 obj = yaffs_InodeToObject(iptr);
2075 T(YAFFS_TRACE_OS, (TSTR("flushing obj %d\n"),
2077 yaffs_FlushFile(obj,1,0);
2083 static void yaffs_FlushSuperBlock(struct super_block *sb, int do_checkpoint)
2085 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2089 yaffs_FlushInodes(sb);
2090 yaffs_UpdateDirtyDirectories(dev);
2091 yaffs_FlushEntireDeviceCache(dev);
2093 yaffs_CheckpointSave(dev);
2097 static unsigned yaffs_bg_gc_urgency(yaffs_Device *dev)
2099 unsigned erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
2100 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2101 unsigned scatteredFree = 0; /* Free chunks not in an erased block */
2103 if(erasedChunks < dev->nFreeChunks)
2104 scatteredFree = (dev->nFreeChunks - erasedChunks);
2106 if(!context->bgRunning)
2108 else if(scatteredFree < (dev->param.nChunksPerBlock * 2))
2110 else if(erasedChunks > dev->nFreeChunks/2)
2112 else if(erasedChunks > dev->nFreeChunks/4)
2118 static int yaffs_do_sync_fs(struct super_block *sb,
2119 int request_checkpoint)
2122 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2123 unsigned int oneshot_checkpoint = (yaffs_auto_checkpoint & 4);
2124 unsigned gc_urgent = yaffs_bg_gc_urgency(dev);
2127 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2128 (TSTR("yaffs_do_sync_fs: gc-urgency %d %s %s%s\n"),
2130 sb->s_dirt ? "dirty" : "clean",
2131 request_checkpoint ? "checkpoint requested" : "no checkpoint",
2132 oneshot_checkpoint ? " one-shot" : "" ));
2134 yaffs_GrossLock(dev);
2135 do_checkpoint = ((request_checkpoint && !gc_urgent) ||
2136 oneshot_checkpoint) &&
2137 !dev->isCheckpointed;
2139 if (sb->s_dirt || do_checkpoint) {
2140 yaffs_FlushSuperBlock(sb, !dev->isCheckpointed && do_checkpoint);
2142 if(oneshot_checkpoint)
2143 yaffs_auto_checkpoint &= ~4;
2145 yaffs_GrossUnlock(dev);
2151 * yaffs background thread functions .
2152 * yaffs_BackgroundThread() the thread function
2153 * yaffs_BackgroundStart() launches the background thread.
2154 * yaffs_BackgroundStop() cleans up the background thread.
2157 * The thread should only run after the yaffs is initialised
2158 * The thread should be stopped before yaffs is unmounted.
2159 * The thread should not do any writing while the fs is in read only.
2162 #ifdef YAFFS_COMPILE_BACKGROUND
2164 void yaffs_background_waker(unsigned long data)
2166 wake_up_process((struct task_struct *)data);
2169 static int yaffs_BackgroundThread(void *data)
2171 yaffs_Device *dev = (yaffs_Device *)data;
2172 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2173 unsigned long now = jiffies;
2174 unsigned long next_dir_update = now;
2175 unsigned long next_gc = now;
2176 unsigned long expires;
2177 unsigned int urgency;
2180 struct timer_list timer;
2182 T(YAFFS_TRACE_BACKGROUND,
2183 (TSTR("yaffs_background starting for dev %p\n"),
2188 while(context->bgRunning){
2189 T(YAFFS_TRACE_BACKGROUND,
2190 (TSTR("yaffs_background\n")));
2192 if(kthread_should_stop())
2198 yaffs_GrossLock(dev);
2202 if(time_after(now, next_dir_update)){
2203 yaffs_UpdateDirtyDirectories(dev);
2204 next_dir_update = now + HZ;
2207 if(time_after(now,next_gc)){
2208 if(!dev->isCheckpointed){
2209 urgency = yaffs_bg_gc_urgency(dev);
2210 gcResult = yaffs_BackgroundGarbageCollect(dev, urgency);
2212 next_gc = now + HZ/20+1;
2213 else if(urgency > 0)
2214 next_gc = now + HZ/10+1;
2216 next_gc = now + HZ * 2;
2218 * gc not running so set to next_dir_update
2219 * to cut down on wake ups
2221 next_gc = next_dir_update;
2223 yaffs_GrossUnlock(dev);
2225 expires = next_dir_update;
2226 if (time_before(next_gc,expires))
2228 if(time_before(expires,now))
2232 timer.expires = expires+1;
2233 timer.data = (unsigned long) current;
2234 timer.function = yaffs_background_waker;
2236 set_current_state(TASK_INTERRUPTIBLE);
2239 del_timer_sync(&timer);
2248 static int yaffs_BackgroundStart(yaffs_Device *dev)
2251 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2253 context->bgRunning = 1;
2255 context->bgThread = kthread_run(yaffs_BackgroundThread,
2256 (void *)dev,"yaffs-bg");
2258 if(IS_ERR(context->bgThread)){
2259 retval = PTR_ERR(context->bgThread);
2260 context->bgThread = NULL;
2261 context->bgRunning = 0;
2266 static void yaffs_BackgroundStop(yaffs_Device *dev)
2268 struct yaffs_LinuxContext *ctxt = yaffs_DeviceToContext(dev);
2270 ctxt->bgRunning = 0;
2272 if( ctxt->bgThread){
2273 kthread_stop(ctxt->bgThread);
2274 ctxt->bgThread = NULL;
2278 static int yaffs_BackgroundThread(void *data)
2283 static int yaffs_BackgroundStart(yaffs_Device *dev)
2288 static void yaffs_BackgroundStop(yaffs_Device *dev)
2294 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2295 static void yaffs_write_super(struct super_block *sb)
2297 static int yaffs_write_super(struct super_block *sb)
2300 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 2);
2302 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2303 (TSTR("yaffs_write_super%s\n"),
2304 request_checkpoint ? " checkpt" : ""));
2306 yaffs_do_sync_fs(sb, request_checkpoint);
2308 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2314 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2315 static int yaffs_sync_fs(struct super_block *sb, int wait)
2317 static int yaffs_sync_fs(struct super_block *sb)
2320 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 1);
2322 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
2323 (TSTR("yaffs_sync_fs%s\n"),
2324 request_checkpoint ? " checkpt" : ""));
2326 yaffs_do_sync_fs(sb, request_checkpoint);
2331 #ifdef YAFFS_USE_OWN_IGET
2333 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2335 struct inode *inode;
2337 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2340 (TSTR("yaffs_iget for %lu\n"), ino));
2342 inode = iget_locked(sb, ino);
2344 return ERR_PTR(-ENOMEM);
2345 if (!(inode->i_state & I_NEW))
2348 /* NB This is called as a side effect of other functions, but
2349 * we had to release the lock to prevent deadlocks, so
2350 * need to lock again.
2353 yaffs_GrossLock(dev);
2355 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2357 yaffs_FillInodeFromObject(inode, obj);
2359 yaffs_GrossUnlock(dev);
2361 unlock_new_inode(inode);
2367 static void yaffs_read_inode(struct inode *inode)
2369 /* NB This is called as a side effect of other functions, but
2370 * we had to release the lock to prevent deadlocks, so
2371 * need to lock again.
2375 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2378 (TSTR("yaffs_read_inode for %d\n"), (int)inode->i_ino));
2380 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2381 yaffs_GrossLock(dev);
2383 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2385 yaffs_FillInodeFromObject(inode, obj);
2387 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2388 yaffs_GrossUnlock(dev);
2393 static YLIST_HEAD(yaffs_context_list);
2394 struct semaphore yaffs_context_lock;
2396 #if 0 /* not used */
2397 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2399 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2401 if (*flags & MS_RDONLY) {
2402 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2405 (TSTR("yaffs_remount_fs: %s: RO\n"), dev->name));
2407 yaffs_GrossLock(dev);
2409 yaffs_FlushSuperBlock(sb,1);
2414 yaffs_GrossUnlock(dev);
2417 (TSTR("yaffs_remount_fs: %s: RW\n"), dev->name));
2424 static void yaffs_put_super(struct super_block *sb)
2426 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2428 T(YAFFS_TRACE_OS, (TSTR("yaffs_put_super\n")));
2430 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2431 (TSTR("Shutting down yaffs background thread\n")));
2432 yaffs_BackgroundStop(dev);
2433 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2434 (TSTR("yaffs background thread shut down\n")));
2436 yaffs_GrossLock(dev);
2438 yaffs_FlushSuperBlock(sb,1);
2440 if (yaffs_DeviceToContext(dev)->putSuperFunc)
2441 yaffs_DeviceToContext(dev)->putSuperFunc(sb);
2444 yaffs_Deinitialise(dev);
2446 yaffs_GrossUnlock(dev);
2448 down(&yaffs_context_lock);
2449 ylist_del_init(&(yaffs_DeviceToContext(dev)->contextList));
2450 up(&yaffs_context_lock);
2452 if (yaffs_DeviceToContext(dev)->spareBuffer) {
2453 YFREE(yaffs_DeviceToContext(dev)->spareBuffer);
2454 yaffs_DeviceToContext(dev)->spareBuffer = NULL;
2461 static void yaffs_MTDPutSuper(struct super_block *sb)
2463 struct mtd_info *mtd = yaffs_DeviceToContext(yaffs_SuperToDevice(sb))->mtd;
2468 put_mtd_device(mtd);
2472 static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev)
2474 struct super_block *sb = yaffs_DeviceToContext(dev)->superBlock;
2476 T(YAFFS_TRACE_OS, (TSTR("yaffs_MarkSuperBlockDirty() sb = %p\n"), sb));
2483 int skip_checkpoint_read;
2484 int skip_checkpoint_write;
2487 int tags_ecc_overridden;
2488 int lazy_loading_enabled;
2489 int lazy_loading_overridden;
2490 int empty_lost_and_found;
2491 int empty_lost_and_found_overridden;
2494 #define MAX_OPT_LEN 30
2495 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2497 char cur_opt[MAX_OPT_LEN + 1];
2501 /* Parse through the options which is a comma seperated list */
2503 while (options_str && *options_str && !error) {
2504 memset(cur_opt, 0, MAX_OPT_LEN + 1);
2507 while(*options_str == ',')
2510 while (*options_str && *options_str != ',') {
2511 if (p < MAX_OPT_LEN) {
2512 cur_opt[p] = *options_str;
2518 if (!strcmp(cur_opt, "inband-tags"))
2519 options->inband_tags = 1;
2520 else if (!strcmp(cur_opt, "tags-ecc-off")){
2521 options->tags_ecc_on = 0;
2522 options->tags_ecc_overridden=1;
2523 } else if (!strcmp(cur_opt, "tags-ecc-on")){
2524 options->tags_ecc_on = 1;
2525 options->tags_ecc_overridden = 1;
2526 } else if (!strcmp(cur_opt, "lazy-loading-off")){
2527 options->lazy_loading_enabled = 0;
2528 options->lazy_loading_overridden=1;
2529 } else if (!strcmp(cur_opt, "lazy-loading-on")){
2530 options->lazy_loading_enabled = 1;
2531 options->lazy_loading_overridden = 1;
2532 } else if (!strcmp(cur_opt, "empty-lost-and-found-off")){
2533 options->empty_lost_and_found = 0;
2534 options->empty_lost_and_found_overridden=1;
2535 } else if (!strcmp(cur_opt, "empty-lost-and-found-on")){
2536 options->empty_lost_and_found = 1;
2537 options->empty_lost_and_found_overridden=1;
2538 } else if (!strcmp(cur_opt, "no-cache"))
2539 options->no_cache = 1;
2540 else if (!strcmp(cur_opt, "no-checkpoint-read"))
2541 options->skip_checkpoint_read = 1;
2542 else if (!strcmp(cur_opt, "no-checkpoint-write"))
2543 options->skip_checkpoint_write = 1;
2544 else if (!strcmp(cur_opt, "no-checkpoint")) {
2545 options->skip_checkpoint_read = 1;
2546 options->skip_checkpoint_write = 1;
2548 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2557 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2558 struct super_block *sb,
2559 void *data, int silent)
2562 struct inode *inode = NULL;
2563 struct dentry *root;
2564 yaffs_Device *dev = 0;
2565 char devname_buf[BDEVNAME_SIZE + 1];
2566 struct mtd_info *mtd;
2568 char *data_str = (char *)data;
2569 struct yaffs_LinuxContext *context = NULL;
2570 yaffs_DeviceParam *param;
2572 yaffs_options options;
2574 sb->s_magic = YAFFS_MAGIC;
2575 sb->s_op = &yaffs_super_ops;
2576 sb->s_flags |= MS_NOATIME;
2578 #ifdef YAFFS_COMPILE_EXPORTFS
2579 sb->s_export_op = &yaffs_export_ops;
2583 printk(KERN_INFO "yaffs: sb is NULL\n");
2584 else if (!sb->s_dev)
2585 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
2586 else if (!yaffs_devname(sb, devname_buf))
2587 printk(KERN_INFO "yaffs: devname is NULL\n");
2589 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
2591 yaffs_devname(sb, devname_buf));
2596 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2598 memset(&options, 0, sizeof(options));
2600 if (yaffs_parse_options(&options, data_str)) {
2601 /* Option parsing failed */
2606 sb->s_blocksize = PAGE_CACHE_SIZE;
2607 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
2610 (TSTR("yaffs_read_super: Using yaffs%d\n"), yaffsVersion));
2612 (TSTR("yaffs_read_super: block size %d\n"),
2613 (int)(sb->s_blocksize)));
2615 T(YAFFS_TRACE_ALWAYS,
2616 (TSTR("yaffs: Attempting MTD mount of %u.%u,\"%s\"\n"),
2617 MAJOR(sb->s_dev), MINOR(sb->s_dev),
2618 yaffs_devname(sb, devname_buf)));
2620 /* Check it's an mtd device..... */
2621 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2622 return NULL; /* This isn't an mtd device */
2624 /* Get the device */
2625 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2627 T(YAFFS_TRACE_ALWAYS,
2628 (TSTR("yaffs: MTD device #%u doesn't appear to exist\n"),
2632 /* Check it's NAND */
2633 if (mtd->type != MTD_NANDFLASH) {
2634 T(YAFFS_TRACE_ALWAYS,
2635 (TSTR("yaffs: MTD device is not NAND it's type %d\n"),
2640 T(YAFFS_TRACE_OS, (TSTR(" erase %p\n"), mtd->erase));
2641 T(YAFFS_TRACE_OS, (TSTR(" read %p\n"), mtd->read));
2642 T(YAFFS_TRACE_OS, (TSTR(" write %p\n"), mtd->write));
2643 T(YAFFS_TRACE_OS, (TSTR(" readoob %p\n"), mtd->read_oob));
2644 T(YAFFS_TRACE_OS, (TSTR(" writeoob %p\n"), mtd->write_oob));
2645 T(YAFFS_TRACE_OS, (TSTR(" block_isbad %p\n"), mtd->block_isbad));
2646 T(YAFFS_TRACE_OS, (TSTR(" block_markbad %p\n"), mtd->block_markbad));
2647 T(YAFFS_TRACE_OS, (TSTR(" %s %d\n"), WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2648 T(YAFFS_TRACE_OS, (TSTR(" oobsize %d\n"), mtd->oobsize));
2649 T(YAFFS_TRACE_OS, (TSTR(" erasesize %d\n"), mtd->erasesize));
2650 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2651 T(YAFFS_TRACE_OS, (TSTR(" size %u\n"), mtd->size));
2653 T(YAFFS_TRACE_OS, (TSTR(" size %lld\n"), mtd->size));
2656 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2658 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2659 T(YAFFS_TRACE_ALWAYS,
2660 (TSTR("yaffs: auto selecting yaffs2\n")));
2664 /* Added NCB 26/5/2006 for completeness */
2665 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2666 T(YAFFS_TRACE_ALWAYS,
2667 (TSTR("yaffs: auto selecting yaffs1\n")));
2673 if (yaffsVersion == 2) {
2674 /* Check for version 2 style functions */
2676 !mtd->block_isbad ||
2677 !mtd->block_markbad ||
2680 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2681 !mtd->read_oob || !mtd->write_oob) {
2684 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2686 T(YAFFS_TRACE_ALWAYS,
2687 (TSTR("yaffs: MTD device does not support required "
2692 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
2693 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
2694 !options.inband_tags) {
2695 T(YAFFS_TRACE_ALWAYS,
2696 (TSTR("yaffs: MTD device does not have the "
2697 "right page sizes\n")));
2701 /* Check for V1 style functions */
2705 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2706 !mtd->read_oob || !mtd->write_oob) {
2709 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2711 T(YAFFS_TRACE_ALWAYS,
2712 (TSTR("yaffs: MTD device does not support required "
2717 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2718 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2719 T(YAFFS_TRACE_ALWAYS,
2720 (TSTR("yaffs: MTD device does not support have the "
2721 "right page sizes\n")));
2726 /* OK, so if we got here, we have an MTD that's NAND and looks
2727 * like it has the right capabilities
2728 * Set the yaffs_Device up for mtd
2731 dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2732 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
2734 if(!dev || !context ){
2744 /* Deep shit could not allocate device structure */
2745 T(YAFFS_TRACE_ALWAYS,
2746 (TSTR("yaffs_read_super: Failed trying to allocate "
2747 "yaffs_Device. \n")));
2750 memset(dev, 0, sizeof(yaffs_Device));
2751 param = &(dev->param);
2753 memset(context,0,sizeof(struct yaffs_LinuxContext));
2754 dev->context = context;
2755 YINIT_LIST_HEAD(&(context->contextList));
2757 context->superBlock = sb;
2761 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2762 sb->s_fs_info = dev;
2764 sb->u.generic_sbp = dev;
2767 yaffs_DeviceToContext(dev)->mtd = mtd;
2768 param->name = mtd->name;
2770 /* Set up the memory size parameters.... */
2772 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2774 param->startBlock = 0;
2775 param->endBlock = nBlocks - 1;
2776 param->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2777 param->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2778 param->nReservedBlocks = 5;
2779 param->nShortOpCaches = (options.no_cache) ? 0 : 10;
2780 param->inbandTags = options.inband_tags;
2782 #ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
2783 param->disableLazyLoad = 1;
2785 #ifdef CONFIG_YAFFS_XATTR
2786 param->enableXattr = 1;
2788 if(options.lazy_loading_overridden)
2789 param->disableLazyLoad = !options.lazy_loading_enabled;
2791 #ifdef CONFIG_YAFFS_DISABLE_TAGS_ECC
2792 param->noTagsECC = 1;
2795 #ifdef CONFIG_YAFFS_DISABLE_BACKGROUND
2797 param->deferDirectoryUpdate = 1;
2800 if(options.tags_ecc_overridden)
2801 param->noTagsECC = !options.tags_ecc_on;
2803 #ifdef CONFIG_YAFFS_EMPTY_LOST_AND_FOUND
2804 param->emptyLostAndFound = 1;
2807 #ifdef CONFIG_YAFFS_DISABLE_BLOCK_REFRESHING
2808 param->refreshPeriod = 0;
2810 param->refreshPeriod = 500;
2813 if(options.empty_lost_and_found_overridden)
2814 param->emptyLostAndFound = options.empty_lost_and_found;
2816 /* ... and the functions. */
2817 if (yaffsVersion == 2) {
2818 param->writeChunkWithTagsToNAND =
2819 nandmtd2_WriteChunkWithTagsToNAND;
2820 param->readChunkWithTagsFromNAND =
2821 nandmtd2_ReadChunkWithTagsFromNAND;
2822 param->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2823 param->queryNANDBlock = nandmtd2_QueryNANDBlock;
2824 yaffs_DeviceToContext(dev)->spareBuffer = YMALLOC(mtd->oobsize);
2825 param->isYaffs2 = 1;
2826 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2827 param->totalBytesPerChunk = mtd->writesize;
2828 param->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2830 param->totalBytesPerChunk = mtd->oobblock;
2831 param->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2833 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2835 param->startBlock = 0;
2836 param->endBlock = nBlocks - 1;
2838 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2839 /* use the MTD interface in yaffs_mtdif1.c */
2840 param->writeChunkWithTagsToNAND =
2841 nandmtd1_WriteChunkWithTagsToNAND;
2842 param->readChunkWithTagsFromNAND =
2843 nandmtd1_ReadChunkWithTagsFromNAND;
2844 param->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2845 param->queryNANDBlock = nandmtd1_QueryNANDBlock;
2847 param->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2848 param->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2850 param->isYaffs2 = 0;
2852 /* ... and common functions */
2853 param->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2854 param->initialiseNAND = nandmtd_InitialiseNAND;
2856 yaffs_DeviceToContext(dev)->putSuperFunc = yaffs_MTDPutSuper;
2858 param->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2859 param->gcControl = yaffs_gc_control_callback;
2861 yaffs_DeviceToContext(dev)->superBlock= sb;
2864 #ifndef CONFIG_YAFFS_DOES_ECC
2865 param->useNANDECC = 1;
2868 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2869 param->wideTnodesDisabled = 1;
2872 param->skipCheckpointRead = options.skip_checkpoint_read;
2873 param->skipCheckpointWrite = options.skip_checkpoint_write;
2875 /* we assume this is protected by lock_kernel() in mount/umount */
2876 down(&yaffs_context_lock);
2877 ylist_add_tail(&(yaffs_DeviceToContext(dev)->contextList), &yaffs_context_list);
2878 up(&yaffs_context_lock);
2880 /* Directory search handling...*/
2881 YINIT_LIST_HEAD(&(yaffs_DeviceToContext(dev)->searchContexts));
2882 param->removeObjectCallback = yaffs_RemoveObjectCallback;
2884 init_MUTEX(&(yaffs_DeviceToContext(dev)->grossLock));
2886 yaffs_GrossLock(dev);
2888 err = yaffs_GutsInitialise(dev);
2891 (TSTR("yaffs_read_super: guts initialised %s\n"),
2892 (err == YAFFS_OK) ? "OK" : "FAILED"));
2895 yaffs_BackgroundStart(dev);
2897 if(!context->bgThread)
2898 param->deferDirectoryUpdate = 0;
2901 /* Release lock before yaffs_get_inode() */
2902 yaffs_GrossUnlock(dev);
2904 /* Create root inode */
2905 if (err == YAFFS_OK)
2906 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2912 inode->i_op = &yaffs_dir_inode_operations;
2913 inode->i_fop = &yaffs_dir_operations;
2915 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: got root inode\n")));
2917 root = d_alloc_root(inode);
2919 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: d_alloc_root done\n")));
2926 sb->s_dirt = !dev->isCheckpointed;
2927 T(YAFFS_TRACE_ALWAYS,
2928 (TSTR("yaffs_read_super: isCheckpointed %d\n"),
2929 dev->isCheckpointed));
2931 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: done\n")));
2936 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2937 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2940 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2943 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2944 static int yaffs_read_super(struct file_system_type *fs,
2945 int flags, const char *dev_name,
2946 void *data, struct vfsmount *mnt)
2949 return get_sb_bdev(fs, flags, dev_name, data,
2950 yaffs_internal_read_super_mtd, mnt);
2953 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2954 int flags, const char *dev_name,
2958 return get_sb_bdev(fs, flags, dev_name, data,
2959 yaffs_internal_read_super_mtd);
2963 static struct file_system_type yaffs_fs_type = {
2964 .owner = THIS_MODULE,
2966 .get_sb = yaffs_read_super,
2967 .kill_sb = kill_block_super,
2968 .fs_flags = FS_REQUIRES_DEV,
2971 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2974 return yaffs_internal_read_super(1, sb, data, silent);
2977 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
2982 #ifdef CONFIG_YAFFS_YAFFS2
2984 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2985 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
2988 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
2991 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2992 static int yaffs2_read_super(struct file_system_type *fs,
2993 int flags, const char *dev_name, void *data,
2994 struct vfsmount *mnt)
2996 return get_sb_bdev(fs, flags, dev_name, data,
2997 yaffs2_internal_read_super_mtd, mnt);
3000 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
3001 int flags, const char *dev_name,
3005 return get_sb_bdev(fs, flags, dev_name, data,
3006 yaffs2_internal_read_super_mtd);
3010 static struct file_system_type yaffs2_fs_type = {
3011 .owner = THIS_MODULE,
3013 .get_sb = yaffs2_read_super,
3014 .kill_sb = kill_block_super,
3015 .fs_flags = FS_REQUIRES_DEV,
3018 static struct super_block *yaffs2_read_super(struct super_block *sb,
3019 void *data, int silent)
3021 return yaffs_internal_read_super(2, sb, data, silent);
3024 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
3028 #endif /* CONFIG_YAFFS_YAFFS2 */
3030 static struct proc_dir_entry *my_proc_entry;
3031 static struct proc_dir_entry *debug_proc_entry;
3033 static char *yaffs_dump_dev_part0(char *buf, yaffs_Device * dev)
3035 buf += sprintf(buf, "startBlock......... %d\n", dev->param.startBlock);
3036 buf += sprintf(buf, "endBlock........... %d\n", dev->param.endBlock);
3037 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->param.totalBytesPerChunk);
3038 buf += sprintf(buf, "useNANDECC......... %d\n", dev->param.useNANDECC);
3039 buf += sprintf(buf, "noTagsECC.......... %d\n", dev->param.noTagsECC);
3040 buf += sprintf(buf, "isYaffs2........... %d\n", dev->param.isYaffs2);
3041 buf += sprintf(buf, "inbandTags......... %d\n", dev->param.inbandTags);
3042 buf += sprintf(buf, "emptyLostAndFound.. %d\n", dev->param.emptyLostAndFound);
3043 buf += sprintf(buf, "disableLazyLoad.... %d\n", dev->param.disableLazyLoad);
3044 buf += sprintf(buf, "refreshPeriod...... %d\n", dev->param.refreshPeriod);
3045 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->param.nShortOpCaches);
3046 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->param.nReservedBlocks);
3048 buf += sprintf(buf, "\n");
3054 static char *yaffs_dump_dev_part1(char *buf, yaffs_Device * dev)
3056 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
3057 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
3058 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
3059 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
3060 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
3061 buf += sprintf(buf, "\n");
3062 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
3063 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
3064 buf += sprintf(buf, "nObjectsCreated.... %d\n", dev->nObjectsCreated);
3065 buf += sprintf(buf, "nFreeObjects....... %d\n", dev->nFreeObjects);
3066 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
3067 buf += sprintf(buf, "\n");
3068 buf += sprintf(buf, "nPageWrites........ %u\n", dev->nPageWrites);
3069 buf += sprintf(buf, "nPageReads......... %u\n", dev->nPageReads);
3070 buf += sprintf(buf, "nBlockErasures..... %u\n", dev->nBlockErasures);
3071 buf += sprintf(buf, "nGCCopies.......... %u\n", dev->nGCCopies);
3072 buf += sprintf(buf, "allGCs............. %u\n", dev->allGCs);
3073 buf += sprintf(buf, "passiveGCs......... %u\n", dev->passiveGCs);
3074 buf += sprintf(buf, "oldestDirtyGCs..... %u\n", dev->oldestDirtyGCs);
3075 buf += sprintf(buf, "backgroundGCs...... %u\n", dev->backgroundGCs);
3076 buf += sprintf(buf, "nRetriedWrites..... %u\n", dev->nRetriedWrites);
3077 buf += sprintf(buf, "nRetireBlocks...... %u\n", dev->nRetiredBlocks);
3078 buf += sprintf(buf, "eccFixed........... %u\n", dev->eccFixed);
3079 buf += sprintf(buf, "eccUnfixed......... %u\n", dev->eccUnfixed);
3080 buf += sprintf(buf, "tagsEccFixed....... %u\n", dev->tagsEccFixed);
3081 buf += sprintf(buf, "tagsEccUnfixed..... %u\n", dev->tagsEccUnfixed);
3082 buf += sprintf(buf, "cacheHits.......... %u\n", dev->cacheHits);
3083 buf += sprintf(buf, "nDeletedFiles...... %u\n", dev->nDeletedFiles);
3084 buf += sprintf(buf, "nUnlinkedFiles..... %u\n", dev->nUnlinkedFiles);
3085 buf += sprintf(buf, "refreshCount....... %u\n", dev->refreshCount);
3087 sprintf(buf, "nBackgroudDeletions %u\n", dev->nBackgroundDeletions);
3092 static int yaffs_proc_read(char *page,
3094 off_t offset, int count, int *eof, void *data)
3096 struct ylist_head *item;
3101 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
3102 * We use 'offset' (*ppos) to indicate where we are in devList.
3103 * This also assumes the user has posted a read buffer large
3104 * enough to hold the complete output; but that's life in /proc.
3109 /* Print header first */
3111 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__"\n");
3113 buf += sprintf(buf,"\n");
3117 down(&yaffs_context_lock);
3119 /* Locate and print the Nth entry. Order N-squared but N is small. */
3120 ylist_for_each(item, &yaffs_context_list) {
3121 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3122 yaffs_Device *dev = dc->dev;
3124 if (n < (step & ~1)) {
3129 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->param.name);
3130 buf = yaffs_dump_dev_part0(buf, dev);
3132 buf = yaffs_dump_dev_part1(buf, dev);
3136 up(&yaffs_context_lock);
3139 return buf - page < count ? buf - page : count;
3142 static int yaffs_stats_proc_read(char *page,
3144 off_t offset, int count, int *eof, void *data)
3146 struct ylist_head *item;
3150 down(&yaffs_context_lock);
3152 /* Locate and print the Nth entry. Order N-squared but N is small. */
3153 ylist_for_each(item, &yaffs_context_list) {
3154 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3155 yaffs_Device *dev = dc->dev;
3161 erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
3162 nObjects = dev->nObjectsCreated -dev->nFreeObjects;
3163 nTnodes = dev->nTnodesCreated - dev->nFreeTnodes;
3166 buf += sprintf(buf,"%d, %d, %d, %u, %u, %d, %d\n",
3167 n, dev->nFreeChunks, erasedChunks,
3168 dev->backgroundGCs, dev->oldestDirtyGCs,
3171 up(&yaffs_context_lock);
3174 return buf - page < count ? buf - page : count;
3178 * Set the verbosity of the warnings and error messages.
3180 * Note that the names can only be a..z or _ with the current code.
3185 unsigned mask_bitfield;
3187 {"allocate", YAFFS_TRACE_ALLOCATE},
3188 {"always", YAFFS_TRACE_ALWAYS},
3189 {"background", YAFFS_TRACE_BACKGROUND},
3190 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
3191 {"buffers", YAFFS_TRACE_BUFFERS},
3192 {"bug", YAFFS_TRACE_BUG},
3193 {"checkpt", YAFFS_TRACE_CHECKPOINT},
3194 {"deletion", YAFFS_TRACE_DELETION},
3195 {"erase", YAFFS_TRACE_ERASE},
3196 {"error", YAFFS_TRACE_ERROR},
3197 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
3198 {"gc", YAFFS_TRACE_GC},
3199 {"lock", YAFFS_TRACE_LOCK},
3200 {"mtd", YAFFS_TRACE_MTD},
3201 {"nandaccess", YAFFS_TRACE_NANDACCESS},
3202 {"os", YAFFS_TRACE_OS},
3203 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
3204 {"scan", YAFFS_TRACE_SCAN},
3205 {"tracing", YAFFS_TRACE_TRACING},
3206 {"sync", YAFFS_TRACE_SYNC},
3207 {"write", YAFFS_TRACE_WRITE},
3209 {"verify", YAFFS_TRACE_VERIFY},
3210 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
3211 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
3212 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
3214 {"all", 0xffffffff},
3219 #define MAX_MASK_NAME_LENGTH 40
3220 static int yaffs_proc_write_trace_options(struct file *file, const char *buf,
3221 unsigned long count, void *data)
3223 unsigned rg = 0, mask_bitfield;
3227 char substring[MAX_MASK_NAME_LENGTH + 1];
3233 rg = yaffs_traceMask;
3235 while (!done && (pos < count)) {
3237 while ((pos < count) && isspace(buf[pos]))
3254 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3256 if (end > buf + pos) {
3257 mask_name = "numeral";
3258 len = end - (buf + pos);
3262 for (x = buf + pos, i = 0;
3263 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3264 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3266 substring[i] = '\0';
3268 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3269 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3270 mask_name = mask_flags[i].mask_name;
3271 mask_bitfield = mask_flags[i].mask_bitfield;
3278 if (mask_name != NULL) {
3282 rg &= ~mask_bitfield;
3285 rg |= mask_bitfield;
3291 rg |= mask_bitfield;
3297 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3299 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3301 if (rg & YAFFS_TRACE_ALWAYS) {
3302 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3304 flag = ((rg & mask_flags[i].mask_bitfield) ==
3305 mask_flags[i].mask_bitfield) ? '+' : '-';
3306 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3314 static int yaffs_proc_write(struct file *file, const char *buf,
3315 unsigned long count, void *data)
3317 return yaffs_proc_write_trace_options(file, buf, count, data);
3320 /* Stuff to handle installation of file systems */
3321 struct file_system_to_install {
3322 struct file_system_type *fst;
3326 static struct file_system_to_install fs_to_install[] = {
3327 {&yaffs_fs_type, 0},
3328 {&yaffs2_fs_type, 0},
3332 static int __init init_yaffs_fs(void)
3335 struct file_system_to_install *fsinst;
3337 T(YAFFS_TRACE_ALWAYS,
3338 (TSTR("yaffs built " __DATE__ " " __TIME__ " Installing. \n")));
3340 #ifdef CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED
3341 T(YAFFS_TRACE_ALWAYS,
3342 (TSTR(" \n\n\n\nYAFFS-WARNING CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED selected.\n\n\n\n")));
3348 init_MUTEX(&yaffs_context_lock);
3350 /* Install the proc_fs entries */
3351 my_proc_entry = create_proc_entry("yaffs",
3355 if (my_proc_entry) {
3356 my_proc_entry->write_proc = yaffs_proc_write;
3357 my_proc_entry->read_proc = yaffs_proc_read;
3358 my_proc_entry->data = NULL;
3362 debug_proc_entry = create_proc_entry("yaffs_stats",
3366 if (debug_proc_entry) {
3367 debug_proc_entry->write_proc = NULL;
3368 debug_proc_entry->read_proc = yaffs_stats_proc_read;
3369 debug_proc_entry->data = NULL;
3373 /* Now add the file system entries */
3375 fsinst = fs_to_install;
3377 while (fsinst->fst && !error) {
3378 error = register_filesystem(fsinst->fst);
3380 fsinst->installed = 1;
3384 /* Any errors? uninstall */
3386 fsinst = fs_to_install;
3388 while (fsinst->fst) {
3389 if (fsinst->installed) {
3390 unregister_filesystem(fsinst->fst);
3391 fsinst->installed = 0;
3400 static void __exit exit_yaffs_fs(void)
3403 struct file_system_to_install *fsinst;
3405 T(YAFFS_TRACE_ALWAYS,
3406 (TSTR("yaffs built " __DATE__ " " __TIME__ " removing. \n")));
3408 remove_proc_entry("yaffs", YPROC_ROOT);
3409 remove_proc_entry("yaffs_stats", YPROC_ROOT);
3411 fsinst = fs_to_install;
3413 while (fsinst->fst) {
3414 if (fsinst->installed) {
3415 unregister_filesystem(fsinst->fst);
3416 fsinst->installed = 0;
3422 module_init(init_yaffs_fs)
3423 module_exit(exit_yaffs_fs)
3425 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
3426 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
3427 MODULE_LICENSE("GPL");