- list_for_each_safe(lh, n, &dev->obj_bucket[i].list) {
- if (lh) {
- obj =
- list_entry(lh, struct yaffs_obj, hash_link);
- parent = obj->parent;
-
- if (yaffs_has_null_parent(dev, obj)) {
- /* These directories are not hanging */
- hanging = 0;
- } else if (!parent
- || parent->variant_type !=
- YAFFS_OBJECT_TYPE_DIRECTORY) {
- hanging = 1;
- } else if (yaffs_has_null_parent(dev, parent)) {
- hanging = 0;
- } else {
- /*
- * Need to follow the parent chain to see if it is hanging.
- */
- hanging = 0;
- depth_limit = 100;
-
- while (parent != dev->root_dir &&
- parent->parent &&
- parent->parent->variant_type ==
- YAFFS_OBJECT_TYPE_DIRECTORY
- && depth_limit > 0) {
- parent = parent->parent;
- depth_limit--;
- }
- if (parent != dev->root_dir)
- hanging = 1;
- }
- if (hanging) {
- T(YAFFS_TRACE_SCAN,
- (TSTR
- ("Hanging object %d moved to lost and found"
- TENDSTR), obj->obj_id));
- yaffs_add_obj_to_dir(dev->lost_n_found,
- obj);
- }
- }
- }
- }
-}
-
-/*
- * Delete directory contents for cleaning up lost and found.
- */
-static void yaffs_del_dir_contents(struct yaffs_obj *dir)
-{
- struct yaffs_obj *obj;
- struct list_head *lh;
- struct list_head *n;
-
- if (dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
- YBUG();
-
- list_for_each_safe(lh, n, &dir->variant.dir_variant.children) {
- if (lh) {
- obj = list_entry(lh, struct yaffs_obj, siblings);
- if (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY)
- yaffs_del_dir_contents(obj);
-
- T(YAFFS_TRACE_SCAN,
- (TSTR("Deleting lost_found object %d" TENDSTR),
- obj->obj_id));
-
- /* Need to use UnlinkObject since Delete would not handle
- * hardlinked objects correctly.
- */
- yaffs_unlink_obj(obj);
- }
- }
-
-}
-
-static void yaffs_empty_l_n_f(struct yaffs_dev *dev)
-{
- yaffs_del_dir_contents(dev->lost_n_found);
-}
-
-static void yaffs_check_obj_details_loaded(struct yaffs_obj *in)
-{
- u8 *chunk_data;
- struct yaffs_obj_hdr *oh;
- struct yaffs_dev *dev;
- struct yaffs_ext_tags tags;
- int result;
- int alloc_failed = 0;
-
- if (!in)
- return;
-
- dev = in->my_dev;
-
- if (in->lazy_loaded && in->hdr_chunk > 0) {
- in->lazy_loaded = 0;
- chunk_data = yaffs_get_temp_buffer(dev, __LINE__);
-
- result =
- yaffs_rd_chunk_tags_nand(dev, in->hdr_chunk, chunk_data,
- &tags);
- oh = (struct yaffs_obj_hdr *)chunk_data;
-
- in->yst_mode = oh->yst_mode;
- yaffs_load_attribs(in, oh);
- yaffs_set_obj_name_from_oh(in, oh);
-
- if (in->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
- in->variant.symlink_variant.alias =
- yaffs_clone_str(oh->alias);
- if (!in->variant.symlink_variant.alias)
- alloc_failed = 1; /* Not returned to caller */
- }
-
- yaffs_release_temp_buffer(dev, chunk_data, __LINE__);
- }
-}
-
-/*------------------------------ Directory Functions ----------------------------- */
-
-/*
- *yaffs_update_parent() handles fixing a directories mtime and ctime when a new
- * link (ie. name) is created or deleted in the directory.
- *
- * ie.
- * create dir/a : update dir's mtime/ctime
- * rm dir/a: update dir's mtime/ctime
- * modify dir/a: don't update dir's mtimme/ctime
- *
- * This can be handled immediately or defered. Defering helps reduce the number
- * of updates when many files in a directory are changed within a brief period.
- *
- * If the directory updating is defered then yaffs_update_dirty_dirs must be
- * called periodically.
- */
-
-static void yaffs_update_parent(struct yaffs_obj *obj)
-{
- struct yaffs_dev *dev;
- if (!obj)
- return;
- dev = obj->my_dev;
- obj->dirty = 1;
- yaffs_load_current_time(obj, 0, 1);
- if (dev->param.defered_dir_update) {
- struct list_head *link = &obj->variant.dir_variant.dirty;
-
- if (list_empty(link)) {
- list_add(link, &dev->dirty_dirs);
- T(YAFFS_TRACE_BACKGROUND,
- (TSTR("Added object %d to dirty directories" TENDSTR),
- obj->obj_id));
- }
-
- } else {
- yaffs_update_oh(obj, NULL, 0, 0, 0, NULL);
- }
-}
-
-void yaffs_update_dirty_dirs(struct yaffs_dev *dev)
-{
- struct list_head *link;
- struct yaffs_obj *obj;
- struct yaffs_dir_var *d_s;
- union yaffs_obj_var *o_v;
-
- T(YAFFS_TRACE_BACKGROUND, (TSTR("Update dirty directories" TENDSTR)));
-
- while (!list_empty(&dev->dirty_dirs)) {
- link = dev->dirty_dirs.next;
- list_del_init(link);
-
- d_s = list_entry(link, struct yaffs_dir_var, dirty);
- o_v = list_entry(d_s, union yaffs_obj_var, dir_variant);
- obj = list_entry(o_v, struct yaffs_obj, variant);
-
- T(YAFFS_TRACE_BACKGROUND,
- (TSTR("Update directory %d" TENDSTR), obj->obj_id));
-
- if (obj->dirty)
- yaffs_update_oh(obj, NULL, 0, 0, 0, NULL);
- }
-}
-
-static void yaffs_remove_obj_from_dir(struct yaffs_obj *obj)
-{
- struct yaffs_dev *dev = obj->my_dev;
- struct yaffs_obj *parent;
-
- yaffs_verify_obj_in_dir(obj);
- parent = obj->parent;
-
- yaffs_verify_dir(parent);
-
- if (dev && dev->param.remove_obj_fn)
- dev->param.remove_obj_fn(obj);
-
- list_del_init(&obj->siblings);
- obj->parent = NULL;
-
- yaffs_verify_dir(parent);
-}
-
-void yaffs_add_obj_to_dir(struct yaffs_obj *directory, struct yaffs_obj *obj)
-{
- if (!directory) {
- T(YAFFS_TRACE_ALWAYS,
- (TSTR
- ("tragedy: Trying to add an object to a null pointer directory"
- TENDSTR)));
- YBUG();
- return;
- }
- if (directory->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) {
- T(YAFFS_TRACE_ALWAYS,
- (TSTR
- ("tragedy: Trying to add an object to a non-directory"
- TENDSTR)));
- YBUG();
- }
-
- if (obj->siblings.prev == NULL) {
- /* Not initialised */
- YBUG();
+ list_for_each_safe(lh, n, &dev->obj_bucket[i].list) {
+ obj = list_entry(lh, struct yaffs_obj, hash_link);
+ parent = obj->parent;
+
+ if (yaffs_has_null_parent(dev, obj)) {
+ /* These directories are not hanging */
+ hanging = 0;
+ } else if (!parent ||
+ parent->variant_type !=
+ YAFFS_OBJECT_TYPE_DIRECTORY) {
+ hanging = 1;
+ } else if (yaffs_has_null_parent(dev, parent)) {
+ hanging = 0;
+ } else {
+ /*
+ * Need to follow the parent chain to
+ * see if it is hanging.
+ */
+ hanging = 0;
+ depth_limit = 100;
+
+ while (parent != dev->root_dir &&
+ parent->parent &&
+ parent->parent->variant_type ==
+ YAFFS_OBJECT_TYPE_DIRECTORY &&
+ depth_limit > 0) {
+ parent = parent->parent;
+ depth_limit--;
+ }
+ if (parent != dev->root_dir)
+ hanging = 1;
+ }
+ if (hanging) {
+ yaffs_trace(YAFFS_TRACE_SCAN,
+ "Hanging object %d moved to lost and found",
+ obj->obj_id);
+ yaffs_add_obj_to_dir(dev->lost_n_found, obj);
+ }
+ }