17 #if !defined(CONFIG_ROMFS_ON_MTD) && !defined(CONFIG_ROMFS_ON_BLOCK)
18 #error no ROMFS backing store interface configured
21 #ifdef CONFIG_ROMFS_ON_MTD
22 #define ROMFS_MTD_READ(sb, ...) mtd_read((sb)->s_mtd, ##__VA_ARGS__)
33 ret = ROMFS_MTD_READ(sb, pos, buflen, &rlen, buf);
34 return (ret < 0 || rlen != buflen) ? -
EIO : 0;
41 unsigned long pos,
size_t maxlen)
51 segment =
min_t(
size_t, maxlen, 16);
52 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
70 static int romfs_mtd_strcmp(
struct super_block *sb,
unsigned long pos,
82 segment =
min_t(
size_t, size + 1, 17);
83 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
87 if (
memcmp(buf, str, len) != 0)
103 #ifdef CONFIG_ROMFS_ON_BLOCK
107 static int romfs_blk_read(
struct super_block *sb,
unsigned long pos,
108 void *buf,
size_t buflen)
110 struct buffer_head *bh;
121 memcpy(buf, bh->b_data + offset, segment);
135 unsigned long pos,
size_t limit)
137 struct buffer_head *bh;
150 buf = bh->b_data +
offset;
151 p =
memchr(buf, 0, segment);
154 return n + (p -
buf);
167 static int romfs_blk_strcmp(
struct super_block *sb,
unsigned long pos,
168 const char *str,
size_t size)
170 struct buffer_head *bh;
173 bool matched, terminated =
false;
182 matched = (
memcmp(bh->b_data + offset, str, segment) == 0);
187 if (matched && size == 0 && offset + segment <
ROMBSIZE) {
188 if (!bh->b_data[offset + segment])
205 matched = !bh->b_data[0];
219 void *buf,
size_t buflen)
223 limit = romfs_maxsize(sb);
226 if (buflen > limit - pos)
227 buflen = limit -
pos;
229 #ifdef CONFIG_ROMFS_ON_MTD
231 return romfs_mtd_read(sb, pos, buf, buflen);
233 #ifdef CONFIG_ROMFS_ON_BLOCK
235 return romfs_blk_read(sb, pos, buf, buflen);
244 unsigned long pos,
size_t maxlen)
248 limit = romfs_maxsize(sb);
251 if (maxlen > limit - pos)
252 maxlen = limit -
pos;
254 #ifdef CONFIG_ROMFS_ON_MTD
256 return romfs_mtd_strnlen(sb, pos, maxlen);
258 #ifdef CONFIG_ROMFS_ON_BLOCK
260 return romfs_blk_strnlen(sb, pos, maxlen);
272 const char *str,
size_t size)
276 limit = romfs_maxsize(sb);
281 if (size + 1 > limit - pos)
284 #ifdef CONFIG_ROMFS_ON_MTD
286 return romfs_mtd_strcmp(sb, pos, str, size);
288 #ifdef CONFIG_ROMFS_ON_BLOCK
290 return romfs_blk_strcmp(sb, pos, str, size);