X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=7ee486a8d0d95cb2afa2dcd2eb69dd368db441de;hb=54721f22512e7c859c4c4a4ae7e5374ecf7fb570;hp=2917a5d817b53d75a6772c0ba04311a495fe4ff2;hpb=f579840dc5fa33617b3c99bf184024373941066a;p=yaffs2.git diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 2917a5d..7ee486a 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -501,6 +501,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 +2661,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;