AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
trunc.c
Go to the documentation of this file.
1
4
5
#include <
core/system.h
>
6
#include <
fs/vfs.h
>
7
#include <
dev/dev.h
>
8
#include <
mm/vm.h
>
9
19
int
vfs_trunc
(
struct
vnode
*
vnode
,
off_t
len)
20
{
21
vfs_log(
LOG_DEBUG
,
"vfs_trunc(vnode=%p, len=%d)\n"
,
vnode
, len);
22
23
/* invalid request */
24
if
(!
vnode
)
25
return
-EINVAL;
26
27
/* a device node has no length to change */
28
if
(
ISDEV
(
vnode
))
29
return
-EINVAL;
30
31
/* invalid request */
32
if
(!
vnode
->
fs
)
33
return
-EINVAL;
34
35
/* the filesystem doesn't support it */
36
if
(!
vnode
->
fs
->
vops
.
trunc
)
37
return
-ENOSYS;
38
39
off_t
old =
vnode
->
size
;
40
int
err =
vnode
->
fs
->
vops
.
trunc
(
vnode
, len);
41
42
/* refresh the file's pages in the page cache between the old end and
43
* the new one */
44
if
(!err)
45
vnode_pages_update
(
vnode
,
MIN
(old, len),
MAX
(old, len));
46
47
return
err;
48
}
49
dev.h
vnode_pages_update
void vnode_pages_update(struct vnode *vnode, off_t start, off_t end)
Reads a file's cached pages again after a write or a truncation changed a range of it.
Definition
vm_object.c:128
system.h
MIN
#define MIN(a, b)
Definition
system.h:11
MAX
#define MAX(a, b)
Definition
system.h:10
LOG_DEBUG
#define LOG_DEBUG
Definition
printk.h:19
fs::vops
struct vops vops
Definition
vfs.h:104
vnode
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition
vfs.h:113
vnode::fs
struct fs * fs
Definition
vfs.h:127
vnode::size
size_t size
Definition
vfs.h:115
vops::trunc
int(*) trunc(struct vnode *vnode, off_t len)
Definition
vfs.h:76
vfs_trunc
int vfs_trunc(struct vnode *vnode, off_t len)
Changes a file's length, through its filesystem.
Definition
trunc.c:19
off_t
long int off_t
Definition
types.h:10
vfs.h
ISDEV
#define ISDEV(vnode)
Definition
vfs.h:209
vm.h
kernel
fs
trunc.c
Generated by
1.18.0