Changeset 76cd345 in mainline for uspace/app/bdwrite/bdwrite.c
- Timestamp:
- 2024-10-28T11:23:47Z (7 months ago)
- Children:
- 978130a
- Parents:
- fad91b9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdwrite/bdwrite.c
rfad91b9 r76cd345 40 40 #include <stdlib.h> 41 41 #include <stdio.h> 42 #include <abi/ipc/ipc.h> 42 43 43 44 static void usage(void); … … 106 107 } 107 108 108 uint8_t *buf = calloc(1, bsize); 109 for (size_t i = 0; i < blkcnt; i++) { 110 memset(buf, (i + 1) % 0x100, bsize); 111 rc = block_write_direct(dev, i + off, 1, buf); 109 uint64_t to_alloc = min(DATA_XFER_LIMIT, bsize * blkcnt); 110 uint8_t *buf = calloc(to_alloc / bsize, bsize); 111 if (buf == NULL) { 112 rc = ENOMEM; 113 goto end; 114 } 115 uint64_t left = blkcnt; 116 while (left > 0) { 117 uint64_t blks_to_write = min(to_alloc / bsize, left); 118 uint8_t *ptr = buf; 119 for (size_t i = 0; i < blks_to_write; i++) { 120 memset(ptr, (i + 1) % 0x100, bsize); 121 ptr = (uint8_t *)((uintptr_t) ptr + bsize); 122 } 123 rc = block_write_direct(dev, off, blks_to_write, buf); 112 124 if (rc != EOK) { 113 125 printf("bdwrite: error writing to \"%s\"\n", name); 114 free(buf); 115 block_fini(dev); 116 return 1; 126 goto end; 117 127 } 128 left -= blks_to_write; 118 129 } 119 130 end: 120 131 free(buf); 121 132 block_fini(dev); 122 return 0;133 return rc; 123 134 bad: 124 135 usage();
Note:
See TracChangeset
for help on using the changeset viewer.