Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rbc41f3a3 rce04ea44  
    3131#include <stdlib.h>
    3232#include <dirent.h>
    33 #include <fcntl.h>
    3433#include <sys/types.h>
    35 #include <sys/stat.h>
    3634#include <macros.h>
    3735#include <getopt.h>
     
    3937#include <str.h>
    4038#include <ctype.h>
     39#include <vfs/vfs.h>
    4140
    4241#include "config.h"
     
    121120        void *buffer;
    122121        bool create_sparse = false;
     122        aoff64_t pos = 0;
    123123
    124124        file_size = 0;
     
    156156        file_name = argv[optind];
    157157
    158         fd = open(file_name, O_CREAT | O_EXCL | O_WRONLY, 0666);
     158        fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MUST_CREATE, MODE_WRITE);
    159159        if (fd < 0) {
    160160                printf("%s: failed to create file %s.\n", cmdname, file_name);
     
    164164        if (create_sparse && file_size > 0) {
    165165                const char byte = 0x00;
    166 
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
    168                         close(fd);
    169                         goto error;
    170                 }
    171 
    172                 rc2 = write(fd, &byte, sizeof(char));
     166               
     167                pos = file_size - 1;
     168                rc2 = vfs_write(fd, &pos, &byte, sizeof(char));
    173169                if (rc2 < 0) {
    174                         close(fd);
     170                        vfs_put(fd);
    175171                        goto error;
    176172                }
     
    187183        while (total_written < file_size) {
    188184                to_write = min(file_size - total_written, BUFFER_SIZE);
    189                 rc = write(fd, buffer, to_write);
     185                rc = vfs_write(fd, &pos, buffer, to_write);
    190186                if (rc <= 0) {
    191187                        printf("%s: Error writing file (%d).\n", cmdname, errno);
    192                         close(fd);
     188                        vfs_put(fd);
    193189                        free(buffer);
    194190                        return CMD_FAILURE;
     
    199195        free(buffer);
    200196
    201         if (close(fd) < 0)
     197        if (vfs_put(fd) < 0)
    202198                goto error;
    203199
Note: See TracChangeset for help on using the changeset viewer.