Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 2 | * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <sys/ioctl.h> |
| 12 | #include <sys/mount.h> |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 13 | #include <sys/socket.h> |
| 14 | #include <sys/stat.h> |
| 15 | #include <sys/un.h> |
Al Viro | 37185b3 | 2012-10-08 03:27:32 +0100 | [diff] [blame] | 16 | #include <os.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 18 | static void copy_stat(struct uml_stat *dst, const struct stat64 *src) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | { |
| 20 | *dst = ((struct uml_stat) { |
| 21 | .ust_dev = src->st_dev, /* device */ |
| 22 | .ust_ino = src->st_ino, /* inode */ |
| 23 | .ust_mode = src->st_mode, /* protection */ |
| 24 | .ust_nlink = src->st_nlink, /* number of hard links */ |
| 25 | .ust_uid = src->st_uid, /* user ID of owner */ |
| 26 | .ust_gid = src->st_gid, /* group ID of owner */ |
| 27 | .ust_size = src->st_size, /* total size, in bytes */ |
| 28 | .ust_blksize = src->st_blksize, /* blocksize for filesys I/O */ |
| 29 | .ust_blocks = src->st_blocks, /* number of blocks allocated */ |
| 30 | .ust_atime = src->st_atime, /* time of last access */ |
| 31 | .ust_mtime = src->st_mtime, /* time of last modification */ |
| 32 | .ust_ctime = src->st_ctime, /* time of last change */ |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | int os_stat_fd(const int fd, struct uml_stat *ubuf) |
| 37 | { |
| 38 | struct stat64 sbuf; |
| 39 | int err; |
| 40 | |
Jeff Dike | 9ead6fe | 2006-07-10 04:45:15 -0700 | [diff] [blame] | 41 | CATCH_EINTR(err = fstat64(fd, &sbuf)); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 42 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 43 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 45 | if (ubuf != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | copy_stat(ubuf, &sbuf); |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 47 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | int os_stat_file(const char *file_name, struct uml_stat *ubuf) |
| 51 | { |
| 52 | struct stat64 sbuf; |
| 53 | int err; |
| 54 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 55 | CATCH_EINTR(err = stat64(file_name, &sbuf)); |
| 56 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 57 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 59 | if (ubuf != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | copy_stat(ubuf, &sbuf); |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 61 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 64 | int os_access(const char *file, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | int amode, err; |
| 67 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 68 | amode = (mode & OS_ACC_R_OK ? R_OK : 0) | |
| 69 | (mode & OS_ACC_W_OK ? W_OK : 0) | |
| 70 | (mode & OS_ACC_X_OK ? X_OK : 0) | |
| 71 | (mode & OS_ACC_F_OK ? F_OK : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | err = access(file, amode); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 74 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 75 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 77 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* FIXME? required only by hostaudio (because it passes ioctls verbatim) */ |
| 81 | int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) |
| 82 | { |
| 83 | int err; |
| 84 | |
| 85 | err = ioctl(fd, cmd, arg); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 86 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 87 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 89 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* FIXME: ensure namebuf in os_get_if_name is big enough */ |
| 93 | int os_get_ifname(int fd, char* namebuf) |
| 94 | { |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 95 | if (ioctl(fd, SIOCGIFNAME, namebuf) < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 96 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 98 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | int os_set_slip(int fd) |
| 102 | { |
| 103 | int disc, sencap; |
| 104 | |
| 105 | disc = N_SLIP; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 106 | if (ioctl(fd, TIOCSETD, &disc) < 0) |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 107 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | sencap = 0; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 110 | if (ioctl(fd, SIOCSIFENCAP, &sencap) < 0) |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 111 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 113 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | int os_mode_fd(int fd, int mode) |
| 117 | { |
| 118 | int err; |
| 119 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 120 | CATCH_EINTR(err = fchmod(fd, mode)); |
| 121 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 122 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 124 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int os_file_type(char *file) |
| 128 | { |
| 129 | struct uml_stat buf; |
| 130 | int err; |
| 131 | |
| 132 | err = os_stat_file(file, &buf); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 133 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 134 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 136 | if (S_ISDIR(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 137 | return OS_TYPE_DIR; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 138 | else if (S_ISLNK(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 139 | return OS_TYPE_SYMLINK; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 140 | else if (S_ISCHR(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 141 | return OS_TYPE_CHARDEV; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 142 | else if (S_ISBLK(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 143 | return OS_TYPE_BLOCKDEV; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 144 | else if (S_ISFIFO(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 145 | return OS_TYPE_FIFO; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 146 | else if (S_ISSOCK(buf.ust_mode)) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 147 | return OS_TYPE_SOCK; |
| 148 | else return OS_TYPE_FILE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 151 | int os_file_mode(const char *file, struct openflags *mode_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | int err; |
| 154 | |
| 155 | *mode_out = OPENFLAGS(); |
| 156 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 157 | err = access(file, W_OK); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 158 | if (err && (errno != EACCES)) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 159 | return -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 160 | else if (!err) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 161 | *mode_out = of_write(*mode_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 163 | err = access(file, R_OK); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 164 | if (err && (errno != EACCES)) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 165 | return -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 166 | else if (!err) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 167 | *mode_out = of_read(*mode_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 169 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 172 | int os_open_file(const char *file, struct openflags flags, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 174 | int fd, err, f = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 176 | if (flags.r && flags.w) |
| 177 | f = O_RDWR; |
| 178 | else if (flags.r) |
| 179 | f = O_RDONLY; |
| 180 | else if (flags.w) |
| 181 | f = O_WRONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | else f = 0; |
| 183 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 184 | if (flags.s) |
| 185 | f |= O_SYNC; |
| 186 | if (flags.c) |
| 187 | f |= O_CREAT; |
| 188 | if (flags.t) |
| 189 | f |= O_TRUNC; |
| 190 | if (flags.e) |
| 191 | f |= O_EXCL; |
Jeff Dike | bf53d85 | 2008-02-04 22:31:18 -0800 | [diff] [blame] | 192 | if (flags.a) |
| 193 | f |= O_APPEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | fd = open64(file, f, mode); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 196 | if (fd < 0) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 197 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 199 | if (flags.cl && fcntl(fd, F_SETFD, 1)) { |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 200 | err = -errno; |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 201 | close(fd); |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 202 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 205 | return fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 208 | int os_connect_socket(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | struct sockaddr_un sock; |
| 211 | int fd, err; |
| 212 | |
| 213 | sock.sun_family = AF_UNIX; |
| 214 | snprintf(sock.sun_path, sizeof(sock.sun_path), "%s", name); |
| 215 | |
| 216 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 217 | if (fd < 0) { |
Paolo 'Blaisorblade' Giarrusso | dc1561a | 2006-02-24 13:03:56 -0800 | [diff] [blame] | 218 | err = -errno; |
| 219 | goto out; |
| 220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | err = connect(fd, (struct sockaddr *) &sock, sizeof(sock)); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 223 | if (err) { |
Paolo 'Blaisorblade' Giarrusso | dc1561a | 2006-02-24 13:03:56 -0800 | [diff] [blame] | 224 | err = -errno; |
| 225 | goto out_close; |
| 226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Paolo 'Blaisorblade' Giarrusso | dc1561a | 2006-02-24 13:03:56 -0800 | [diff] [blame] | 228 | return fd; |
| 229 | |
| 230 | out_close: |
| 231 | close(fd); |
| 232 | out: |
| 233 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | void os_close_file(int fd) |
| 237 | { |
| 238 | close(fd); |
| 239 | } |
Anton Ivanov | 0565103 | 2014-03-07 18:37:47 +0000 | [diff] [blame] | 240 | int os_fsync_file(int fd) |
| 241 | { |
| 242 | if (fsync(fd) < 0) |
| 243 | return -errno; |
| 244 | return 0; |
| 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 247 | int os_seek_file(int fd, unsigned long long offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 249 | unsigned long long actual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
| 251 | actual = lseek64(fd, offset, SEEK_SET); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 252 | if (actual != offset) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 253 | return -errno; |
| 254 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | int os_read_file(int fd, void *buf, int len) |
| 258 | { |
Jeff Dike | 3d56404 | 2007-05-06 14:51:32 -0700 | [diff] [blame] | 259 | int n = read(fd, buf, len); |
| 260 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 261 | if (n < 0) |
Jeff Dike | 3d56404 | 2007-05-06 14:51:32 -0700 | [diff] [blame] | 262 | return -errno; |
| 263 | return n; |
| 264 | } |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | int os_write_file(int fd, const void *buf, int len) |
| 267 | { |
Jeff Dike | 3d56404 | 2007-05-06 14:51:32 -0700 | [diff] [blame] | 268 | int n = write(fd, (void *) buf, len); |
| 269 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 270 | if (n < 0) |
Jeff Dike | 3d56404 | 2007-05-06 14:51:32 -0700 | [diff] [blame] | 271 | return -errno; |
| 272 | return n; |
| 273 | } |
| 274 | |
Richard Weinberger | 805f11a | 2013-08-18 13:30:06 +0200 | [diff] [blame] | 275 | int os_sync_file(int fd) |
| 276 | { |
| 277 | int n = fsync(fd); |
| 278 | |
| 279 | if (n < 0) |
| 280 | return -errno; |
| 281 | return n; |
| 282 | } |
| 283 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 284 | int os_file_size(const char *file, unsigned long long *size_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | { |
| 286 | struct uml_stat buf; |
| 287 | int err; |
| 288 | |
| 289 | err = os_stat_file(file, &buf); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 290 | if (err < 0) { |
| 291 | printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file, |
| 292 | -err); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 293 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 296 | if (S_ISBLK(buf.ust_mode)) { |
Nicolas George | 2c392a4 | 2007-09-18 22:46:21 -0700 | [diff] [blame] | 297 | int fd; |
| 298 | long blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 300 | fd = open(file, O_RDONLY, 0); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 301 | if (fd < 0) { |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 302 | err = -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 303 | printk(UM_KERN_ERR "Couldn't open \"%s\", " |
| 304 | "errno = %d\n", file, errno); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 305 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 307 | if (ioctl(fd, BLKGETSIZE, &blocks) < 0) { |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 308 | err = -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 309 | printk(UM_KERN_ERR "Couldn't get the block size of " |
| 310 | "\"%s\", errno = %d\n", file, errno); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 311 | close(fd); |
| 312 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | *size_out = ((long long) blocks) * 512; |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 315 | close(fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 317 | else *size_out = buf.ust_size; |
| 318 | |
| 319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 322 | int os_file_modtime(const char *file, unsigned long *modtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | struct uml_stat buf; |
| 325 | int err; |
| 326 | |
| 327 | err = os_stat_file(file, &buf); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 328 | if (err < 0) { |
| 329 | printk(UM_KERN_ERR "Couldn't stat \"%s\" : err = %d\n", file, |
| 330 | -err); |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 331 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | *modtime = buf.ust_mtime; |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 335 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } |
| 337 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 338 | int os_set_exec_close(int fd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 340 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 342 | CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 344 | if (err < 0) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 345 | return -errno; |
| 346 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | int os_pipe(int *fds, int stream, int close_on_exec) |
| 350 | { |
| 351 | int err, type = stream ? SOCK_STREAM : SOCK_DGRAM; |
| 352 | |
| 353 | err = socketpair(AF_UNIX, type, 0, fds); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 354 | if (err < 0) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 355 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 357 | if (!close_on_exec) |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 358 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 360 | err = os_set_exec_close(fds[0]); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 361 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | goto error; |
| 363 | |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 364 | err = os_set_exec_close(fds[1]); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 365 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | goto error; |
| 367 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | error: |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 371 | printk(UM_KERN_ERR "os_pipe : Setting FD_CLOEXEC failed, err = %d\n", |
| 372 | -err); |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 373 | close(fds[1]); |
| 374 | close(fds[0]); |
| 375 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Jeff Dike | bf8fde7 | 2008-02-04 22:31:04 -0800 | [diff] [blame] | 378 | int os_set_fd_async(int fd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Jeff Dike | bf8fde7 | 2008-02-04 22:31:04 -0800 | [diff] [blame] | 380 | int err, flags; |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 381 | |
Jeff Dike | bf8fde7 | 2008-02-04 22:31:04 -0800 | [diff] [blame] | 382 | flags = fcntl(fd, F_GETFL); |
| 383 | if (flags < 0) |
| 384 | return -errno; |
| 385 | |
| 386 | flags |= O_ASYNC | O_NONBLOCK; |
| 387 | if (fcntl(fd, F_SETFL, flags) < 0) { |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 388 | err = -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 389 | printk(UM_KERN_ERR "os_set_fd_async : failed to set O_ASYNC " |
| 390 | "and O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 391 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Jeff Dike | bf8fde7 | 2008-02-04 22:31:04 -0800 | [diff] [blame] | 394 | if ((fcntl(fd, F_SETSIG, SIGIO) < 0) || |
| 395 | (fcntl(fd, F_SETOWN, os_getpid()) < 0)) { |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 396 | err = -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 397 | printk(UM_KERN_ERR "os_set_fd_async : Failed to fcntl F_SETOWN " |
Jeff Dike | bf8fde7 | 2008-02-04 22:31:04 -0800 | [diff] [blame] | 398 | "(or F_SETSIG) fd %d, errno = %d\n", fd, errno); |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 399 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 402 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | int os_clear_fd_async(int fd) |
| 406 | { |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 407 | int flags; |
| 408 | |
| 409 | flags = fcntl(fd, F_GETFL); |
| 410 | if (flags < 0) |
| 411 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | flags &= ~(O_ASYNC | O_NONBLOCK); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 414 | if (fcntl(fd, F_SETFL, flags) < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 415 | return -errno; |
| 416 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | int os_set_fd_block(int fd, int blocking) |
| 420 | { |
| 421 | int flags; |
| 422 | |
| 423 | flags = fcntl(fd, F_GETFL); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 424 | if (flags < 0) |
| 425 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 427 | if (blocking) |
| 428 | flags &= ~O_NONBLOCK; |
| 429 | else |
| 430 | flags |= O_NONBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 432 | if (fcntl(fd, F_SETFL, flags) < 0) |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 433 | return -errno; |
| 434 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 435 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | int os_accept_connection(int fd) |
| 439 | { |
| 440 | int new; |
| 441 | |
| 442 | new = accept(fd, NULL, 0); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 443 | if (new < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 444 | return -errno; |
| 445 | return new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | #ifndef SHUT_RD |
| 449 | #define SHUT_RD 0 |
| 450 | #endif |
| 451 | |
| 452 | #ifndef SHUT_WR |
| 453 | #define SHUT_WR 1 |
| 454 | #endif |
| 455 | |
| 456 | #ifndef SHUT_RDWR |
| 457 | #define SHUT_RDWR 2 |
| 458 | #endif |
| 459 | |
| 460 | int os_shutdown_socket(int fd, int r, int w) |
| 461 | { |
| 462 | int what, err; |
| 463 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 464 | if (r && w) |
| 465 | what = SHUT_RDWR; |
| 466 | else if (r) |
| 467 | what = SHUT_RD; |
| 468 | else if (w) |
| 469 | what = SHUT_WR; |
| 470 | else |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 471 | return -EINVAL; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | err = shutdown(fd, what); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 474 | if (err < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 475 | return -errno; |
| 476 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | int os_rcv_fd(int fd, int *helper_pid_out) |
| 480 | { |
| 481 | int new, n; |
| 482 | char buf[CMSG_SPACE(sizeof(new))]; |
| 483 | struct msghdr msg; |
| 484 | struct cmsghdr *cmsg; |
| 485 | struct iovec iov; |
| 486 | |
| 487 | msg.msg_name = NULL; |
| 488 | msg.msg_namelen = 0; |
| 489 | iov = ((struct iovec) { .iov_base = helper_pid_out, |
| 490 | .iov_len = sizeof(*helper_pid_out) }); |
| 491 | msg.msg_iov = &iov; |
| 492 | msg.msg_iovlen = 1; |
| 493 | msg.msg_control = buf; |
| 494 | msg.msg_controllen = sizeof(buf); |
| 495 | msg.msg_flags = 0; |
| 496 | |
| 497 | n = recvmsg(fd, &msg, 0); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 498 | if (n < 0) |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 499 | return -errno; |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 500 | else if (n != iov.iov_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | *helper_pid_out = -1; |
| 502 | |
| 503 | cmsg = CMSG_FIRSTHDR(&msg); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 504 | if (cmsg == NULL) { |
| 505 | printk(UM_KERN_ERR "rcv_fd didn't receive anything, " |
| 506 | "error = %d\n", errno); |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 507 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 509 | if ((cmsg->cmsg_level != SOL_SOCKET) || |
| 510 | (cmsg->cmsg_type != SCM_RIGHTS)) { |
| 511 | printk(UM_KERN_ERR "rcv_fd didn't receive a descriptor\n"); |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 512 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | new = ((int *) CMSG_DATA(cmsg))[0]; |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 516 | return new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
WANG Cong | c9a3072 | 2008-02-04 22:30:35 -0800 | [diff] [blame] | 519 | int os_create_unix_socket(const char *file, int len, int close_on_exec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
| 521 | struct sockaddr_un addr; |
| 522 | int sock, err; |
| 523 | |
| 524 | sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 525 | if (sock < 0) |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 526 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 528 | if (close_on_exec) { |
Jeff Dike | 512b6fb | 2007-10-16 01:27:11 -0700 | [diff] [blame] | 529 | err = os_set_exec_close(sock); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 530 | if (err < 0) |
| 531 | printk(UM_KERN_ERR "create_unix_socket : " |
| 532 | "close_on_exec failed, err = %d", -err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | addr.sun_family = AF_UNIX; |
| 536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | snprintf(addr.sun_path, len, "%s", file); |
| 538 | |
| 539 | err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 540 | if (err < 0) |
Jeff Dike | b4fd310 | 2005-09-16 19:27:49 -0700 | [diff] [blame] | 541 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 543 | return sock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | void os_flush_stdout(void) |
| 547 | { |
| 548 | fflush(stdout); |
| 549 | } |
| 550 | |
| 551 | int os_lock_file(int fd, int excl) |
| 552 | { |
| 553 | int type = excl ? F_WRLCK : F_RDLCK; |
| 554 | struct flock lock = ((struct flock) { .l_type = type, |
| 555 | .l_whence = SEEK_SET, |
| 556 | .l_start = 0, |
| 557 | .l_len = 0 } ); |
| 558 | int err, save; |
| 559 | |
| 560 | err = fcntl(fd, F_SETLK, &lock); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 561 | if (!err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | goto out; |
| 563 | |
| 564 | save = -errno; |
| 565 | err = fcntl(fd, F_GETLK, &lock); |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 566 | if (err) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | err = -errno; |
| 568 | goto out; |
| 569 | } |
| 570 | |
Jeff Dike | 1adfd60 | 2008-02-04 22:31:05 -0800 | [diff] [blame] | 571 | printk(UM_KERN_ERR "F_SETLK failed, file already locked by pid %d\n", |
| 572 | lock.l_pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | err = save; |
| 574 | out: |
Jeff Dike | 108ffa8 | 2006-07-10 04:45:14 -0700 | [diff] [blame] | 575 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
Al Viro | 005a59e | 2009-04-21 01:27:08 -0400 | [diff] [blame] | 577 | |
| 578 | unsigned os_major(unsigned long long dev) |
| 579 | { |
| 580 | return major(dev); |
| 581 | } |
| 582 | |
| 583 | unsigned os_minor(unsigned long long dev) |
| 584 | { |
| 585 | return minor(dev); |
| 586 | } |
| 587 | |
| 588 | unsigned long long os_makedev(unsigned major, unsigned minor) |
| 589 | { |
| 590 | return makedev(major, minor); |
| 591 | } |