staticvoid copy_stat(struct uml_stat *dst, conststruct 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(constint fd, struct uml_stat *ubuf)
{ struct stat64 sbuf; int err;
CATCH_EINTR(err = fstat64(fd, &sbuf)); if (err < 0) return -errno;
if (ubuf != NULL)
copy_stat(ubuf, &sbuf); return err;
}
int os_stat_file(constchar *file_name, struct uml_stat *ubuf)
{ struct stat64 sbuf; int err;
CATCH_EINTR(err = stat64(file_name, &sbuf)); if (err < 0) return -errno;
if (ubuf != NULL)
copy_stat(ubuf, &sbuf); return err;
}
int os_access(constchar *file, int mode)
{ int amode, err;
/* 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_mode_fd(int fd, int mode)
{ int err;
CATCH_EINTR(err = fchmod(fd, mode)); if (err < 0) return -errno;
return 0;
}
int os_file_type(char *file)
{ struct uml_stat buf; int err;
err = os_stat_file(file, &buf); if (err < 0) return err;
/** * os_rcv_fd_msg - receive message with (optional) FDs * @fd: the FD to receive from * @fds: the array for FDs to write to * @n_fds: number of FDs to receive (@fds array size) * @data: the message buffer * @data_len: the size of the message to receive * * Receive a message with FDs. * * Returns: the size of the received message, or an error code
*/
ssize_t os_rcv_fd_msg(int fd, int *fds, unsignedint n_fds, void *data, size_t data_len)
{ #define MAX_RCV_FDS 2 char buf[CMSG_SPACE(sizeof(*fds) * MAX_RCV_FDS)]; struct cmsghdr *cmsg; struct iovec iov = {
.iov_base = data,
.iov_len = data_len,
}; struct msghdr msg = {
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = buf,
.msg_controllen = CMSG_SPACE(sizeof(*fds) * n_fds),
}; int n;
if (n_fds > MAX_RCV_FDS) return -EINVAL;
n = recvmsg(fd, &msg, 0); if (n < 0) return -errno;
int os_poll(unsignedint n, constint *fds)
{ /* currently need 2 FDs at most so avoid dynamic allocation */ struct pollfd pollfds[2] = {}; unsignedint i; int ret;
if (n > ARRAY_SIZE(pollfds)) return -EINVAL;
for (i = 0; i < n; i++) {
pollfds[i].fd = fds[i];
pollfds[i].events = POLLIN;
}
ret = poll(pollfds, n, -1); if (ret < 0) return -errno;
/* Return the index of the available FD */ for (i = 0; i < n; i++) { if (pollfds[i].revents) return i;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.