wipefs3
Wipes existing file systems on a volume
Usage
⟨wipefs.h ⟩ int wipefs_alloc (int fd, , size_t block_size, , wipefs_ctx *handle, int wipefs_include_blocks (wipefs_ctx handle, , off_t block_offset, , off_t nblocks, int wipefs_except_blocks (wipefs_ctx handle, , off_t block_offset, , off_t nblocks, int wipefs_wipe (wipefs_ctx handle, void wipefs_free (wipefs_ctx *handle,
Library
library “libutil ”
Overview
The wipefs family of functions wipe existing file systems on a volume. A
DKIOCUNMAP
ioctl is sent to the device to invalidate all of its content.
Then zeroes are written to various locations that are used by various file systems to recognize their content and mount their volumes.
This is usually used by the newfs_* utilities before they create new file systems on the volume, so that the existing file system will not be mounted accidentally after the new file system is created.
NOTE:
These routines do not overwrite all volume structures.
These routines do not securely erase the previous content.
They only overwrite enough to make sure that the normal utilities will no longer recognize any file system content.
It is possible that previous file system content could be recovered by other means.
The
wipefs_alloc
() function initializes a
wipefs_ctx
object (which is an opaque data type).
file_desc
is the file handle of the volume to be wiped, which can be a block device node, a character device node, or a file.
file_desc
must be opened with write access. If
block_size
is 0, this function calls
ioctl(2
) to get the block size. A valid
block_size,
must be supplied if
file_desc
is a regular file. This function does not write any data to the volume.
The
wipefs_include_blocks
() function tells wipefs to write zeroes in the block range provided, in addition to any other ranges
it would normally write. This may be more efficient than if the caller were to write this range
separately, especially if the block range overlaps or is contiguous with other ranges that wipefs
will write. This function does not write any data to the volume. If this function is called
multiple times, the union of all the ranges provided will be written by
wipefs_wipe(.
) The
wipefs_except_blocks
() function tells wipefs not to write anything in the block range provided. This function is used for performance
optimizations if the caller will write to these blocks. It is the caller's responsibility to write to these blocks.
Otherwise, some file systems may still be recognized on the volume. This function does not write any data to the
volume. If this function is called multiple times, the union of all the ranges provided will be excluded from being
written by
wipefs_wipe(.
) The
wipefs_wipe
() function sends a
DKIOCUNMAP
ioctl and then writes data to the volume to wipe out existing file systems on it.
CAUTION:
this function destroys any file system or partition scheme on the volume represented by
file_desc, .
If
file_desc
represents the entire disk (e.g. /dev/diskX), the partition map of the disk will be destroyed. If
file_desc
represents a partition (e.g., /dev/diskXsY), only the file system in that partition is destroyed. Although the partition scheme or file system on
file_desc
may be beyond repair after
wipefs_wipe(,
) this function is not designed as a means to safely delete all data. It is possible that some user data (or intact file systems in some partitions) may still be recovered.
The
wipefs_free
() function frees the allocated
wipefs_ctx
handle and set
*handlep
to NULL.
Return values
The
wipefs_alloc(,
) wipefs_include_blocks(,
) wipefs_except_blocks
() and
wipefs_wipe
() functions return 0 on success, or will fail and return an error code.
Each function may return
ENOMEM
if insufficient memory is available. In addition, if
block_size
is not provided,
wipefs_alloc
() may return any error
ioctl(2
) returns;
wipefs_wipe
() may return any error
pwrite(2
) returns.
Releases
106 releases since Mac OS X 10.6; the text changed 1 time.