Lines Matching +full:- +full:i

5  * SPDX-License-Identifier: BSD-3-Clause
21 (void*)cfg, cfg->context, in lfs_filebd_createcfg()
22 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog, in lfs_filebd_createcfg()
23 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, in lfs_filebd_createcfg()
24 cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count, in lfs_filebd_createcfg()
25 path, (void*)bdcfg, bdcfg->erase_value); in lfs_filebd_createcfg()
26 lfs_filebd_t *bd = cfg->context; in lfs_filebd_createcfg()
27 bd->cfg = bdcfg; in lfs_filebd_createcfg()
30 bd->fd = open(path, O_RDWR | O_CREAT, 0666); in lfs_filebd_createcfg()
31 if (bd->fd < 0) { in lfs_filebd_createcfg()
32 int err = -errno; in lfs_filebd_createcfg()
33 LFS_FILEBD_TRACE("lfs_filebd_createcfg -> %d", err); in lfs_filebd_createcfg()
37 LFS_FILEBD_TRACE("lfs_filebd_createcfg -> %d", 0); in lfs_filebd_createcfg()
47 (void*)cfg, cfg->context, in lfs_filebd_create()
48 (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog, in lfs_filebd_create()
49 (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, in lfs_filebd_create()
50 cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count, in lfs_filebd_create()
52 static const struct lfs_filebd_config defaults = {.erase_value=-1}; in lfs_filebd_create()
54 LFS_FILEBD_TRACE("lfs_filebd_create -> %d", err); in lfs_filebd_create()
60 lfs_filebd_t *bd = cfg->context; in lfs_filebd_destroy()
61 int err = close(bd->fd); in lfs_filebd_destroy()
63 err = -errno; in lfs_filebd_destroy()
64 LFS_FILEBD_TRACE("lfs_filebd_destroy -> %d", err); in lfs_filebd_destroy()
67 LFS_FILEBD_TRACE("lfs_filebd_destroy -> %d", 0); in lfs_filebd_destroy()
76 lfs_filebd_t *bd = cfg->context; in lfs_filebd_read()
79 LFS_ASSERT(off % cfg->read_size == 0); in lfs_filebd_read()
80 LFS_ASSERT(size % cfg->read_size == 0); in lfs_filebd_read()
81 LFS_ASSERT(block < cfg->block_count); in lfs_filebd_read()
84 if (bd->cfg->erase_value != -1) { in lfs_filebd_read()
85 memset(buffer, bd->cfg->erase_value, size); in lfs_filebd_read()
89 off_t res1 = lseek(bd->fd, in lfs_filebd_read()
90 (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); in lfs_filebd_read()
92 int err = -errno; in lfs_filebd_read()
93 LFS_FILEBD_TRACE("lfs_filebd_read -> %d", err); in lfs_filebd_read()
97 ssize_t res2 = read(bd->fd, buffer, size); in lfs_filebd_read()
99 int err = -errno; in lfs_filebd_read()
100 LFS_FILEBD_TRACE("lfs_filebd_read -> %d", err); in lfs_filebd_read()
104 LFS_FILEBD_TRACE("lfs_filebd_read -> %d", 0); in lfs_filebd_read()
112 lfs_filebd_t *bd = cfg->context; in lfs_filebd_prog()
115 LFS_ASSERT(off % cfg->prog_size == 0); in lfs_filebd_prog()
116 LFS_ASSERT(size % cfg->prog_size == 0); in lfs_filebd_prog()
117 LFS_ASSERT(block < cfg->block_count); in lfs_filebd_prog()
120 if (bd->cfg->erase_value != -1) { in lfs_filebd_prog()
121 off_t res1 = lseek(bd->fd, in lfs_filebd_prog()
122 (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); in lfs_filebd_prog()
124 int err = -errno; in lfs_filebd_prog()
125 LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); in lfs_filebd_prog()
129 for (lfs_off_t i = 0; i < size; i++) { in lfs_filebd_prog() local
131 ssize_t res2 = read(bd->fd, &c, 1); in lfs_filebd_prog()
133 int err = -errno; in lfs_filebd_prog()
134 LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); in lfs_filebd_prog()
138 LFS_ASSERT(c == bd->cfg->erase_value); in lfs_filebd_prog()
143 off_t res1 = lseek(bd->fd, in lfs_filebd_prog()
144 (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); in lfs_filebd_prog()
146 int err = -errno; in lfs_filebd_prog()
147 LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); in lfs_filebd_prog()
151 ssize_t res2 = write(bd->fd, buffer, size); in lfs_filebd_prog()
153 int err = -errno; in lfs_filebd_prog()
154 LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); in lfs_filebd_prog()
158 LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", 0); in lfs_filebd_prog()
164 lfs_filebd_t *bd = cfg->context; in lfs_filebd_erase()
167 LFS_ASSERT(block < cfg->block_count); in lfs_filebd_erase()
170 if (bd->cfg->erase_value != -1) { in lfs_filebd_erase()
171 off_t res1 = lseek(bd->fd, (off_t)block*cfg->block_size, SEEK_SET); in lfs_filebd_erase()
173 int err = -errno; in lfs_filebd_erase()
174 LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", err); in lfs_filebd_erase()
178 for (lfs_off_t i = 0; i < cfg->block_size; i++) { in lfs_filebd_erase() local
179 ssize_t res2 = write(bd->fd, &(uint8_t){bd->cfg->erase_value}, 1); in lfs_filebd_erase()
181 int err = -errno; in lfs_filebd_erase()
182 LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", err); in lfs_filebd_erase()
188 LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", 0); in lfs_filebd_erase()
195 lfs_filebd_t *bd = cfg->context; in lfs_filebd_sync()
196 int err = fsync(bd->fd); in lfs_filebd_sync()
198 err = -errno; in lfs_filebd_sync()
199 LFS_FILEBD_TRACE("lfs_filebd_sync -> %d", 0); in lfs_filebd_sync()
203 LFS_FILEBD_TRACE("lfs_filebd_sync -> %d", 0); in lfs_filebd_sync()