Add ability to hide lost_n_found directory
[yaffs2.git] / yaffs_guts.c
index 1c0ae71320a52fc5645e09fd76e5203c348ab8c7..c89b29ca86f7c92c8a56344698ef8e7515e35b82 100644 (file)
@@ -1922,21 +1922,18 @@ static int yaffs_new_obj_id(struct yaffs_dev *dev)
        struct list_head *i;
        u32 n = (u32) bucket;
 
-       /* Now find an object value that has not already been taken
-        * by scanning the list.
+       /*
+        * Now find an object value that has not already been taken
+        * by scanning the list, incrementing each time by number of buckets.
         */
-
        while (!found) {
                found = 1;
                n += YAFFS_NOBJECT_BUCKETS;
-               if (1 || dev->obj_bucket[bucket].count > 0) {
-                       list_for_each(i, &dev->obj_bucket[bucket].list) {
-                               /* If there is already one in the list */
-                               if (i && list_entry(i, struct yaffs_obj,
-                                                   hash_link)->obj_id == n) {
-                                       found = 0;
-                               }
-                       }
+               list_for_each(i, &dev->obj_bucket[bucket].list) {
+                       /* Check if this value is already taken. */
+                       if (i && list_entry(i, struct yaffs_obj,
+                                           hash_link)->obj_id == n)
+                               found = 0;
                }
        }
        return n;
@@ -2004,7 +2001,7 @@ static struct yaffs_obj *yaffs_new_obj(struct yaffs_dev *dev, int number,
        switch (type) {
        case YAFFS_OBJECT_TYPE_FILE:
                the_obj->variant.file_variant.file_size = 0;
-               the_obj->variant.file_variant.scanned_size = 0;
+               the_obj->variant.file_variant.stored_size = 0;
                the_obj->variant.file_variant.shrink_size =
                                                yaffs_max_file_size(dev);
                the_obj->variant.file_variant.top_level = 0;
@@ -2550,9 +2547,9 @@ static inline int yaffs_gc_process_chunk(struct yaffs_dev *dev,
                        /* Update file size */
                        if (object->variant_type == YAFFS_OBJECT_TYPE_FILE) {
                                yaffs_oh_size_load(oh,
-                                   object->variant.file_variant.file_size);
+                                   object->variant.file_variant.stored_size);
                                tags.extra_file_size =
-                                   object->variant.file_variant.file_size;
+                                   object->variant.file_variant.stored_size;
                        }
 
                        yaffs_verify_oh(object, oh, &tags, 1);
@@ -3053,6 +3050,7 @@ static int yaffs_wr_data_obj(struct yaffs_obj *in, int inode_chunk,
        int new_chunk_id;
        struct yaffs_ext_tags new_tags;
        struct yaffs_dev *dev = in->my_dev;
+       loff_t endpos;
 
        yaffs_check_gc(dev, 0);
 
@@ -3074,13 +3072,24 @@ static int yaffs_wr_data_obj(struct yaffs_obj *in, int inode_chunk,
            (prev_chunk_id > 0) ? prev_tags.serial_number + 1 : 1;
        new_tags.n_bytes = n_bytes;
 
-       if (n_bytes < 1 || n_bytes > dev->param.total_bytes_per_chunk) {
+       if (n_bytes < 1 || n_bytes > dev->data_bytes_per_chunk) {
                yaffs_trace(YAFFS_TRACE_ERROR,
                  "Writing %d bytes to chunk!!!!!!!!!",
                   n_bytes);
                BUG();
        }
 
+       /*
+        * If this is a data chunk and the write goes past the end of the stored
+        * size then update the stored_size.
+        */
+       if (inode_chunk > 0) {
+               endpos =  (inode_chunk - 1) * dev->data_bytes_per_chunk +
+                               n_bytes;
+               if (in->variant.file_variant.stored_size < endpos)
+                       in->variant.file_variant.stored_size = endpos;
+       }
+
        new_chunk_id =
            yaffs_write_new_chunk(dev, buffer, &new_tags, use_reserve);
 
@@ -3093,7 +3102,6 @@ static int yaffs_wr_data_obj(struct yaffs_obj *in, int inode_chunk,
                yaffs_verify_file_sane(in);
        }
        return new_chunk_id;
-
 }
 
 
@@ -3322,7 +3330,7 @@ int yaffs_update_oh(struct yaffs_obj *in, const YCHAR *name, int force,
        case YAFFS_OBJECT_TYPE_FILE:
                if (oh->parent_obj_id != YAFFS_OBJECTID_DELETED &&
                    oh->parent_obj_id != YAFFS_OBJECTID_UNLINKED)
-                       file_size = in->variant.file_variant.file_size;
+                       file_size = in->variant.file_variant.stored_size;
                yaffs_oh_size_load(oh, file_size);
                break;
        case YAFFS_OBJECT_TYPE_HARDLINK:
@@ -3743,6 +3751,7 @@ void yaffs_resize_file_down(struct yaffs_obj *obj, loff_t new_size)
        }
 
        obj->variant.file_variant.file_size = new_size;
+       obj->variant.file_variant.stored_size = new_size;
 
        yaffs_prune_tree(dev, &obj->variant.file_variant);
 }
@@ -4083,7 +4092,7 @@ static int yaffs_unlink_worker(struct yaffs_obj *obj)
        }
 }
 
-static int yaffs_unlink_obj(struct yaffs_obj *obj)
+int yaffs_unlink_obj(struct yaffs_obj *obj)
 {
        if (obj && obj->unlink_allowed)
                return yaffs_unlink_worker(obj);
@@ -4626,8 +4635,11 @@ static int yaffs_check_dev_fns(struct yaffs_dev *dev)
 static int yaffs_create_initial_dir(struct yaffs_dev *dev)
 {
        /* Initialise the unlinked, deleted, root and lost+found directories */
-       dev->lost_n_found = dev->root_dir = NULL;
-       dev->unlinked_dir = dev->del_dir = NULL;
+       dev->lost_n_found = NULL;
+       dev->root_dir = NULL;
+       dev->unlinked_dir = NULL;
+       dev->del_dir = NULL;
+
        dev->unlinked_dir =
            yaffs_create_fake_dir(dev, YAFFS_OBJECTID_UNLINKED, S_IFDIR);
        dev->del_dir =
@@ -4639,9 +4651,15 @@ static int yaffs_create_initial_dir(struct yaffs_dev *dev)
            yaffs_create_fake_dir(dev, YAFFS_OBJECTID_LOSTNFOUND,
                                  YAFFS_LOSTNFOUND_MODE | S_IFDIR);
 
-       if (dev->lost_n_found && dev->root_dir && dev->unlinked_dir
-           && dev->del_dir) {
-               yaffs_add_obj_to_dir(dev->root_dir, dev->lost_n_found);
+       if (dev->lost_n_found &&
+               dev->root_dir &&
+               dev->unlinked_dir &&
+               dev->del_dir) {
+                       /* If lost-n-found is hidden then yank it out of the directory tree. */
+                       if (dev->param.hide_lost_n_found)
+                               list_del_init(&dev->lost_n_found->siblings);
+                       else
+                               yaffs_add_obj_to_dir(dev->root_dir, dev->lost_n_found);
                return YAFFS_OK;
        }
        return YAFFS_FAIL;
@@ -5022,8 +5040,15 @@ void yaffs_deinitialise(struct yaffs_dev *dev)
 
                kfree(dev->gc_cleanup_list);
 
-               for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++)
+               for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
                        kfree(dev->temp_buffer[i].buffer);
+                       dev->temp_buffer[i].buffer = NULL;
+               }
+
+               kfree(dev->checkpt_buffer);
+               dev->checkpt_buffer = NULL;
+               kfree(dev->checkpt_block_list);
+               dev->checkpt_block_list = NULL;
 
                dev->is_mounted = 0;