}
+void format_test(const char *mountpt)
+{
+ int ret;
+
+ yaffs_start_up();
+
+ ret = yaffs_format(mountpt, 0, 0, 0);
+ printf("yaffs_format(...,0, 0, 0) of unmounted returned %d\n", ret);
+
+ yaffs_mount(mountpt);
+
+ ret = yaffs_format(mountpt, 0, 0, 0);
+ printf("yaffs_format(...,0, 0, 0) of mounted returned %d\n", ret);
+
+ ret = yaffs_format(mountpt, 1, 0, 0);
+ printf("yaffs_format(...,1, 0, 0) of mounted returned %d\n", ret);
+
+ ret = yaffs_mount(mountpt);
+ printf("mount should return 0 returned %d\n", ret);
+
+ ret = yaffs_format(mountpt, 1, 0, 1);
+ printf("yaffs_format(...,1, 0, 1) of mounted returned %d\n", ret);
+
+ ret = yaffs_mount(mountpt);
+ printf("mount should return -1 returned %d\n", ret);
+}
int random_seed;
int simulate_power_failure;
// link_follow_test("/yaffs2");
//basic_utime_test("/yaffs2");
- max_files_test("/yaffs2");
+
+ format_test("/yaffs2");
+
+ //max_files_test("/yaffs2");
//start_twice("/yaffs2");
YCFLAGS += -DCONFIG_YAFFS_YAFFS2 -DNO_Y_INLINE
YCFLAGS += -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
+#
+# To enable 32-bit loff_t uncomment the following
+#
+YCFLAGS += -DY_LOFF_T=int
+
CFLAGS += $(YCFLAGS)
CPPFLAGS += $(YCFLAGS)
#
# Inspired yaffs kernel patching script
-set -e -x
+#set -e -x
UBOOTDIR=$1
return yaffs_unmount2(path, 0);
}
+int yaffs_format(const YCHAR *path,
+ int unmount_flag,
+ int force_unmount_flag,
+ int remount_flag)
+{
+ int retVal = 0;
+ struct yaffs_dev *dev = NULL;
+ int result;
+
+ if (!path) {
+ yaffsfs_SetError(-EFAULT);
+ return -1;
+ }
+
+ if (yaffsfs_CheckPath(path) < 0) {
+ yaffsfs_SetError(-ENAMETOOLONG);
+ return -1;
+ }
+
+ yaffsfs_Lock();
+ dev = yaffsfs_FindMountPoint(path);
+
+ if (dev) {
+ int was_mounted = dev->is_mounted;
+
+ if (dev->is_mounted && unmount_flag) {
+ int inUse;
+ yaffs_flush_whole_cache(dev);
+ yaffs_checkpoint_save(dev);
+ inUse = yaffsfs_IsDevBusy(dev);
+ if (!inUse || force_unmount_flag) {
+ if (inUse)
+ yaffsfs_BreakDeviceHandles(dev);
+ yaffs_deinitialise(dev);
+ }
+ }
+
+ if(dev->is_mounted) {
+ yaffsfs_SetError(-EBUSY);
+ retVal = -1;
+ } else {
+ yaffs_format_dev(dev);
+ if(was_mounted && remount_flag) {
+ result = yaffs_guts_initialise(dev);
+ if (result == YAFFS_FAIL) {
+ yaffsfs_SetError(-ENOMEM);
+ retVal = -1;
+ }
+ }
+ }
+ } else {
+ yaffsfs_SetError(-ENODEV);
+ retVal = -1;
+ }
+
+ yaffsfs_Unlock();
+ return retVal;
+
+}
+
+
Y_LOFF_T yaffs_freespace(const YCHAR *path)
{
Y_LOFF_T retVal = -1;
int yaffs_unmount2(const YCHAR *path, int force);
int yaffs_remount(const YCHAR *path, int force, int read_only);
+int yaffs_format(const YCHAR *path,
+ int unmount_flag,
+ int force_unmount_flag,
+ int remount_flag);
int yaffs_sync(const YCHAR *path) ;
return n_free;
}
+
+int yaffs_format_dev(struct yaffs_dev *dev)
+{
+ int i;
+ enum yaffs_block_state state;
+ u32 dummy;
+
+ if(dev->is_mounted)
+ return YAFFS_FAIL;
+
+ /*
+ * The runtime variables might not have been set up,
+ * so set up what we need.
+ */
+ dev->internal_start_block = dev->param.start_block;
+ dev->internal_end_block = dev->param.end_block;
+ dev->block_offset = 0;
+ dev->chunk_offset = 0;
+
+ if (dev->param.start_block == 0) {
+ dev->internal_start_block = dev->param.start_block + 1;
+ dev->internal_end_block = dev->param.end_block + 1;
+ dev->block_offset = 1;
+ dev->chunk_offset = dev->param.chunks_per_block;
+ }
+
+ for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) {
+ yaffs_query_init_block_state(dev, i, &state, &dummy);
+ if (state != YAFFS_BLOCK_STATE_DEAD)
+ yaffs_erase_block(dev, i);
+ }
+
+ return YAFFS_OK;
+}
+
+
/*
* Marshalling functions to get loff_t file sizes into and out of
* object headers.
int yaffs_is_non_empty_dir(struct yaffs_obj *obj);
+int yaffs_format_dev(struct yaffs_dev *dev);
+
void yaffs_addr_to_chunk(struct yaffs_dev *dev, loff_t addr,
int *chunk_out, u32 *offset_out);
/*