Lines Matching refs:dir

264 static int lfs1_pred(lfs1_t *lfs1, const lfs1_block_t dir[2], lfs1_dir_t *pdir);
265 static int lfs1_parent(lfs1_t *lfs1, const lfs1_block_t dir[2],
353 d->u.dir[0] = lfs1_fromle32(d->u.dir[0]); in lfs1_entry_fromle32()
354 d->u.dir[1] = lfs1_fromle32(d->u.dir[1]); in lfs1_entry_fromle32()
358 d->u.dir[0] = lfs1_tole32(d->u.dir[0]); in lfs1_entry_tole32()
359 d->u.dir[1] = lfs1_tole32(d->u.dir[1]); in lfs1_entry_tole32()
408 static int lfs1_dir_alloc(lfs1_t *lfs1, lfs1_dir_t *dir) { in lfs1_dir_alloc() argument
411 int err = lfs1_alloc(lfs1, &dir->pair[i]); in lfs1_dir_alloc()
419 int err = lfs1_bd_read(lfs1, dir->pair[0], 0, &dir->d.rev, 4); in lfs1_dir_alloc()
425 dir->d.rev = lfs1_fromle32(dir->d.rev); in lfs1_dir_alloc()
429 dir->d.rev += 1; in lfs1_dir_alloc()
430 dir->d.size = sizeof(dir->d)+4; in lfs1_dir_alloc()
431 dir->d.tail[0] = 0xffffffff; in lfs1_dir_alloc()
432 dir->d.tail[1] = 0xffffffff; in lfs1_dir_alloc()
433 dir->off = sizeof(dir->d); in lfs1_dir_alloc()
440 lfs1_dir_t *dir, const lfs1_block_t pair[2]) { in lfs1_dir_fetch() argument
457 if (valid && lfs1_scmp(test.rev, dir->d.rev) < 0) { in lfs1_dir_fetch()
486 dir->pair[0] = tpair[(i+0) % 2]; in lfs1_dir_fetch()
487 dir->pair[1] = tpair[(i+1) % 2]; in lfs1_dir_fetch()
488 dir->off = sizeof(dir->d); in lfs1_dir_fetch()
489 dir->d = test; in lfs1_dir_fetch()
508 static int lfs1_dir_commit(lfs1_t *lfs1, lfs1_dir_t *dir, in lfs1_dir_commit() argument
511 dir->d.rev += 1; in lfs1_dir_commit()
514 lfs1_pairswap(dir->pair); in lfs1_dir_commit()
516 dir->d.size += regions[i].newlen - regions[i].oldlen; in lfs1_dir_commit()
519 const lfs1_block_t oldpair[2] = {dir->pair[0], dir->pair[1]}; in lfs1_dir_commit()
524 int err = lfs1_bd_erase(lfs1, dir->pair[0]); in lfs1_dir_commit()
533 lfs1_dir_tole32(&dir->d); in lfs1_dir_commit()
534 lfs1_crc(&crc, &dir->d, sizeof(dir->d)); in lfs1_dir_commit()
535 err = lfs1_bd_prog(lfs1, dir->pair[0], 0, &dir->d, sizeof(dir->d)); in lfs1_dir_commit()
536 lfs1_dir_fromle32(&dir->d); in lfs1_dir_commit()
545 lfs1_off_t oldoff = sizeof(dir->d); in lfs1_dir_commit()
546 lfs1_off_t newoff = sizeof(dir->d); in lfs1_dir_commit()
547 while (newoff < (0x7fffffff & dir->d.size)-4) { in lfs1_dir_commit()
550 err = lfs1_bd_prog(lfs1, dir->pair[0], in lfs1_dir_commit()
570 err = lfs1_bd_prog(lfs1, dir->pair[0], newoff, &data, 1); in lfs1_dir_commit()
584 err = lfs1_bd_prog(lfs1, dir->pair[0], newoff, &crc, 4); in lfs1_dir_commit()
603 err = lfs1_bd_crc(lfs1, dir->pair[0], 0, in lfs1_dir_commit()
604 (0x7fffffff & dir->d.size)-4, &ncrc); in lfs1_dir_commit()
617 LFS1_DEBUG("Bad block at %" PRIu32, dir->pair[0]); in lfs1_dir_commit()
631 int err = lfs1_alloc(lfs1, &dir->pair[0]); in lfs1_dir_commit()
640 oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]); in lfs1_dir_commit()
641 int err = lfs1_relocate(lfs1, oldpair, dir->pair); in lfs1_dir_commit()
649 if (lfs1_paircmp(d->pair, dir->pair) == 0) { in lfs1_dir_commit()
650 d->pair[0] = dir->pair[0]; in lfs1_dir_commit()
651 d->pair[1] = dir->pair[1]; in lfs1_dir_commit()
658 static int lfs1_dir_update(lfs1_t *lfs1, lfs1_dir_t *dir, in lfs1_dir_update() argument
661 int err = lfs1_dir_commit(lfs1, dir, (struct lfs1_region[]){ in lfs1_dir_update()
669 static int lfs1_dir_append(lfs1_t *lfs1, lfs1_dir_t *dir, in lfs1_dir_append() argument
673 if (dir->d.size + lfs1_entry_size(entry) <= lfs1->cfg->block_size) { in lfs1_dir_append()
674 entry->off = dir->d.size - 4; in lfs1_dir_append()
677 int err = lfs1_dir_commit(lfs1, dir, (struct lfs1_region[]){ in lfs1_dir_append()
686 if (!(0x80000000 & dir->d.size)) { in lfs1_dir_append()
687 lfs1_dir_t olddir = *dir; in lfs1_dir_append()
688 int err = lfs1_dir_alloc(lfs1, dir); in lfs1_dir_append()
693 dir->d.tail[0] = olddir.d.tail[0]; in lfs1_dir_append()
694 dir->d.tail[1] = olddir.d.tail[1]; in lfs1_dir_append()
695 entry->off = dir->d.size - 4; in lfs1_dir_append()
697 err = lfs1_dir_commit(lfs1, dir, (struct lfs1_region[]){ in lfs1_dir_append()
707 olddir.d.tail[0] = dir->pair[0]; in lfs1_dir_append()
708 olddir.d.tail[1] = dir->pair[1]; in lfs1_dir_append()
712 int err = lfs1_dir_fetch(lfs1, dir, dir->d.tail); in lfs1_dir_append()
719 static int lfs1_dir_remove(lfs1_t *lfs1, lfs1_dir_t *dir, lfs1_entry_t *entry) { in lfs1_dir_remove() argument
721 if ((dir->d.size & 0x7fffffff) == sizeof(dir->d)+4 in lfs1_dir_remove()
724 int res = lfs1_pred(lfs1, dir->pair, &pdir); in lfs1_dir_remove()
730 pdir.d.size &= dir->d.size | 0x7fffffff; in lfs1_dir_remove()
731 pdir.d.tail[0] = dir->d.tail[0]; in lfs1_dir_remove()
732 pdir.d.tail[1] = dir->d.tail[1]; in lfs1_dir_remove()
738 int err = lfs1_dir_commit(lfs1, dir, (struct lfs1_region[]){ in lfs1_dir_remove()
747 if (lfs1_paircmp(f->pair, dir->pair) == 0) { in lfs1_dir_remove()
758 if (lfs1_paircmp(d->pair, dir->pair) == 0) { in lfs1_dir_remove()
769 static int lfs1_dir_next(lfs1_t *lfs1, lfs1_dir_t *dir, lfs1_entry_t *entry) { in lfs1_dir_next() argument
770 while (dir->off + sizeof(entry->d) > (0x7fffffff & dir->d.size)-4) { in lfs1_dir_next()
771 if (!(0x80000000 & dir->d.size)) { in lfs1_dir_next()
772 entry->off = dir->off; in lfs1_dir_next()
776 int err = lfs1_dir_fetch(lfs1, dir, dir->d.tail); in lfs1_dir_next()
781 dir->off = sizeof(dir->d); in lfs1_dir_next()
782 dir->pos += sizeof(dir->d) + 4; in lfs1_dir_next()
785 int err = lfs1_bd_read(lfs1, dir->pair[0], dir->off, in lfs1_dir_next()
792 entry->off = dir->off; in lfs1_dir_next()
793 dir->off += lfs1_entry_size(entry); in lfs1_dir_next()
794 dir->pos += lfs1_entry_size(entry); in lfs1_dir_next()
798 static int lfs1_dir_find(lfs1_t *lfs1, lfs1_dir_t *dir, in lfs1_dir_find() argument
806 entry->d.u.dir[0] = lfs1->root[0]; in lfs1_dir_find()
807 entry->d.u.dir[1] = lfs1->root[1]; in lfs1_dir_find()
859 int err = lfs1_dir_fetch(lfs1, dir, entry->d.u.dir); in lfs1_dir_find()
866 err = lfs1_dir_next(lfs1, dir, entry); in lfs1_dir_find()
877 int res = lfs1_bd_cmp(lfs1, dir->pair[0], in lfs1_dir_find()
927 lfs1_dir_t dir; in lfs1_mkdir() local
928 err = lfs1_dir_alloc(lfs1, &dir); in lfs1_mkdir()
932 dir.d.tail[0] = cwd.d.tail[0]; in lfs1_mkdir()
933 dir.d.tail[1] = cwd.d.tail[1]; in lfs1_mkdir()
935 err = lfs1_dir_commit(lfs1, &dir, NULL, 0); in lfs1_mkdir()
944 entry.d.u.dir[0] = dir.pair[0]; in lfs1_mkdir()
945 entry.d.u.dir[1] = dir.pair[1]; in lfs1_mkdir()
947 cwd.d.tail[0] = dir.pair[0]; in lfs1_mkdir()
948 cwd.d.tail[1] = dir.pair[1]; in lfs1_mkdir()
959 int lfs1_dir_open(lfs1_t *lfs1, lfs1_dir_t *dir, const char *path) { in lfs1_dir_open() argument
960 dir->pair[0] = lfs1->root[0]; in lfs1_dir_open()
961 dir->pair[1] = lfs1->root[1]; in lfs1_dir_open()
964 int err = lfs1_dir_find(lfs1, dir, &entry, &path); in lfs1_dir_open()
971 err = lfs1_dir_fetch(lfs1, dir, entry.d.u.dir); in lfs1_dir_open()
978 dir->head[0] = dir->pair[0]; in lfs1_dir_open()
979 dir->head[1] = dir->pair[1]; in lfs1_dir_open()
980 dir->pos = sizeof(dir->d) - 2; in lfs1_dir_open()
981 dir->off = sizeof(dir->d); in lfs1_dir_open()
984 dir->next = lfs1->dirs; in lfs1_dir_open()
985 lfs1->dirs = dir; in lfs1_dir_open()
990 int lfs1_dir_close(lfs1_t *lfs1, lfs1_dir_t *dir) { in lfs1_dir_close() argument
993 if (*p == dir) { in lfs1_dir_close()
994 *p = dir->next; in lfs1_dir_close()
1002 int lfs1_dir_read(lfs1_t *lfs1, lfs1_dir_t *dir, struct lfs1_info *info) { in lfs1_dir_read() argument
1006 if (dir->pos == sizeof(dir->d) - 2) { in lfs1_dir_read()
1009 dir->pos += 1; in lfs1_dir_read()
1011 } else if (dir->pos == sizeof(dir->d) - 1) { in lfs1_dir_read()
1014 dir->pos += 1; in lfs1_dir_read()
1020 int err = lfs1_dir_next(lfs1, dir, &entry); in lfs1_dir_read()
1052 int err = lfs1_bd_read(lfs1, dir->pair[0], in lfs1_dir_read()
1062 int lfs1_dir_seek(lfs1_t *lfs1, lfs1_dir_t *dir, lfs1_off_t off) { in lfs1_dir_seek() argument
1064 int err = lfs1_dir_rewind(lfs1, dir); in lfs1_dir_seek()
1068 dir->pos = off; in lfs1_dir_seek()
1070 while (off > (0x7fffffff & dir->d.size)) { in lfs1_dir_seek()
1071 off -= 0x7fffffff & dir->d.size; in lfs1_dir_seek()
1072 if (!(0x80000000 & dir->d.size)) { in lfs1_dir_seek()
1076 err = lfs1_dir_fetch(lfs1, dir, dir->d.tail); in lfs1_dir_seek()
1082 dir->off = off; in lfs1_dir_seek()
1086 lfs1_soff_t lfs1_dir_tell(lfs1_t *lfs1, lfs1_dir_t *dir) { in lfs1_dir_tell() argument
1088 return dir->pos; in lfs1_dir_tell()
1091 int lfs1_dir_rewind(lfs1_t *lfs1, lfs1_dir_t *dir) { in lfs1_dir_rewind() argument
1093 int err = lfs1_dir_fetch(lfs1, dir, dir->head); in lfs1_dir_rewind()
1098 dir->pair[0] = dir->head[0]; in lfs1_dir_rewind()
1099 dir->pair[1] = dir->head[1]; in lfs1_dir_rewind()
1100 dir->pos = sizeof(dir->d) - 2; in lfs1_dir_rewind()
1101 dir->off = sizeof(dir->d); in lfs1_dir_rewind()
1849 if (lfs1_paircmp(entry.d.u.dir, lfs1->root) == 0) { in lfs1_stat()
1879 lfs1_dir_t dir; in lfs1_remove() local
1884 err = lfs1_dir_fetch(lfs1, &dir, entry.d.u.dir); in lfs1_remove()
1887 } else if (dir.d.size != sizeof(dir.d)+4) { in lfs1_remove()
1900 int res = lfs1_pred(lfs1, dir.pair, &cwd); in lfs1_remove()
1906 cwd.d.tail[0] = dir.d.tail[0]; in lfs1_remove()
1907 cwd.d.tail[1] = dir.d.tail[1]; in lfs1_remove()
1956 lfs1_dir_t dir; in lfs1_rename() local
1961 err = lfs1_dir_fetch(lfs1, &dir, preventry.d.u.dir); in lfs1_rename()
1964 } else if (dir.d.size != sizeof(dir.d)+4) { in lfs1_rename()
2003 int res = lfs1_pred(lfs1, dir.pair, &newcwd); in lfs1_rename()
2009 newcwd.d.tail[0] = dir.d.tail[0]; in lfs1_rename()
2010 newcwd.d.tail[1] = dir.d.tail[1]; in lfs1_rename()
2202 lfs1_dir_t dir; in lfs1_mount() local
2204 err = lfs1_dir_fetch(lfs1, &dir, (const lfs1_block_t[2]){0, 1}); in lfs1_mount()
2210 err = lfs1_bd_read(lfs1, dir.pair[0], sizeof(dir.d), in lfs1_mount()
2258 lfs1_dir_t dir; in lfs1_traverse() local
2270 int err = lfs1_dir_fetch(lfs1, &dir, cwd); in lfs1_traverse()
2276 while (dir.off + sizeof(entry.d) <= (0x7fffffff & dir.d.size)-4) { in lfs1_traverse()
2277 err = lfs1_bd_read(lfs1, dir.pair[0], dir.off, in lfs1_traverse()
2284 dir.off += lfs1_entry_size(&entry); in lfs1_traverse()
2294 cwd[0] = dir.d.tail[0]; in lfs1_traverse()
2295 cwd[1] = dir.d.tail[1]; in lfs1_traverse()
2324 static int lfs1_pred(lfs1_t *lfs1, const lfs1_block_t dir[2], lfs1_dir_t *pdir) { in lfs1_pred()
2336 if (lfs1_paircmp(pdir->d.tail, dir) == 0) { in lfs1_pred()
2349 static int lfs1_parent(lfs1_t *lfs1, const lfs1_block_t dir[2], in lfs1_parent()
2376 lfs1_paircmp(entry->d.u.dir, dir) == 0) { in lfs1_parent()
2437 entry.d.u.dir[0] = newpair[0]; in lfs1_relocate()
2438 entry.d.u.dir[1] = newpair[1]; in lfs1_relocate()
2522 if (!lfs1_pairsync(entry.d.u.dir, pdir.d.tail)) { in lfs1_deorphan()
2525 entry.d.u.dir[0], entry.d.u.dir[1]); in lfs1_deorphan()
2527 pdir.d.tail[0] = entry.d.u.dir[0]; in lfs1_deorphan()
2528 pdir.d.tail[1] = entry.d.u.dir[1]; in lfs1_deorphan()
2560 entry.d.u.dir[0], entry.d.u.dir[1]); in lfs1_deorphan()
2567 entry.d.u.dir[0], entry.d.u.dir[1]); in lfs1_deorphan()