-#ifdef YAFFS_USE_TRUNCATE_SETSIZE
- truncate_setsize(inode, newsize);
- return 0;
-#else
- truncate_inode_pages(&inode->i_data, newsize);
- return 0;
-#endif
-
-}
-
-static unsigned yaffs_gc_control_callback(struct yaffs_dev *dev)
-{
- return yaffs_gc_control;
-}
-
-static void yaffs_gross_lock(struct yaffs_dev *dev)
-{
- yaffs_trace(YAFFS_TRACE_LOCK, "yaffs locking %p", current);
- mutex_lock(&(yaffs_dev_to_lc(dev)->gross_lock));
- yaffs_trace(YAFFS_TRACE_LOCK, "yaffs locked %p", current);
-}
-
-static void yaffs_gross_unlock(struct yaffs_dev *dev)
-{
- yaffs_trace(YAFFS_TRACE_LOCK, "yaffs unlocking %p", current);
- mutex_unlock(&(yaffs_dev_to_lc(dev)->gross_lock));
-}
-
-#ifdef YAFFS_COMPILE_EXPORTFS
-
-static struct inode *yaffs2_nfs_get_inode(struct super_block *sb, uint64_t ino,
- uint32_t generation)
-{
- return Y_IGET(sb, ino);
-}
-
-static struct dentry *yaffs2_fh_to_dentry(struct super_block *sb,
- struct fid *fid, int fh_len,
- int fh_type)
-{
- return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
- yaffs2_nfs_get_inode);
-}
-
-static struct dentry *yaffs2_fh_to_parent(struct super_block *sb,
- struct fid *fid, int fh_len,
- int fh_type)
-{
- return generic_fh_to_parent(sb, fid, fh_len, fh_type,
- yaffs2_nfs_get_inode);
-}
-
-struct dentry *yaffs2_get_parent(struct dentry *dentry)
-{
-
- struct super_block *sb = dentry->d_inode->i_sb;
- struct dentry *parent = ERR_PTR(-ENOENT);
- struct inode *inode;
- unsigned long parent_ino;
- struct yaffs_obj *d_obj;
- struct yaffs_obj *parent_obj;
-
- d_obj = yaffs_inode_to_obj(dentry->d_inode);
-
- if (d_obj) {
- parent_obj = d_obj->parent;
- if (parent_obj) {
- parent_ino = yaffs_get_obj_inode(parent_obj);
- inode = Y_IGET(sb, parent_ino);
-
- if (IS_ERR(inode)) {
- parent = ERR_CAST(inode);
- } else {
- parent = d_obtain_alias(inode);
- if (!IS_ERR(parent)) {
- parent = ERR_PTR(-ENOMEM);
- iput(inode);
- }
- }
- }
- }
-
- return parent;
-}
-
-/* Just declare a zero structure as a NULL value implies
- * using the default functions of exportfs.
- */
-
-static struct export_operations yaffs_export_ops = {
- .fh_to_dentry = yaffs2_fh_to_dentry,
- .fh_to_parent = yaffs2_fh_to_parent,
- .get_parent = yaffs2_get_parent,
-};
-
-#endif
-
-/*-----------------------------------------------------------------*/
-/* Directory search context allows us to unlock access to yaffs during
- * filldir without causing problems with the directory being modified.
- * This is similar to the tried and tested mechanism used in yaffs direct.
- *
- * A search context iterates along a doubly linked list of siblings in the
- * directory. If the iterating object is deleted then this would corrupt
- * the list iteration, likely causing a crash. The search context avoids
- * this by using the remove_obj_fn to move the search context to the
- * next object before the object is deleted.
- *
- * Many readdirs (and thus seach conexts) may be alive simulateously so
- * each struct yaffs_dev has a list of these.
- *
- * A seach context lives for the duration of a readdir.
- *
- * All these functions must be called while yaffs is locked.
- */
-
-struct yaffs_search_context {
- struct yaffs_dev *dev;
- struct yaffs_obj *dir_obj;
- struct yaffs_obj *next_return;
- struct list_head others;
-};
-
-/*
- * yaffs_new_search() creates a new search context, initialises it and
- * adds it to the device's search context list.
- *
- * Called at start of readdir.
- */
-static struct yaffs_search_context *yaffs_new_search(struct yaffs_obj *dir)
-{
- struct yaffs_dev *dev = dir->my_dev;
- struct yaffs_search_context *sc =
- kmalloc(sizeof(struct yaffs_search_context), GFP_NOFS);
- if (sc) {
- sc->dir_obj = dir;
- sc->dev = dev;
- if (list_empty(&sc->dir_obj->variant.dir_variant.children))
- sc->next_return = NULL;
- else
- sc->next_return =
- list_entry(dir->variant.dir_variant.children.next,
- struct yaffs_obj, siblings);
- INIT_LIST_HEAD(&sc->others);
- list_add(&sc->others, &(yaffs_dev_to_lc(dev)->search_contexts));
- }
- return sc;
-}
-
-/*
- * yaffs_search_end() disposes of a search context and cleans up.
- */
-static void yaffs_search_end(struct yaffs_search_context *sc)
-{
- if (sc) {
- list_del(&sc->others);
- kfree(sc);
- }
-}
-
-/*
- * yaffs_search_advance() moves a search context to the next object.
- * Called when the search iterates or when an object removal causes
- * the search context to be moved to the next object.
- */
-static void yaffs_search_advance(struct yaffs_search_context *sc)
-{
- if (!sc)
- return;
-
- if (sc->next_return == NULL ||
- list_empty(&sc->dir_obj->variant.dir_variant.children))
- sc->next_return = NULL;
- else {
- struct list_head *next = sc->next_return->siblings.next;
-
- if (next == &sc->dir_obj->variant.dir_variant.children)
- sc->next_return = NULL; /* end of list */
- else
- sc->next_return =
- list_entry(next, struct yaffs_obj, siblings);
- }
-}
-
-/*
- * yaffs_remove_obj_callback() is called when an object is unlinked.
- * We check open search contexts and advance any which are currently
- * on the object being iterated.
- */
-static void yaffs_remove_obj_callback(struct yaffs_obj *obj)
-{
-
- struct list_head *i;
- struct yaffs_search_context *sc;
- struct list_head *search_contexts =
- &(yaffs_dev_to_lc(obj->my_dev)->search_contexts);
-
- /* Iterate through the directory search contexts.
- * If any are currently on the object being removed, then advance
- * the search context to the next object to prevent a hanging pointer.
- */
- list_for_each(i, search_contexts) {
- sc = list_entry(i, struct yaffs_search_context, others);
- if (sc->next_return == obj)
- yaffs_search_advance(sc);
- }
-
-}
-
-/*-----------------------------------------------------------------*/
-
-static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
- int buflen)
-{
- unsigned char *alias;
- int ret;
-
- struct yaffs_dev *dev = yaffs_dentry_to_obj(dentry)->my_dev;
-
- yaffs_gross_lock(dev);
-
- alias = yaffs_get_symlink_alias(yaffs_dentry_to_obj(dentry));
-
- yaffs_gross_unlock(dev);
-
- if (!alias)
- return -ENOMEM;
-
- ret = vfs_readlink(dentry, buffer, buflen, alias);
- kfree(alias);
- return ret;
-}
-
-#if (YAFFS_NEW_FOLLOW_LINK == 1)
-static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
-{
- void *ret;
-#else
-static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
-{
- int ret
-#endif
- unsigned char *alias;
- int ret_int = 0;
- struct yaffs_dev *dev = yaffs_dentry_to_obj(dentry)->my_dev;
-
- yaffs_gross_lock(dev);
-
- alias = yaffs_get_symlink_alias(yaffs_dentry_to_obj(dentry));
- yaffs_gross_unlock(dev);
-
- if (!alias) {
- ret_int = -ENOMEM;
- goto out;
- }
-#if (YAFFS_NEW_FOLLOW_LINK == 1)
- nd_set_link(nd, alias);
- ret = alias;
-out:
- if (ret_int)
- ret = ERR_PTR(ret_int);
- return ret;
-#else
- ret = vfs_follow_link(nd, alias);
- kfree(alias);
-out:
- if (ret_int)
- ret = ret_int;
- return ret;
-#endif
-}
-
-#if (YAFFS_NEW_FOLLOW_LINK == 1)
-void yaffs_put_link(struct dentry *dentry, struct nameidata *nd, void *alias)
-{
- kfree(alias);
-}
-#endif
-
-struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
- struct yaffs_obj *obj);
-
-/*
- * Lookup is used to find objects in the fs
- */
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
-
-static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
- struct nameidata *n)
-#else
-static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
-#endif
-{
- struct yaffs_obj *obj;
- struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
-
- struct yaffs_dev *dev = yaffs_inode_to_obj(dir)->my_dev;
-
- if (current != yaffs_dev_to_lc(dev)->readdir_process)
- yaffs_gross_lock(dev);
-
- yaffs_trace(YAFFS_TRACE_OS, "yaffs_lookup for %d:%s",
- yaffs_inode_to_obj(dir)->obj_id, dentry->d_name.name);
-
- obj = yaffs_find_by_name(yaffs_inode_to_obj(dir), dentry->d_name.name);
-
- obj = yaffs_get_equivalent_obj(obj); /* in case it was a hardlink */
-
- /* Can't hold gross lock when calling yaffs_get_inode() */
- if (current != yaffs_dev_to_lc(dev)->readdir_process)
- yaffs_gross_unlock(dev);
-
- if (obj) {
- yaffs_trace(YAFFS_TRACE_OS,
- "yaffs_lookup found %d", obj->obj_id);