aboutsummaryrefslogtreecommitdiffstats
path: root/arch/um/os-Linux/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/um/os-Linux/file.c')
-rw-r--r--arch/um/os-Linux/file.c102
1 files changed, 45 insertions, 57 deletions
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index 5f10c3031ef2..b542a3a021bf 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -82,13 +82,6 @@ int os_access(const char* file, int mode)
82 return 0; 82 return 0;
83} 83}
84 84
85void os_print_error(int error, const char* str)
86{
87 errno = error < 0 ? -error : error;
88
89 perror(str);
90}
91
92/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */ 85/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */
93int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) 86int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
94{ 87{
@@ -181,19 +174,19 @@ int os_file_mode(char *file, struct openflags *mode_out)
181 174
182 *mode_out = OPENFLAGS(); 175 *mode_out = OPENFLAGS();
183 176
184 err = os_access(file, OS_ACC_W_OK); 177 err = access(file, W_OK);
185 if((err < 0) && (err != -EACCES)) 178 if(err && (errno != EACCES))
186 return(err); 179 return -errno;
187 180 else if(!err)
188 *mode_out = of_write(*mode_out); 181 *mode_out = of_write(*mode_out);
189
190 err = os_access(file, OS_ACC_R_OK);
191 if((err < 0) && (err != -EACCES))
192 return(err);
193 182
194 *mode_out = of_read(*mode_out); 183 err = access(file, R_OK);
184 if(err && (errno != EACCES))
185 return -errno;
186 else if(!err)
187 *mode_out = of_read(*mode_out);
195 188
196 return(0); 189 return err;
197} 190}
198 191
199int os_open_file(char *file, struct openflags flags, int mode) 192int os_open_file(char *file, struct openflags flags, int mode)
@@ -212,15 +205,15 @@ int os_open_file(char *file, struct openflags flags, int mode)
212 205
213 fd = open64(file, f, mode); 206 fd = open64(file, f, mode);
214 if(fd < 0) 207 if(fd < 0)
215 return(-errno); 208 return -errno;
216 209
217 if(flags.cl && fcntl(fd, F_SETFD, 1)){ 210 if(flags.cl && fcntl(fd, F_SETFD, 1)){
218 err = -errno; 211 err = -errno;
219 os_close_file(fd); 212 close(fd);
220 return err; 213 return err;
221 } 214 }
222 215
223 return(fd); 216 return fd;
224} 217}
225 218
226int os_connect_socket(char *name) 219int os_connect_socket(char *name)
@@ -292,31 +285,33 @@ int os_file_size(char *file, unsigned long long *size_out)
292 err = os_stat_file(file, &buf); 285 err = os_stat_file(file, &buf);
293 if(err < 0){ 286 if(err < 0){
294 printk("Couldn't stat \"%s\" : err = %d\n", file, -err); 287 printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
295 return(err); 288 return err;
296 } 289 }
297 290
298 if(S_ISBLK(buf.ust_mode)){ 291 if(S_ISBLK(buf.ust_mode)){
299 int fd; 292 int fd;
300 long blocks; 293 long blocks;
301 294
302 fd = os_open_file(file, of_read(OPENFLAGS()), 0); 295 fd = open(file, O_RDONLY, 0);
303 if(fd < 0){ 296 if(fd < 0) {
304 printk("Couldn't open \"%s\", errno = %d\n", file, -fd); 297 err = -errno;
305 return(fd); 298 printk("Couldn't open \"%s\", errno = %d\n", file,
299 errno);
300 return err;
306 } 301 }
307 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ 302 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
308 err = -errno; 303 err = -errno;
309 printk("Couldn't get the block size of \"%s\", " 304 printk("Couldn't get the block size of \"%s\", "
310 "errno = %d\n", file, errno); 305 "errno = %d\n", file, errno);
311 os_close_file(fd); 306 close(fd);
312 return(err); 307 return err;
313 } 308 }
314 *size_out = ((long long) blocks) * 512; 309 *size_out = ((long long) blocks) * 512;
315 os_close_file(fd); 310 close(fd);
316 return(0);
317 } 311 }
318 *size_out = buf.ust_size; 312 else *size_out = buf.ust_size;
319 return(0); 313
314 return 0;
320} 315}
321 316
322int os_file_modtime(char *file, unsigned long *modtime) 317int os_file_modtime(char *file, unsigned long *modtime)
@@ -334,35 +329,28 @@ int os_file_modtime(char *file, unsigned long *modtime)
334 return 0; 329 return 0;
335} 330}
336 331
337int os_get_exec_close(int fd, int* close_on_exec) 332int os_get_exec_close(int fd, int *close_on_exec)
338{ 333{
339 int ret; 334 int ret;
340 335
341 do { 336 CATCH_EINTR(ret = fcntl(fd, F_GETFD));
342 ret = fcntl(fd, F_GETFD);
343 } while((ret < 0) && (errno == EINTR)) ;
344 337
345 if(ret < 0) 338 if(ret < 0)
346 return(-errno); 339 return -errno;
347 340
348 *close_on_exec = (ret&FD_CLOEXEC) ? 1 : 0; 341 *close_on_exec = (ret & FD_CLOEXEC) ? 1 : 0;
349 return(ret); 342 return ret;
350} 343}
351 344
352int os_set_exec_close(int fd, int close_on_exec) 345int os_set_exec_close(int fd)
353{ 346{
354 int flag, err; 347 int err;
355
356 if(close_on_exec) flag = FD_CLOEXEC;
357 else flag = 0;
358 348
359 do { 349 CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC));
360 err = fcntl(fd, F_SETFD, flag);
361 } while((err < 0) && (errno == EINTR)) ;
362 350
363 if(err < 0) 351 if(err < 0)
364 return(-errno); 352 return -errno;
365 return(err); 353 return err;
366} 354}
367 355
368int os_pipe(int *fds, int stream, int close_on_exec) 356int os_pipe(int *fds, int stream, int close_on_exec)
@@ -371,16 +359,16 @@ int os_pipe(int *fds, int stream, int close_on_exec)
371 359
372 err = socketpair(AF_UNIX, type, 0, fds); 360 err = socketpair(AF_UNIX, type, 0, fds);
373 if(err < 0) 361 if(err < 0)
374 return(-errno); 362 return -errno;
375 363
376 if(!close_on_exec) 364 if(!close_on_exec)
377 return(0); 365 return 0;
378 366
379 err = os_set_exec_close(fds[0], 1); 367 err = os_set_exec_close(fds[0]);
380 if(err < 0) 368 if(err < 0)
381 goto error; 369 goto error;
382 370
383 err = os_set_exec_close(fds[1], 1); 371 err = os_set_exec_close(fds[1]);
384 if(err < 0) 372 if(err < 0)
385 goto error; 373 goto error;
386 374
@@ -388,9 +376,9 @@ int os_pipe(int *fds, int stream, int close_on_exec)
388 376
389 error: 377 error:
390 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 378 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
391 os_close_file(fds[1]); 379 close(fds[1]);
392 os_close_file(fds[0]); 380 close(fds[0]);
393 return(err); 381 return err;
394} 382}
395 383
396int os_set_fd_async(int fd, int owner) 384int os_set_fd_async(int fd, int owner)
@@ -537,7 +525,7 @@ int os_create_unix_socket(char *file, int len, int close_on_exec)
537 return -errno; 525 return -errno;
538 526
539 if(close_on_exec) { 527 if(close_on_exec) {
540 err = os_set_exec_close(sock, 1); 528 err = os_set_exec_close(sock);
541 if(err < 0) 529 if(err < 0)
542 printk("create_unix_socket : close_on_exec failed, " 530 printk("create_unix_socket : close_on_exec failed, "
543 "err = %d", -err); 531 "err = %d", -err);