---
name: "VOP_OPEN"
section: "9"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/VOP_OPEN"
---

# VOP\_OPEN(9)

open or close a file

## NAME

**VOP\_OPEN**, **VOP\_CLOSE** – open or close a file

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/vnode.h\>**

*int*\

**VOP\_OPEN**(*struct vnode \*vp*, *int mode*, *struct ucred \*cred*, *struct thread \*td*, *int fdidx*);

*int*\

**VOP\_CLOSE**(*struct vnode \*vp*, *int mode*, *struct ucred \*cred*, *struct thread \*td*);

## DESCRIPTION

The **VOP\_OPEN**() entry point is called before a file is accessed by a process and the **VOP\_CLOSE**() entry point is called after a file is finished with by the process.

The arguments are:

- *vp*

  The vnode of the file.

- *mode*

  The access mode required by the calling process.

- *td*

  The thread which is accessing the file.

Additionally, **VOP\_OPEN**() can accept a file descriptor number in *fdidx*; this is useful for file systems which require such information, e.g., fdescfs(5).

The access mode is a set of flags, including FREAD, FWRITE, O\_NONBLOCK, O\_APPEND.

## LOCKS

**VOP\_OPEN**() expects *vp* to be locked on entry and will leave it locked on return.

**VOP\_CLOSE**() expects at least a reference to be associated with the vnode and does not care whether the vnode is locked or not. The lock and reference state is left unchanged on return. Note that *vn\_close* expects an unlocked, referenced vnode and will dereference the vnode prior to returning.

## IMPLEMENTATION NOTES

The *fdidx* argument to **VOP\_OPEN**() is currently unused, use ‘-1’ for the meantime; however, this will change in future.

## RETURN VALUES

Zero is returned on success, otherwise an error code is returned.

## PSEUDOCODE

```
int
vop_open(struct vnode *vp, int mode, struct ucred *cred, struct thread *td)
{
    /*
     * Most file systems don't do much here.
     */
    return 0;
}
```

## SEE ALSO

[vnode(9)](/vnode/9.md), [VOP\_LOOKUP(9)](/VOP_LOOKUP/9.md)

## AUTHORS

This manual page was written by Doug Rabson.
