Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1adfd609 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds
Browse files

uml: style fixes in file.c



arch/um/os-Linux/file.c needed some style work -
	updated the copyright
	cleaned up the includes
	CodingStyle fixes
	added some missing CATCH_EINTRs
	os_set_owner was unused, so it is gone
	all printks now have severities
	fcntl(F_GETFL) was being called without checking the return
	removed an obsolete comment

Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent bf8fde78
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -131,7 +131,6 @@ extern int os_set_exec_close(int fd);
extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
extern int os_get_ifname(int fd, char *namebuf);
extern int os_set_slip(int fd);
extern int os_set_owner(int fd, int pid);
extern int os_mode_fd(int fd, int mode);

extern int os_seek_file(int fd, unsigned long long offset);
+118 −114
Original line number Diff line number Diff line
/*
 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 * Licensed under the GPL
 */

@@ -8,13 +8,12 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include "kern_constants.h"
#include "os.h"
#include "user.h"

@@ -55,10 +54,7 @@ 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)) ;

	CATCH_EINTR(err = stat64(file_name, &sbuf));
	if (err < 0)
		return -errno;

@@ -71,8 +67,10 @@ 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) ;
	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)
@@ -117,26 +115,11 @@ int os_set_slip(int fd)
	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;
}

int os_mode_fd(int fd, int mode)
{
	int err;

	do {
		err = fchmod(fd, mode);
	} while((err < 0) && (errno==EINTR)) ;

	CATCH_EINTR(err = fchmod(fd, mode));
	if (err < 0)
		return -errno;

@@ -192,15 +175,22 @@ int os_open_file(const char *file, struct openflags flags, int mode)
{
	int fd, err, f = 0;

	if(flags.r && flags.w) f = O_RDWR;
	else if(flags.r) f = O_RDONLY;
	else if(flags.w) f = O_WRONLY;
	if (flags.r && flags.w)
		f = O_RDWR;
	else if (flags.r)
		f = O_RDONLY;
	else if (flags.w)
		f = O_WRONLY;
	else f = 0;

	if(flags.s) f |= O_SYNC;
	if(flags.c) f |= O_CREAT;
	if(flags.t) f |= O_TRUNC;
	if(flags.e) f |= O_EXCL;
	if (flags.s)
		f |= O_SYNC;
	if (flags.c)
		f |= O_CREAT;
	if (flags.t)
		f |= O_TRUNC;
	if (flags.e)
		f |= O_EXCL;

	fd = open64(file, f, mode);
	if (fd < 0)
@@ -283,7 +273,8 @@ int os_file_size(const char *file, unsigned long long *size_out)

	err = os_stat_file(file, &buf);
	if (err < 0) {
		printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
		printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
		       -err);
		return err;
	}

@@ -294,14 +285,14 @@ int os_file_size(const char *file, unsigned long long *size_out)
		fd = open(file, O_RDONLY, 0);
		if (fd < 0) {
			err = -errno;
			printk("Couldn't open \"%s\", errno = %d\n", file,
			       errno);
			printk(UM_KERN_ERR "Couldn't open \"%s\", "
			       "errno = %d\n", file, errno);
			return err;
		}
		if (ioctl(fd, BLKGETSIZE, &blocks) < 0) {
			err = -errno;
			printk("Couldn't get the block size of \"%s\", "
			       "errno = %d\n", file, errno);
			printk(UM_KERN_ERR "Couldn't get the block size of "
			       "\"%s\", errno = %d\n", file, errno);
			close(fd);
			return err;
		}
@@ -320,7 +311,8 @@ int os_file_modtime(const char *file, unsigned long *modtime)

	err = os_stat_file(file, &buf);
	if (err < 0) {
		printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
		printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file,
		       -err);
		return err;
	}

@@ -361,7 +353,8 @@ int os_pipe(int *fds, int stream, int close_on_exec)
	return 0;

 error:
	printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
	printk(UM_KERN_ERR "os_pipe : Setting FD_CLOEXEC failed, err = %d\n",
	       -err);
	close(fds[1]);
	close(fds[0]);
	return err;
