X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=a26998439ccefd2f0d4fe6b2119c15e65dee3cf1;hp=def672dbafc783a9fbc2c0c034ad8ec4635821c5;hb=a18ab52ca5907e885dcf3b8f31639c77c0641ee2;hpb=5587d9d89d5fb9c31fd723e85949f85da70ef3a9 diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index def672d..a269984 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -122,6 +122,8 @@ static void yaffsfs_InitHandles(void) if (yaffsfs_handlesInitialised) return; + yaffsfs_handlesInitialised = 1; + memset(yaffsfs_inode, 0, sizeof(yaffsfs_inode)); memset(yaffsfs_fd, 0, sizeof(yaffsfs_fd)); memset(yaffsfs_handle, 0, sizeof(yaffsfs_handle)); @@ -2661,6 +2663,67 @@ int yaffs_unmount(const YCHAR *path) 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;