Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.7 KiB

  1. .\" $OpenBSD: opendisk.3,v 1.6 2009/09/29 12:56:15 jmc Exp $
  2. .\" $NetBSD: opendisk.3,v 1.4 1999/07/02 15:49:12 simonb Exp $
  3. .\"
  4. .\" Copyright (c) 1997 The NetBSD Foundation, Inc.
  5. .\" All rights reserved.
  6. .\"
  7. .\" This code is derived from software contributed to The NetBSD Foundation
  8. .\" by Luke Mewburn.
  9. .\"
  10. .\" Redistribution and use in source and binary forms, with or without
  11. .\" modification, are permitted provided that the following conditions
  12. .\" are met:
  13. .\" 1. Redistributions of source code must retain the above copyright
  14. .\" notice, this list of conditions and the following disclaimer.
  15. .\" 2. Redistributions in binary form must reproduce the above copyright
  16. .\" notice, this list of conditions and the following disclaimer in the
  17. .\" documentation and/or other materials provided with the distribution.
  18. .\"
  19. .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  20. .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  23. .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. .\" POSSIBILITY OF SUCH DAMAGE.
  30. .\"
  31. .Dd $Mdocdate: September 29 2009 $
  32. .Dt OPENDISK 3
  33. .Os
  34. .Sh NAME
  35. .Nm opendisk
  36. .Nd open a disk's
  37. .Dq raw
  38. partition
  39. .Sh SYNOPSIS
  40. .Fd #include <sys/types.h>
  41. .Fd #include <util.h>
  42. .Ft int
  43. .Fo opendisk
  44. .Fa "const char *path"
  45. .Fa "int flags"
  46. .Fa "char *buf"
  47. .Fa "size_t buflen"
  48. .Fa "int iscooked"
  49. .Fc
  50. .Sh DESCRIPTION
  51. .Fn opendisk
  52. opens
  53. .Fa path ,
  54. for reading and/or writing as specified by the argument
  55. .Fa flags
  56. using
  57. .Xr open 2 ,
  58. and the file descriptor is returned to the caller.
  59. .Fa buf
  60. is used to store the resultant filename.
  61. .Fa buflen
  62. is the size, in bytes, of the array referenced by
  63. .Fa buf
  64. (usually
  65. .Dv MAXPATHLEN
  66. bytes).
  67. If
  68. .Fa iscooked
  69. is non zero, the
  70. .Dq cooked
  71. partition (block device) is opened, rather than the
  72. .Dq raw
  73. partition (character device).
  74. .Pp
  75. .Fn opendisk
  76. attempts to open the following variations of
  77. .Fa path ,
  78. in order:
  79. .Bl -tag -width "/dev/rpathX"
  80. .It Pa path
  81. The pathname as given.
  82. .It Pa path Ns Em X
  83. .Fa path
  84. with a suffix of
  85. .Sq Em X ,
  86. where
  87. .Sq Em X
  88. represents the raw partition of the device, as determined by
  89. .Xr getrawpartition 3 ,
  90. usually
  91. .Dq c .
  92. .El
  93. .Pp
  94. If
  95. .Fa iscooked
  96. is zero, then the following two variations are attempted:
  97. .Bl -tag -width "/dev/rpathX"
  98. .It Pa /dev/rpath
  99. .Fa path
  100. with a prefix of
  101. .Dq Pa /dev/r .
  102. .It Pa /dev/rpath Ns Em X
  103. .Fa path
  104. with a prefix of
  105. .Dq Pa /dev/r
  106. and a suffix of
  107. .Sq Em X
  108. (q.v.).
  109. .El
  110. .Pp
  111. Otherwise (i.e.,
  112. .Fa iscooked
  113. is non-zero), the following variations are attempted:
  114. .Bl -tag -width "/dev/rpathX"
  115. .It Pa /dev/path
  116. .Fa path
  117. with a prefix of
  118. .Dq Pa /dev/ .
  119. .It Pa /dev/path Ns Em X
  120. .Fa path
  121. with a prefix of
  122. .Dq Pa /dev/
  123. and a suffix of
  124. .Sq Em X
  125. (q.v.).
  126. .El
  127. .Sh RETURN VALUES
  128. An open file descriptor, or -1 if the
  129. .Xr open 2
  130. failed.
  131. .Sh ERRORS
  132. .Fn opendisk
  133. may set
  134. .Va errno
  135. to one of the following values:
  136. .Bl -tag -width Er
  137. .It Bq Er EINVAL
  138. .Dv O_CREAT
  139. was set in
  140. .Fa flags ,
  141. or
  142. .Xr getrawpartition 3
  143. didn't return a valid partition.
  144. .El
  145. .Pp
  146. The
  147. .Fn opendisk
  148. function
  149. may also set
  150. .Va errno
  151. to any value specified by the
  152. .Xr open 2
  153. function.
  154. .Sh SEE ALSO
  155. .Xr open 2 ,
  156. .Xr getrawpartition 3
  157. .Sh HISTORY
  158. The
  159. .Fn opendisk
  160. function first appeared in
  161. .Nx 1.3 .