static const char *yaffs_error_str(void) { int error = yaffsfs_GetLastError(); if (error < 0) error = -error; switch (error) { case EBUSY: return "Busy"; case ENODEV: return "No such device"; case EINVAL: return "Invalid parameter"; case ENFILE: return "Too many open files"; case EBADF: return "Bad handle"; case EACCES: return "Wrong permissions"; case EXDEV: return "Not on same device"; case ENOENT: return "No such entry"; case ENOSPC: return "Device full"; case EROFS: return "Read only file system"; case ERANGE: return "Range error"; case ENOTEMPTY: return "Not empty"; case ENAMETOOLONG: return "Name too long"; case ENOMEM: return "Out of memory"; case EFAULT: return "Fault"; case EEXIST: return "Name exists"; case ENOTDIR: return "Not a directory"; case EISDIR: return "Not permitted on a directory"; case ELOOP: return "Symlink loop"; case 0: return "No error"; default: return "Unknown error"; } }
static void UpdateCounter(const char *name, unsigned *val, int initialise) { int inh=-1; int outh=-1; unsigned x[2]; int nread = 0; int nwritten = 0; x[0] = x[1] = 0; if(initialise){ x[0] = 0; x[1] = 1; } else { inh = yaffs_open(name,O_RDONLY, S_IREAD | S_IWRITE); if(inh >= 0){ nread = yaffs_read(inh,x,sizeof(x)); yaffs_close(inh); } if(nread != sizeof(x) || x[0] + 1 != x[1]){ printf("Error reading counter %s handle %d, x[0] %u x[1] %u last error %d\n", name, inh, x[0], x[1],yaffsfs_GetLastError()); FatalError(); } x[0]++; x[1]++; } outh = yaffs_open(fullTempCounterName, O_RDWR | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE); if(outh >= 0){ nwritten = yaffs_write(outh,x,sizeof(x)); yaffs_close(outh); yaffs_rename(fullTempCounterName,name); } if(nwritten != sizeof(x)){ printf("Error writing counter %s handle %d, x[0] %u x[1] %u\n", name, inh, x[0], x[1]); FatalError(); } *val = x[0]; printf("##\n" "## Set counter %s to %u\n" "##\n", name,x[0]); }