---
name: "ufs_disk_write"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/ufs_disk_close"
---

# ufs\_disk\_write(3)

open and close userland UFS disks

Part of [ufs\_disk\_close(3)](/ufs_disk_close/3.md).

## NAME

**ufs\_disk\_close**, **ufs\_disk\_fillout**, **ufs\_disk\_fillout\_blank**, **ufs\_disk\_write** – open and close userland UFS disks

## LIBRARY

library “libufs”

## SYNOPSIS

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

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

**#include \<ufs/ufs/ufsmount.h\>**

**#include \<ufs/ufs/dinode.h\>**

**#include \<ufs/ffs/fs.h\>**

**#include \<libufs.h\>**

*int*\

**ufs\_disk\_close**(*struct uufsd \*disk*);

*int*\

**ufs\_disk\_fillout**(*struct uufsd \*disk*, *const char \*name*);

*int*\

**ufs\_disk\_fillout\_blank**(*struct uufsd \*disk*, *const char \*name*);

*int*\

**ufs\_disk\_write**(*struct uufsd \*disk*);

## DESCRIPTION

The **ufs\_disk\_close**() function closes a disk and frees internal memory related to it. It does not free the *disk* structure.

The **ufs\_disk\_fillout**() and **ufs\_disk\_fillout\_blank**() functions open a disk specified by *name* and populate the structure pointed to by *disk*. The structure referenced by the *disk* pointer must be aligned to at least the alignment specified by LIBUFS\_ALIGN that is defined in the ⟨libufs.h⟩ header file. The disk is opened read-only. The specified *name* may be either a mountpoint, a device name or a filesystem image. The **ufs\_disk\_fillout**() function assumes there is a valid superblock and will fail if not, whereas the **ufs\_disk\_fillout\_blank**() function makes no assumptions of that sort.

The **ufs\_disk\_write**() function attempts to re-open a disk as writable if it is not currently.

## ERRORS

The function **ufs\_disk\_close**() has no failure points.

The function **ufs\_disk\_fillout**() may fail for any of the reasons **ufs\_disk\_fillout\_blank**() might, as well as for any reason [sbread(3)](/sbread/3.md) might.

The **ufs\_disk\_fillout\_blank**() may fail and set *errno* for any of the errors specified for the library functions [open(2)](/open/2.md), [strdup(3)](/strdup/3.md). Additionally, it may follow the [libufs(3)](/libufs/3.md) error methodologies in situations where no device could be found to open.

The function **ufs\_disk\_write**() may fail and set *errno* for any of the errors specified for the library functions [open(2)](/open/2.md) and [stat(2)](/stat/2.md). Namely, it will fail if the disk in question may not be written to.

## SEE ALSO

[open(2)](/open/2.md), [getfsfile(3)](/getfsfile/3.md), [libufs(3)](/libufs/3.md), [sbread(3)](/sbread/3.md)

## HISTORY

These functions first appeared as part of [libufs(3)](/libufs/3.md) in FreeBSD 5.0.

## AUTHORS

Juli Mallett ⟨*jmallett@FreeBSD.org*⟩
