Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F174052964
D60149.id188131.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D60149.id188131.diff
View Options
diff --git a/usr.bin/mkimg/image.h b/usr.bin/mkimg/image.h
--- a/usr.bin/mkimg/image.h
+++ b/usr.bin/mkimg/image.h
@@ -37,6 +37,7 @@
int image_copyout(int fd);
int image_copyout_done(int fd);
int image_copyout_region(int fd, lba_t blk, lba_t size);
+int image_buffer_region(char *buffer, lba_t blk, lba_t size);
int image_copyout_zeroes(int fd, size_t count);
int image_data(lba_t blk, lba_t size);
lba_t image_get_size(void);
diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c
--- a/usr.bin/mkimg/image.c
+++ b/usr.bin/mkimg/image.c
@@ -600,6 +600,32 @@
return (0);
}
+static int
+image_buffer_file(char *buffer, size_t size, int ifd, off_t iofs)
+{
+ void *mp;
+ char *buf, *p;
+ size_t iosz, sz;
+ off_t iof;
+
+ iosz = secsz * image_swap_pgsz;
+ p = buffer;
+
+ while (size > 0) {
+ sz = (size > iosz) ? iosz : size;
+ buf = mp = image_file_map(ifd, iofs, sz, &iof);
+ if (buf == NULL)
+ return (errno);
+ buf += iof;
+ memcpy(p, buf, sz);
+ image_file_unmap(mp, sz, iof);
+ size -= sz;
+ iofs += sz;
+ p += sz;
+ }
+ return (0);
+}
+
int
image_copyout_region(int fd, lba_t blk, lba_t size)
{
@@ -639,6 +665,48 @@
return (error);
}
+int
+image_buffer_region(char *buf, lba_t blk, lba_t size)
+{
+ char *p;
+ struct chunk *ch;
+ size_t ofs, sz;
+ int error;
+
+ size *= secsz;
+
+ p = buf;
+ error = 0;
+ while (!error && size > 0) {
+ ch = image_chunk_find(blk);
+ if (ch == NULL) {
+ error = EINVAL;
+ break;
+ }
+ ofs = (blk - ch->ch_block) * secsz;
+ sz = ch->ch_size - ofs;
+ sz = ((lba_t)sz < size) ? sz : (size_t)size;
+ switch (ch->ch_type) {
+ case CH_TYPE_ZEROES:
+ memset(p, 0, sz);
+ break;
+ case CH_TYPE_FILE:
+ error = image_buffer_file(p, sz, ch->ch_u.file.fd,
+ ch->ch_u.file.ofs + ofs);
+ break;
+ case CH_TYPE_MEMORY:
+ memcpy(p, ch->ch_u.mem.ptr, sz);
+ break;
+ default:
+ assert(0);
+ }
+ size -= sz;
+ blk += sz / secsz;
+ p += sz;
+ }
+ return (error);
+}
+
int
image_data(lba_t blk, lba_t size)
{
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 1, 5:58 AM (10 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39971708
Default Alt Text
D60149.id188131.diff (1 KB)
Attached To
Mode
D60149: mkimg: Add image_buffer_region
Attached
Detach File
Event Timeline
Log In to Comment