X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=yaffs_guts.c;h=8acb59ba655bae1b3029c037e14acc1dd4e70a03;hp=6166d985a62708dc35f67e9e8123a195b6f299f6;hb=1658295946bc589b4d351e75a59bd697630cd9e1;hpb=fc4028b21ae665f45c149e66b10d13374721383c diff --git a/yaffs_guts.c b/yaffs_guts.c index 6166d98..8acb59b 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -280,7 +280,8 @@ static void yaffs_handle_chunk_wr_error(struct yaffs_dev *dev, int nand_chunk, static inline int yaffs_hash_fn(int n) { - n = abs(n); + if(n < 0) + n = -n; return n % YAFFS_NOBJECT_BUCKETS; } @@ -696,6 +697,11 @@ void yaffs_set_obj_name_from_oh(struct yaffs_obj *obj, #endif } +loff_t yaffs_max_file_size(struct yaffs_dev *dev) +{ + return ((loff_t) YAFFS_MAX_CHUNK_ID) * dev->data_bytes_per_chunk; +} + /*-------------------- TNODES ------------------- * List of spare tnodes @@ -1953,7 +1959,8 @@ struct yaffs_obj *yaffs_new_obj(struct yaffs_dev *dev, int number, 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.shrink_size = ~0; /* max */ + the_obj->variant.file_variant.shrink_size = + yaffs_max_file_size(dev); the_obj->variant.file_variant.top_level = 0; the_obj->variant.file_variant.top = tn; break; @@ -3681,17 +3688,26 @@ int yaffs_wr_file(struct yaffs_obj *in, const u8 *buffer, loff_t offset, /* ---------------------- File resizing stuff ------------------ */ -static void yaffs_prune_chunks(struct yaffs_obj *in, int new_size) +static void yaffs_prune_chunks(struct yaffs_obj *in, loff_t new_size) { struct yaffs_dev *dev = in->my_dev; - int old_size = in->variant.file_variant.file_size; + loff_t old_size = in->variant.file_variant.file_size; int i; int chunk_id; - int last_del = 1 + (old_size - 1) / dev->data_bytes_per_chunk; - int start_del = 1 + (new_size + dev->data_bytes_per_chunk - 1) / - dev->data_bytes_per_chunk; + u32 dummy; + int last_del; + int start_del; + + if(old_size > 0) + yaffs_addr_to_chunk(dev, old_size - 1, &last_del, &dummy); + else + last_del = 0; + yaffs_addr_to_chunk(dev, new_size + dev->data_bytes_per_chunk - 1, + &start_del, &dummy); + last_del++; + start_del++; /* Delete backwards so that we don't end up with holes if * power is lost part-way through the operation.