X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=a26998439ccefd2f0d4fe6b2119c15e65dee3cf1;hp=2917a5d817b53d75a6772c0ba04311a495fe4ff2;hb=e5daa72b0083831ab762a650860687fe7d25d6b3;hpb=f579840dc5fa33617b3c99bf184024373941066a diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 2917a5d..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)); @@ -501,6 +503,9 @@ static struct yaffs_dev *yaffsfs_FindDevice(const YCHAR *path, thisMatchLength = 0; matching = 1; + if(!p) + continue; + while (matching && *p && *leftOver) { /* Skip over any /s */ while (yaffsfs_IsPathDivider(*p)) @@ -2658,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;