Changeset 368ee04 in mainline for uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
- Timestamp:
- 2017-04-05T18:10:39Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r39f892a9 r368ee04 31 31 #include <stdlib.h> 32 32 #include <dirent.h> 33 #include <fcntl.h>34 33 #include <sys/types.h> 35 #include <sys/stat.h>36 34 #include <macros.h> 37 35 #include <getopt.h> … … 39 37 #include <str.h> 40 38 #include <ctype.h> 39 #include <vfs/vfs.h> 41 40 42 41 #include "config.h" … … 121 120 void *buffer; 122 121 bool create_sparse = false; 122 aoff64_t pos = 0; 123 123 124 124 file_size = 0; … … 156 156 file_name = argv[optind]; 157 157 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); 159 159 if (fd < 0) { 160 160 printf("%s: failed to create file %s.\n", cmdname, file_name); … … 164 164 if (create_sparse && file_size > 0) { 165 165 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)); 173 169 if (rc2 < 0) { 174 close(fd);170 vfs_put(fd); 175 171 goto error; 176 172 } … … 187 183 while (total_written < file_size) { 188 184 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); 190 186 if (rc <= 0) { 191 187 printf("%s: Error writing file (%d).\n", cmdname, errno); 192 close(fd);188 vfs_put(fd); 193 189 free(buffer); 194 190 return CMD_FAILURE; … … 199 195 free(buffer); 200 196 201 if ( close(fd) < 0)197 if (vfs_put(fd) < 0) 202 198 goto error; 203 199
Note:
See TracChangeset
for help on using the changeset viewer.