Changeset 76cd345 in mainline


Ignore:
Timestamp:
2024-10-28T11:23:47Z (7 months ago)
Author:
Miroslav Cimerman <mc@…>
Children:
978130a
Parents:
fad91b9
Message:

bdwrite: write as many blocks as possible at once

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdwrite/bdwrite.c

    rfad91b9 r76cd345  
    4040#include <stdlib.h>
    4141#include <stdio.h>
     42#include <abi/ipc/ipc.h>
    4243
    4344static void usage(void);
     
    106107        }
    107108
    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);
    112124                if (rc != EOK) {
    113125                        printf("bdwrite: error writing to \"%s\"\n", name);
    114                         free(buf);
    115                         block_fini(dev);
    116                         return 1;
     126                        goto end;
    117127                }
     128                left -= blks_to_write;
    118129        }
    119 
     130end:
    120131        free(buf);
    121132        block_fini(dev);
    122         return 0;
     133        return rc;
    123134bad:
    124135        usage();
Note: See TracChangeset for help on using the changeset viewer.