+static void copy_stat(struct uml_stat *dst, struct stat64 *src)
+{
+ *dst = ((struct uml_stat) {
+ .ust_dev = src->st_dev, /* device */
+ .ust_ino = src->st_ino, /* inode */
+ .ust_mode = src->st_mode, /* protection */
+ .ust_nlink = src->st_nlink, /* number of hard links */
+ .ust_uid = src->st_uid, /* user ID of owner */
+ .ust_gid = src->st_gid, /* group ID of owner */
+ .ust_size = src->st_size, /* total size, in bytes */
+ .ust_blksize = src->st_blksize, /* blocksize for filesys I/O */
+ .ust_blocks = src->st_blocks, /* number of blocks allocated */
+ .ust_atime = src->st_atime, /* time of last access */
+ .ust_mtime = src->st_mtime, /* time of last modification */
+ .ust_ctime = src->st_ctime, /* time of last change */
+ });
+}
+
+int os_stat_fd(const int fd, struct uml_stat *ubuf)
+{
+ struct stat64 sbuf;
+ int err;
+
+ do {
+ err = fstat64(fd, &sbuf);
+ } while((err < 0) && (errno == EINTR)) ;
+
+ if(err < 0)
+ return(-errno);
+
+ if(ubuf != NULL)
+ copy_stat(ubuf, &sbuf);
+ return(err);
+}
+
+int os_stat_file(const char *file_name, struct uml_stat *ubuf)
+{
+ struct stat64 sbuf;
+ int err;
+
+ do {
+ err = stat64(file_name, &sbuf);
+ } while((err < 0) && (errno == EINTR)) ;
+
+ if(err < 0)
+ return(-errno);
+
+ if(ubuf != NULL)
+ copy_stat(ubuf, &sbuf);
+ return(err);
+}
+
+int os_access(const char* file, int mode)
+{
+ int amode, err;
+
+ amode=(mode&OS_ACC_R_OK ? R_OK : 0) | (mode&OS_ACC_W_OK ? W_OK : 0) |
+ (mode&OS_ACC_X_OK ? X_OK : 0) | (mode&OS_ACC_F_OK ? F_OK : 0) ;
+
+ err = access(file, amode);
+ if(err < 0)
+ return(-errno);
+
+ return(0);
+}
+
+void os_print_error(int error, const char* str)
+{
+ errno = error < 0 ? -error : error;
+
+ perror(str);
+}
+
+/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */
+int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
+{
+ int err;
+
+ err = ioctl(fd, cmd, arg);
+ if(err < 0)
+ return(-errno);
+
+ return(err);
+}
+
+int os_window_size(int fd, int *rows, int *cols)
+{
+ struct winsize size;
+
+ if(ioctl(fd, TIOCGWINSZ, &size) < 0)
+ return(-errno);
+
+ *rows = size.ws_row;
+ *cols = size.ws_col;
+
+ return(0);
+}
+
+int os_new_tty_pgrp(int fd, int pid)
+{
+ if(ioctl(fd, TIOCSCTTY, 0) < 0){
+ printk("TIOCSCTTY failed, errno = %d\n", errno);
+ return(-errno);
+ }
+
+ if(tcsetpgrp(fd, pid) < 0){
+ printk("tcsetpgrp failed, errno = %d\n", errno);
+ return(-errno);
+ }
+
+ return(0);
+}
+
+/* FIXME: ensure namebuf in os_get_if_name is big enough */
+int os_get_ifname(int fd, char* namebuf)
+{
+ if(ioctl(fd, SIOCGIFNAME, namebuf) < 0)
+ return(-errno);
+
+ return(0);
+}
+
+int os_set_slip(int fd)
+{
+ int disc, sencap;
+
+ disc = N_SLIP;
+ if(ioctl(fd, TIOCSETD, &disc) < 0){
+ printk("Failed to set slip line discipline - "
+ "errno = %d\n", errno);
+ return(-errno);
+ }
+
+ sencap = 0;
+ if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){
+ printk("Failed to set slip encapsulation - "
+ "errno = %d\n", errno);
+ return(-errno);
+ }
+
+ return(0);
+}
+
+int os_set_owner(int fd, int pid)
+{
+ if(fcntl(fd, F_SETOWN, pid) < 0){
+ int save_errno = errno;
+
+ if(fcntl(fd, F_GETOWN, 0) != pid)
+ return(-save_errno);
+ }
+
+ return(0);
+}
+
+/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */
+int os_sigio_async(int master, int slave)