fsdelete.c
836 Bytes
#include <PR/bcp.h>
#include "os.h"
#include "os_bbfs.h"
#include "bbint.h"
s32
osBbFDelete(const char* name) {
unsigned char fname[BB_INODE16_NAMELEN];
s32 rv;
BbFat16* fat;
int i;
__osBbFsFormatName(fname, name);
if (!fname[0]) return BBFS_ERR_INVALID;
if ((rv = __osBbFsGetAccess()) < 0) return rv;
fat = __osBbFat;
rv = BBFS_ERR_ENTRY;
for(i = 0; i < BB_INODE16_ENTRIES; i++) {
if (fat->inode[i].type &&
bcmp(fname, fat->inode[i].name, BB_INODE16_NAMELEN) == 0) {
u16 b;
/* free all of the blocks */
for(b = fat->inode[i].block; b != BB_FAT_LAST; ) {
u16 o = BB_FAT16_NEXT(fat,b);
BB_FAT16_NEXT(fat,b) = BB_FAT_AVAIL;
b = o;
}
bzero(fat->inode+i, sizeof(BbInode));
rv = __osBbFsSync(0);
break;
}
}
__osBbFsRelAccess();
return rv;
}