@@ -378,15 +371,15 @@ int os_set_fd_async(int fd)
	flags |= O_ASYNC | O_NONBLOCK;
	if (fcntl(fd, F_SETFL, flags) < 0) {
		err = -errno;
		printk("os_set_fd_async : failed to set O_ASYNC and "
		       "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
		printk(UM_KERN_ERR "os_set_fd_async : failed to set O_ASYNC "
		       "and O_NONBLOCK on fd # %d, errno = %d\n", fd, errno);
		return err;
	}

	if ((fcntl(fd, F_SETSIG, SIGIO) < 0) ||
	    (fcntl(fd, F_SETOWN, os_getpid()) < 0)) {
		err = -errno;
		printk("os_set_fd_async : Failed to fcntl F_SETOWN "
		printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN "
		       "(or F_SETSIG) fd %d, errno = %d\n", fd, errno);
		return err;
	}
@@ -396,7 +389,11 @@ int os_set_fd_async(int fd)

int os_clear_fd_async(int fd)
{
	int flags = fcntl(fd, F_GETFL);
	int flags;

	flags = fcntl(fd, F_GETFL);
	if (flags < 0)
		return -errno;

	flags &= ~(O_ASYNC | O_NONBLOCK);
	if (fcntl(fd, F_SETFL, flags) < 0)
@@ -409,9 +406,13 @@ int os_set_fd_block(int fd, int blocking)
	int flags;

	flags = fcntl(fd, F_GETFL);
	if (flags < 0)
		return -errno;

	if(blocking) flags &= ~O_NONBLOCK;
	else flags |= O_NONBLOCK;
	if (blocking)
		flags &= ~O_NONBLOCK;
	else
		flags |= O_NONBLOCK;

	if (fcntl(fd, F_SETFL, flags) < 0)
		return -errno;
@@ -445,13 +446,15 @@ int os_shutdown_socket(int fd, int r, int w)
{
	int what, err;

	if(r && w) what = SHUT_RDWR;
	else if(r) what = SHUT_RD;
	else if(w) what = SHUT_WR;
	else {
		printk("os_shutdown_socket : neither r or w was set\n");
	if (r && w)
		what = SHUT_RDWR;
	else if (r)
		what = SHUT_RD;
	else if (w)
		what = SHUT_WR;
	else
		return -EINVAL;
	}

	err = shutdown(fd, what);
	if (err < 0)
		return -errno;
@@ -484,12 +487,13 @@ int os_rcv_fd(int fd, int *helper_pid_out)

	cmsg = CMSG_FIRSTHDR(&msg);
	if (cmsg == NULL) {
		printk("rcv_fd didn't receive anything, error = %d\n", errno);
		printk(UM_KERN_ERR "rcv_fd didn't receive anything, "
		       "error = %d\n", errno);
		return -1;
	}
	if ((cmsg->cmsg_level != SOL_SOCKET) ||
	    (cmsg->cmsg_type != SCM_RIGHTS)) {
		printk("rcv_fd didn't receive a descriptor\n");
		printk(UM_KERN_ERR "rcv_fd didn't receive a descriptor\n");
		return -1;
	}

@@ -509,13 +513,12 @@ int os_create_unix_socket(const char *file, int len, int close_on_exec)
	if (close_on_exec) {
		err = os_set_exec_close(sock);
		if (err < 0)
			printk("create_unix_socket : close_on_exec failed, "
		       "err = %d", -err);
			printk(UM_KERN_ERR "create_unix_socket : "
			       "close_on_exec failed, err = %d", -err);
	}

	addr.sun_family = AF_UNIX;

	/* XXX Be more careful about overflow */
	snprintf(addr.sun_path, len, "%s", file);

	err = bind(sock, (struct sockaddr *) &addr, sizeof(addr));
@@ -550,7 +553,8 @@ int os_lock_file(int fd, int excl)
		goto out;
	}

	printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid);
	printk(UM_KERN_ERR "F_SETLK failed, file already locked by pid %d\n",
	       lock.l_pid);
	err = save;
 out:
	return err;