file.c (597473720f4dc69749542bfcfed4a927a43d935e) | file.c (5d38f324993f49d1226ec81efe045834b46cd85a) |
---|---|
1/* 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 * Licensed under the GPL 4 */ 5 6#include <stdio.h> 7#include <unistd.h> 8#include <errno.h> 9#include <fcntl.h> 10#include <signal.h> 11#include <sys/ioctl.h> 12#include <sys/mount.h> 13#include <sys/socket.h> 14#include <sys/stat.h> 15#include <sys/sysmacros.h> 16#include <sys/un.h> 17#include <sys/types.h> | 1/* 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) 3 * Licensed under the GPL 4 */ 5 6#include <stdio.h> 7#include <unistd.h> 8#include <errno.h> 9#include <fcntl.h> 10#include <signal.h> 11#include <sys/ioctl.h> 12#include <sys/mount.h> 13#include <sys/socket.h> 14#include <sys/stat.h> 15#include <sys/sysmacros.h> 16#include <sys/un.h> 17#include <sys/types.h> |
18#include <sys/eventfd.h> |
|
18#include <os.h> 19 20static void copy_stat(struct uml_stat *dst, const struct stat64 *src) 21{ 22 *dst = ((struct uml_stat) { 23 .ust_dev = src->st_dev, /* device */ 24 .ust_ino = src->st_ino, /* inode */ 25 .ust_mode = src->st_mode, /* protection */ --- 589 unchanged lines hidden (view full) --- 615{ 616 int n = fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset, len); 617 618 if (n < 0) 619 return -errno; 620 return n; 621} 622 | 19#include <os.h> 20 21static void copy_stat(struct uml_stat *dst, const struct stat64 *src) 22{ 23 *dst = ((struct uml_stat) { 24 .ust_dev = src->st_dev, /* device */ 25 .ust_ino = src->st_ino, /* inode */ 26 .ust_mode = src->st_mode, /* protection */ --- 589 unchanged lines hidden (view full) --- 616{ 617 int n = fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, offset, len); 618 619 if (n < 0) 620 return -errno; 621 return n; 622} 623 |
624int os_eventfd(unsigned int initval, int flags) 625{ 626 int fd = eventfd(initval, flags); 627 628 if (fd < 0) 629 return -errno; 630 return fd; 631} 632 633int os_sendmsg_fds(int fd, const void *buf, unsigned int len, const int *fds, 634 unsigned int fds_num) 635{ 636 struct iovec iov = { 637 .iov_base = (void *) buf, 638 .iov_len = len, 639 }; 640 union { 641 char control[CMSG_SPACE(sizeof(*fds) * OS_SENDMSG_MAX_FDS)]; 642 struct cmsghdr align; 643 } u; 644 unsigned int fds_size = sizeof(*fds) * fds_num; 645 struct msghdr msg = { 646 .msg_iov = &iov, 647 .msg_iovlen = 1, 648 .msg_control = u.control, 649 .msg_controllen = CMSG_SPACE(fds_size), 650 }; 651 struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); 652 int err; 653 654 if (fds_num > OS_SENDMSG_MAX_FDS) 655 return -EINVAL; 656 memset(u.control, 0, sizeof(u.control)); 657 cmsg->cmsg_level = SOL_SOCKET; 658 cmsg->cmsg_type = SCM_RIGHTS; 659 cmsg->cmsg_len = CMSG_LEN(fds_size); 660 memcpy(CMSG_DATA(cmsg), fds, fds_size); 661 err = sendmsg(fd, &msg, 0); 662 663 if (err < 0) 664 return -errno; 665 return err; 666} |
|