| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
#include <linux/string.h> |
|---|
| 8 |
#include <linux/mm.h> |
|---|
| 9 |
#include <linux/utime.h> |
|---|
| 10 |
#include <linux/file.h> |
|---|
| 11 |
#include <linux/smp_lock.h> |
|---|
| 12 |
#include <linux/quotaops.h> |
|---|
| 13 |
#include <linux/dnotify.h> |
|---|
| 14 |
#include <linux/module.h> |
|---|
| 15 |
#include <linux/slab.h> |
|---|
| 16 |
#include <linux/tty.h> |
|---|
| 17 |
#include <linux/namei.h> |
|---|
| 18 |
#include <linux/backing-dev.h> |
|---|
| 19 |
#include <linux/security.h> |
|---|
| 20 |
#include <linux/mount.h> |
|---|
| 21 |
#include <linux/vfs.h> |
|---|
| 22 |
#include <asm/uaccess.h> |
|---|
| 23 |
#include <linux/fs.h> |
|---|
| 24 |
#include <linux/pagemap.h> |
|---|
| 25 |
|
|---|
| 26 |
#include <asm/unistd.h> |
|---|
| 27 |
#include <asm/callgate.h> |
|---|
| 28 |
int vfs_statfs(struct super_block *sb, struct kstatfs *buf) |
|---|
| 29 |
{ |
|---|
| 30 |
int retval = -ENODEV; |
|---|
| 31 |
|
|---|
| 32 |
if (sb) { |
|---|
| 33 |
retval = -ENOSYS; |
|---|
| 34 |
if (sb->s_op->statfs) { |
|---|
| 35 |
memset(buf, 0, sizeof(*buf)); |
|---|
| 36 |
retval = security_sb_statfs(sb); |
|---|
| 37 |
if (retval) |
|---|
| 38 |
return retval; |
|---|
| 39 |
retval = sb->s_op->statfs(sb, buf); |
|---|
| 40 |
if (retval == 0 && buf->f_frsize == 0) |
|---|
| 41 |
buf->f_frsize = buf->f_bsize; |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
return retval; |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
EXPORT_SYMBOL(vfs_statfs); |
|---|
| 48 |
|
|---|
| 49 |
static int vfs_statfs_native(struct super_block *sb, struct statfs *buf) |
|---|
| 50 |
{ |
|---|
| 51 |
struct kstatfs st; |
|---|
| 52 |
int retval; |
|---|
| 53 |
|
|---|
| 54 |
retval = vfs_statfs(sb, &st); |
|---|
| 55 |
if (retval) |
|---|
| 56 |
return retval; |
|---|
| 57 |
|
|---|
| 58 |
if (sizeof(*buf) == sizeof(st)) |
|---|
| 59 |
memcpy(buf, &st, sizeof(st)); |
|---|
| 60 |
else { |
|---|
| 61 |
if (sizeof buf->f_blocks == 4) { |
|---|
| 62 |
if ((st.f_blocks | st.f_bfree | st.f_bavail) & |
|---|
| 63 |
0xffffffff00000000ULL) |
|---|
| 64 |
return -EOVERFLOW; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
if (st.f_files != -1 && |
|---|
| 70 |
(st.f_files & 0xffffffff00000000ULL)) |
|---|
| 71 |
return -EOVERFLOW; |
|---|
| 72 |
if (st.f_ffree != -1 && |
|---|
| 73 |
(st.f_ffree & 0xffffffff00000000ULL)) |
|---|
| 74 |
return -EOVERFLOW; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
buf->f_type = st.f_type; |
|---|
| 78 |
buf->f_bsize = st.f_bsize; |
|---|
| 79 |
buf->f_blocks = st.f_blocks; |
|---|
| 80 |
buf->f_bfree = st.f_bfree; |
|---|
| 81 |
buf->f_bavail = st.f_bavail; |
|---|
| 82 |
buf->f_files = st.f_files; |
|---|
| 83 |
buf->f_ffree = st.f_ffree; |
|---|
| 84 |
buf->f_fsid = st.f_fsid; |
|---|
| 85 |
buf->f_namelen = st.f_namelen; |
|---|
| 86 |
buf->f_frsize = st.f_frsize; |
|---|
| 87 |
memset(buf->f_spare, 0, sizeof(buf->f_spare)); |
|---|
| 88 |
} |
|---|
| 89 |
return 0; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
static int vfs_statfs64(struct super_block *sb, struct statfs64 *buf) |
|---|
| 93 |
{ |
|---|
| 94 |
struct kstatfs st; |
|---|
| 95 |
int retval; |
|---|
| 96 |
|
|---|
| 97 |
retval = vfs_statfs(sb, &st); |
|---|
| 98 |
if (retval) |
|---|
| 99 |
return retval; |
|---|
| 100 |
|
|---|
| 101 |
if (sizeof(*buf) == sizeof(st)) |
|---|
| 102 |
memcpy(buf, &st, sizeof(st)); |
|---|
| 103 |
else { |
|---|
| 104 |
buf->f_type = st.f_type; |
|---|
| 105 |
buf->f_bsize = st.f_bsize; |
|---|
| 106 |
buf->f_blocks = st.f_blocks; |
|---|
| 107 |
buf->f_bfree = st.f_bfree; |
|---|
| 108 |
buf->f_bavail = st.f_bavail; |
|---|
| 109 |
buf->f_files = st.f_files; |
|---|
| 110 |
buf->f_ffree = st.f_ffree; |
|---|
| 111 |
buf->f_fsid = st.f_fsid; |
|---|
| 112 |
buf->f_namelen = st.f_namelen; |
|---|
| 113 |
buf->f_frsize = st.f_frsize; |
|---|
| 114 |
memset(buf->f_spare, 0, sizeof(buf->f_spare)); |
|---|
| 115 |
} |
|---|
| 116 |
return 0; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
asmlinkage long sys_statfs(const char __user * path, struct statfs __user * buf) |
|---|
| 120 |
{ |
|---|
| 121 |
struct nameidata nd; |
|---|
| 122 |
int error; |
|---|
| 123 |
|
|---|
| 124 |
error = user_path_walk(path, &nd); |
|---|
| 125 |
if (!error) { |
|---|
| 126 |
struct statfs tmp; |
|---|
| 127 |
error = vfs_statfs_native(nd.dentry->d_inode->i_sb, &tmp); |
|---|
| 128 |
if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) |
|---|
| 129 |
error = -EFAULT; |
|---|
| 130 |
path_release(&nd); |
|---|
| 131 |
} |
|---|
| 132 |
return error; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
asmlinkage long sys_statfs64(const char __user *path, size_t sz, struct statfs64 __user *buf) |
|---|
| 137 |
{ |
|---|
| 138 |
struct nameidata nd; |
|---|
| 139 |
long error; |
|---|
| 140 |
|
|---|
| 141 |
if (sz != sizeof(*buf)) |
|---|
| 142 |
return -EINVAL; |
|---|
| 143 |
error = user_path_walk(path, &nd); |
|---|
| 144 |
if (!error) { |
|---|
| 145 |
struct statfs64 tmp; |
|---|
| 146 |
error = vfs_statfs64(nd.dentry->d_inode->i_sb, &tmp); |
|---|
| 147 |
if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) |
|---|
| 148 |
error = -EFAULT; |
|---|
| 149 |
path_release(&nd); |
|---|
| 150 |
} |
|---|
| 151 |
return error; |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
asmlinkage long sys_fstatfs(unsigned int fd, struct statfs __user * buf) |
|---|
| 156 |
{ |
|---|
| 157 |
struct file * file; |
|---|
| 158 |
struct statfs tmp; |
|---|
| 159 |
int error; |
|---|
| 160 |
|
|---|
| 161 |
error = -EBADF; |
|---|
| 162 |
file = fget(fd); |
|---|
| 163 |
if (!file) |
|---|
| 164 |
goto out; |
|---|
| 165 |
error = vfs_statfs_native(file->f_dentry->d_inode->i_sb, &tmp); |
|---|
| 166 |
if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) |
|---|
| 167 |
error = -EFAULT; |
|---|
| 168 |
fput(file); |
|---|
| 169 |
out: |
|---|
| 170 |
return error; |
|---|
| 171 |
} |
|---|
| 172 |
|
|---|
| 173 |
asmlinkage long sys_fstatfs64(unsigned int fd, size_t sz, struct statfs64 __user *buf) |
|---|
| 174 |
{ |
|---|
| 175 |
struct file * file; |
|---|
| 176 |
struct statfs64 tmp; |
|---|
| 177 |
int error; |
|---|
| 178 |
|
|---|
| 179 |
if (sz != sizeof(*buf)) |
|---|
| 180 |
return -EINVAL; |
|---|
| 181 |
|
|---|
| 182 |
error = -EBADF; |
|---|
| 183 |
file = fget(fd); |
|---|
| 184 |
if (!file) |
|---|
| 185 |
goto out; |
|---|
| 186 |
error = vfs_statfs64(file->f_dentry->d_inode->i_sb, &tmp); |
|---|
| 187 |
if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) |
|---|
| 188 |
error = -EFAULT; |
|---|
| 189 |
fput(file); |
|---|
| 190 |
out: |
|---|
| 191 |
return error; |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
int do_truncate(struct dentry *dentry, loff_t length) |
|---|
| 195 |
{ |
|---|
| 196 |
int err; |
|---|
| 197 |
struct iattr newattrs; |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
if (length < 0) |
|---|
| 201 |
return -EINVAL; |
|---|
| 202 |
|
|---|
| 203 |
newattrs.ia_size = length; |
|---|
| 204 |
newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; |
|---|
| 205 |
down(&dentry->d_inode->i_sem); |
|---|
| 206 |
down_write(&dentry->d_inode->i_alloc_sem); |
|---|
| 207 |
err = notify_change(dentry, &newattrs); |
|---|
| 208 |
up_write(&dentry->d_inode->i_alloc_sem); |
|---|
| 209 |
up(&dentry->d_inode->i_sem); |
|---|
| 210 |
return err; |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
static inline long do_sys_truncate(const char __user * path, loff_t length) |
|---|
| 214 |
{ |
|---|
| 215 |
struct nameidata nd; |
|---|
| 216 |
struct inode * inode; |
|---|
| 217 |
int error; |
|---|
| 218 |
|
|---|
| 219 |
error = -EINVAL; |
|---|
| 220 |
if (length < 0) |
|---|
| 221 |
goto out; |
|---|
| 222 |
|
|---|
| 223 |
error = user_path_walk(path, &nd); |
|---|
| 224 |
if (error) |
|---|
| 225 |
goto out; |
|---|
| 226 |
inode = nd.dentry->d_inode; |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
error = -EISDIR; |
|---|
| 230 |
if (S_ISDIR(inode->i_mode)) |
|---|
| 231 |
goto dput_and_out; |
|---|
| 232 |
|
|---|
| 233 |
error = -EINVAL; |
|---|
| 234 |
if (!S_ISREG(inode->i_mode)) |
|---|
| 235 |
goto dput_and_out; |
|---|
| 236 |
|
|---|
| 237 |
error = permission(inode,MAY_WRITE,&nd); |
|---|
| 238 |
if (error) |
|---|
| 239 |
goto dput_and_out; |
|---|
| 240 |
|
|---|
| 241 |
error = -EROFS; |
|---|
| 242 |
if (IS_RDONLY(inode)) |
|---|
| 243 |
goto dput_and_out; |
|---|
| 244 |
|
|---|
| 245 |
error = -EPERM; |
|---|
| 246 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
|---|
| 247 |
goto dput_and_out; |
|---|
| 248 |
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
error = break_lease(inode, FMODE_WRITE); |
|---|
| 253 |
if (error) |
|---|
| 254 |
goto dput_and_out; |
|---|
| 255 |
|
|---|
| 256 |
error = get_write_access(inode); |
|---|
| 257 |
if (error) |
|---|
| 258 |
goto dput_and_out; |
|---|
| 259 |
|
|---|
| 260 |
error = locks_verify_truncate(inode, NULL, length); |
|---|
| 261 |
if (!error) { |
|---|
| 262 |
DQUOT_INIT(inode); |
|---|
| 263 |
error = do_truncate(nd.dentry, length); |
|---|
| 264 |
} |
|---|
| 265 |
put_write_access(inode); |
|---|
| 266 |
|
|---|
| 267 |
dput_and_out: |
|---|
| 268 |
path_release(&nd); |
|---|
| 269 |
out: |
|---|
| 270 |
return error; |
|---|
| 271 |
} |
|---|
| 272 |
|
|---|
| 273 |
asmlinkage long sys_truncate(const char __user * path, unsigned long length) |
|---|
| 274 |
{ |
|---|
| 275 |
|
|---|
| 276 |
return do_sys_truncate(path, (long)length); |
|---|
| 277 |
} |
|---|
| 278 |
|
|---|
| 279 |
static inline long do_sys_ftruncate(unsigned int fd, loff_t length, int small) |
|---|
| 280 |
{ |
|---|
| 281 |
struct inode * inode; |
|---|
| 282 |
struct dentry *dentry; |
|---|
| 283 |
struct file * file; |
|---|
| 284 |
int error; |
|---|
| 285 |
|
|---|
| 286 |
error = -EINVAL; |
|---|
| 287 |
if (length < 0) |
|---|
| 288 |
goto out; |
|---|
| 289 |
error = -EBADF; |
|---|
| 290 |
file = fget(fd); |
|---|
| 291 |
if (!file) |
|---|
| 292 |
goto out; |
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
if (file->f_flags & O_LARGEFILE) |
|---|
| 296 |
small = 0; |
|---|
| 297 |
|
|---|
| 298 |
dentry = file->f_dentry; |
|---|
| 299 |
inode = dentry->d_inode; |
|---|
| 300 |
error = -EINVAL; |
|---|
| 301 |
if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE)) |
|---|
| 302 |
goto out_putf; |
|---|
| 303 |
|
|---|
| 304 |
error = -EINVAL; |
|---|
| 305 |
|
|---|
| 306 |
if (small && length > MAX_NON_LFS) |
|---|
| 307 |
goto out_putf; |
|---|
| 308 |
|
|---|
| 309 |
error = -EPERM; |
|---|
| 310 |
if (IS_APPEND(inode)) |
|---|
| 311 |
goto out_putf; |
|---|
| 312 |
|
|---|
| 313 |
error = locks_verify_truncate(inode, file, length); |
|---|
| 314 |
if (!error) |
|---|
| 315 |
error = do_truncate(dentry, length); |
|---|
| 316 |
out_putf: |
|---|
| 317 |
fput(file); |
|---|
| 318 |
out: |
|---|
| 319 |
return error; |
|---|
| 320 |
} |
|---|
| 321 |
|
|---|
| 322 |
asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length) |
|---|
| 323 |
{ |
|---|
| 324 |
return do_sys_ftruncate(fd, length, 1); |
|---|
| 325 |
} |
|---|
| 326 |
|
|---|
| 327 |
|
|---|
| 328 |
#if BITS_PER_LONG == 32 |
|---|
| 329 |
asmlinkage long sys_truncate64(const char __user * path, loff_t length) |
|---|
| 330 |
{ |
|---|
| 331 |
return do_sys_truncate(path, length); |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length) |
|---|
| 335 |
{ |
|---|
| 336 |
return do_sys_ftruncate(fd, length, 0); |
|---|
| 337 |
} |
|---|
| 338 |
#endif |
|---|
| 339 |
|
|---|
| 340 |
#ifdef __ARCH_WANT_SYS_UTIME |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * times) |
|---|
| 354 |
{ |
|---|
| 355 |
int error; |
|---|
| 356 |
struct nameidata nd; |
|---|
| 357 |
struct inode * inode; |
|---|
| 358 |
struct iattr newattrs; |
|---|
| 359 |
|
|---|
| 360 |
error = user_path_walk(filename, &nd); |
|---|
| 361 |
if (error) |
|---|
| 362 |
goto out; |
|---|
| 363 |
inode = nd.dentry->d_inode; |
|---|
| 364 |
|
|---|
| 365 |
error = -EROFS; |
|---|
| 366 |
if (IS_RDONLY(inode)) |
|---|
| 367 |
goto dput_and_out; |
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; |
|---|
| 371 |
if (times) { |
|---|
| 372 |
error = -EPERM; |
|---|
| 373 |
if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
|---|
| 374 |
goto dput_and_out; |
|---|
| 375 |
|
|---|
| 376 |
error = get_user(newattrs.ia_atime.tv_sec, ×->actime); |
|---|
| 377 |
newattrs.ia_atime.tv_nsec = 0; |
|---|
| 378 |
if (!error) |
|---|
| 379 |
error = get_user(newattrs.ia_mtime.tv_sec, ×->modtime); |
|---|
| 380 |
newattrs.ia_mtime.tv_nsec = 0; |
|---|
| 381 |
if (error) |
|---|
| 382 |
goto dput_and_out; |
|---|
| 383 |
|
|---|
| 384 |
newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET; |
|---|
| 385 |
} else { |
|---|
| 386 |
error = -EACCES; |
|---|
| 387 |
if (IS_IMMUTABLE(inode)) |
|---|
| 388 |
goto dput_and_out; |
|---|
| 389 |
|
|---|
| 390 |
if (current->fsuid != inode->i_uid && |
|---|
| 391 |
(error = permission(inode,MAY_WRITE,&nd)) != 0) |
|---|
| 392 |
goto dput_and_out; |
|---|
| 393 |
} |
|---|
| 394 |
down(&inode->i_sem); |
|---|
| 395 |
error = notify_change(nd.dentry, &newattrs); |
|---|
| 396 |
up(&inode->i_sem); |
|---|
| 397 |
dput_and_out: |
|---|
| 398 |
path_release(&nd); |
|---|
| 399 |
out: |
|---|
| 400 |
return error; |
|---|
| 401 |
} |
|---|
| 402 |
|
|---|
| 403 |
#endif |
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
long do_utimes(char __user * filename, struct timeval * times) |
|---|
| 410 |
{ |
|---|
| 411 |
int error; |
|---|
| 412 |
struct nameidata nd; |
|---|
| 413 |
struct inode * inode; |
|---|
| 414 |
struct iattr newattrs; |
|---|
| 415 |
|
|---|
| 416 |
error = user_path_walk(filename, &nd); |
|---|
| 417 |
|
|---|
| 418 |
if (error) |
|---|
| 419 |
goto out; |
|---|
| 420 |
inode = nd.dentry->d_inode; |
|---|
| 421 |
|
|---|
| 422 |
error = -EROFS; |
|---|
| 423 |
if (IS_RDONLY(inode)) |
|---|
| 424 |
goto dput_and_out; |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME; |
|---|
| 428 |
if (times) { |
|---|
| 429 |
error = -EPERM; |
|---|
| 430 |
if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) |
|---|
| 431 |
goto dput_and_out; |
|---|
| 432 |
|
|---|
| 433 |
newattrs.ia_atime.tv_sec = times[0].tv_sec; |
|---|
| 434 |
newattrs.ia_atime.tv_nsec = times[0].tv_usec * 1000; |
|---|
| 435 |
newattrs.ia_mtime.tv_sec = times[1].tv_sec; |
|---|
| 436 |
newattrs.ia_mtime.tv_nsec = times[1].tv_usec * 1000; |
|---|
| 437 |
newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET; |
|---|
| 438 |
} else { |
|---|
| 439 |
error = -EACCES; |
|---|
| 440 |
if (IS_IMMUTABLE(inode)) |
|---|
| 441 |
goto dput_and_out; |
|---|
| 442 |
|
|---|
| 443 |
if (current->fsuid != inode->i_uid && |
|---|
| 444 |
(error = permission(inode,MAY_WRITE,&nd)) != 0) |
|---|
| 445 |
goto dput_and_out; |
|---|
| 446 |
} |
|---|
| 447 |
down(&inode->i_sem); |
|---|
| 448 |
error = notify_change(nd.dentry, &newattrs); |
|---|
| 449 |
up(&inode->i_sem); |
|---|
| 450 |
dput_and_out: |
|---|
| 451 |
path_release(&nd); |
|---|
| 452 |
out: |
|---|
| 453 |
return error; |
|---|
| 454 |
} |
|---|
| 455 |
|
|---|
| 456 |
asmlinkage long sys_utimes(char __user * filename, struct timeval __user * utimes) |
|---|
| 457 |
{ |
|---|
| 458 |
struct timeval times[2]; |
|---|
| 459 |
|
|---|
| 460 |
if (utimes && copy_from_user(×, utimes, sizeof(times))) |
|---|
| 461 |
return -EFAULT; |
|---|
| 462 |
return do_utimes(filename, utimes ? times : NULL); |
|---|
| 463 |
} |
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
asmlinkage long sys_access(const char __user * filename, int mode) |
|---|
| 472 |
{ |
|---|
| 473 |
struct nameidata nd; |
|---|
| 474 |
int old_fsuid, old_fsgid; |
|---|
| 475 |
kernel_cap_t old_cap; |
|---|
| 476 |
int res; |
|---|
| 477 |
|
|---|
| 478 |
if (mode & ~S_IRWXO) |
|---|
| 479 |
return -EINVAL; |
|---|
| 480 |
|
|---|
| 481 |
old_fsuid = current->fsuid; |
|---|
| 482 |
old_fsgid = current->fsgid; |
|---|
| 483 |
old_cap = current->cap_effective; |
|---|
| 484 |
|
|---|
| 485 |
current->fsuid = current->uid; |
|---|
| 486 |
current->fsgid = current->gid; |
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
if (current->uid) |
|---|
| 497 |
cap_clear(current->cap_effective); |
|---|
| 498 |
else |
|---|
| 499 |
current->cap_effective = current->cap_permitted; |
|---|
| 500 |
|
|---|
| 501 |
res = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_ACCESS, &nd); |
|---|
| 502 |
if (!res) { |
|---|
| 503 |
res = permission(nd.dentry->d_inode, mode, &nd); |
|---|
| 504 |
|
|---|
| 505 |
if(!res && (mode & S_IWOTH) && IS_RDONLY(nd.dentry->d_inode) |
|---|
| 506 |
&& !special_file(nd.dentry->d_inode->i_mode)) |
|---|
| 507 |
res = -EROFS; |
|---|
| 508 |
path_release(&nd); |
|---|
| 509 |
} |
|---|
| 510 |
|
|---|
| 511 |
current->fsuid = old_fsuid; |
|---|
| 512 |
current->fsgid = old_fsgid; |
|---|
| 513 |
current->cap_effective = old_cap; |
|---|
| 514 |
|
|---|
| 515 |
return res; |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
asmlinkage long sys_chdir(const char __user * filename) |
|---|
| 519 |
{ |
|---|
| 520 |
struct nameidata nd; |
|---|
| 521 |
int error; |
|---|
| 522 |
|
|---|
| 523 |
error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); |
|---|
| 524 |
if (error) |
|---|
| 525 |
goto out; |
|---|
| 526 |
|
|---|
| 527 |
error = permission(nd.dentry->d_inode,MAY_EXEC,&nd); |
|---|
| 528 |
if (error) |
|---|
| 529 |
goto dput_and_out; |
|---|
| 530 |
|
|---|
| 531 |
set_fs_pwd(current->fs, nd.mnt, nd.dentry); |
|---|
| 532 |
|
|---|
| 533 |
dput_and_out: |
|---|
| 534 |
path_release(&nd); |
|---|
| 535 |
out: |
|---|
| 536 |
return error; |
|---|
| 537 |
} |
|---|
| 538 |
|
|---|
| 539 |
asmlinkage long sys_fchdir(unsigned int fd) |
|---|
| 540 |
{ |
|---|
| 541 |
struct file *file; |
|---|
| 542 |
struct dentry *dentry; |
|---|
| 543 |
struct inode *inode; |
|---|
| 544 |
struct vfsmount *mnt; |
|---|
| 545 |
int error; |
|---|
| 546 |
|
|---|
| 547 |
error = -EBADF; |
|---|
| 548 |
file = fget(fd); |
|---|
| 549 |
if (!file) |
|---|
| 550 |
goto out; |
|---|
| 551 |
|
|---|
| 552 |
dentry = file->f_dentry; |
|---|
| 553 |
mnt = file->f_vfsmnt; |
|---|
| 554 |
inode = dentry->d_inode; |
|---|
| 555 |
|
|---|
| 556 |
error = -ENOTDIR; |
|---|
| 557 |
if (!S_ISDIR(inode->i_mode)) |
|---|
| 558 |
goto out_putf; |
|---|
| 559 |
|
|---|
| 560 |
error = permission(inode, MAY_EXEC, NULL); |
|---|
| 561 |
if (!error) |
|---|
| 562 |
set_fs_pwd(current->fs, mnt, dentry); |
|---|
| 563 |
out_putf: |
|---|
| 564 |
fput(file); |
|---|
| 565 |
out: |
|---|
| 566 |
return error; |
|---|
| 567 |
} |
|---|
| 568 |
|
|---|
| 569 |
asmlinkage long sys_chroot(const char __user * filename) |
|---|
| 570 |
{ |
|---|
| 571 |
struct nameidata nd; |
|---|
| 572 |
int error; |
|---|
| 573 |
|
|---|
| 574 |
error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd); |
|---|
| 575 |
if (error) |
|---|
| 576 |
goto out; |
|---|
| 577 |
|
|---|
| 578 |
error = permission(nd.dentry->d_inode,MAY_EXEC,&nd); |
|---|
| 579 |
if (error) |
|---|
| 580 |
goto dput_and_out; |
|---|
| 581 |
|
|---|
| 582 |
error = -EPERM; |
|---|
| 583 |
if (!capable(CAP_SYS_CHROOT)) |
|---|
| 584 |
goto dput_and_out; |
|---|
| 585 |
|
|---|
| 586 |
set_fs_root(current->fs, nd.mnt, nd.dentry); |
|---|
| 587 |
set_fs_altroot(); |
|---|
| 588 |
error = 0; |
|---|
| 589 |
dput_and_out: |
|---|
| 590 |
path_release(&nd); |
|---|
| 591 |
out: |
|---|
| 592 |
return error; |
|---|
| 593 |
} |
|---|
| 594 |
|
|---|
| 595 |
asmlinkage long sys_fchmod(unsigned int fd, mode_t mode) |
|---|
| 596 |
{ |
|---|
| 597 |
struct inode * inode; |
|---|
| 598 |
struct dentry * dentry; |
|---|
| 599 |
struct file * file; |
|---|
| 600 |
int err = -EBADF; |
|---|
| 601 |
struct iattr newattrs; |
|---|
| 602 |
|
|---|
| 603 |
file = fget(fd); |
|---|
| 604 |
if (!file) |
|---|
| 605 |
goto out; |
|---|
| 606 |
|
|---|
| 607 |
dentry = file->f_dentry; |
|---|
| 608 |
inode = dentry->d_inode; |
|---|
| 609 |
|
|---|
| 610 |
err = -EROFS; |
|---|
| 611 |
if (IS_RDONLY(inode)) |
|---|
| 612 |
goto out_putf; |
|---|
| 613 |
err = -EPERM; |
|---|
| 614 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
|---|
| 615 |
goto out_putf; |
|---|
| 616 |
down(&inode->i_sem); |
|---|
| 617 |
if (mode == (mode_t) -1) |
|---|
| 618 |
mode = inode->i_mode; |
|---|
| 619 |
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); |
|---|
| 620 |
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; |
|---|
| 621 |
err = notify_change(dentry, &newattrs); |
|---|
| 622 |
up(&inode->i_sem); |
|---|
| 623 |
|
|---|
| 624 |
out_putf: |
|---|
| 625 |
fput(file); |
|---|
| 626 |
out: |
|---|
| 627 |
return err; |
|---|
| 628 |
} |
|---|
| 629 |
|
|---|
| 630 |
asmlinkage long sys_chmod(const char __user * filename, mode_t mode) |
|---|
| 631 |
{ |
|---|
| 632 |
struct nameidata nd; |
|---|
| 633 |
struct inode * inode; |
|---|
| 634 |
int error; |
|---|
| 635 |
struct iattr newattrs; |
|---|
| 636 |
|
|---|
| 637 |
error = user_path_walk(filename, &nd); |
|---|
| 638 |
if (error) |
|---|
| 639 |
goto out; |
|---|
| 640 |
inode = nd.dentry->d_inode; |
|---|
| 641 |
|
|---|
| 642 |
error = -EROFS; |
|---|
| 643 |
if (IS_RDONLY(inode)) |
|---|
| 644 |
goto dput_and_out; |
|---|
| 645 |
|
|---|
| 646 |
error = -EPERM; |
|---|
| 647 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
|---|
| 648 |
goto dput_and_out; |
|---|
| 649 |
|
|---|
| 650 |
down(&inode->i_sem); |
|---|
| 651 |
if (mode == (mode_t) -1) |
|---|
| 652 |
mode = inode->i_mode; |
|---|
| 653 |
newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); |
|---|
| 654 |
newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; |
|---|
| 655 |
error = notify_change(nd.dentry, &newattrs); |
|---|
| 656 |
up(&inode->i_sem); |
|---|
| 657 |
|
|---|
| 658 |
dput_and_out: |
|---|
| 659 |
path_release(&nd); |
|---|
| 660 |
out: |
|---|
| 661 |
return error; |
|---|
| 662 |
} |
|---|
| 663 |
|
|---|
| 664 |
static int chown_common(struct dentry * dentry, uid_t user, gid_t group) |
|---|
| 665 |
{ |
|---|
| 666 |
struct inode * inode; |
|---|
| 667 |
int error; |
|---|
| 668 |
struct iattr newattrs; |
|---|
| 669 |
|
|---|
| 670 |
error = -ENOENT; |
|---|
| 671 |
if (!(inode = dentry->d_inode)) { |
|---|
| 672 |
printk(KERN_ERR "chown_common: NULL inode\n"); |
|---|
| 673 |
goto out; |
|---|
| 674 |
} |
|---|
| 675 |
error = -EROFS; |
|---|
| 676 |
if (IS_RDONLY(inode)) |
|---|
| 677 |
goto out; |
|---|
| 678 |
error = -EPERM; |
|---|
| 679 |
if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) |
|---|
| 680 |
goto out; |
|---|
| 681 |
newattrs.ia_valid = ATTR_CTIME; |
|---|
| 682 |
if (user != (uid_t) -1) { |
|---|
| 683 |
newattrs.ia_valid |= ATTR_UID; |
|---|
| 684 |
newattrs.ia_uid = user; |
|---|
| 685 |
} |
|---|
| 686 |
if (group != (gid_t) -1) { |
|---|
| 687 |
newattrs.ia_valid |= ATTR_GID; |
|---|
| 688 |
newattrs.ia_gid = group; |
|---|
| 689 |
} |
|---|
| 690 |
if (!S_ISDIR(inode->i_mode)) |
|---|
| 691 |
newattrs.ia_valid |= ATTR_KILL_SUID|ATTR_KILL_SGID; |
|---|
| 692 |
down(&inode->i_sem); |
|---|
| 693 |
error = notify_change(dentry, &newattrs); |
|---|
| 694 |
up(&inode->i_sem); |
|---|
| 695 |
out: |
|---|
| 696 |
return error; |
|---|
| 697 |
} |
|---|
| 698 |
|
|---|
| 699 |
asmlinkage long sys_chown(const char __user * filename, uid_t user, gid_t group) |
|---|
| 700 |
{ |
|---|
| 701 |
struct nameidata nd; |
|---|
| 702 |
int error; |
|---|
| 703 |
|
|---|
| 704 |
error = user_path_walk(filename, &nd); |
|---|
| 705 |
if (!error) { |
|---|
| 706 |
error = chown_common(nd.dentry, user, group); |
|---|
| 707 |
path_release(&nd); |
|---|
| 708 |
} |
|---|
| 709 |
return error; |
|---|
| 710 |
} |
|---|
| 711 |
|
|---|
| 712 |
asmlinkage long sys_lchown(const char __user * filename, uid_t user, gid_t group) |
|---|
| 713 |
{ |
|---|
| 714 |
struct nameidata nd; |
|---|
| 715 |
int error; |
|---|
| 716 |
|
|---|
| 717 |
error = user_path_walk_link(filename, &nd); |
|---|
| 718 |
if (!error) { |
|---|
| 719 |
error = chown_common(nd.dentry, user, group); |
|---|
| 720 |
path_release(&nd); |
|---|
| 721 |
} |
|---|
| 722 |
return error; |
|---|
| 723 |
} |
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group) |
|---|
| 727 |
{ |
|---|
| 728 |
struct file * file; |
|---|
| 729 |
int error = -EBADF; |
|---|
| 730 |
|
|---|
| 731 |
file = fget(fd); |
|---|
| 732 |
if (file) { |
|---|
| 733 |
error = chown_common(file->f_dentry, user, group); |
|---|
| 734 |
fput(file); |
|---|
| 735 |
} |
|---|
| 736 |
return error; |
|---|
| 737 |
} |
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
|
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
|
|---|
| 746 |
|
|---|
| 747 |
|
|---|
| 748 |
|
|---|
| 749 |
|
|---|
| 750 |
|
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
struct file *filp_open(const char * filename, int flags, int mode) |
|---|
| 754 |
{ |
|---|
| 755 |
int namei_flags, error; |
|---|
| 756 |
struct nameidata nd; |
|---|
| 757 |
|
|---|
| 758 |
namei_flags = flags; |
|---|
| 759 |
if ((namei_flags+1) & O_ACCMODE) |
|---|
| 760 |
namei_flags++; |
|---|
| 761 |
if (namei_flags & O_TRUNC) |
|---|
| 762 |
namei_flags |= 2; |
|---|
| 763 |
|
|---|
| 764 |
error = open_namei(filename, namei_flags, mode, &nd); |
|---|
| 765 |
if (!error) |
|---|
| 766 |
return dentry_open(nd.dentry, nd.mnt, flags); |
|---|
| 767 |
|
|---|
| 768 |
return ERR_PTR(error); |
|---|
| 769 |
} |
|---|
| 770 |
|
|---|
| 771 |
EXPORT_SYMBOL(filp_open); |
|---|
| 772 |
|
|---|
| 773 |
struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags) |
|---|
| 774 |
{ |
|---|
| 775 |
struct file * f; |
|---|
| 776 |
struct inode *inode; |
|---|
| 777 |
int error; |
|---|
| 778 |
|
|---|
| 779 |
unsigned long args[2]; |
|---|
| 780 |
error = -ENFILE; |
|---|
| 781 |
f = get_empty_filp(); |
|---|
| 782 |
if (!f) |
|---|
| 783 |
goto cleanup_dentry; |
|---|
| 784 |
f->f_flags = flags; |
|---|
| 785 |
f->f_mode = (flags+1) & O_ACCMODE; |
|---|
| 786 |
inode = dentry->d_inode; |
|---|
| 787 |
if (f->f_mode & FMODE_WRITE) { |
|---|
| 788 |
error = get_write_access(inode); |
|---|
| 789 |
if (error) |
|---|
| 790 |
goto cleanup_file; |
|---|
| 791 |
} |
|---|
| 792 |
|
|---|
| 793 |
f->f_mapping = inode->i_mapping; |
|---|
| 794 |
f->f_dentry = dentry; |
|---|
| 795 |
f->f_vfsmnt = mnt; |
|---|
| 796 |
f->f_pos = 0; |
|---|
| 797 |
f->f_op = fops_get(inode->i_fop); |
|---|
| 798 |
file_move(f, &inode->i_sb->s_files); |
|---|
| 799 |
|
|---|
| 800 |
if (f->f_op && f->f_op->open) { |
|---|
| 801 |
if ((unsigned long) f->f_op->open > PAGE_OFFSET) |
|---|
| 802 |
error = f->f_op->open(inode,f); |
|---|
| 803 |
else { |
|---|
| 804 |
CALLDRIVER_PREP2(open, inode, f) |
|---|
| 805 |
error = calldriver((unsigned long) f->f_op->open, open_args, open_sizes, 2, current->mm, 3, 0); |
|---|
| 806 |
} |
|---|
| 807 |
if (error) |
|---|
| 808 |
goto cleanup_all; |
|---|
| 809 |
} |
|---|
| 810 |
f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); |
|---|
| 811 |
|
|---|
| 812 |
file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); |
|---|
| 813 |
|
|---|
| 814 |
|
|---|
| 815 |
if (f->f_flags & O_DIRECT) { |
|---|
| 816 |
if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO) { |
|---|
| 817 |
fput(f); |
|---|
| 818 |
f = ERR_PTR(-EINVAL); |
|---|
| 819 |
} |
|---|
| 820 |
} |
|---|
| 821 |
|
|---|
| 822 |
return f; |
|---|
| 823 |
|
|---|
| 824 |
cleanup_all: |
|---|
| 825 |
fops_put(f->f_op); |
|---|
| 826 |
if (f->f_mode & FMODE_WRITE) |
|---|
| 827 |
put_write_access(inode); |
|---|
| 828 |
file_kill(f); |
|---|
| 829 |
f->f_dentry = NULL; |
|---|
| 830 |
f->f_vfsmnt = NULL; |
|---|
| 831 |
cleanup_file: |
|---|
| 832 |
put_filp(f); |
|---|
| 833 |
cleanup_dentry: |
|---|
| 834 |
dput(dentry); |
|---|
| 835 |
mntput(mnt); |
|---|
| 836 |
return ERR_PTR(error); |
|---|
| 837 |
} |
|---|
| 838 |
|
|---|
| 839 |
EXPORT_SYMBOL(dentry_open); |
|---|
| 840 |
|
|---|
| 841 |
|
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
int get_unused_fd(void) |
|---|
| 845 |
{ |
|---|
| 846 |
struct files_struct * files = current->files; |
|---|
| 847 |
int fd, error; |
|---|
| 848 |
|
|---|
| 849 |
error = -EMFILE; |
|---|
| 850 |
spin_lock(&files->file_lock); |
|---|
| 851 |
|
|---|
| 852 |
repeat: |
|---|
| 853 |
fd = find_next_zero_bit(files->open_fds->fds_bits, |
|---|
| 854 |
files->max_fdset, |
|---|
| 855 |
files->next_fd); |
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
|
|---|
| 861 |
if (fd >= current->rlim[RLIMIT_NOFILE].rlim_cur) |
|---|
| 862 |
goto out; |
|---|
| 863 |
|
|---|
| 864 |
|
|---|
| 865 |
if (fd >= files->max_fdset) { |
|---|
| 866 |
error = expand_fdset(files, fd); |
|---|
| 867 |
if (!error) { |
|---|
| 868 |
error = -EMFILE; |
|---|
| 869 |
goto repeat; |
|---|
| 870 |
} |
|---|
| 871 |
goto out; |
|---|
| 872 |
} |
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
if (fd >= files->max_fds) { |
|---|
| 878 |
error = expand_fd_array(files, fd); |
|---|
| 879 |
if (!error) { |
|---|
| 880 |
error = -EMFILE; |
|---|
| 881 |
goto repeat; |
|---|
| 882 |
} |
|---|
| 883 |
goto out; |
|---|
| 884 |
} |
|---|
| 885 |
|
|---|
| 886 |
FD_SET(fd, files->open_fds); |
|---|
| 887 |
FD_CLR(fd, files->close_on_exec); |
|---|
| 888 |
files->next_fd = fd + 1; |
|---|
| 889 |
#if 1 |
|---|
| 890 |
|
|---|
| 891 |
if (files->fd[fd] != NULL) { |
|---|
| 892 |
printk(KERN_WARNING "get_unused_fd: slot %d not NULL!\n", fd); |
|---|
| 893 |
files->fd[fd] = NULL; |
|---|
| 894 |
} |
|---|
| 895 |
#endif |
|---|
| 896 |
error = fd; |
|---|
| 897 |
|
|---|
| 898 |
out: |
|---|
| 899 |
spin_unlock(&files->file_lock); |
|---|
| 900 |
return error; |
|---|
| 901 |
} |
|---|
| 902 |
|
|---|
| 903 |
EXPORT_SYMBOL(get_unused_fd); |
|---|
| 904 |
|
|---|
| 905 |
static inline void __put_unused_fd(struct files_struct *files, unsigned int fd) |
|---|
| 906 |
{ |
|---|
| 907 |
__FD_CLR(fd, files->open_fds); |
|---|
| 908 |
if (fd < files->next_fd) |
|---|
| 909 |
files->next_fd = fd; |
|---|
| 910 |
} |
|---|
| 911 |
|
|---|
| 912 |
void fastcall put_unused_fd(unsigned int fd) |
|---|
| 913 |
{ |
|---|
| 914 |
struct files_struct *files = current->files; |
|---|
| 915 |
spin_lock(&files->file_lock); |
|---|
| 916 |
__put_unused_fd(files, fd); |
|---|
| 917 |
spin_unlock(&files->file_lock); |
|---|
| 918 |
} |
|---|
| 919 |
|
|---|
| 920 |
EXPORT_SYMBOL(put_unused_fd); |
|---|
| 921 |
|
|---|
| 922 |
|
|---|
| 923 |
|
|---|
| 924 |
|
|---|
| 925 |
|
|---|
| 926 |
|
|---|
| 927 |
|
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
void fastcall fd_install(unsigned int fd, struct file * file) |
|---|
| 936 |
{ |
|---|
| 937 |
struct files_struct *files = current->files; |
|---|
| 938 |
spin_lock(&files->file_lock); |
|---|
| 939 |
if (unlikely(files->fd[fd] != NULL)) |
|---|
| 940 |
BUG(); |
|---|
| 941 |
files->fd[fd] = file; |
|---|
| 942 |
spin_unlock(&files->file_lock); |
|---|
| 943 |
} |
|---|
| 944 |
|
|---|
| 945 |
EXPORT_SYMBOL(fd_install); |
|---|
| 946 |
|
|---|
| 947 |
asmlinkage long sys_open(const char __user * filename, int flags, int mode) |
|---|
| 948 |
{ |
|---|
| 949 |
char * tmp; |
|---|
| 950 |
int fd, error; |
|---|
| 951 |
|
|---|
| 952 |
#if BITS_PER_LONG != 32 |
|---|
| 953 |
flags |= O_LARGEFILE; |
|---|
| 954 |
#endif |
|---|
| 955 |
tmp = getname(filename); |
|---|
| 956 |
fd = PTR_ERR(tmp); |
|---|
| 957 |
if (!IS_ERR(tmp)) { |
|---|
| 958 |
fd = get_unused_fd(); |
|---|
| 959 |
if (fd >= 0) { |
|---|
| 960 |
struct file *f = filp_open(tmp, flags, mode); |
|---|
| 961 |
error = PTR_ERR(f); |
|---|
| 962 |
if (IS_ERR(f)) |
|---|
| 963 |
goto out_error; |
|---|
| 964 |
fd_install(fd, f); |
|---|
| 965 |
} |
|---|
| 966 |
out: |
|---|
| 967 |
putname(tmp); |
|---|
| 968 |
} |
|---|
| 969 |
return fd; |
|---|
| 970 |
|
|---|
| 971 |
out_error: |
|---|
| 972 |
put_unused_fd(fd); |
|---|
| 973 |
fd = error; |
|---|
| 974 |
goto out; |
|---|
| 975 |
} |
|---|
| 976 |
EXPORT_SYMBOL_GPL(sys_open); |
|---|
| 977 |
|
|---|
| 978 |
#ifndef __alpha__ |
|---|
| 979 |
|
|---|
| 980 |
|
|---|
| 981 |
|
|---|
| 982 |
|
|---|
| 983 |
|
|---|
| 984 |
asmlinkage long sys_creat(const char __user * pathname, int mode) |
|---|
| 985 |
{ |
|---|
| 986 |
return sys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode); |
|---|
| 987 |
} |
|---|
| 988 |
|
|---|
| 989 |
#endif |
|---|
| 990 |
|
|---|
| 991 |
|
|---|
| 992 |
|
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 |
int filp_close(struct file *filp, fl_owner_t id) |
|---|
| 996 |
{ |
|---|
| 997 |
int retval; |
|---|
| 998 |
struct task_struct *tsk; |
|---|
| 999 |
|
|---|
| 1000 |
retval = filp->f_error; |
|---|
| 1001 |
if (retval) |
|---|
| 1002 |
filp->f_error = 0; |
|---|
| 1003 |
|
|---|
| 1004 |
if (!file_count(filp)) { |
|---|
| 1005 |
printk(KERN_ERR "VFS: Close: file count is 0\n"); |
|---|
| 1006 |
return retval; |
|---|
| 1007 |
} |
|---|
| 1008 |
|
|---|
| 1009 |
if (filp->f_op && filp->f_op->flush) { |
|---|
| 1010 |
int err; |
|---|
| 1011 |
if ((unsigned long) filp->f_op->flush > PAGE_OFFSET) |
|---|
| 1012 |
err = filp->f_op->flush(filp); |
|---|
| 1013 |
else { |
|---|
| 1014 |
unsigned int size=sizeof(*filp); |
|---|
| 1015 |
void *args[1]={filp}; |
|---|
| 1016 |
err=calldriver((unsigned long) filp->f_op->flush, args, &size, 1, current->mm, 1, 0); |
|---|
| 1017 |
} |
|---|
| 1018 |
if (!retval) |
|---|
| 1019 |
retval = err; |
|---|
| 1020 |
} |
|---|
| 1021 |
if (filp->f_op && (unsigned long) filp->f_op < PAGE_OFFSET) { |
|---|
| 1022 |
tsk=find_worker_thread((unsigned long) filp->f_op, 0); |
|---|
| 1023 |
tsk->available=1; |
|---|
| 1024 |
put_module(tsk->driver_id); |
|---|
| 1025 |
} |
|---|
| 1026 |
|
|---|
| 1027 |
dnotify_flush(filp, id); |
|---|
| 1028 |
locks_remove_posix(filp, id); |
|---|
| 1029 |
fput(filp); |
|---|
| 1030 |
return retval; |
|---|
| 1031 |
} |
|---|
| 1032 |
|
|---|
| 1033 |
EXPORT_SYMBOL(filp_close); |
|---|
| 1034 |
|
|---|
| 1035 |
|
|---|
| 1036 |
|
|---|
| 1037 |
|
|---|
| 1038 |
|
|---|
| 1039 |
|
|---|
| 1040 |
asmlinkage long sys_close(unsigned int fd) |
|---|
| 1041 |
{ |
|---|
| 1042 |
struct file * filp; |
|---|
| 1043 |
struct files_struct *files = current->files; |
|---|
| 1044 |
|
|---|
| 1045 |
spin_lock(&files->file_lock); |
|---|
| 1046 |
if (fd >= files->max_fds) |
|---|
| 1047 |
goto out_unlock; |
|---|
| 1048 |
filp = files->fd[fd]; |
|---|
| 1049 |
if (!filp) |
|---|
| 1050 |
goto out_unlock; |
|---|
| 1051 |
files->fd[fd] = NULL; |
|---|
| 1052 |
FD_CLR(fd, files->close_on_exec); |
|---|
| 1053 |
__put_unused_fd(files, fd); |
|---|
| 1054 |
spin_unlock(&files->file_lock); |
|---|
| 1055 |
return filp_close(filp, files); |
|---|
| 1056 |
|
|---|
| 1057 |
out_unlock: |
|---|
| 1058 |
spin_unlock(&files->file_lock); |
|---|
| 1059 |
return -EBADF; |
|---|
| 1060 |
} |
|---|
| 1061 |
|
|---|
| 1062 |
EXPORT_SYMBOL(sys_close); |
|---|
| 1063 |
|
|---|
| 1064 |
|
|---|
| 1065 |
|
|---|
| 1066 |
|
|---|
| 1067 |
|
|---|
| 1068 |
asmlinkage long sys_vhangup(void) |
|---|
| 1069 |
{ |
|---|
| 1070 |
if (capable(CAP_SYS_TTY_CONFIG)) { |
|---|
| 1071 |
tty_vhangup(current->signal->tty); |
|---|
| 1072 |
return 0; |
|---|
| 1073 |
} |
|---|
| 1074 |
return -EPERM; |
|---|
| 1075 |
} |
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
|
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
|
|---|
| 1083 |
int generic_file_open(struct inode * inode, struct file * filp) |
|---|
| 1084 |
{ |
|---|
| 1085 |
if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) |
|---|
| 1086 |
return -EFBIG; |
|---|
| 1087 |
return 0; |
|---|
| 1088 |
} |
|---|
| 1089 |
|
|---|
| 1090 |
EXPORT_SYMBOL(generic_file_open); |
|---|