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.c143
1 files changed, 68 insertions, 75 deletions
diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c
index 09251338d99e..189fa677085a 100644
--- a/arch/um/os-Linux/file.c
+++ b/arch/um/os-Linux/file.c
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
@@ -18,6 +18,7 @@
18#include "os.h" 18#include "os.h"
19#include "user.h" 19#include "user.h"
20#include "kern_util.h" 20#include "kern_util.h"
21#include "user_util.h"
21 22
22static void copy_stat(struct uml_stat *dst, struct stat64 *src) 23static void copy_stat(struct uml_stat *dst, struct stat64 *src)
23{ 24{
@@ -42,16 +43,13 @@ int os_stat_fd(const int fd, struct uml_stat *ubuf)
42 struct stat64 sbuf; 43 struct stat64 sbuf;
43 int err; 44 int err;
44 45
45 do { 46 CATCH_EINTR(err = fstat64(fd, &sbuf));
46 err = fstat64(fd, &sbuf);
47 } while((err < 0) && (errno == EINTR)) ;
48
49 if(err < 0) 47 if(err < 0)
50 return(-errno); 48 return -errno;
51 49
52 if(ubuf != NULL) 50 if(ubuf != NULL)
53 copy_stat(ubuf, &sbuf); 51 copy_stat(ubuf, &sbuf);
54 return(err); 52 return err;
55} 53}
56 54
57int os_stat_file(const char *file_name, struct uml_stat *ubuf) 55int os_stat_file(const char *file_name, struct uml_stat *ubuf)
@@ -64,11 +62,11 @@ int os_stat_file(const char *file_name, struct uml_stat *ubuf)
64 } while((err < 0) && (errno == EINTR)) ; 62 } while((err < 0) && (errno == EINTR)) ;
65 63
66 if(err < 0) 64 if(err < 0)
67 return(-errno); 65 return -errno;
68 66
69 if(ubuf != NULL) 67 if(ubuf != NULL)
70 copy_stat(ubuf, &sbuf); 68 copy_stat(ubuf, &sbuf);
71 return(err); 69 return err;
72} 70}
73 71
74int os_access(const char* file, int mode) 72int os_access(const char* file, int mode)
@@ -80,9 +78,9 @@ int os_access(const char* file, int mode)
80 78
81 err = access(file, amode); 79 err = access(file, amode);
82 if(err < 0) 80 if(err < 0)
83 return(-errno); 81 return -errno;
84 82
85 return(0); 83 return 0;
86} 84}
87 85
88void os_print_error(int error, const char* str) 86void os_print_error(int error, const char* str)
@@ -99,9 +97,9 @@ int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
99 97
100 err = ioctl(fd, cmd, arg); 98 err = ioctl(fd, cmd, arg);
101 if(err < 0) 99 if(err < 0)
102 return(-errno); 100 return -errno;
103 101
104 return(err); 102 return err;
105} 103}
106 104
107int os_window_size(int fd, int *rows, int *cols) 105int os_window_size(int fd, int *rows, int *cols)
@@ -109,12 +107,12 @@ int os_window_size(int fd, int *rows, int *cols)
109 struct winsize size; 107 struct winsize size;
110 108
111 if(ioctl(fd, TIOCGWINSZ, &size) < 0) 109 if(ioctl(fd, TIOCGWINSZ, &size) < 0)
112 return(-errno); 110 return -errno;
113 111
114 *rows = size.ws_row; 112 *rows = size.ws_row;
115 *cols = size.ws_col; 113 *cols = size.ws_col;
116 114
117 return(0); 115 return 0;
118} 116}
119 117
120int os_new_tty_pgrp(int fd, int pid) 118int os_new_tty_pgrp(int fd, int pid)
@@ -125,16 +123,16 @@ int os_new_tty_pgrp(int fd, int pid)
125 if(tcsetpgrp(fd, pid) < 0) 123 if(tcsetpgrp(fd, pid) < 0)
126 return -errno; 124 return -errno;
127 125
128 return(0); 126 return 0;
129} 127}
130 128
131/* FIXME: ensure namebuf in os_get_if_name is big enough */ 129/* FIXME: ensure namebuf in os_get_if_name is big enough */
132int os_get_ifname(int fd, char* namebuf) 130int os_get_ifname(int fd, char* namebuf)
133{ 131{
134 if(ioctl(fd, SIOCGIFNAME, namebuf) < 0) 132 if(ioctl(fd, SIOCGIFNAME, namebuf) < 0)
135 return(-errno); 133 return -errno;
136 134
137 return(0); 135 return 0;
138} 136}
139 137
140int os_set_slip(int fd) 138int os_set_slip(int fd)
@@ -149,7 +147,7 @@ int os_set_slip(int fd)
149 if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) 147 if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
150 return -errno; 148 return -errno;
151 149
152 return(0); 150 return 0;
153} 151}
154 152
155int os_set_owner(int fd, int pid) 153int os_set_owner(int fd, int pid)
@@ -158,10 +156,10 @@ int os_set_owner(int fd, int pid)
158 int save_errno = errno; 156 int save_errno = errno;
159 157
160 if(fcntl(fd, F_GETOWN, 0) != pid) 158 if(fcntl(fd, F_GETOWN, 0) != pid)
161 return(-save_errno); 159 return -save_errno;
162 } 160 }
163 161
164 return(0); 162 return 0;
165} 163}
166 164
167/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */ 165/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */
@@ -192,9 +190,9 @@ int os_mode_fd(int fd, int mode)
192 } while((err < 0) && (errno==EINTR)) ; 190 } while((err < 0) && (errno==EINTR)) ;
193 191
194 if(err < 0) 192 if(err < 0)
195 return(-errno); 193 return -errno;
196 194
197 return(0); 195 return 0;
198} 196}
199 197
200int os_file_type(char *file) 198int os_file_type(char *file)
@@ -204,15 +202,21 @@ int os_file_type(char *file)
204 202
205 err = os_stat_file(file, &buf); 203 err = os_stat_file(file, &buf);
206 if(err < 0) 204 if(err < 0)
207 return(err); 205 return err;
208 206
209 if(S_ISDIR(buf.ust_mode)) return(OS_TYPE_DIR); 207 if(S_ISDIR(buf.ust_mode))
210 else if(S_ISLNK(buf.ust_mode)) return(OS_TYPE_SYMLINK); 208 return OS_TYPE_DIR;
211 else if(S_ISCHR(buf.ust_mode)) return(OS_TYPE_CHARDEV); 209 else if(S_ISLNK(buf.ust_mode))
212 else if(S_ISBLK(buf.ust_mode)) return(OS_TYPE_BLOCKDEV); 210 return OS_TYPE_SYMLINK;
213 else if(S_ISFIFO(buf.ust_mode)) return(OS_TYPE_FIFO); 211 else if(S_ISCHR(buf.ust_mode))
214 else if(S_ISSOCK(buf.ust_mode)) return(OS_TYPE_SOCK); 212 return OS_TYPE_CHARDEV;
215 else return(OS_TYPE_FILE); 213 else if(S_ISBLK(buf.ust_mode))
214 return OS_TYPE_BLOCKDEV;
215 else if(S_ISFIFO(buf.ust_mode))
216 return OS_TYPE_FIFO;
217 else if(S_ISSOCK(buf.ust_mode))
218 return OS_TYPE_SOCK;
219 else return OS_TYPE_FILE;
216} 220}
217 221
218int os_file_mode(char *file, struct openflags *mode_out) 222int os_file_mode(char *file, struct openflags *mode_out)
@@ -302,8 +306,8 @@ int os_seek_file(int fd, __u64 offset)
302 306
303 actual = lseek64(fd, offset, SEEK_SET); 307 actual = lseek64(fd, offset, SEEK_SET);
304 if(actual != offset) 308 if(actual != offset)
305 return(-errno); 309 return -errno;
306 return(0); 310 return 0;
307} 311}
308 312
309static int fault_buffer(void *start, int len, 313static int fault_buffer(void *start, int len,
@@ -314,13 +318,13 @@ static int fault_buffer(void *start, int len,
314 318
315 for(i = 0; i < len; i += page){ 319 for(i = 0; i < len; i += page){
316 if((*copy_proc)(start + i, &c, sizeof(c))) 320 if((*copy_proc)(start + i, &c, sizeof(c)))
317 return(-EFAULT); 321 return -EFAULT;
318 } 322 }
319 if((len % page) != 0){ 323 if((len % page) != 0){
320 if((*copy_proc)(start + len - 1, &c, sizeof(c))) 324 if((*copy_proc)(start + len - 1, &c, sizeof(c)))
321 return(-EFAULT); 325 return -EFAULT;
322 } 326 }
323 return(0); 327 return 0;
324} 328}
325 329
326static int file_io(int fd, void *buf, int len, 330static int file_io(int fd, void *buf, int len,
@@ -334,26 +338,26 @@ static int file_io(int fd, void *buf, int len,
334 if((n < 0) && (errno == EFAULT)){ 338 if((n < 0) && (errno == EFAULT)){
335 err = fault_buffer(buf, len, copy_user_proc); 339 err = fault_buffer(buf, len, copy_user_proc);
336 if(err) 340 if(err)
337 return(err); 341 return err;
338 n = (*io_proc)(fd, buf, len); 342 n = (*io_proc)(fd, buf, len);
339 } 343 }
340 } while((n < 0) && (errno == EINTR)); 344 } while((n < 0) && (errno == EINTR));
341 345
342 if(n < 0) 346 if(n < 0)
343 return(-errno); 347 return -errno;
344 return(n); 348 return n;
345} 349}
346 350
347int os_read_file(int fd, void *buf, int len) 351int os_read_file(int fd, void *buf, int len)
348{ 352{
349 return(file_io(fd, buf, len, (int (*)(int, void *, int)) read, 353 return file_io(fd, buf, len, (int (*)(int, void *, int)) read,
350 copy_from_user_proc)); 354 copy_from_user_proc);
351} 355}
352 356
353int os_write_file(int fd, const void *buf, int len) 357int os_write_file(int fd, const void *buf, int len)
354{ 358{
355 return(file_io(fd, (void *) buf, len, 359 return file_io(fd, (void *) buf, len,
356 (int (*)(int, void *, int)) write, copy_to_user_proc)); 360 (int (*)(int, void *, int)) write, copy_to_user_proc);
357} 361}
358 362
359int os_file_size(char *file, unsigned long long *size_out) 363int os_file_size(char *file, unsigned long long *size_out)
@@ -398,11 +402,11 @@ int os_file_modtime(char *file, unsigned long *modtime)
398 err = os_stat_file(file, &buf); 402 err = os_stat_file(file, &buf);
399 if(err < 0){ 403 if(err < 0){
400 printk("Couldn't stat \"%s\" : err = %d\n", file, -err); 404 printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
401 return(err); 405 return err;
402 } 406 }
403 407
404 *modtime = buf.ust_mtime; 408 *modtime = buf.ust_mtime;
405 return(0); 409 return 0;
406} 410}
407 411
408int os_get_exec_close(int fd, int* close_on_exec) 412int os_get_exec_close(int fd, int* close_on_exec)
@@ -455,7 +459,7 @@ int os_pipe(int *fds, int stream, int close_on_exec)
455 if(err < 0) 459 if(err < 0)
456 goto error; 460 goto error;
457 461
458 return(0); 462 return 0;
459 463
460 error: 464 error:
461 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 465 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
@@ -486,12 +490,12 @@ int os_set_fd_async(int fd, int owner)
486 (fcntl(fd, F_SETOWN, owner) < 0)){ 490 (fcntl(fd, F_SETOWN, owner) < 0)){
487 err = -errno; 491 err = -errno;
488 printk("os_set_fd_async : Failed to fcntl F_SETOWN " 492 printk("os_set_fd_async : Failed to fcntl F_SETOWN "
489 "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, 493 "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd,
490 owner, errno); 494 owner, errno);
491 return err; 495 return err;
492 } 496 }
493 497
494 return(0); 498 return 0;
495} 499}
496 500
497int os_clear_fd_async(int fd) 501int os_clear_fd_async(int fd)
@@ -500,8 +504,8 @@ int os_clear_fd_async(int fd)
500 504
501 flags &= ~(O_ASYNC | O_NONBLOCK); 505 flags &= ~(O_ASYNC | O_NONBLOCK);
502 if(fcntl(fd, F_SETFL, flags) < 0) 506 if(fcntl(fd, F_SETFL, flags) < 0)
503 return(-errno); 507 return -errno;
504 return(0); 508 return 0;
505} 509}
506 510
507int os_set_fd_block(int fd, int blocking) 511int os_set_fd_block(int fd, int blocking)
@@ -516,7 +520,7 @@ int os_set_fd_block(int fd, int blocking)
516 if(fcntl(fd, F_SETFL, flags) < 0) 520 if(fcntl(fd, F_SETFL, flags) < 0)
517 return -errno; 521 return -errno;
518 522
519 return(0); 523 return 0;
520} 524}
521 525
522int os_accept_connection(int fd) 526int os_accept_connection(int fd)
@@ -524,9 +528,9 @@ int os_accept_connection(int fd)
524 int new; 528 int new;
525 529
526 new = accept(fd, NULL, 0); 530 new = accept(fd, NULL, 0);
527 if(new < 0) 531 if(new < 0)
528 return(-errno); 532 return -errno;
529 return(new); 533 return new;
530} 534}
531 535
532#ifndef SHUT_RD 536#ifndef SHUT_RD
@@ -550,12 +554,12 @@ int os_shutdown_socket(int fd, int r, int w)
550 else if(w) what = SHUT_WR; 554 else if(w) what = SHUT_WR;
551 else { 555 else {
552 printk("os_shutdown_socket : neither r or w was set\n"); 556 printk("os_shutdown_socket : neither r or w was set\n");
553 return(-EINVAL); 557 return -EINVAL;
554 } 558 }
555 err = shutdown(fd, what); 559 err = shutdown(fd, what);
556 if(err < 0) 560 if(err < 0)
557 return(-errno); 561 return -errno;
558 return(0); 562 return 0;
559} 563}
560 564
561int os_rcv_fd(int fd, int *helper_pid_out) 565int os_rcv_fd(int fd, int *helper_pid_out)
@@ -578,7 +582,7 @@ int os_rcv_fd(int fd, int *helper_pid_out)
578 582
579 n = recvmsg(fd, &msg, 0); 583 n = recvmsg(fd, &msg, 0);
580 if(n < 0) 584 if(n < 0)
581 return(-errno); 585 return -errno;
582 586
583 else if(n != sizeof(iov.iov_len)) 587 else if(n != sizeof(iov.iov_len))
584 *helper_pid_out = -1; 588 *helper_pid_out = -1;
@@ -586,16 +590,16 @@ int os_rcv_fd(int fd, int *helper_pid_out)
586 cmsg = CMSG_FIRSTHDR(&msg); 590 cmsg = CMSG_FIRSTHDR(&msg);
587 if(cmsg == NULL){ 591 if(cmsg == NULL){
588 printk("rcv_fd didn't receive anything, error = %d\n", errno); 592 printk("rcv_fd didn't receive anything, error = %d\n", errno);
589 return(-1); 593 return -1;
590 } 594 }
591 if((cmsg->cmsg_level != SOL_SOCKET) || 595 if((cmsg->cmsg_level != SOL_SOCKET) ||
592 (cmsg->cmsg_type != SCM_RIGHTS)){ 596 (cmsg->cmsg_type != SCM_RIGHTS)){
593 printk("rcv_fd didn't receive a descriptor\n"); 597 printk("rcv_fd didn't receive a descriptor\n");
594 return(-1); 598 return -1;
595 } 599 }
596 600
597 new = ((int *) CMSG_DATA(cmsg))[0]; 601 new = ((int *) CMSG_DATA(cmsg))[0];
598 return(new); 602 return new;
599} 603}
600 604
601int os_create_unix_socket(char *file, int len, int close_on_exec) 605int os_create_unix_socket(char *file, int len, int close_on_exec)
@@ -623,7 +627,7 @@ int os_create_unix_socket(char *file, int len, int close_on_exec)
623 if(err < 0) 627 if(err < 0)
624 return -errno; 628 return -errno;
625 629
626 return(sock); 630 return sock;
627} 631}
628 632
629void os_flush_stdout(void) 633void os_flush_stdout(void)
@@ -654,16 +658,5 @@ int os_lock_file(int fd, int excl)
654 printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid); 658 printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid);
655 err = save; 659 err = save;
656 out: 660 out:
657 return(err); 661 return err;
658} 662}
659
660/*
661 * Overrides for Emacs so that we follow Linus's tabbing style.
662 * Emacs will notice this stuff at the end of the file and automatically
663 * adjust the settings for this buffer only. This must remain at the end
664 * of the file.
665 * ---------------------------------------------------------------------------
666 * Local variables:
667 * c-file-style: "linux"
668 * End:
669 */