-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathulwrite.c
More file actions
45 lines (34 loc) · 969 Bytes
/
ulwrite.c
File metadata and controls
45 lines (34 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "common.h"
ul_result execute(app_ctx * ctx) {
ul_page buffer[UL_WRPAGS];
ul_result ret;
unsigned int page = min(ctx->uldev.type->pages, ctx->startPage);
unsigned int count = min(ctx->uldev.type->pages - page, ctx->pageCount);
fprintf(stderr, "Writing %u pages starting at page 0x%02X (lenient: %s)\n", count, page, ctx->lenient ? "true" : "false");
while (count > 0) {
if (!fread(buffer, sizeof(buffer), 1, stdin)) {
fprintf(stderr, "* End of input stream *\n");
return UL_ERROR;
}
ret = ul_write(&ctx->uldev, page, buffer);
if (ret) {
fprintf(stderr, "* Error writing page 0x%02X (%d) *\n", page, ret);
if (ctx->lenient == false || ret == UL_WRONGPASS) {
return ret;
}
}
page += UL_WRPAGS;
count -= UL_WRPAGS;
}
return UL_OK;
}
int main(int argc, char ** argv) {
app_ctx ctx;
ul_result ret = initialize(argc, argv, &ctx);
if (ret) {
return ret;
}
ret = execute(&ctx);
finalize(&ctx);
return ret;
}