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){
1456 yaffs_GrossLock(dev);
1459 yaffs_GrossLock(dev);
1465 (TSTR("yaffs_readdir: entry .. ino %d \n"),
1466 (int)f->f_dentry->d_parent->d_inode->i_ino));
1467 yaffs_GrossUnlock(dev);
1468 if (filldir(dirent, "..", 2, offset,
1469 f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0){
1470 yaffs_GrossLock(dev);
1473 yaffs_GrossLock(dev);
1480 /* If the directory has changed since the open or last call to
1481 readdir, rewind to after the 2 canned entries. */
1482 if (f->f_version != inode->i_version) {
1485 f->f_version = inode->i_version;
1488 while(sc->nextReturn){
1491 if (curoffs >= offset) {
1492 int this_inode = yaffs_GetObjectInode(l);
1493 int this_type = yaffs_GetObjectType(l);
1495 yaffs_GetObjectName(l, name,
1496 YAFFS_MAX_NAME_LENGTH + 1);
1498 (TSTR("yaffs_readdir: %s inode %d\n"),
1499 name, yaffs_GetObjectInode(l)));
1501 yaffs_GrossUnlock(dev);
1509 yaffs_GrossLock(dev);
1513 yaffs_GrossLock(dev);
1518 yaffs_SearchAdvance(sc);
1522 yaffs_EndSearch(sc);
1523 yaffs_DeviceToContext(dev)->readdirProcess = NULL;
1524 yaffs_GrossUnlock(dev);
1532 * File creation. Allocate an inode, and we're done..
1535 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
1538 #define YCRED(x) (x->cred)
1541 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1542 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1545 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1549 struct inode *inode;
1551 yaffs_Object *obj = NULL;
1554 yaffs_Object *parent = yaffs_InodeToObject(dir);
1556 int error = -ENOSPC;
1557 uid_t uid = YCRED(current)->fsuid;
1558 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1560 if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
1565 (TSTR("yaffs_mknod: parent object %d type %d\n"),
1566 parent->objectId, parent->variantType));
1569 (TSTR("yaffs_mknod: could not get parent object\n")));
1573 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making oject for %s, "
1574 "mode %x dev %x\n"),
1575 dentry->d_name.name, mode, rdev));
1577 dev = parent->myDev;
1579 yaffs_GrossLock(dev);
1581 switch (mode & S_IFMT) {
1583 /* Special (socket, fifo, device...) */
1584 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making special\n")));
1585 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1586 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1587 gid, old_encode_dev(rdev));
1589 obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
1593 case S_IFREG: /* file */
1594 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making file\n")));
1595 obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
1598 case S_IFDIR: /* directory */
1600 (TSTR("yaffs_mknod: making directory\n")));
1601 obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
1604 case S_IFLNK: /* symlink */
1605 T(YAFFS_TRACE_OS, (TSTR("yaffs_mknod: making symlink\n")));
1606 obj = NULL; /* Do we ever get here? */
1610 /* Can not call yaffs_get_inode() with gross lock held */
1611 yaffs_GrossUnlock(dev);
1614 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
1615 d_instantiate(dentry, inode);
1616 update_dir_time(dir);
1618 (TSTR("yaffs_mknod created object %d count = %d\n"),
1619 obj->objectId, atomic_read(&inode->i_count)));
1621 yaffs_FillInodeFromObject(dir,parent);
1624 (TSTR("yaffs_mknod failed making object\n")));
1631 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
1634 T(YAFFS_TRACE_OS, (TSTR("yaffs_mkdir\n")));
1635 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
1639 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1640 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1641 struct nameidata *n)
1643 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
1646 T(YAFFS_TRACE_OS,(TSTR("yaffs_create\n")));
1647 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
1650 static int yaffs_unlink(struct inode *dir, struct dentry *dentry)
1658 (TSTR("yaffs_unlink %d:%s\n"),
1660 dentry->d_name.name));
1661 obj = yaffs_InodeToObject(dir);
1664 yaffs_GrossLock(dev);
1666 retVal = yaffs_Unlink(obj, dentry->d_name.name);
1668 if (retVal == YAFFS_OK) {
1669 dentry->d_inode->i_nlink--;
1671 yaffs_GrossUnlock(dev);
1672 mark_inode_dirty(dentry->d_inode);
1673 update_dir_time(dir);
1676 yaffs_GrossUnlock(dev);
1683 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1684 struct dentry *dentry)
1686 struct inode *inode = old_dentry->d_inode;
1687 yaffs_Object *obj = NULL;
1688 yaffs_Object *link = NULL;
1691 T(YAFFS_TRACE_OS, (TSTR("yaffs_link\n")));
1693 obj = yaffs_InodeToObject(inode);
1696 yaffs_GrossLock(dev);
1698 if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
1699 link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
1703 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1704 d_instantiate(dentry, old_dentry->d_inode);
1705 atomic_inc(&old_dentry->d_inode->i_count);
1707 (TSTR("yaffs_link link count %d i_count %d\n"),
1708 old_dentry->d_inode->i_nlink,
1709 atomic_read(&old_dentry->d_inode->i_count)));
1712 yaffs_GrossUnlock(dev);
1715 update_dir_time(dir);
1722 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1723 const char *symname)
1727 uid_t uid = YCRED(current)->fsuid;
1728 gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
1730 T(YAFFS_TRACE_OS, (TSTR("yaffs_symlink\n")));
1732 dev = yaffs_InodeToObject(dir)->myDev;
1733 yaffs_GrossLock(dev);
1734 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
1735 S_IFLNK | S_IRWXUGO, uid, gid, symname);
1736 yaffs_GrossUnlock(dev);
1739 struct inode *inode;
1741 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1742 d_instantiate(dentry, inode);
1743 update_dir_time(dir);
1744 T(YAFFS_TRACE_OS, (TSTR("symlink created OK\n")));
1747 T(YAFFS_TRACE_OS, (TSTR("symlink not created\n")));
1753 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1754 static int yaffs_sync_object(struct file *file, int datasync)
1756 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1763 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 34))
1764 struct dentry *dentry = file->f_path.dentry;
1767 obj = yaffs_DentryToObject(dentry);
1771 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
1772 (TSTR("yaffs_sync_object\n")));
1773 yaffs_GrossLock(dev);
1774 yaffs_FlushFile(obj, 1, datasync);
1775 yaffs_GrossUnlock(dev);
1780 * The VFS layer already does all the dentry stuff for rename.
1782 * NB: POSIX says you can rename an object over an old object of the same name
1784 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1785 struct inode *new_dir, struct dentry *new_dentry)
1788 int retVal = YAFFS_FAIL;
1789 yaffs_Object *target;
1791 T(YAFFS_TRACE_OS, (TSTR("yaffs_rename\n")));
1792 dev = yaffs_InodeToObject(old_dir)->myDev;
1794 yaffs_GrossLock(dev);
1796 /* Check if the target is an existing directory that is not empty. */
1797 target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
1798 new_dentry->d_name.name);
1802 if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
1803 !ylist_empty(&target->variant.directoryVariant.children)) {
1805 T(YAFFS_TRACE_OS, (TSTR("target is non-empty dir\n")));
1807 retVal = YAFFS_FAIL;
1809 /* Now does unlinking internally using shadowing mechanism */
1810 T(YAFFS_TRACE_OS, (TSTR("calling yaffs_RenameObject\n")));
1812 retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
1813 old_dentry->d_name.name,
1814 yaffs_InodeToObject(new_dir),
1815 new_dentry->d_name.name);
1817 yaffs_GrossUnlock(dev);
1819 if (retVal == YAFFS_OK) {
1821 new_dentry->d_inode->i_nlink--;
1822 mark_inode_dirty(new_dentry->d_inode);
1825 update_dir_time(old_dir);
1826 if(old_dir != new_dir)
1827 update_dir_time(new_dir);
1834 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
1836 struct inode *inode = dentry->d_inode;
1841 (TSTR("yaffs_setattr of object %d\n"),
1842 yaffs_InodeToObject(inode)->objectId));
1844 /* Fail if a requested resize >= 2GB */
1845 if (attr->ia_valid & ATTR_SIZE &&
1846 (attr->ia_size >> 31))
1850 error = inode_change_ok(inode, attr);
1854 error = inode_setattr(inode, attr);
1855 T(YAFFS_TRACE_OS,(TSTR("inode_setattr called\n")));
1856 if (attr->ia_valid & ATTR_SIZE)
1857 truncate_inode_pages(&inode->i_data,attr->ia_size);
1859 dev = yaffs_InodeToObject(inode)->myDev;
1860 if (attr->ia_valid & ATTR_SIZE){
1861 T(YAFFS_TRACE_OS,(TSTR("resize to %d(%x)\n"),
1862 (int)(attr->ia_size),(int)(attr->ia_size)));
1864 yaffs_GrossLock(dev);
1865 result = yaffs_SetAttributes(yaffs_InodeToObject(inode), attr);
1866 if(result == YAFFS_OK) {
1871 yaffs_GrossUnlock(dev);
1876 (TSTR("yaffs_setattr done returning %d\n"),error));
1881 #ifdef CONFIG_YAFFS_XATTR
1882 int yaffs_setxattr(struct dentry *dentry, const char *name,
1883 const void *value, size_t size, int flags)
1885 struct inode *inode = dentry->d_inode;
1888 yaffs_Object *obj = yaffs_InodeToObject(inode);
1891 (TSTR("yaffs_setxattr of object %d\n"),
1898 yaffs_GrossLock(dev);
1899 result = yaffs_SetXAttribute(obj, name, value, size, flags);
1900 if(result == YAFFS_OK)
1904 yaffs_GrossUnlock(dev);
1908 (TSTR("yaffs_setxattr done returning %d\n"),error));
1914 ssize_t yaffs_getxattr(struct dentry *dentry, const char *name, void *buff,
1917 struct inode *inode = dentry->d_inode;
1920 yaffs_Object *obj = yaffs_InodeToObject(inode);
1923 (TSTR("yaffs_getxattr of object %d\n"),
1929 yaffs_GrossLock(dev);
1930 error = yaffs_GetXAttribute(obj, name, buff, size);
1931 yaffs_GrossUnlock(dev);
1935 (TSTR("yaffs_getxattr done returning %d\n"),error));
1940 int yaffs_removexattr(struct dentry *dentry, const char *name)
1942 struct inode *inode = dentry->d_inode;
1945 yaffs_Object *obj = yaffs_InodeToObject(inode);
1948 (TSTR("yaffs_removexattr of object %d\n"),
1955 yaffs_GrossLock(dev);
1956 result = yaffs_RemoveXAttribute(obj, name);
1957 if(result == YAFFS_OK)
1961 yaffs_GrossUnlock(dev);
1965 (TSTR("yaffs_removexattr done returning %d\n"),error));
1970 ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size)
1972 struct inode *inode = dentry->d_inode;
1975 yaffs_Object *obj = yaffs_InodeToObject(inode);
1978 (TSTR("yaffs_listxattr of object %d\n"),
1984 yaffs_GrossLock(dev);
1985 error = yaffs_ListXAttributes(obj, buff, size);
1986 yaffs_GrossUnlock(dev);
1990 (TSTR("yaffs_listxattr done returning %d\n"),error));
1998 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1999 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
2001 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
2002 struct super_block *sb = dentry->d_sb;
2003 #elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2004 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
2006 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2008 static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
2010 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2013 T(YAFFS_TRACE_OS, (TSTR("yaffs_statfs\n")));
2015 yaffs_GrossLock(dev);
2017 buf->f_type = YAFFS_MAGIC;
2018 buf->f_bsize = sb->s_blocksize;
2019 buf->f_namelen = 255;
2021 if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
2022 /* Do this if chunk size is not a power of 2 */
2024 uint64_t bytesInDev;
2027 bytesInDev = ((uint64_t)((dev->param.endBlock - dev->param.startBlock + 1))) *
2028 ((uint64_t)(dev->param.nChunksPerBlock * dev->nDataBytesPerChunk));
2030 do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
2031 buf->f_blocks = bytesInDev;
2033 bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
2034 ((uint64_t)(dev->nDataBytesPerChunk));
2036 do_div(bytesFree, sb->s_blocksize);
2038 buf->f_bfree = bytesFree;
2040 } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
2043 (dev->param.endBlock - dev->param.startBlock + 1) *
2044 dev->param.nChunksPerBlock /
2045 (sb->s_blocksize / dev->nDataBytesPerChunk);
2047 yaffs_GetNumberOfFreeChunks(dev) /
2048 (sb->s_blocksize / dev->nDataBytesPerChunk);
2051 (dev->param.endBlock - dev->param.startBlock + 1) *
2052 dev->param.nChunksPerBlock *
2053 (dev->nDataBytesPerChunk / sb->s_blocksize);
2056 yaffs_GetNumberOfFreeChunks(dev) *
2057 (dev->nDataBytesPerChunk / sb->s_blocksize);
2062 buf->f_bavail = buf->f_bfree;
2064 yaffs_GrossUnlock(dev);
2070 static void yaffs_FlushInodes(struct super_block *sb)
2075 list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
2076 obj = yaffs_InodeToObject(iptr);
2078 T(YAFFS_TRACE_OS, (TSTR("flushing obj %d\n"),
2080 yaffs_FlushFile(obj,1,0);
2086 static void yaffs_FlushSuperBlock(struct super_block *sb, int do_checkpoint)
2088 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2092 yaffs_FlushInodes(sb);
2093 yaffs_UpdateDirtyDirectories(dev);
2094 yaffs_FlushEntireDeviceCache(dev);
2096 yaffs_CheckpointSave(dev);
2100 static unsigned yaffs_bg_gc_urgency(yaffs_Device *dev)
2102 unsigned erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
2103 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2104 unsigned scatteredFree = 0; /* Free chunks not in an erased block */
2106 if(erasedChunks < dev->nFreeChunks)
2107 scatteredFree = (dev->nFreeChunks - erasedChunks);
2109 if(!context->bgRunning)
2111 else if(scatteredFree < (dev->param.nChunksPerBlock * 2))
2113 else if(erasedChunks > dev->nFreeChunks/2)
2115 else if(erasedChunks > dev->nFreeChunks/4)
2121 static int yaffs_do_sync_fs(struct super_block *sb,
2122 int request_checkpoint)
2125 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2126 unsigned int oneshot_checkpoint = (yaffs_auto_checkpoint & 4);
2127 unsigned gc_urgent = yaffs_bg_gc_urgency(dev);
2130 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2131 (TSTR("yaffs_do_sync_fs: gc-urgency %d %s %s%s\n"),
2133 sb->s_dirt ? "dirty" : "clean",
2134 request_checkpoint ? "checkpoint requested" : "no checkpoint",
2135 oneshot_checkpoint ? " one-shot" : "" ));
2137 yaffs_GrossLock(dev);
2138 do_checkpoint = ((request_checkpoint && !gc_urgent) ||
2139 oneshot_checkpoint) &&
2140 !dev->isCheckpointed;
2142 if (sb->s_dirt || do_checkpoint) {
2143 yaffs_FlushSuperBlock(sb, !dev->isCheckpointed && do_checkpoint);
2145 if(oneshot_checkpoint)
2146 yaffs_auto_checkpoint &= ~4;
2148 yaffs_GrossUnlock(dev);
2154 * yaffs background thread functions .
2155 * yaffs_BackgroundThread() the thread function
2156 * yaffs_BackgroundStart() launches the background thread.
2157 * yaffs_BackgroundStop() cleans up the background thread.
2160 * The thread should only run after the yaffs is initialised
2161 * The thread should be stopped before yaffs is unmounted.
2162 * The thread should not do any writing while the fs is in read only.
2165 #ifdef YAFFS_COMPILE_BACKGROUND
2167 void yaffs_background_waker(unsigned long data)
2169 wake_up_process((struct task_struct *)data);
2172 static int yaffs_BackgroundThread(void *data)
2174 yaffs_Device *dev = (yaffs_Device *)data;
2175 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2176 unsigned long now = jiffies;
2177 unsigned long next_dir_update = now;
2178 unsigned long next_gc = now;
2179 unsigned long expires;
2180 unsigned int urgency;
2183 struct timer_list timer;
2185 T(YAFFS_TRACE_BACKGROUND,
2186 (TSTR("yaffs_background starting for dev %p\n"),
2191 while(context->bgRunning){
2192 T(YAFFS_TRACE_BACKGROUND,
2193 (TSTR("yaffs_background\n")));
2195 if(kthread_should_stop())
2201 yaffs_GrossLock(dev);
2205 if(time_after(now, next_dir_update)){
2206 yaffs_UpdateDirtyDirectories(dev);
2207 next_dir_update = now + HZ;
2210 if(time_after(now,next_gc)){
2211 if(!dev->isCheckpointed){
2212 urgency = yaffs_bg_gc_urgency(dev);
2213 gcResult = yaffs_BackgroundGarbageCollect(dev, urgency);
2215 next_gc = now + HZ/20+1;
2216 else if(urgency > 0)
2217 next_gc = now + HZ/10+1;
2219 next_gc = now + HZ * 2;
2221 * gc not running so set to next_dir_update
2222 * to cut down on wake ups
2224 next_gc = next_dir_update;
2226 yaffs_GrossUnlock(dev);
2228 expires = next_dir_update;
2229 if (time_before(next_gc,expires))
2231 if(time_before(expires,now))
2234 init_timer_on_stack(&timer);
2235 timer.expires = expires+1;
2236 timer.data = (unsigned long) current;
2237 timer.function = yaffs_background_waker;
2239 set_current_state(TASK_INTERRUPTIBLE);
2242 del_timer_sync(&timer);
2251 static int yaffs_BackgroundStart(yaffs_Device *dev)
2254 struct yaffs_LinuxContext *context = yaffs_DeviceToContext(dev);
2256 context->bgRunning = 1;
2258 context->bgThread = kthread_run(yaffs_BackgroundThread,
2259 (void *)dev,"yaffs-bg-%d",context->mount_id);
2261 if(IS_ERR(context->bgThread)){
2262 retval = PTR_ERR(context->bgThread);
2263 context->bgThread = NULL;
2264 context->bgRunning = 0;
2269 static void yaffs_BackgroundStop(yaffs_Device *dev)
2271 struct yaffs_LinuxContext *ctxt = yaffs_DeviceToContext(dev);
2273 ctxt->bgRunning = 0;
2275 if( ctxt->bgThread){
2276 kthread_stop(ctxt->bgThread);
2277 ctxt->bgThread = NULL;
2281 static int yaffs_BackgroundThread(void *data)
2286 static int yaffs_BackgroundStart(yaffs_Device *dev)
2291 static void yaffs_BackgroundStop(yaffs_Device *dev)
2297 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2298 static void yaffs_write_super(struct super_block *sb)
2300 static int yaffs_write_super(struct super_block *sb)
2303 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 2);
2305 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC | YAFFS_TRACE_BACKGROUND,
2306 (TSTR("yaffs_write_super%s\n"),
2307 request_checkpoint ? " checkpt" : ""));
2309 yaffs_do_sync_fs(sb, request_checkpoint);
2311 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2317 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2318 static int yaffs_sync_fs(struct super_block *sb, int wait)
2320 static int yaffs_sync_fs(struct super_block *sb)
2323 unsigned request_checkpoint = (yaffs_auto_checkpoint >= 1);
2325 T(YAFFS_TRACE_OS | YAFFS_TRACE_SYNC,
2326 (TSTR("yaffs_sync_fs%s\n"),
2327 request_checkpoint ? " checkpt" : ""));
2329 yaffs_do_sync_fs(sb, request_checkpoint);
2334 #ifdef YAFFS_USE_OWN_IGET
2336 static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2338 struct inode *inode;
2340 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2343 (TSTR("yaffs_iget for %lu\n"), ino));
2345 inode = iget_locked(sb, ino);
2347 return ERR_PTR(-ENOMEM);
2348 if (!(inode->i_state & I_NEW))
2351 /* NB This is called as a side effect of other functions, but
2352 * we had to release the lock to prevent deadlocks, so
2353 * need to lock again.
2356 yaffs_GrossLock(dev);
2358 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2360 yaffs_FillInodeFromObject(inode, obj);
2362 yaffs_GrossUnlock(dev);
2364 unlock_new_inode(inode);
2370 static void yaffs_read_inode(struct inode *inode)
2372 /* NB This is called as a side effect of other functions, but
2373 * we had to release the lock to prevent deadlocks, so
2374 * need to lock again.
2378 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2381 (TSTR("yaffs_read_inode for %d\n"), (int)inode->i_ino));
2383 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2384 yaffs_GrossLock(dev);
2386 obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2388 yaffs_FillInodeFromObject(inode, obj);
2390 if(current != yaffs_DeviceToContext(dev)->readdirProcess)
2391 yaffs_GrossUnlock(dev);
2396 static YLIST_HEAD(yaffs_context_list);
2397 struct semaphore yaffs_context_lock;
2399 #if 0 /* not used */
2400 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2402 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2404 if (*flags & MS_RDONLY) {
2405 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2408 (TSTR("yaffs_remount_fs: %s: RO\n"), dev->name));
2410 yaffs_GrossLock(dev);
2412 yaffs_FlushSuperBlock(sb,1);
2417 yaffs_GrossUnlock(dev);
2420 (TSTR("yaffs_remount_fs: %s: RW\n"), dev->name));
2427 static void yaffs_put_super(struct super_block *sb)
2429 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2431 T(YAFFS_TRACE_OS, (TSTR("yaffs_put_super\n")));
2433 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2434 (TSTR("Shutting down yaffs background thread\n")));
2435 yaffs_BackgroundStop(dev);
2436 T(YAFFS_TRACE_OS | YAFFS_TRACE_BACKGROUND,
2437 (TSTR("yaffs background thread shut down\n")));
2439 yaffs_GrossLock(dev);
2441 yaffs_FlushSuperBlock(sb,1);
2443 if (yaffs_DeviceToContext(dev)->putSuperFunc)
2444 yaffs_DeviceToContext(dev)->putSuperFunc(sb);
2447 yaffs_Deinitialise(dev);
2449 yaffs_GrossUnlock(dev);
2451 down(&yaffs_context_lock);
2452 ylist_del_init(&(yaffs_DeviceToContext(dev)->contextList));
2453 up(&yaffs_context_lock);
2455 if (yaffs_DeviceToContext(dev)->spareBuffer) {
2456 YFREE(yaffs_DeviceToContext(dev)->spareBuffer);
2457 yaffs_DeviceToContext(dev)->spareBuffer = NULL;
2464 static void yaffs_MTDPutSuper(struct super_block *sb)
2466 struct mtd_info *mtd = yaffs_DeviceToContext(yaffs_SuperToDevice(sb))->mtd;
2471 put_mtd_device(mtd);
2475 static void yaffs_MarkSuperBlockDirty(yaffs_Device *dev)
2477 struct super_block *sb = yaffs_DeviceToContext(dev)->superBlock;
2479 T(YAFFS_TRACE_OS, (TSTR("yaffs_MarkSuperBlockDirty() sb = %p\n"), sb));
2486 int skip_checkpoint_read;
2487 int skip_checkpoint_write;
2490 int tags_ecc_overridden;
2491 int lazy_loading_enabled;
2492 int lazy_loading_overridden;
2493 int empty_lost_and_found;
2494 int empty_lost_and_found_overridden;
2497 #define MAX_OPT_LEN 30
2498 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2500 char cur_opt[MAX_OPT_LEN + 1];
2504 /* Parse through the options which is a comma seperated list */
2506 while (options_str && *options_str && !error) {
2507 memset(cur_opt, 0, MAX_OPT_LEN + 1);
2510 while(*options_str == ',')
2513 while (*options_str && *options_str != ',') {
2514 if (p < MAX_OPT_LEN) {
2515 cur_opt[p] = *options_str;
2521 if (!strcmp(cur_opt, "inband-tags"))
2522 options->inband_tags = 1;
2523 else if (!strcmp(cur_opt, "tags-ecc-off")){
2524 options->tags_ecc_on = 0;
2525 options->tags_ecc_overridden=1;
2526 } else if (!strcmp(cur_opt, "tags-ecc-on")){
2527 options->tags_ecc_on = 1;
2528 options->tags_ecc_overridden = 1;
2529 } else if (!strcmp(cur_opt, "lazy-loading-off")){
2530 options->lazy_loading_enabled = 0;
2531 options->lazy_loading_overridden=1;
2532 } else if (!strcmp(cur_opt, "lazy-loading-on")){
2533 options->lazy_loading_enabled = 1;
2534 options->lazy_loading_overridden = 1;
2535 } else if (!strcmp(cur_opt, "empty-lost-and-found-off")){
2536 options->empty_lost_and_found = 0;
2537 options->empty_lost_and_found_overridden=1;
2538 } else if (!strcmp(cur_opt, "empty-lost-and-found-on")){
2539 options->empty_lost_and_found = 1;
2540 options->empty_lost_and_found_overridden=1;
2541 } else if (!strcmp(cur_opt, "no-cache"))
2542 options->no_cache = 1;
2543 else if (!strcmp(cur_opt, "no-checkpoint-read"))
2544 options->skip_checkpoint_read = 1;
2545 else if (!strcmp(cur_opt, "no-checkpoint-write"))
2546 options->skip_checkpoint_write = 1;
2547 else if (!strcmp(cur_opt, "no-checkpoint")) {
2548 options->skip_checkpoint_read = 1;
2549 options->skip_checkpoint_write = 1;
2551 printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2560 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2561 struct super_block *sb,
2562 void *data, int silent)
2565 struct inode *inode = NULL;
2566 struct dentry *root;
2567 yaffs_Device *dev = 0;
2568 char devname_buf[BDEVNAME_SIZE + 1];
2569 struct mtd_info *mtd;
2571 char *data_str = (char *)data;
2572 struct yaffs_LinuxContext *context = NULL;
2573 yaffs_DeviceParam *param;
2575 yaffs_options options;
2579 struct yaffs_LinuxContext *context_iterator;
2580 struct ylist_head *l;
2582 sb->s_magic = YAFFS_MAGIC;
2583 sb->s_op = &yaffs_super_ops;
2584 sb->s_flags |= MS_NOATIME;
2586 #ifdef YAFFS_COMPILE_EXPORTFS
2587 sb->s_export_op = &yaffs_export_ops;
2591 printk(KERN_INFO "yaffs: sb is NULL\n");
2592 else if (!sb->s_dev)
2593 printk(KERN_INFO "yaffs: sb->s_dev is NULL\n");
2594 else if (!yaffs_devname(sb, devname_buf))
2595 printk(KERN_INFO "yaffs: devname is NULL\n");
2597 printk(KERN_INFO "yaffs: dev is %d name is \"%s\"\n",
2599 yaffs_devname(sb, devname_buf));
2604 printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2606 memset(&options, 0, sizeof(options));
2608 if (yaffs_parse_options(&options, data_str)) {
2609 /* Option parsing failed */
2614 sb->s_blocksize = PAGE_CACHE_SIZE;
2615 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
2618 (TSTR("yaffs_read_super: Using yaffs%d\n"), yaffsVersion));
2620 (TSTR("yaffs_read_super: block size %d\n"),
2621 (int)(sb->s_blocksize)));
2623 T(YAFFS_TRACE_ALWAYS,
2624 (TSTR("yaffs: Attempting MTD mount of %u.%u,\"%s\"\n"),
2625 MAJOR(sb->s_dev), MINOR(sb->s_dev),
2626 yaffs_devname(sb, devname_buf)));
2628 /* Check it's an mtd device..... */
2629 if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2630 return NULL; /* This isn't an mtd device */
2632 /* Get the device */
2633 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2635 T(YAFFS_TRACE_ALWAYS,
2636 (TSTR("yaffs: MTD device #%u doesn't appear to exist\n"),
2640 /* Check it's NAND */
2641 if (mtd->type != MTD_NANDFLASH) {
2642 T(YAFFS_TRACE_ALWAYS,
2643 (TSTR("yaffs: MTD device is not NAND it's type %d\n"),
2648 T(YAFFS_TRACE_OS, (TSTR(" erase %p\n"), mtd->erase));
2649 T(YAFFS_TRACE_OS, (TSTR(" read %p\n"), mtd->read));
2650 T(YAFFS_TRACE_OS, (TSTR(" write %p\n"), mtd->write));
2651 T(YAFFS_TRACE_OS, (TSTR(" readoob %p\n"), mtd->read_oob));
2652 T(YAFFS_TRACE_OS, (TSTR(" writeoob %p\n"), mtd->write_oob));
2653 T(YAFFS_TRACE_OS, (TSTR(" block_isbad %p\n"), mtd->block_isbad));
2654 T(YAFFS_TRACE_OS, (TSTR(" block_markbad %p\n"), mtd->block_markbad));
2655 T(YAFFS_TRACE_OS, (TSTR(" %s %d\n"), WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2656 T(YAFFS_TRACE_OS, (TSTR(" oobsize %d\n"), mtd->oobsize));
2657 T(YAFFS_TRACE_OS, (TSTR(" erasesize %d\n"), mtd->erasesize));
2658 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2659 T(YAFFS_TRACE_OS, (TSTR(" size %u\n"), mtd->size));
2661 T(YAFFS_TRACE_OS, (TSTR(" size %lld\n"), mtd->size));
2664 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2666 if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2667 T(YAFFS_TRACE_ALWAYS,
2668 (TSTR("yaffs: auto selecting yaffs2\n")));
2672 /* Added NCB 26/5/2006 for completeness */
2673 if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2674 T(YAFFS_TRACE_ALWAYS,
2675 (TSTR("yaffs: auto selecting yaffs1\n")));
2681 if (yaffsVersion == 2) {
2682 /* Check for version 2 style functions */
2684 !mtd->block_isbad ||
2685 !mtd->block_markbad ||
2688 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2689 !mtd->read_oob || !mtd->write_oob) {
2692 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2694 T(YAFFS_TRACE_ALWAYS,
2695 (TSTR("yaffs: MTD device does not support required "
2700 if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
2701 mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
2702 !options.inband_tags) {
2703 T(YAFFS_TRACE_ALWAYS,
2704 (TSTR("yaffs: MTD device does not have the "
2705 "right page sizes\n")));
2709 /* Check for V1 style functions */
2713 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2714 !mtd->read_oob || !mtd->write_oob) {
2717 !mtd->read_ecc || !mtd->read_oob || !mtd->write_oob) {
2719 T(YAFFS_TRACE_ALWAYS,
2720 (TSTR("yaffs: MTD device does not support required "
2725 if (WRITE_SIZE(mtd) < YAFFS_BYTES_PER_CHUNK ||
2726 mtd->oobsize != YAFFS_BYTES_PER_SPARE) {
2727 T(YAFFS_TRACE_ALWAYS,
2728 (TSTR("yaffs: MTD device does not support have the "
2729 "right page sizes\n")));
2734 /* OK, so if we got here, we have an MTD that's NAND and looks
2735 * like it has the right capabilities
2736 * Set the yaffs_Device up for mtd
2739 dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
2740 context = kmalloc(sizeof(struct yaffs_LinuxContext),GFP_KERNEL);
2742 if(!dev || !context ){
2752 /* Deep shit could not allocate device structure */
2753 T(YAFFS_TRACE_ALWAYS,
2754 (TSTR("yaffs_read_super: Failed trying to allocate "
2755 "yaffs_Device. \n")));
2758 memset(dev, 0, sizeof(yaffs_Device));
2759 param = &(dev->param);
2761 memset(context,0,sizeof(struct yaffs_LinuxContext));
2762 dev->context = context;
2763 YINIT_LIST_HEAD(&(context->contextList));
2765 context->superBlock = sb;
2769 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2770 sb->s_fs_info = dev;
2772 sb->u.generic_sbp = dev;
2775 yaffs_DeviceToContext(dev)->mtd = mtd;
2776 param->name = mtd->name;
2778 /* Set up the memory size parameters.... */
2780 nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
2782 param->startBlock = 0;
2783 param->endBlock = nBlocks - 1;
2784 param->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
2785 param->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
2786 param->nReservedBlocks = 5;
2787 param->nShortOpCaches = (options.no_cache) ? 0 : 10;
2788 param->inbandTags = options.inband_tags;
2790 #ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
2791 param->disableLazyLoad = 1;
2793 #ifdef CONFIG_YAFFS_XATTR
2794 param->enableXattr = 1;
2796 if(options.lazy_loading_overridden)
2797 param->disableLazyLoad = !options.lazy_loading_enabled;
2799 #ifdef CONFIG_YAFFS_DISABLE_TAGS_ECC
2800 param->noTagsECC = 1;
2803 #ifdef CONFIG_YAFFS_DISABLE_BACKGROUND
2805 param->deferDirectoryUpdate = 1;
2808 if(options.tags_ecc_overridden)
2809 param->noTagsECC = !options.tags_ecc_on;
2811 #ifdef CONFIG_YAFFS_EMPTY_LOST_AND_FOUND
2812 param->emptyLostAndFound = 1;
2815 #ifdef CONFIG_YAFFS_DISABLE_BLOCK_REFRESHING
2816 param->refreshPeriod = 0;
2818 param->refreshPeriod = 500;
2821 if(options.empty_lost_and_found_overridden)
2822 param->emptyLostAndFound = options.empty_lost_and_found;
2824 /* ... and the functions. */
2825 if (yaffsVersion == 2) {
2826 param->writeChunkWithTagsToNAND =
2827 nandmtd2_WriteChunkWithTagsToNAND;
2828 param->readChunkWithTagsFromNAND =
2829 nandmtd2_ReadChunkWithTagsFromNAND;
2830 param->markNANDBlockBad = nandmtd2_MarkNANDBlockBad;
2831 param->queryNANDBlock = nandmtd2_QueryNANDBlock;
2832 yaffs_DeviceToContext(dev)->spareBuffer = YMALLOC(mtd->oobsize);
2833 param->isYaffs2 = 1;
2834 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2835 param->totalBytesPerChunk = mtd->writesize;
2836 param->nChunksPerBlock = mtd->erasesize / mtd->writesize;
2838 param->totalBytesPerChunk = mtd->oobblock;
2839 param->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
2841 nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
2843 param->startBlock = 0;
2844 param->endBlock = nBlocks - 1;
2846 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2847 /* use the MTD interface in yaffs_mtdif1.c */
2848 param->writeChunkWithTagsToNAND =
2849 nandmtd1_WriteChunkWithTagsToNAND;
2850 param->readChunkWithTagsFromNAND =
2851 nandmtd1_ReadChunkWithTagsFromNAND;
2852 param->markNANDBlockBad = nandmtd1_MarkNANDBlockBad;
2853 param->queryNANDBlock = nandmtd1_QueryNANDBlock;
2855 param->writeChunkToNAND = nandmtd_WriteChunkToNAND;
2856 param->readChunkFromNAND = nandmtd_ReadChunkFromNAND;
2858 param->isYaffs2 = 0;
2860 /* ... and common functions */
2861 param->eraseBlockInNAND = nandmtd_EraseBlockInNAND;
2862 param->initialiseNAND = nandmtd_InitialiseNAND;
2864 yaffs_DeviceToContext(dev)->putSuperFunc = yaffs_MTDPutSuper;
2866 param->markSuperBlockDirty = yaffs_MarkSuperBlockDirty;
2867 param->gcControl = yaffs_gc_control_callback;
2869 yaffs_DeviceToContext(dev)->superBlock= sb;
2872 #ifndef CONFIG_YAFFS_DOES_ECC
2873 param->useNANDECC = 1;
2876 #ifdef CONFIG_YAFFS_DISABLE_WIDE_TNODES
2877 param->wideTnodesDisabled = 1;
2880 param->skipCheckpointRead = options.skip_checkpoint_read;
2881 param->skipCheckpointWrite = options.skip_checkpoint_write;
2883 down(&yaffs_context_lock);
2884 /* Get a mount id */
2886 for(mount_id=0; ! found; mount_id++){
2888 ylist_for_each(l,&yaffs_context_list){
2889 context_iterator = ylist_entry(l,struct yaffs_LinuxContext,contextList);
2890 if(context_iterator->mount_id == mount_id)
2894 context->mount_id = mount_id;
2896 ylist_add_tail(&(yaffs_DeviceToContext(dev)->contextList), &yaffs_context_list);
2897 up(&yaffs_context_lock);
2899 /* Directory search handling...*/
2900 YINIT_LIST_HEAD(&(yaffs_DeviceToContext(dev)->searchContexts));
2901 param->removeObjectCallback = yaffs_RemoveObjectCallback;
2903 init_MUTEX(&(yaffs_DeviceToContext(dev)->grossLock));
2905 yaffs_GrossLock(dev);
2907 err = yaffs_GutsInitialise(dev);
2910 (TSTR("yaffs_read_super: guts initialised %s\n"),
2911 (err == YAFFS_OK) ? "OK" : "FAILED"));
2914 yaffs_BackgroundStart(dev);
2916 if(!context->bgThread)
2917 param->deferDirectoryUpdate = 0;
2920 /* Release lock before yaffs_get_inode() */
2921 yaffs_GrossUnlock(dev);
2923 /* Create root inode */
2924 if (err == YAFFS_OK)
2925 inode = yaffs_get_inode(sb, S_IFDIR | 0755, 0,
2931 inode->i_op = &yaffs_dir_inode_operations;
2932 inode->i_fop = &yaffs_dir_operations;
2934 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: got root inode\n")));
2936 root = d_alloc_root(inode);
2938 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: d_alloc_root done\n")));
2945 sb->s_dirt = !dev->isCheckpointed;
2946 T(YAFFS_TRACE_ALWAYS,
2947 (TSTR("yaffs_read_super: isCheckpointed %d\n"),
2948 dev->isCheckpointed));
2950 T(YAFFS_TRACE_OS, (TSTR("yaffs_read_super: done\n")));
2955 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2956 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
2959 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
2962 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2963 static int yaffs_read_super(struct file_system_type *fs,
2964 int flags, const char *dev_name,
2965 void *data, struct vfsmount *mnt)
2968 return get_sb_bdev(fs, flags, dev_name, data,
2969 yaffs_internal_read_super_mtd, mnt);
2972 static struct super_block *yaffs_read_super(struct file_system_type *fs,
2973 int flags, const char *dev_name,
2977 return get_sb_bdev(fs, flags, dev_name, data,
2978 yaffs_internal_read_super_mtd);
2982 static struct file_system_type yaffs_fs_type = {
2983 .owner = THIS_MODULE,
2985 .get_sb = yaffs_read_super,
2986 .kill_sb = kill_block_super,
2987 .fs_flags = FS_REQUIRES_DEV,
2990 static struct super_block *yaffs_read_super(struct super_block *sb, void *data,
2993 return yaffs_internal_read_super(1, sb, data, silent);
2996 static DECLARE_FSTYPE(yaffs_fs_type, "yaffs", yaffs_read_super,
3001 #ifdef CONFIG_YAFFS_YAFFS2
3003 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
3004 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
3007 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
3010 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3011 static int yaffs2_read_super(struct file_system_type *fs,
3012 int flags, const char *dev_name, void *data,
3013 struct vfsmount *mnt)
3015 return get_sb_bdev(fs, flags, dev_name, data,
3016 yaffs2_internal_read_super_mtd, mnt);
3019 static struct super_block *yaffs2_read_super(struct file_system_type *fs,
3020 int flags, const char *dev_name,
3024 return get_sb_bdev(fs, flags, dev_name, data,
3025 yaffs2_internal_read_super_mtd);
3029 static struct file_system_type yaffs2_fs_type = {
3030 .owner = THIS_MODULE,
3032 .get_sb = yaffs2_read_super,
3033 .kill_sb = kill_block_super,
3034 .fs_flags = FS_REQUIRES_DEV,
3037 static struct super_block *yaffs2_read_super(struct super_block *sb,
3038 void *data, int silent)
3040 return yaffs_internal_read_super(2, sb, data, silent);
3043 static DECLARE_FSTYPE(yaffs2_fs_type, "yaffs2", yaffs2_read_super,
3047 #endif /* CONFIG_YAFFS_YAFFS2 */
3049 static struct proc_dir_entry *my_proc_entry;
3050 static struct proc_dir_entry *debug_proc_entry;
3052 static char *yaffs_dump_dev_part0(char *buf, yaffs_Device * dev)
3054 buf += sprintf(buf, "startBlock......... %d\n", dev->param.startBlock);
3055 buf += sprintf(buf, "endBlock........... %d\n", dev->param.endBlock);
3056 buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->param.totalBytesPerChunk);
3057 buf += sprintf(buf, "useNANDECC......... %d\n", dev->param.useNANDECC);
3058 buf += sprintf(buf, "noTagsECC.......... %d\n", dev->param.noTagsECC);
3059 buf += sprintf(buf, "isYaffs2........... %d\n", dev->param.isYaffs2);
3060 buf += sprintf(buf, "inbandTags......... %d\n", dev->param.inbandTags);
3061 buf += sprintf(buf, "emptyLostAndFound.. %d\n", dev->param.emptyLostAndFound);
3062 buf += sprintf(buf, "disableLazyLoad.... %d\n", dev->param.disableLazyLoad);
3063 buf += sprintf(buf, "refreshPeriod...... %d\n", dev->param.refreshPeriod);
3064 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->param.nShortOpCaches);
3065 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->param.nReservedBlocks);
3067 buf += sprintf(buf, "\n");
3073 static char *yaffs_dump_dev_part1(char *buf, yaffs_Device * dev)
3075 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
3076 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
3077 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
3078 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
3079 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
3080 buf += sprintf(buf, "\n");
3081 buf += sprintf(buf, "nTnodes............ %d\n", dev->nTnodes);
3082 buf += sprintf(buf, "nObjects........... %d\n", dev->nObjects);
3083 buf += sprintf(buf, "nFreeChunks........ %d\n", dev->nFreeChunks);
3084 buf += sprintf(buf, "\n");
3085 buf += sprintf(buf, "nPageWrites........ %u\n", dev->nPageWrites);
3086 buf += sprintf(buf, "nPageReads......... %u\n", dev->nPageReads);
3087 buf += sprintf(buf, "nBlockErasures..... %u\n", dev->nBlockErasures);
3088 buf += sprintf(buf, "nGCCopies.......... %u\n", dev->nGCCopies);
3089 buf += sprintf(buf, "allGCs............. %u\n", dev->allGCs);
3090 buf += sprintf(buf, "passiveGCs......... %u\n", dev->passiveGCs);
3091 buf += sprintf(buf, "oldestDirtyGCs..... %u\n", dev->oldestDirtyGCs);
3092 buf += sprintf(buf, "backgroundGCs...... %u\n", dev->backgroundGCs);
3093 buf += sprintf(buf, "nRetriedWrites..... %u\n", dev->nRetriedWrites);
3094 buf += sprintf(buf, "nRetireBlocks...... %u\n", dev->nRetiredBlocks);
3095 buf += sprintf(buf, "eccFixed........... %u\n", dev->eccFixed);
3096 buf += sprintf(buf, "eccUnfixed......... %u\n", dev->eccUnfixed);
3097 buf += sprintf(buf, "tagsEccFixed....... %u\n", dev->tagsEccFixed);
3098 buf += sprintf(buf, "tagsEccUnfixed..... %u\n", dev->tagsEccUnfixed);
3099 buf += sprintf(buf, "cacheHits.......... %u\n", dev->cacheHits);
3100 buf += sprintf(buf, "nDeletedFiles...... %u\n", dev->nDeletedFiles);
3101 buf += sprintf(buf, "nUnlinkedFiles..... %u\n", dev->nUnlinkedFiles);
3102 buf += sprintf(buf, "refreshCount....... %u\n", dev->refreshCount);
3104 sprintf(buf, "nBackgroudDeletions %u\n", dev->nBackgroundDeletions);
3109 static int yaffs_proc_read(char *page,
3111 off_t offset, int count, int *eof, void *data)
3113 struct ylist_head *item;
3118 /* Get proc_file_read() to step 'offset' by one on each sucessive call.
3119 * We use 'offset' (*ppos) to indicate where we are in devList.
3120 * This also assumes the user has posted a read buffer large
3121 * enough to hold the complete output; but that's life in /proc.
3126 /* Print header first */
3128 buf += sprintf(buf, "YAFFS built:" __DATE__ " " __TIME__"\n");
3130 buf += sprintf(buf,"\n");
3134 down(&yaffs_context_lock);
3136 /* Locate and print the Nth entry. Order N-squared but N is small. */
3137 ylist_for_each(item, &yaffs_context_list) {
3138 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3139 yaffs_Device *dev = dc->dev;
3141 if (n < (step & ~1)) {
3146 buf += sprintf(buf, "\nDevice %d \"%s\"\n", n, dev->param.name);
3147 buf = yaffs_dump_dev_part0(buf, dev);
3149 buf = yaffs_dump_dev_part1(buf, dev);
3153 up(&yaffs_context_lock);
3156 return buf - page < count ? buf - page : count;
3159 static int yaffs_stats_proc_read(char *page,
3161 off_t offset, int count, int *eof, void *data)
3163 struct ylist_head *item;
3167 down(&yaffs_context_lock);
3169 /* Locate and print the Nth entry. Order N-squared but N is small. */
3170 ylist_for_each(item, &yaffs_context_list) {
3171 struct yaffs_LinuxContext *dc = ylist_entry(item, struct yaffs_LinuxContext, contextList);
3172 yaffs_Device *dev = dc->dev;
3176 erasedChunks = dev->nErasedBlocks * dev->param.nChunksPerBlock;
3178 buf += sprintf(buf,"%d, %d, %d, %u, %u, %u, %u\n",
3179 n, dev->nFreeChunks, erasedChunks,
3180 dev->backgroundGCs, dev->oldestDirtyGCs,
3181 dev->nObjects, dev->nTnodes);
3183 up(&yaffs_context_lock);
3186 return buf - page < count ? buf - page : count;
3190 * Set the verbosity of the warnings and error messages.
3192 * Note that the names can only be a..z or _ with the current code.
3197 unsigned mask_bitfield;
3199 {"allocate", YAFFS_TRACE_ALLOCATE},
3200 {"always", YAFFS_TRACE_ALWAYS},
3201 {"background", YAFFS_TRACE_BACKGROUND},
3202 {"bad_blocks", YAFFS_TRACE_BAD_BLOCKS},
3203 {"buffers", YAFFS_TRACE_BUFFERS},
3204 {"bug", YAFFS_TRACE_BUG},
3205 {"checkpt", YAFFS_TRACE_CHECKPOINT},
3206 {"deletion", YAFFS_TRACE_DELETION},
3207 {"erase", YAFFS_TRACE_ERASE},
3208 {"error", YAFFS_TRACE_ERROR},
3209 {"gc_detail", YAFFS_TRACE_GC_DETAIL},
3210 {"gc", YAFFS_TRACE_GC},
3211 {"lock", YAFFS_TRACE_LOCK},
3212 {"mtd", YAFFS_TRACE_MTD},
3213 {"nandaccess", YAFFS_TRACE_NANDACCESS},
3214 {"os", YAFFS_TRACE_OS},
3215 {"scan_debug", YAFFS_TRACE_SCAN_DEBUG},
3216 {"scan", YAFFS_TRACE_SCAN},
3217 {"tracing", YAFFS_TRACE_TRACING},
3218 {"sync", YAFFS_TRACE_SYNC},
3219 {"write", YAFFS_TRACE_WRITE},
3221 {"verify", YAFFS_TRACE_VERIFY},
3222 {"verify_nand", YAFFS_TRACE_VERIFY_NAND},
3223 {"verify_full", YAFFS_TRACE_VERIFY_FULL},
3224 {"verify_all", YAFFS_TRACE_VERIFY_ALL},
3226 {"all", 0xffffffff},
3231 #define MAX_MASK_NAME_LENGTH 40
3232 static int yaffs_proc_write_trace_options(struct file *file, const char *buf,
3233 unsigned long count, void *data)
3235 unsigned rg = 0, mask_bitfield;
3239 char substring[MAX_MASK_NAME_LENGTH + 1];
3245 rg = yaffs_traceMask;
3247 while (!done && (pos < count)) {
3249 while ((pos < count) && isspace(buf[pos]))
3266 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3268 if (end > buf + pos) {
3269 mask_name = "numeral";
3270 len = end - (buf + pos);
3274 for (x = buf + pos, i = 0;
3275 (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3276 i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3278 substring[i] = '\0';
3280 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3281 if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3282 mask_name = mask_flags[i].mask_name;
3283 mask_bitfield = mask_flags[i].mask_bitfield;
3290 if (mask_name != NULL) {
3294 rg &= ~mask_bitfield;
3297 rg |= mask_bitfield;
3303 rg |= mask_bitfield;
3309 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3311 printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3313 if (rg & YAFFS_TRACE_ALWAYS) {
3314 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3316 flag = ((rg & mask_flags[i].mask_bitfield) ==
3317 mask_flags[i].mask_bitfield) ? '+' : '-';
3318 printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3326 static int yaffs_proc_write(struct file *file, const char *buf,
3327 unsigned long count, void *data)
3329 return yaffs_proc_write_trace_options(file, buf, count, data);
3332 /* Stuff to handle installation of file systems */
3333 struct file_system_to_install {
3334 struct file_system_type *fst;
3338 static struct file_system_to_install fs_to_install[] = {
3339 {&yaffs_fs_type, 0},
3340 {&yaffs2_fs_type, 0},
3344 static int __init init_yaffs_fs(void)
3347 struct file_system_to_install *fsinst;
3349 T(YAFFS_TRACE_ALWAYS,
3350 (TSTR("yaffs built " __DATE__ " " __TIME__ " Installing. \n")));
3352 #ifdef CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED
3353 T(YAFFS_TRACE_ALWAYS,
3354 (TSTR(" \n\n\n\nYAFFS-WARNING CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED selected.\n\n\n\n")));
3360 init_MUTEX(&yaffs_context_lock);
3362 /* Install the proc_fs entries */
3363 my_proc_entry = create_proc_entry("yaffs",
3367 if (my_proc_entry) {
3368 my_proc_entry->write_proc = yaffs_proc_write;
3369 my_proc_entry->read_proc = yaffs_proc_read;
3370 my_proc_entry->data = NULL;
3374 debug_proc_entry = create_proc_entry("yaffs_stats",
3378 if (debug_proc_entry) {
3379 debug_proc_entry->write_proc = NULL;
3380 debug_proc_entry->read_proc = yaffs_stats_proc_read;
3381 debug_proc_entry->data = NULL;
3385 /* Now add the file system entries */
3387 fsinst = fs_to_install;
3389 while (fsinst->fst && !error) {
3390 error = register_filesystem(fsinst->fst);
3392 fsinst->installed = 1;
3396 /* Any errors? uninstall */
3398 fsinst = fs_to_install;
3400 while (fsinst->fst) {
3401 if (fsinst->installed) {
3402 unregister_filesystem(fsinst->fst);
3403 fsinst->installed = 0;
3412 static void __exit exit_yaffs_fs(void)
3415 struct file_system_to_install *fsinst;
3417 T(YAFFS_TRACE_ALWAYS,
3418 (TSTR("yaffs built " __DATE__ " " __TIME__ " removing. \n")));
3420 remove_proc_entry("yaffs", YPROC_ROOT);
3421 remove_proc_entry("yaffs_stats", YPROC_ROOT);
3423 fsinst = fs_to_install;
3425 while (fsinst->fst) {
3426 if (fsinst->installed) {
3427 unregister_filesystem(fsinst->fst);
3428 fsinst->installed = 0;
3434 module_init(init_yaffs_fs)
3435 module_exit(exit_yaffs_fs)
3437 MODULE_DESCRIPTION("YAFFS2 - a NAND specific flash file system");
3438 MODULE_AUTHOR("Charles Manning, Aleph One Ltd., 2002-2010");
3439 MODULE_LICENSE("GPL");