Changeset 368ee04 in mainline for uspace/app/sysinst/futil.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 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/sysinst/futil.c
r39f892a9 r368ee04 35 35 #include <dirent.h> 36 36 #include <errno.h> 37 #include <fcntl.h>38 37 #include <stdbool.h> 39 38 #include <stdio.h> 40 39 #include <stdlib.h> 41 #include < sys/stat.h>40 #include <vfs/vfs.h> 42 41 #include <sys/types.h> 43 42 #include <dirent.h> … … 60 59 ssize_t nr, nw; 61 60 int rc; 61 aoff64_t posr = 0, posw = 0; 62 62 63 63 printf("Copy '%s' to '%s'.\n", srcp, destp); 64 64 65 sf = open(srcp, O_RDONLY);65 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 66 66 if (sf < 0) 67 67 return EIO; 68 68 69 df = open(destp, O_CREAT | O_WRONLY, 0);69 df = vfs_lookup_open(destp, WALK_REGULAR | WALK_MAY_CREATE, MODE_WRITE); 70 70 if (df < 0) 71 71 return EIO; 72 72 73 73 do { 74 nr = read(sf, buf, BUF_SIZE);74 nr = vfs_read(sf, &posr, buf, BUF_SIZE); 75 75 if (nr == 0) 76 76 break; … … 78 78 return EIO; 79 79 80 nw = write(df, buf, nr);80 nw = vfs_write(df, &posw, buf, nr); 81 81 if (nw <= 0) 82 82 return EIO; 83 83 } while (true); 84 84 85 (void) close(sf);85 (void) vfs_put(sf); 86 86 87 rc = close(df);87 rc = vfs_put(df); 88 88 if (rc < 0) 89 89 return EIO; … … 118 118 return ENOMEM; 119 119 120 rc = stat(srcp, &s);120 rc = vfs_stat_path(srcp, &s); 121 121 if (rc != EOK) 122 122 return EIO; … … 128 128 } else if (s.is_directory) { 129 129 printf("Create directory '%s'\n", destp); 130 rc = mkdir(destp, 0);130 rc = vfs_link_path(destp, KIND_DIRECTORY, NULL); 131 131 if (rc != EOK) 132 132 return EIO; … … 157 157 int sf; 158 158 ssize_t nr; 159 off64_t off;160 159 size_t fsize; 161 160 char *data; 161 struct stat st; 162 162 163 sf = open(srcp, O_RDONLY);163 sf = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ); 164 164 if (sf < 0) 165 165 return ENOENT; 166 166 167 off = lseek(sf, 0, SEEK_END);168 if (off == (off64_t)-1)167 if (vfs_stat(sf, &st) != EOK) { 168 vfs_put(sf); 169 169 return EIO; 170 } 170 171 171 fsize = (size_t)off; 172 173 off = lseek(sf, 0, SEEK_SET); 174 if (off == (off64_t)-1) 175 return EIO; 172 fsize = st.size; 176 173 177 174 data = calloc(fsize, 1); 178 if (data == NULL) 175 if (data == NULL) { 176 vfs_put(sf); 179 177 return ENOMEM; 178 } 180 179 181 nr = read(sf, data, fsize); 182 if (nr != (ssize_t)fsize) 180 nr = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize); 181 if (nr != (ssize_t)fsize) { 182 vfs_put(sf); 183 free(data); 183 184 return EIO; 185 } 184 186 185 (void) close(sf);187 (void) vfs_put(sf); 186 188 *rdata = data; 187 189 *rsize = fsize;
Note:
See TracChangeset
for help on using the changeset viewer.