]> git.saurik.com Git - apple/libutil.git/blame - wipefs.3
libutil-47.30.1.tar.gz
[apple/libutil.git] / wipefs.3
CommitLineData
1bd2040a 1.\"\r
afa5f1bd 2.\" Copyright (c) 2008,2011 Apple Inc. All rights reserved.\r
1bd2040a
A
3.\"\r
4.\" @APPLE_LICENSE_HEADER_START@\r
5.\" \r
6.\" This file contains Original Code and/or Modifications of Original Code\r
7.\" as defined in and that are subject to the Apple Public Source License\r
8.\" Version 2.0 (the 'License'). You may not use this file except in\r
9.\" compliance with the License. Please obtain a copy of the License at\r
10.\" http://www.opensource.apple.com/apsl/ and read it before using this\r
11.\" file.\r
12.\" \r
13.\" The Original Code and all software distributed under the License are\r
14.\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER\r
15.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,\r
16.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,\r
17.\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.\r
18.\" Please see the License for the specific language governing rights and\r
19.\" limitations under the License.\r
20.\" \r
21.\" @APPLE_LICENSE_HEADER_END@\r
22.\"\r
afa5f1bd 23.Dd 6/30/11 \" DATE \r
1bd2040a
A
24.Dt libutil 3 \" Program name and manual section number \r
25.Os Mac OS X\r
26.Sh NAME \" Section Header - required - don't modify \r
27.\" The following lines are read in generating the apropos(man -k) database. Use only key\r
28.\" words here as the database is built based on the words here and in the .ND line. \r
29.Nm wipefs_alloc ,\r
30.Nm wipefs_except_blocks ,\r
31.Nm wipefs_wipe ,\r
32.Nm wipefs_free\r
33.\" Use .Nm macro to designate other names for the documented program.\r
34.Nd wipes existing file systems on a volume\r
35.Sh LIBRARY \" Section Header - required - don't modify\r
36.Lb libutil\r
37.Sh SYNOPSIS\r
38.In wipefs.h\r
39.Ft int\r
40.Fo wipefs_alloc\r
afa5f1bd 41.Fa "int fd"\r
1bd2040a 42.Fa "size_t block_size"\r
afa5f1bd
A
43.Fa "wipefs_ctx *handle"\r
44.Fc\r
45.Ft int\r
46.Fo wipefs_include_blocks\r
47.Fa "wipefs_ctx handle"\r
48.Fa "off_t block_offset"\r
49.Fa "off_t nblocks"\r
1bd2040a
A
50.Fc\r
51.Ft int\r
52.Fo wipefs_except_blocks\r
53.Fa "wipefs_ctx handle"\r
afa5f1bd 54.Fa "off_t block_offset"\r
1bd2040a
A
55.Fa "off_t nblocks"\r
56.Fc\r
57.Ft int\r
58.Fo wipefs_wipe\r
59.Fa "wipefs_ctx handle"\r
60.Fc\r
61.Ft void\r
62.Fo wipefs_free\r
afa5f1bd 63.Fa "wipefs_ctx *handle"\r
1bd2040a
A
64.Fc\r
65.Sh DESCRIPTION \" Section Header - required - don't modify\r
afa5f1bd
A
66The wipefs family of functions wipe existing file systems on a volume. A\r
67.Li DKIOCUNMAP\r
68ioctl is sent to the device to invalidate all of its content.\r
69Then zeroes are written to various locations that are used by various file systems to recognize their content and mount their volumes.\r
70This 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.\r
71.Pp\r
72.Sy NOTE:\r
73These routines do not overwrite all volume structures.\r
74These routines do not securely erase the previous content.\r
75They only overwrite enough to make sure that the normal utilities will no longer recognize any file system content.\r
76It is possible that previous file system content could be recovered by other means.\r
1bd2040a
A
77.Pp\r
78The\r
79.Fn wipefs_alloc\r
80function initializes a\r
81.Fa wipefs_ctx\r
82object (which is an opaque data type).\r
83.Fa file_desc\r
84is the file handle of the volume to be wiped, which can be a block device node, a character device node, or a file.\r
85.Fa file_desc\r
86must be opened with write access. If\r
87.Fa block_size\r
88is 0, this function calls\r
89.Xr ioctl 2\r
90to get the block size. A valid\r
91.Fa block_size \r
92must be supplied if \r
93.Fa file_desc\r
94is a regular file. This function does not write any data to the volume.\r
95.Pp\r
96The\r
afa5f1bd
A
97.Fn wipefs_include_blocks\r
98function tells wipefs to write zeroes in the block range provided, in addition to any other ranges\r
99it would normally write. This may be more efficient than if the caller were to write this range\r
100separately, especially if the block range overlaps or is contiguous with other ranges that wipefs\r
101will write. This function does not write any data to the volume. If this function is called\r
102multiple times, the union of all the ranges provided will be written by\r
103.Fn wipefs_wipe .\r
104.Pp\r
105The\r
1bd2040a
A
106.Fn wipefs_except_blocks\r
107function tells wipefs not to write anything in the block range provided. This function is used for performance\r
108optimizations if the caller will write to these blocks. It is the caller's responsibility to write to these blocks.\r
109Otherwise, some file systems may still be recognized on the volume. This function does not write any data to the\r
110volume. If this function is called multiple times, the union of all the ranges provided will be excluded from being\r
111written by\r
112.Fn wipefs_wipe .\r
113.Pp\r
114The\r
115.Fn wipefs_wipe\r
afa5f1bd
A
116function sends a\r
117.Li DKIOCUNMAP\r
118ioctl and then writes data to the volume to wipe out existing file systems on it.\r
119.Sy CAUTION:\r
1bd2040a
A
120this function destroys any file system or partition scheme on the volume represented by\r
121.Fa file_desc .\r
122If\r
123.Fa file_desc\r
124represents the entire disk (e.g. /dev/diskX), the partition map of the disk will be destroyed. If\r
125.Fa file_desc\r
126represents a partition (e.g., /dev/diskXsY), only the file system in that partition is destroyed. Although the partition scheme or file system on\r
127.Fa file_desc\r
128may be beyond repair after \r
129.Fn wipefs_wipe ,\r
130this 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.\r
131.Pp\r
132The\r
133.Fn wipefs_free\r
134function frees the allocated \r
135.Fa wipefs_ctx\r
136handle and set\r
137.Fa *handlep\r
138to NULL.\r
139.Sh RETURN VALUES\r
140The\r
141.Fn wipefs_alloc ,\r
afa5f1bd 142.Fn wipefs_include_blocks ,\r
1bd2040a
A
143.Fn wipefs_except_blocks\r
144and\r
145.Fn wipefs_wipe\r
146functions return 0 on success, or will fail and return an error code.\r
147Each function may return\r
148.Fa ENOMEM\r
149if insufficient memory is available. In addition, if\r
150.Fa block_size\r
151is not provided,\r
152.Fn wipefs_alloc\r
153may return any error\r
154.Xr ioctl 2\r
155returns;\r
156.Fn wipefs_wipe\r
157may return any error\r
158.Xr pwrite 2\r
159returns.\r
160.\" .Sh BUGS \" Document known, unremedied bugs \r
161.\".Sh HISTORY \" Document history if command behaves in a unique manner \r
162.\"The wipefs family of functions first appeared in Mac OS X Leopard (10.5.3).\r