findfreeblock.c 570 B

12345678910111213141516171819202122232425262728
  1. #include "logfsos.h"
  2. #include "logfs.h"
  3. #include "nandfs.h"
  4. #include "local.h"
  5. long
  6. nandfsfindfreeblock(Nandfs *nandfs, long *freeblocksp)
  7. {
  8. long bestnewblock;
  9. long bestnerase;
  10. long i;
  11. if (freeblocksp)
  12. *freeblocksp = 0;
  13. for (i = 0, bestnewblock = -1, bestnerase = 0x7fffffff; i < nandfs->ll.blocks; i++) {
  14. long nerase;
  15. if (nandfsgettag(nandfs, i) == LogfsTnone) {
  16. if (freeblocksp) {
  17. (*freeblocksp)++;
  18. }
  19. if ((nerase = nandfsgetnerase(nandfs, i)) < bestnerase) {
  20. bestnewblock = i;
  21. bestnerase = nerase;
  22. }
  23. }
  24. }
  25. return bestnewblock;
  26. }