- unsigned long parent_ino;
- yaffs_Object *d_obj;
- yaffs_Object *parent_obj;
-
- d_obj = yaffs_InodeToObject(dentry->d_inode);
-
- if (d_obj) {
- parent_obj = d_obj->parent;
- if (parent_obj) {
- parent_ino = yaffs_GetObjectInode(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 removeObjectCallback 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 yaffs_Device 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_SearchContext {
- yaffs_Device *dev;
- yaffs_Object *dirObj;
- yaffs_Object *nextReturn;
- struct ylist_head others;
-};
-
-/*
- * yaffs_NewSearch() 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_SearchContext * yaffs_NewSearch(yaffs_Object *dir)
-{
- yaffs_Device *dev = dir->myDev;
- struct yaffs_SearchContext *sc = YMALLOC(sizeof(struct yaffs_SearchContext));
- if(sc){
- sc->dirObj = dir;
- sc->dev = dev;
- if( ylist_empty(&sc->dirObj->variant.directoryVariant.children))
- sc->nextReturn = NULL;
- else
- sc->nextReturn = ylist_entry(
- dir->variant.directoryVariant.children.next,
- yaffs_Object,siblings);
- YINIT_LIST_HEAD(&sc->others);
- ylist_add(&sc->others,&(yaffs_DeviceToLC(dev)->searchContexts));
- }
- return sc;
-}
-
-/*
- * yaffs_EndSearch() disposes of a search context and cleans up.
- */
-static void yaffs_EndSearch(struct yaffs_SearchContext * sc)
-{
- if(sc){
- ylist_del(&sc->others);
- YFREE(sc);
- }
-}
-
-/*
- * yaffs_SearchAdvance() 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_SearchAdvance(struct yaffs_SearchContext *sc)
-{
- if(!sc)
- return;
-
- if( sc->nextReturn == NULL ||
- ylist_empty(&sc->dirObj->variant.directoryVariant.children))
- sc->nextReturn = NULL;
- else {
- struct ylist_head *next = sc->nextReturn->siblings.next;
-
- if( next == &sc->dirObj->variant.directoryVariant.children)
- sc->nextReturn = NULL; /* end of list */
- else
- sc->nextReturn = ylist_entry(next,yaffs_Object,siblings);
- }
-}
-
-/*
- * yaffs_RemoveObjectCallback() 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_RemoveObjectCallback(yaffs_Object *obj)
-{
-
- struct ylist_head *i;
- struct yaffs_SearchContext *sc;
- struct ylist_head *search_contexts = &(yaffs_DeviceToLC(obj->myDev)->searchContexts);
-
-
- /* 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.
- */
- ylist_for_each(i, search_contexts) {
- if (i) {
- sc = ylist_entry(i, struct yaffs_SearchContext,others);
- if(sc->nextReturn == obj)
- yaffs_SearchAdvance(sc);
- }
- }
-
-}
-
-
-/*-----------------------------------------------------------------*/
-
-static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
- int buflen)
-{
- unsigned char *alias;
- int ret;
-
- yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
-
- yaffs_GrossLock(dev);
-
- alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
-
- yaffs_GrossUnlock(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)
-#else
-static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
-#endif
-{
- unsigned char *alias;
- int ret;
- yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
-
- yaffs_GrossLock(dev);
-
- alias = yaffs_GetSymlinkAlias(yaffs_DentryToObject(dentry));
- yaffs_GrossUnlock(dev);
-
- if (!alias) {
- ret = -ENOMEM;
- goto out;
- }
-
-#if (YAFFS_NEW_FOLLOW_LINK == 1)
- nd_set_link(nd, alias);
- ret = (int)alias;
-out:
- return ERR_PTR(ret);
-#else
- ret = vfs_follow_link(nd, alias);
- kfree(alias);
-out:
- 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,
- yaffs_Object *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
-{
- yaffs_Object *obj;
- struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
-
- yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
-
- if(current != yaffs_DeviceToLC(dev)->readdirProcess)
- yaffs_GrossLock(dev);
-
- T(YAFFS_TRACE_OS,
- (TSTR("yaffs_lookup for %d:%s\n"),
- yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
-
- obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
- dentry->d_name.name);
-
- obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */