Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | |
2 | #include <fs/types.h> |
||
3 | #include <fs/errno.h> |
||
4 | #include <fs/task.h> |
||
5 | #include <fs/maccess.h> |
||
6 | #include <fs/fcntl.h> |
||
7 | |||
8 | #include "file.h" |
||
9 | #include "inode.h" |
||
10 | #include "dentry.h" |
||
11 | #include "fileop.h" |
||
12 | #include "dentryop.h" |
||
13 | #include "inodeop.h" |
||
14 | #include "fsconst.h" |
||
15 | #include "fs.h" |
||
16 | |||
17 | int k_ftruncate(int fd, __off_t len) |
||
18 | { |
||
19 | struct inode *in; |
||
20 | int res; |
||
21 | __pid_t pid; |
||
22 | |||
23 | call_to_fs(); |
||
24 | |||
25 | /* don't try to use a bad file descriptor */ |
||
26 | pid=__get_pid(); |
||
27 | if (check_fd(pid,fd)) { |
||
28 | printk(KERN_INFO "k_ftruncate: using bad file descriptor"); |
||
29 | return_from_fs(-EBADF); |
||
30 | } |
||
31 | |||
32 | /* don't try to write a directory */ |
||
33 | if (file_ptr(pid,fd)->f_flag_isdir) return_from_fs(-EBADF); |
||
34 | |||
35 | /* if in read only mode (errno OK?)*/ |
||
36 | if (*fildesfflags_ptr(pid,fd)&O_RDONLY) |
||
37 | return_from_fs(-EPERM); |
||
38 | |||
39 | /* acquire write lock on inode's file */ |
||
40 | in=file_ptr(pid,fd)->f_dentry->d_inode; |
||
41 | __rwlock_wrlock(&in->i_lock); |
||
42 | |||
43 | /* |
||
44 | if (*fildesfflags_ptr(pid,fd)&O_APPEND) |
||
45 | if (file_ptr(pid,fd)->f_pos!= |
||
46 | file_ptr(pid,fd)->f_dentry->d_inode->i_st.st_size) { |
||
47 | __off_t off; |
||
48 | off=file_ptr(pid,fd)->f_op->lseek(file_ptr(pid,fd),0,SEEK_END); |
||
49 | if (off!=file_ptr(pid,fd)->f_dentry->d_inode->i_st.st_size) { |
||
50 | sz=-ESPIPE; |
||
51 | goto SKIP; |
||
52 | } |
||
53 | } |
||
54 | */ |
||
55 | |||
56 | /* truncate */ |
||
57 | res=in->i_op->truncate(in,len); |
||
58 | |||
59 | /* release the lock */ |
||
60 | __rwlock_wrunlock(&in->i_lock); |
||
61 | |||
62 | return_from_fs(res); |
||
63 | } |