Lines Matching +full:segment +full:- +full:1 +full:a
1 // SPDX-License-Identifier: GPL-2.0-or-later
18 #define ROMFS_MTD_READ(sb, ...) mtd_read((sb)->s_mtd, ##__VA_ARGS__)
30 return (ret < 0 || rlen != buflen) ? -EIO : 0; in romfs_mtd_read()
34 * determine the length of a string in a romfs image on an MTD device
40 size_t segment; in romfs_mtd_strnlen() local
45 /* scan the string up to 16 bytes at a time */ in romfs_mtd_strnlen()
47 segment = min_t(size_t, maxlen, 16); in romfs_mtd_strnlen()
48 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf); in romfs_mtd_strnlen()
53 return n + (p - buf); in romfs_mtd_strnlen()
54 maxlen -= len; in romfs_mtd_strnlen()
63 * compare a string to one in a romfs image on MTD
64 * - return 1 if matched, 0 if differ, -ve if error
70 size_t len, segment; in romfs_mtd_strcmp() local
73 /* scan the string up to 16 bytes at a time, and attempt to grab the in romfs_mtd_strcmp()
78 segment = min_t(size_t, size + 1, 17); in romfs_mtd_strcmp()
79 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf); in romfs_mtd_strcmp()
82 len--; in romfs_mtd_strcmp()
86 size -= len; in romfs_mtd_strcmp()
95 return 1; in romfs_mtd_strcmp()
101 * read data from an romfs image on a block device
108 size_t segment; in romfs_blk_read() local
110 /* copy the string up to blocksize bytes at a time */ in romfs_blk_read()
112 offset = pos & (ROMBSIZE - 1); in romfs_blk_read()
113 segment = min_t(size_t, buflen, ROMBSIZE - offset); in romfs_blk_read()
116 return -EIO; in romfs_blk_read()
117 memcpy(buf, bh->b_data + offset, segment); in romfs_blk_read()
119 buf += segment; in romfs_blk_read()
120 buflen -= segment; in romfs_blk_read()
121 pos += segment; in romfs_blk_read()
128 * determine the length of a string in romfs on a block device
136 size_t segment; in romfs_blk_strnlen() local
139 /* scan the string up to blocksize bytes at a time */ in romfs_blk_strnlen()
141 offset = pos & (ROMBSIZE - 1); in romfs_blk_strnlen()
142 segment = min_t(size_t, limit, ROMBSIZE - offset); in romfs_blk_strnlen()
145 return -EIO; in romfs_blk_strnlen()
146 buf = bh->b_data + offset; in romfs_blk_strnlen()
147 p = memchr(buf, 0, segment); in romfs_blk_strnlen()
150 return n + (p - buf); in romfs_blk_strnlen()
151 limit -= segment; in romfs_blk_strnlen()
152 pos += segment; in romfs_blk_strnlen()
153 n += segment; in romfs_blk_strnlen()
160 * compare a string to one in a romfs image on a block device
161 * - return 1 if matched, 0 if differ, -ve if error
168 size_t segment; in romfs_blk_strcmp() local
171 /* compare string up to a block at a time */ in romfs_blk_strcmp()
173 offset = pos & (ROMBSIZE - 1); in romfs_blk_strcmp()
174 segment = min_t(size_t, size, ROMBSIZE - offset); in romfs_blk_strcmp()
177 return -EIO; in romfs_blk_strcmp()
178 matched = (memcmp(bh->b_data + offset, str, segment) == 0); in romfs_blk_strcmp()
180 size -= segment; in romfs_blk_strcmp()
181 pos += segment; in romfs_blk_strcmp()
182 str += segment; in romfs_blk_strcmp()
183 if (matched && size == 0 && offset + segment < ROMBSIZE) { in romfs_blk_strcmp()
184 if (!bh->b_data[offset + segment]) in romfs_blk_strcmp()
197 BUG_ON((pos & (ROMBSIZE - 1)) != 0); in romfs_blk_strcmp()
200 return -EIO; in romfs_blk_strcmp()
201 matched = !bh->b_data[0]; in romfs_blk_strcmp()
207 return 1; in romfs_blk_strcmp()
220 if (pos >= limit || buflen > limit - pos) in romfs_dev_read()
221 return -EIO; in romfs_dev_read()
224 if (sb->s_mtd) in romfs_dev_read()
228 if (sb->s_bdev) in romfs_dev_read()
231 return -EIO; in romfs_dev_read()
235 * determine the length of a string in romfs
244 return -EIO; in romfs_dev_strnlen()
245 if (maxlen > limit - pos) in romfs_dev_strnlen()
246 maxlen = limit - pos; in romfs_dev_strnlen()
249 if (sb->s_mtd) in romfs_dev_strnlen()
253 if (sb->s_bdev) in romfs_dev_strnlen()
256 return -EIO; in romfs_dev_strnlen()
260 * compare a string to one in romfs
261 * - the string to be compared to, str, may not be NUL-terminated; instead the
263 * - return 1 if matched, 0 if differ, -ve if error
272 return -EIO; in romfs_dev_strcmp()
274 return -ENAMETOOLONG; in romfs_dev_strcmp()
275 if (size + 1 > limit - pos) in romfs_dev_strcmp()
276 return -EIO; in romfs_dev_strcmp()
279 if (sb->s_mtd) in romfs_dev_strcmp()
283 if (sb->s_bdev) in romfs_dev_strcmp()
286 return -EIO; in romfs_dev_strcmp()