this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added Apple libutil, fix libcxx rpath

+4669 -7
+1
etc/dylib.conf
··· 3 3 /usr/lib/libc++.1.dylib=libc++.so.1 4 4 /usr/lib/libc++abi.dylib=libc++abi.so.1 5 5 /usr/lib/libiconv.2.dylib=libiconv.so 6 + /usr/lib/libutil.dylib=libutil.so 6 7
+1
src/CMakeLists.txt
··· 59 59 add_subdirectory(libmalloc) 60 60 add_subdirectory(libunwind) 61 61 add_subdirectory(libsystem) 62 + add_subdirectory(libutil) 62 63 add_subdirectory(keymgr) 63 64 add_subdirectory(libiconv) 64 65 add_subdirectory(duct/src)
+2 -2
src/dyld/CMakeLists.txt
··· 29 29 30 30 add_executable(dyld-bin ${dyld_SRCS}) 31 31 set_target_properties(dyld-bin PROPERTIES OUTPUT_NAME dyld${SUFFIX}) 32 - target_link_libraries(dyld-bin dyld util mach-o) 32 + target_link_libraries(dyld-bin dyld darling-util mach-o) 33 33 34 34 #if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") 35 35 add_executable(dyldd dyldd.cpp) 36 - target_link_libraries(dyldd dyld util mach-o) 36 + target_link_libraries(dyldd dyld darling-util mach-o) 37 37 install(TARGETS dyldd DESTINATION bin) 38 38 #endif (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64") 39 39
+1 -1
src/libc/locale/FreeBSD/mbtowc.c
··· 43 43 NORMALIZE_LOCALE(loc); 44 44 if (s == NULL) { 45 45 /* No support for state dependent encodings. */ 46 - loc->__mbs_mbtowc = initial; 46 + // loc->__mbs_mbtowc = initial; 47 47 return (0); 48 48 } 49 49 rval = loc->__lc_ctype->__mbrtowc(pwc, s, n, &loc->__mbs_mbtowc, loc);
+1 -1
src/libdyld/CMakeLists.txt
··· 57 57 SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 58 58 59 59 add_library(dyld SHARED ${dyld_SRCS}) 60 - target_link_libraries(dyld -ldl -lpthread mach-o util) 60 + target_link_libraries(dyld -ldl -lpthread mach-o darling-util) 61 61 62 62 install(TARGETS dyld DESTINATION lib${SUFFIX}/darling) 63 63
+1 -1
src/libmach-o/CMakeLists.txt
··· 23 23 add_library(mach-o SHARED ${mach-o_SRCS}) 24 24 set_target_properties(mach-o PROPERTIES VERSION 1.0.0 SOVERSION 1.0) 25 25 set_target_properties(mach-o PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") 26 - target_link_libraries(mach-o -ldl -lpthread util) 26 + target_link_libraries(mach-o -ldl -lpthread darling-util) 27 27 28 28 install(TARGETS mach-o DESTINATION "lib${SUFFIX}/darling") 29 29
+36
src/libutil/CMakeLists.txt
··· 1 + project(libutil) 2 + 3 + cmake_minimum_required(VERSION 2.4.0) 4 + 5 + if(COMMAND cmake_policy) 6 + cmake_policy(SET CMP0003 NEW) 7 + endif(COMMAND cmake_policy) 8 + 9 + 10 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdinc -D__DARWIN_UNIX03 -fPIC -w") 11 + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc -nostdinc++ -D__DARWIN_UNIX03 -fPIC -w") 12 + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib -Wl,--unresolved-symbols=ignore-all -Wl,--version-script=${DARLING_TOP_DIRECTORY}/darwin.map") 13 + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 14 + include_directories(${DARLING_TOP_DIRECTORY}/src/libc/include) 15 + include_directories(${DARLING_TOP_DIRECTORY}/src/external/libcxx/include) 16 + 17 + set(util_SRCS 18 + ExtentManager.cpp 19 + getmntopts.c 20 + humanize_number.c 21 + pidfile.c 22 + realhostname.c 23 + reexec_to_match_kernel.c 24 + trimdomain.c 25 + tzlink.c 26 + wipefs.cpp 27 + ) 28 + 29 + SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling") 30 + SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 31 + SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) 32 + 33 + add_library(util SHARED ${util_SRCS}) 34 + target_link_libraries(util system) 35 + 36 + install(TARGETS util DESTINATION lib${SUFFIX}/darling)
+305
src/libutil/ExtentManager.cpp
··· 1 + /* 2 + * Copyright (c) 2008-2009,2011 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + // 24 + // ExtentManager.cpp 25 + // 26 + 27 + #include "ExtentManager.h" 28 + 29 + void 30 + ExtentManager::Init(uint32_t theBlockSize, uint32_t theNativeBlockSize, off_t theTotalBytes) 31 + { 32 + blockSize = theBlockSize; 33 + nativeBlockSize = theNativeBlockSize; 34 + totalBytes = theTotalBytes; 35 + totalBlocks = howmany(totalBytes, blockSize); 36 + 37 + // add sentry empty extents at both sides so empty partition doesn't need to be handled specially 38 + AddBlockRangeExtent(0, 0); 39 + AddBlockRangeExtent(totalBlocks, 0); 40 + } 41 + 42 + void 43 + ExtentManager::MergeExtent(const ExtentInfo &a, const ExtentInfo &b, ExtentInfo *c) 44 + { 45 + // merge ext into *curIt 46 + c->blockAddr = min(a.blockAddr, b.blockAddr); 47 + c->numBlocks = max(a.blockAddr + a.numBlocks, b.blockAddr + b.numBlocks) - c->blockAddr; 48 + } 49 + 50 + void 51 + ExtentManager::AddBlockRangeExtent(off_t blockAddr, off_t numBlocks) 52 + { 53 + struct ExtentInfo ext, newExt; 54 + ListExtIt curIt, newIt; 55 + bool merged = false; 56 + 57 + // make the range a valid range 58 + if ((blockAddr > totalBlocks) || (blockAddr + numBlocks < 0)) { // totally out of range, do nothing 59 + return; 60 + } 61 + if (blockAddr < 0) { 62 + numBlocks = blockAddr + numBlocks; 63 + blockAddr = 0; 64 + } 65 + if (blockAddr + numBlocks > totalBlocks) { 66 + numBlocks = totalBlocks - blockAddr; 67 + } 68 + 69 + ext.blockAddr = blockAddr; 70 + ext.numBlocks = numBlocks; 71 + 72 + for (curIt = extentList.begin(); curIt != extentList.end(); curIt++) { 73 + if (BeforeExtent(ext, *curIt)) 74 + break; 75 + if (!BeforeExtent(*curIt, ext)) { // overlapped extents 76 + MergeExtent(ext, *curIt, &newExt); 77 + *curIt = newExt; 78 + merged = true; 79 + break; 80 + } 81 + } 82 + 83 + // insert ext before curIt 84 + if (!merged) { 85 + curIt = extentList.insert(curIt, ext); // throws bad_alloc when out of memory 86 + } 87 + 88 + // merge the extents 89 + newIt = curIt; 90 + curIt = extentList.begin(); 91 + while (curIt != extentList.end()) { 92 + if (curIt == newIt || BeforeExtent(*curIt, *newIt)) { // curIt is before newIt 93 + curIt++; 94 + continue; 95 + } 96 + if (BeforeExtent(*newIt, *curIt)) { // curIt is after newIt now, we are done 97 + break; 98 + } 99 + // merge the two extents 100 + MergeExtent(*curIt, *newIt, &newExt); 101 + *newIt = newExt; 102 + curIt = extentList.erase(curIt); 103 + } 104 + // printf("After %s(%lld, %lld)\n", __func__, blockAddr, numBlocks); DebugPrint(); 105 + } // ExtentManager::AddBlockRangeExtent 106 + 107 + void 108 + ExtentManager::RemoveBlockRangeExtent(off_t blockAddr, off_t numBlocks) 109 + { 110 + struct ExtentInfo ext, newExt; 111 + ListExtIt curIt; 112 + 113 + ext.blockAddr = blockAddr; 114 + ext.numBlocks = numBlocks; 115 + 116 + curIt = extentList.begin(); 117 + while (curIt != extentList.end()) { 118 + if (BeforeExtent(*curIt, ext)) { 119 + curIt++; 120 + continue; 121 + } 122 + if (BeforeExtent(ext, *curIt)) // we are done 123 + break; 124 + 125 + // 126 + // If we get here, the input extent and *curIt have at least one block in common. 127 + // That is, they overlap in some way. Thus *curIt needs to change, be removed, 128 + // or be split into two non-contiguous extents. 129 + // 130 + 131 + if (curIt->blockAddr >= ext.blockAddr && 132 + curIt->blockAddr + curIt->numBlocks <= ext.blockAddr + ext.numBlocks) { 133 + // 134 + // The input extent totally contains *curIt, so remove *curIt. 135 + // 136 + curIt = extentList.erase(curIt); 137 + } else if (curIt->blockAddr < ext.blockAddr && 138 + curIt->blockAddr + curIt->numBlocks > ext.blockAddr + ext.numBlocks) { 139 + // 140 + // The input extent does not include the start of *curIt, nor the end of *curIt, 141 + // so split *curIt into two extents. 142 + // 143 + newExt.blockAddr = ext.blockAddr + ext.numBlocks; 144 + newExt.numBlocks = curIt->blockAddr + curIt->numBlocks - newExt.blockAddr; 145 + curIt->numBlocks = ext.blockAddr - curIt->blockAddr; 146 + curIt++; 147 + extentList.insert(curIt, newExt); // throws bad_alloc when out of memory 148 + curIt++; 149 + } else { 150 + // 151 + // The input extent contains either the start or the end of *curIt, but not both. 152 + // The remove will leave either the end or the start of *curIt (respectively) and 153 + // not change the number of extents in the list. 154 + // 155 + if (curIt->blockAddr >= ext.blockAddr) { 156 + // 157 + // Remove the start of *curIt by updating both its starting block and size. 158 + // 159 + assert(curIt->blockAddr + curIt->numBlocks > ext.blockAddr + ext.numBlocks); 160 + newExt.blockAddr = ext.blockAddr + ext.numBlocks; 161 + newExt.numBlocks = curIt->blockAddr + curIt->numBlocks - newExt.blockAddr; 162 + *curIt = newExt; 163 + } else { 164 + // 165 + // Remove the end of *curIt by updating its size. 166 + // 167 + curIt->numBlocks = ext.blockAddr - curIt->blockAddr; 168 + } 169 + curIt++; 170 + } 171 + } 172 + //printf("After %s(%lld, %lld)\n", __func__, blockAddr, numBlocks); DebugPrint(); 173 + } 174 + 175 + void 176 + ExtentManager::AddByteRangeExtent(off_t byteAddr, off_t numBytes) 177 + { 178 + off_t blockAddr = byteAddr / blockSize; 179 + off_t blockAddrOfLastByte = (byteAddr + numBytes - 1) / blockSize; 180 + off_t numBlocks = blockAddrOfLastByte - blockAddr + 1; 181 + AddBlockRangeExtent(blockAddr, numBlocks); 182 + } 183 + 184 + void 185 + ExtentManager::DebugPrint() 186 + { 187 + ListExtIt it; 188 + 189 + for (it = extentList.begin(); it != extentList.end(); it++) { 190 + printf("[%lld, %lld] ", it->blockAddr, it->numBlocks); 191 + } 192 + printf("\n"); 193 + } 194 + 195 + 196 + #if UNIT_TEST 197 + 198 + /* 199 + clang++ -arch i386 -arch x86_64 -DUNIT_TEST ExtentManager.cpp -o ExtentManager && ./ExtentManager 200 + */ 201 + 202 + #include <cstdio> 203 + #include <cstdlib> 204 + 205 + const char *DebugDescription(class ExtentManager *extMan) 206 + { 207 + char *result = strdup(""); 208 + char *temp; 209 + 210 + ListExtIt it; 211 + 212 + for (it = extMan->extentList.begin(); it != extMan->extentList.end(); it++) { 213 + temp = result; 214 + asprintf(&result, "%s[%lld, %lld] ", temp, it->blockAddr, it->numBlocks); 215 + free(temp); 216 + } 217 + 218 + return result; 219 + } 220 + 221 + int SimpleTestCase(off_t addAddr, off_t addBlocks, off_t removeAddr, off_t removeBlocks, const char *expectedResult) 222 + { 223 + class ExtentManager extMan; 224 + const char *actualResult; 225 + int result = 0; 226 + 227 + extMan.Init(512, 512, 512*999); 228 + extMan.AddBlockRangeExtent(addAddr, addBlocks); 229 + extMan.RemoveBlockRangeExtent(removeAddr, removeBlocks); 230 + actualResult = DebugDescription(&extMan); 231 + if (strcmp(actualResult, expectedResult)) 232 + { 233 + fprintf(stderr, 234 + "SimpleTestCase(%lld, %lld, %lld, %lld) failed.\n" 235 + " Expected result: %s\n" 236 + " Actual result: %s\n", 237 + addAddr, addBlocks, removeAddr, removeBlocks, 238 + expectedResult, actualResult); 239 + result = 1; 240 + } 241 + free((void *)actualResult); 242 + 243 + return result; 244 + } 245 + 246 + int main(void) 247 + { 248 + int failed = 0; 249 + class ExtentManager *extMan; 250 + 251 + // Create an extent, and remove one contained inside, 252 + // leaving the start and end of the original extent. 253 + // Create: [xxxxxxxxxx] 254 + // Remove: [......] 255 + failed |= SimpleTestCase(10, 10, 12, 6, "[0, 0] [10, 2] [18, 2] [999, 0] "); 256 + 257 + // Create an extent, and remove the whole extent. 258 + // Create: [xxxxxxxxxx] 259 + // Remove: [..........] 260 + failed |= SimpleTestCase(10, 10, 10, 10, "[0, 0] [999, 0] "); 261 + 262 + // Create an extent, and remove the first part of the extent. 263 + // Create: [xxxxxxxxxx] 264 + // Remove: [......] 265 + failed |= SimpleTestCase(10, 10, 10, 6, "[0, 0] [16, 4] [999, 0] "); 266 + 267 + // Create an extent, and remove the last part of the extent. 268 + // Create: [xxxxxxxxxx] 269 + // Remove: [......] 270 + failed |= SimpleTestCase(10, 10, 14, 6, "[0, 0] [10, 4] [999, 0] "); 271 + 272 + // Create an extent and remove before the start, through the middle. 273 + // Create: [xxxxxxxxxx] 274 + // Remove: [..........] 275 + failed |= SimpleTestCase(10, 10, 6, 10, "[0, 0] [16, 4] [999, 0] "); 276 + 277 + // Create an extent and remove from middle to past the end. 278 + // Create: [xxxxxxxxxx] 279 + // Remove: [..........] 280 + failed |= SimpleTestCase(10, 10, 14, 10, "[0, 0] [10, 4] [999, 0] "); 281 + 282 + // Create an extent and remove from before through past end. 283 + // Create: [xxxxxxxxxx] 284 + // Remove: [..............] 285 + failed |= SimpleTestCase(10, 10, 6, 18, "[0, 0] [999, 0] "); 286 + 287 + // Create an extent and remove purely before the extent. 288 + // Create: [xxxxxxxxxx] 289 + // Remove: [...] 290 + failed |= SimpleTestCase(10, 10, 2, 5, "[0, 0] [10, 10] [999, 0] "); 291 + 292 + // Create an extent and remove purely after the extent. 293 + // Create: [xxxxxxxxxx] 294 + // Remove: [...] 295 + failed |= SimpleTestCase(10, 10, 22, 5, "[0, 0] [10, 10] [999, 0] "); 296 + 297 + if (failed) 298 + printf("FAIL!\n"); 299 + else 300 + printf("Success.\n"); 301 + 302 + return failed; 303 + } 304 + 305 + #endif /* UNIT_TEST */
+74
src/libutil/ExtentManager.h
··· 1 + /* 2 + * Copyright (c) 2008 Computer, Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + // 24 + // ExtentManager.h 25 + // 26 + #ifndef EXTENTMANAGER_H 27 + #define EXTENTMANAGER_H 28 + 29 + #include <list> 30 + #include <vector> 31 + #include <algorithm> 32 + #include <sys/types.h> 33 + #include <sys/errno.h> 34 + #include <cstdio> 35 + #include <cassert> 36 + using namespace std; 37 + 38 + struct ExtentInfo { 39 + off_t blockAddr; 40 + off_t numBlocks; 41 + }; 42 + 43 + inline bool BeforeExtent(const ExtentInfo &a, const ExtentInfo &b) 44 + { 45 + return (a.blockAddr + a.numBlocks) < b.blockAddr; 46 + } 47 + 48 + typedef list<ExtentInfo>::iterator ListExtIt; 49 + 50 + class ExtentManager { 51 + public: 52 + ExtentManager() : blockSize(0), totalBytes(0), totalBlocks(0) {}; 53 + ~ExtentManager() {}; 54 + 55 + void Init(uint32_t theBlockSize, uint32_t theNativeBlockSize, off_t theTotalBytes); 56 + 57 + void AddBlockRangeExtent(off_t blockAddr, off_t numBlocks); 58 + void AddByteRangeExtent(off_t byteAddr, off_t numBytes); 59 + void RemoveBlockRangeExtent(off_t blockAddr, off_t numBlocks); 60 + 61 + void DebugPrint(); 62 + 63 + protected: 64 + void MergeExtent(const ExtentInfo &a, const ExtentInfo &b, ExtentInfo *c); 65 + 66 + public: 67 + size_t blockSize; 68 + size_t nativeBlockSize; 69 + off_t totalBytes; 70 + off_t totalBlocks; 71 + list<ExtentInfo> extentList; 72 + }; 73 + 74 + #endif // #ifndef EXTENTMANAGER_H
+296
src/libutil/getmntopts.3
··· 1 + .\" $NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $ 2 + .\" 3 + .\" Copyright (c) 1994 4 + .\" The Regents of the University of California. All rights reserved. 5 + .\" 6 + .\" Redistribution and use in source and binary forms, with or without 7 + .\" modification, are permitted provided that the following conditions 8 + .\" are met: 9 + .\" 1. Redistributions of source code must retain the above copyright 10 + .\" notice, this list of conditions and the following disclaimer. 11 + .\" 2. Redistributions in binary form must reproduce the above copyright 12 + .\" notice, this list of conditions and the following disclaimer in the 13 + .\" documentation and/or other materials provided with the distribution. 14 + .\" 3. Neither the name of the University nor the names of its contributors 15 + .\" may be used to endorse or promote products derived from this software 16 + .\" without specific prior written permission. 17 + .\" 18 + .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 + .\" SUCH DAMAGE. 29 + .\" 30 + .\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95 31 + .\" 32 + .Dd May 4, 2010 33 + .Dt GETMNTOPTS 3 34 + .Os 35 + .Sh NAME 36 + .Nm getmntopts 37 + .Nd scan mount options 38 + .Sh LIBRARY 39 + .Lb libutil 40 + .Sh SYNOPSIS 41 + .In mntopts.h 42 + .Ft mntoptparse_t 43 + .Fn getmntopts "const char *options" "const struct mntopt *mopts" "int *flagp" "int *altflagp" 44 + .Ft const char * 45 + .Fn getmntoptstr "mntoptparse_t mp" "const char *opt" 46 + .Ft long 47 + .Fn getmntoptnum "mntoptparse_t mp" "const char *opt" 48 + .Ft void 49 + .Fn freemntopts "mntoptparse_t mp" 50 + .Sh DESCRIPTION 51 + The 52 + .Fn getmntopts 53 + function takes a comma separated option list and a list 54 + of valid option names, and computes the bitmasks 55 + corresponding to the requested set of options. 56 + .Pp 57 + The string 58 + .Ar options 59 + is broken down into a sequence of comma separated tokens. 60 + Each token is looked up in the table described by 61 + .Ar mopts 62 + and the bits in 63 + the word referenced by either 64 + .Ar flagp 65 + or 66 + .Ar altflagp 67 + (depending on the 68 + .Dv m_altloc 69 + field of the option's table entry) 70 + are updated. 71 + The flag words are not initialized by 72 + .Fn getmntopts . 73 + The table, 74 + .Ar mopts , 75 + has the following format: 76 + .Bd -literal 77 + struct mntopt { 78 + const char *m_option; /* option name */ 79 + int m_inverse; /* negative option, e.g., "dev" */ 80 + int m_flag; /* bit to set, e.g., MNT_RDONLY */ 81 + int m_altloc; /* use altflagp rather than flagp */ 82 + }; 83 + .Ed 84 + .Pp 85 + The members of this structure are: 86 + .Bl -tag -width m_inverse 87 + .It Fa m_option 88 + the option name, 89 + for example 90 + .Dq suid . 91 + .It Fa m_inverse 92 + tells 93 + .Fn getmntopts 94 + that the name has the inverse meaning of the bit. 95 + For example, 96 + .Dq suid 97 + is the string, whereas the mount flag is 98 + .Dv MNT_NOSUID . 99 + In this case, the sense of the string and the flag 100 + are inverted, so the 101 + .Fa m_inverse 102 + flag should be set. 103 + .It Fa m_flag 104 + the value of the bit to be set or cleared in 105 + the flag word when the option is recognized. 106 + The bit is set when the option is discovered, 107 + but cleared if the option name was preceded 108 + by the letters 109 + .Dq no . 110 + The 111 + .Fa m_inverse 112 + flag causes these two operations to be reversed. 113 + .It Fa m_altloc 114 + the bit should be set or cleared in 115 + .Ar altflagp 116 + rather than 117 + .Ar flagp . 118 + .El 119 + .Pp 120 + Each of the user visible 121 + .Dv MNT_ 122 + flags has a corresponding 123 + .Dv MOPT_ 124 + macro which defines an appropriate 125 + .Li "struct mntopt" 126 + entry. 127 + To simplify the program interface and ensure consistency across all 128 + programs, a general purpose macro, 129 + .Dv MOPT_STDOPTS , 130 + is defined which contains an entry for all the generic VFS options: 131 + .Bd -literal -offset indent 132 + MOPT_USERQUOTA, 133 + MOPT_GROUPQUOTA, 134 + MOPT_FSTAB_COMPAT, 135 + MOPT_NODEV, 136 + MOPT_NOEXEC, 137 + MOPT_NOSUID, 138 + MOPT_RDONLY, 139 + MOPT_UNION, 140 + MOPT_BROWSE, 141 + MOPT_AUTOMOUNTED, 142 + MOPT_DEFWRITE, 143 + MOPT_NOATIME, 144 + MOPT_PERMISSIONS, 145 + MOPT_IGNORE_OWNERSHIP, 146 + MOPT_QUARANTINE, 147 + MOPT_CPROTECT 148 + .Ed 149 + .Pp 150 + In addition, the macros 151 + .Dv MOPT_FORCE 152 + and 153 + .Dv MOPT_UPDATE 154 + exist to enable the 155 + .Dv MNT_FORCE 156 + and 157 + .Dv MNT_UPDATE 158 + flags to be set. 159 + Finally, the table must be terminated by an entry with a 160 + .Dv NULL 161 + first element. 162 + .Pp 163 + .Fn getmntopts 164 + returns a 165 + .Li "mntoptparse_t" 166 + handle that can be used in subsequent 167 + .Fn getmntoptstr 168 + and 169 + .Fn getmntoptnum 170 + calls to fetch a value for an option and that must be freed with a call 171 + to 172 + .Fn freemntopts . 173 + If an error occurred, then if the external integer value 174 + .Va getmnt_silent 175 + is zero then 176 + .Fn getmntopts 177 + prints an error message and exits; 178 + if 179 + .Va getmnt_silent 180 + is non-zero then 181 + .Fn getmntopts 182 + returns 183 + .Dv NULL . 184 + .Pp 185 + The 186 + .Fn getmntoptstr 187 + function returns the string value of the named option, if such a value 188 + was set in the option string. 189 + If the value was not set, then if the external integer value 190 + .Va getmnt_silent 191 + is zero then 192 + .Fn getmntoptstr 193 + prints an error message and exits; 194 + if 195 + .Va getmnt_silent 196 + is non-zero then 197 + .Fn getmntoptstr 198 + returns 199 + .Dv NULL . 200 + .Pp 201 + The 202 + .Fn getmntoptnum 203 + returns the long value of the named option, if such a value was set in the 204 + option string. 205 + If the value was not set, or could not be converted from a string to a 206 + long, then if the external integer value 207 + .Va getmnt_silent 208 + is zero then 209 + .Fn getmntoptnum 210 + prints an error message and exits; 211 + if 212 + .Va getmnt_silent 213 + is non-zero then 214 + .Fn getmntoptnum 215 + returns \-1. 216 + .Pp 217 + The 218 + .Fn freemntopts 219 + frees the storage used by 220 + .Fn getmntopts . 221 + .Sh RETURN VALUES 222 + .Fn getmntopts 223 + returns 224 + .Dv NULL 225 + if an error occurred. 226 + Note that some bits may already have been set in 227 + .Va flagp 228 + and 229 + .Va altflagp 230 + even if 231 + .Dv NULL 232 + is returned. 233 + .Fn getmntoptstr 234 + returns 235 + .Dv NULL 236 + if an error occurred. 237 + .Fn getmntoptnum 238 + returns \-1 if an error occurred. 239 + .Sh EXAMPLES 240 + Most commands will use the standard option set. 241 + Local filesystems which support the 242 + .Dv MNT_UPDATE 243 + flag, would also have an 244 + .Dv MOPT_UPDATE 245 + entry. 246 + This can be declared and used as follows: 247 + .Bd -literal -offset indent 248 + #include \*[Lt]mntopts.h\*[Gt] 249 + 250 + static const struct mntopt mopts[] = { 251 + MOPT_STDOPTS, 252 + MOPT_UPDATE, 253 + { NULL } 254 + }; 255 + 256 + \&... 257 + 258 + long val; 259 + mntoptparse_t mp; 260 + mntflags = mntaltflags = 0; 261 + 262 + \&... 263 + 264 + mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags); 265 + 266 + if (mp == NULL) 267 + err(EXIT_FAILURE, "getmntopts"); 268 + 269 + \&... 270 + 271 + val = getmntoptnum(mp, "rsize"); 272 + freemntopts(mp); 273 + .Ed 274 + .Sh DIAGNOSTICS 275 + If the external integer variable 276 + .Va getmnt_silent 277 + is zero then the 278 + .Fn getmntopts , 279 + .Fn getmntoptstr , 280 + and 281 + .Fn getmntoptnum 282 + functions display an error message and exit if an error occurred. 283 + By default 284 + .Va getmnt_silent 285 + is zero. 286 + .Sh SEE ALSO 287 + .Xr err 3 , 288 + .Xr mount 8 289 + .Sh HISTORY 290 + The 291 + .Fn getmntopts 292 + function appeared in 293 + .Bx 4.4 . 294 + It was moved to the utilities library and enhanced to retrieve option 295 + values in 296 + .Nx 2.0 .
+188
src/libutil/getmntopts.c
··· 1 + /* $NetBSD: getmntopts.c,v 1.3 2003/08/07 16:44:58 agc Exp $ */ 2 + 3 + /*- 4 + * Copyright (c) 1994 5 + * The Regents of the University of California. All rights reserved. 6 + * 7 + * Redistribution and use in source and binary forms, with or without 8 + * modification, are permitted provided that the following conditions 9 + * are met: 10 + * 1. Redistributions of source code must retain the above copyright 11 + * notice, this list of conditions and the following disclaimer. 12 + * 2. Redistributions in binary form must reproduce the above copyright 13 + * notice, this list of conditions and the following disclaimer in the 14 + * documentation and/or other materials provided with the distribution. 15 + * 3. Neither the name of the University nor the names of its contributors 16 + * may be used to endorse or promote products derived from this software 17 + * without specific prior written permission. 18 + * 19 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 + * SUCH DAMAGE. 30 + */ 31 + 32 + #include <sys/cdefs.h> 33 + #ifndef lint 34 + #if 0 35 + static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; 36 + #else 37 + __RCSID("$NetBSD: getmntopts.c,v 1.3 2003/08/07 16:44:58 agc Exp $"); 38 + #endif 39 + #endif /* not lint */ 40 + 41 + #include <sys/param.h> 42 + 43 + #include <err.h> 44 + #include <errno.h> 45 + #include <fstab.h> 46 + #include <stdlib.h> 47 + #include <string.h> 48 + 49 + #include <mntopts.h> 50 + 51 + int getmnt_silent = 0; 52 + 53 + static const char errmsg[] = "-o %s: option not supported"; 54 + 55 + struct mntoptparse { 56 + const char *options; 57 + const struct mntopt *mopts; 58 + char *optbuf; 59 + char **optarg; 60 + }; 61 + 62 + const char * 63 + getmntoptstr(mntoptparse_t mp, const char *opt) 64 + { 65 + const struct mntopt *m; 66 + 67 + for (m = mp->mopts; m->m_option != NULL; m++) 68 + if (strcasecmp(opt, m->m_option) == 0) 69 + break; 70 + 71 + if (m->m_option == NULL) { 72 + if (getmnt_silent == 0) 73 + errx(1, errmsg, opt); 74 + else 75 + return NULL; 76 + } 77 + 78 + return mp->optarg[m - mp->mopts]; 79 + } 80 + 81 + long 82 + getmntoptnum(mntoptparse_t mp, const char *opt) 83 + { 84 + char *ep; 85 + long rv; 86 + void (*fun)(int, const char *, ...) = NULL; 87 + const char *val = getmntoptstr(mp, opt); 88 + 89 + if (val == NULL) { 90 + if (getmnt_silent == 0) 91 + errx(1, "Missing %s argument", opt); 92 + else 93 + return -1; 94 + } 95 + 96 + errno = 0; 97 + rv = strtol(val, &ep, 0); 98 + 99 + if (*ep) 100 + fun = errx; 101 + 102 + if (errno == ERANGE && (rv == LONG_MAX || rv == LONG_MIN)) 103 + fun = err; 104 + 105 + if (fun) { 106 + if (getmnt_silent != 0) 107 + return -1; 108 + (*fun)(1, "Invalid %s argument `%s'", opt, val); 109 + } 110 + return rv; 111 + } 112 + 113 + void 114 + freemntopts(mntoptparse_t mp) 115 + { 116 + free(mp->optbuf); 117 + free(mp->optarg); 118 + free(mp); 119 + } 120 + 121 + mntoptparse_t 122 + getmntopts(const char *options, const struct mntopt *m0, int *flagp, 123 + int *altflagp) 124 + { 125 + const struct mntopt *m; 126 + int negative; 127 + char *opt, *p, *ctx = NULL; 128 + int *thisflagp; 129 + size_t nopts; 130 + mntoptparse_t mp; 131 + 132 + for (nopts = 0, m = m0; m->m_option != NULL; ++m, nopts++) 133 + continue; 134 + 135 + if ((mp = malloc(sizeof(struct mntoptparse))) == NULL) 136 + return NULL; 137 + 138 + /* Copy option string, since it is about to be torn asunder... */ 139 + if ((mp->optbuf = strdup(options)) == NULL) { 140 + free(mp); 141 + return NULL; 142 + } 143 + 144 + if ((mp->optarg = calloc(nopts, sizeof(char *))) == NULL) { 145 + free(mp->optbuf); 146 + free(mp); 147 + return NULL; 148 + } 149 + 150 + mp->mopts = m0; 151 + mp->options = options; 152 + 153 + for (opt = mp->optbuf; (opt = strtok_r(opt, ",", &ctx)) != NULL; opt = NULL) { 154 + /* Check for "no" prefix. */ 155 + if (opt[0] == 'n' && opt[1] == 'o') { 156 + negative = 1; 157 + opt += 2; 158 + } else 159 + negative = 0; 160 + 161 + /* 162 + * for options with assignments in them (ie. quotas) 163 + * ignore the assignment as it's handled elsewhere 164 + */ 165 + p = strchr(opt, '='); 166 + if (p) { 167 + *p++ = '\0'; 168 + } 169 + 170 + /* Scan option table. */ 171 + for (m = m0; m->m_option != NULL; ++m) 172 + if (strcasecmp(opt, m->m_option) == 0) 173 + break; 174 + 175 + /* Save flag, or fail if option is not recognised. */ 176 + if (m->m_option) { 177 + mp->optarg[m - m0] = p; 178 + thisflagp = m->m_altloc ? altflagp : flagp; 179 + if (negative == m->m_inverse) 180 + *thisflagp |= m->m_flag; 181 + else 182 + *thisflagp &= ~m->m_flag; 183 + } else if (!getmnt_silent) { 184 + errx(1, errmsg, opt); 185 + } 186 + } 187 + return mp; 188 + }
+148
src/libutil/humanize_number.3
··· 1 + .\" $NetBSD: humanize_number.3,v 1.4 2003/04/16 13:34:37 wiz Exp $ 2 + .\" $FreeBSD: src/lib/libutil/humanize_number.3,v 1.8 2005/04/10 12:15:25 delphij Exp $ 3 + .\" 4 + .\" Copyright (c) 1999, 2002 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 and by Tomas Svensson. 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 + .\" 3. All advertising materials mentioning features or use of this software 19 + .\" must display the following acknowledgement: 20 + .\" This product includes software developed by the NetBSD 21 + .\" Foundation, Inc. and its contributors. 22 + .\" 4. Neither the name of The NetBSD Foundation nor the names of its 23 + .\" contributors may be used to endorse or promote products derived 24 + .\" from this software without specific prior written permission. 25 + .\" 26 + .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 + .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 + .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 + .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 + .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 + .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 + .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 + .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 + .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 + .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 + .\" POSSIBILITY OF SUCH DAMAGE. 37 + .\" 38 + .Dd May 25, 2004 39 + .Dt HUMANIZE_NUMBER 3 40 + .Os 41 + .Sh NAME 42 + .Nm humanize_number 43 + .Nd format a number into a human readable form 44 + .Sh LIBRARY 45 + .Lb libutil 46 + .Sh SYNOPSIS 47 + .In libutil.h 48 + .Ft int 49 + .Fo humanize_number 50 + .Fa "char *buf" "size_t len" "int64_t number" "const char *suffix" 51 + .Fa "int scale" "int flags" 52 + .Fc 53 + .Sh DESCRIPTION 54 + The 55 + .Fn humanize_number 56 + function formats the signed 64-bit quantity given in 57 + .Fa number 58 + into 59 + .Fa buffer . 60 + A space and then 61 + .Fa suffix 62 + is appended to the end. 63 + The buffer pointed to by 64 + .Fa buffer 65 + must be at least 66 + .Fa len 67 + bytes long. 68 + .Pp 69 + If the formatted number (including 70 + .Fa suffix ) 71 + would be too long to fit into 72 + .Fa buffer , 73 + then divide 74 + .Fa number 75 + by 1024 until it will. 76 + In this case, prefix 77 + .Fa suffix 78 + with the appropriate SI designator. 79 + .Pp 80 + The prefixes are: 81 + .Bl -column "Prefix" "Description" "Multiplier" -offset indent 82 + .It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier" 83 + .It Li k Ta No kilo Ta 1024 84 + .It Li M Ta No mega Ta 1048576 85 + .It Li G Ta No giga Ta 1073741824 86 + .It Li T Ta No tera Ta 1099511627776 87 + .It Li P Ta No peta Ta 1125899906842624 88 + .It Li E Ta No exa Ta 1152921504606846976 89 + .El 90 + .Pp 91 + The 92 + .Fa len 93 + argument must be at least 4 plus the length of 94 + .Fa suffix , 95 + in order to ensure a useful result is generated into 96 + .Fa buffer . 97 + To use a specific prefix, specify this as 98 + .Fa scale 99 + (multiplier = 1024 ^ scale). 100 + This cannot be combined with any of the 101 + .Fa scale 102 + flags below. 103 + .Pp 104 + The following flags may be passed in 105 + .Fa scale : 106 + .Bl -tag -width ".Dv HN_DIVISOR_1000" -offset indent 107 + .It Dv HN_AUTOSCALE 108 + Format the buffer using the lowest multiplier possible. 109 + .It Dv HN_GETSCALE 110 + Return the prefix index number (the number of times 111 + .Fa number 112 + must be divided to fit) instead of formatting it to the buffer. 113 + .El 114 + .Pp 115 + The following flags may be passed in 116 + .Fa flags : 117 + .Bl -tag -width ".Dv HN_DIVISOR_1000" -offset indent 118 + .It Dv HN_DECIMAL 119 + If the final result is less than 10, display it using one digit. 120 + .It Dv HN_NOSPACE 121 + Do not put a space between 122 + .Fa number 123 + and the prefix. 124 + .It Dv HN_B 125 + Use 126 + .Ql B 127 + (bytes) as prefix if the original result does not have a prefix. 128 + .It Dv HN_DIVISOR_1000 129 + Divide 130 + .Fa number 131 + with 1000 instead of 1024. 132 + .El 133 + .Sh RETURN VALUES 134 + The 135 + .Fn humanize_number 136 + function returns the number of characters stored in 137 + .Fa buffer 138 + (excluding the terminating 139 + .Dv NUL ) 140 + upon success, or \-1 upon failure. 141 + If 142 + .Dv HN_GETSCALE 143 + is specified, the prefix index number will be returned instead. 144 + .Sh HISTORY 145 + The 146 + .Fn humanize_number 147 + function first appeared in 148 + .Nx 2.0 .
+159
src/libutil/humanize_number.c
··· 1 + /* $NetBSD: humanize_number.c,v 1.8 2004/07/27 01:56:24 enami Exp $ */ 2 + 3 + /* 4 + * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. 5 + * All rights reserved. 6 + * 7 + * This code is derived from software contributed to The NetBSD Foundation 8 + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 + * NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson. 10 + * 11 + * Redistribution and use in source and binary forms, with or without 12 + * modification, are permitted provided that the following conditions 13 + * are met: 14 + * 1. Redistributions of source code must retain the above copyright 15 + * notice, this list of conditions and the following disclaimer. 16 + * 2. Redistributions in binary form must reproduce the above copyright 17 + * notice, this list of conditions and the following disclaimer in the 18 + * documentation and/or other materials provided with the distribution. 19 + * 3. All advertising materials mentioning features or use of this software 20 + * must display the following acknowledgement: 21 + * This product includes software developed by the NetBSD 22 + * Foundation, Inc. and its contributors. 23 + * 4. Neither the name of The NetBSD Foundation nor the names of its 24 + * contributors may be used to endorse or promote products derived 25 + * from this software without specific prior written permission. 26 + * 27 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 + * POSSIBILITY OF SUCH DAMAGE. 38 + */ 39 + 40 + #include <sys/cdefs.h> 41 + 42 + #include <sys/types.h> 43 + #include <assert.h> 44 + #include <stdio.h> 45 + #include <stdlib.h> 46 + #include <string.h> 47 + #include <locale.h> 48 + #include <libutil.h> 49 + #include <stdint.h> 50 + #include <limits.h> 51 + 52 + int 53 + humanize_number(char *buf, size_t len, int64_t bytes, 54 + const char *suffix, int scale, int flags) 55 + { 56 + const char *prefixes, *sep; 57 + int b, i, r, maxscale, s1, s2, sign; 58 + int64_t divisor, max; 59 + // We multiply bytes by 100 to deal with rounding, so we need something 60 + // big enough to hold LLONG_MAX * 100. On 64-bit we can use 128-bit wide 61 + // integers with __int128_t, but on 32-bit we have to use long double. 62 + #ifdef __LP64__ 63 + __int128_t scalable = (__int128_t)bytes; 64 + #else 65 + long double scalable = (long double)bytes; 66 + #endif 67 + size_t baselen; 68 + 69 + assert(buf != NULL); 70 + assert(suffix != NULL); 71 + assert(scale >= 0); 72 + 73 + if (flags & HN_DIVISOR_1000) { 74 + /* SI for decimal multiplies */ 75 + divisor = 1000; 76 + if (flags & HN_B) 77 + prefixes = "B\0k\0M\0G\0T\0P\0E"; 78 + else 79 + prefixes = "\0\0k\0M\0G\0T\0P\0E"; 80 + } else { 81 + /* 82 + * binary multiplies 83 + * XXX IEC 60027-2 recommends Ki, Mi, Gi... 84 + */ 85 + divisor = 1024; 86 + if (flags & HN_B) 87 + prefixes = "B\0K\0M\0G\0T\0P\0E"; 88 + else 89 + prefixes = "\0\0K\0M\0G\0T\0P\0E"; 90 + } 91 + 92 + #define SCALE2PREFIX(scale) (&prefixes[(scale) << 1]) 93 + maxscale = 7; 94 + 95 + if (scale >= maxscale && 96 + (scale & (HN_AUTOSCALE | HN_GETSCALE)) == 0) 97 + return (-1); 98 + 99 + if (buf == NULL || suffix == NULL) 100 + return (-1); 101 + 102 + if (len > 0) 103 + buf[0] = '\0'; 104 + if (bytes < 0) { 105 + sign = -1; 106 + scalable *= -100; 107 + baselen = 3; /* sign, digit, prefix */ 108 + } else { 109 + sign = 1; 110 + scalable *= 100; 111 + baselen = 2; /* digit, prefix */ 112 + } 113 + if (flags & HN_NOSPACE) 114 + sep = ""; 115 + else { 116 + sep = " "; 117 + baselen++; 118 + } 119 + baselen += strlen(suffix); 120 + 121 + /* Check if enough room for `x y' + suffix + `\0' */ 122 + if (len < baselen + 1) 123 + return (-1); 124 + 125 + if (scale & (HN_AUTOSCALE | HN_GETSCALE)) { 126 + /* See if there is additional columns can be used. */ 127 + for (max = 100, i = len - baselen; i-- > 0;) 128 + max *= 10; 129 + 130 + for (i = 0; scalable >= max && i < maxscale; i++) 131 + scalable /= divisor; 132 + 133 + if (scale & HN_GETSCALE) 134 + return (i); 135 + } else 136 + for (i = 0; i < scale && i < maxscale; i++) 137 + scalable /= divisor; 138 + 139 + /* If a value <= 9.9 after rounding and ... */ 140 + if (scalable < 995 && i > 0 && flags & HN_DECIMAL) { 141 + /* baselen + \0 + .N */ 142 + if (len < baselen + 1 + 2) 143 + return (-1); 144 + b = ((int)scalable + 5) / 10; 145 + s1 = b / 10; 146 + s2 = b % 10; 147 + r = snprintf(buf, len, "%s%d%s%d%s%s%s", 148 + ((sign == -1) ? "-" : ""), 149 + s1, localeconv()->decimal_point, s2, 150 + sep, SCALE2PREFIX(i), suffix); 151 + } else 152 + r = snprintf(buf, len, "%s%lld%s%s%s", 153 + /* LONGLONG */ 154 + ((sign == -1) ? "-" : ""), 155 + (long long)((scalable + 50) / 100), 156 + sep, SCALE2PREFIX(i), suffix); 157 + 158 + return (r); 159 + }
+20
src/libutil/libutil.exports
··· 1 + _freemntopts 2 + _getmnt_silent 3 + _getmntoptnum 4 + _getmntopts 5 + _getmntoptstr 6 + _humanize_number 7 + _pidfile_close 8 + _pidfile_open 9 + _pidfile_remove 10 + _pidfile_write 11 + _realhostname 12 + _realhostname_sa 13 + _reexec_to_match_kernel 14 + _reexec_to_match_lp64ness 15 + _tzlink 16 + _wipefs_alloc 17 + _wipefs_except_blocks 18 + _wipefs_free 19 + _wipefs_include_blocks 20 + _wipefs_wipe
+93
src/libutil/libutil.h
··· 1 + /* 2 + * Copyright (c) 1996 Peter Wemm <peter@FreeBSD.org>. 3 + * All rights reserved. 4 + * Copyright (c) 2002 Networks Associates Technology, Inc. 5 + * All rights reserved. 6 + * 7 + * Portions of this software were developed for the FreeBSD Project by 8 + * ThinkSec AS and NAI Labs, the Security Research Division of Network 9 + * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 10 + * ("CBOSS"), as part of the DARPA CHATS research program. 11 + * 12 + * Redistribution and use in source and binary forms, with or without 13 + * modification, is permitted provided that the following conditions 14 + * are met: 15 + * 1. Redistributions of source code must retain the above copyright 16 + * notice, this list of conditions and the following disclaimer. 17 + * 2. Redistributions in binary form must reproduce the above copyright 18 + * notice, this list of conditions and the following disclaimer in the 19 + * documentation and/or other materials provided with the distribution. 20 + * 3. The name of the author may not be used to endorse or promote 21 + * products derived from this software without specific prior written 22 + * permission. 23 + * 24 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 + * SUCH DAMAGE. 35 + * 36 + * $FreeBSD: src/lib/libutil/libutil.h,v 1.42 2006/02/18 11:25:28 des Exp $ 37 + */ 38 + 39 + #ifndef _LIBUTIL_H_ 40 + #define _LIBUTIL_H_ 41 + 42 + #include <unistd.h> 43 + #include <stdbool.h> 44 + 45 + #ifdef _SYS_PARAM_H_ 46 + /* for pidfile.c */ 47 + struct pidfh { 48 + int pf_fd; 49 + char pf_path[MAXPATHLEN + 1]; 50 + dev_t pf_dev; 51 + ino_t pf_ino; 52 + }; 53 + #endif 54 + 55 + struct in_addr; 56 + struct sockaddr; 57 + 58 + __BEGIN_DECLS 59 + int humanize_number(char *_buf, size_t _len, int64_t _number, 60 + const char *_suffix, int _scale, int _flags); 61 + 62 + int realhostname(char *host, size_t hsize, const struct in_addr *ip); 63 + int realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, 64 + int addrlen); 65 + 66 + #ifdef _SYS_PARAM_H_ 67 + struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr); 68 + int pidfile_write(struct pidfh *pfh); 69 + int pidfile_close(struct pidfh *pfh); 70 + int pidfile_remove(struct pidfh *pfh); 71 + #endif 72 + 73 + int reexec_to_match_kernel(void); 74 + int reexec_to_match_lp64ness(bool isLP64); 75 + 76 + __END_DECLS 77 + 78 + /* return values from realhostname() */ 79 + #define HOSTNAME_FOUND (0) 80 + #define HOSTNAME_INCORRECTNAME (1) 81 + #define HOSTNAME_INVALIDADDR (2) 82 + #define HOSTNAME_INVALIDNAME (3) 83 + 84 + /* humanize_number(3) */ 85 + #define HN_DECIMAL 0x01 86 + #define HN_NOSPACE 0x02 87 + #define HN_B 0x04 88 + #define HN_DIVISOR_1000 0x08 89 + 90 + #define HN_GETSCALE 0x10 91 + #define HN_AUTOSCALE 0x20 92 + 93 + #endif /* !_LIBUTIL_H_ */
+34
src/libutil/libutil.plist
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 + <plist version="1.0"> 4 + <array> 5 + <dict> 6 + <key>OpenSourceSCM</key> 7 + <string>cvs -d freebsdanoncvs@anoncvs.FreeBSD.org:/home/ncvs co libutil</string> 8 + <key>OpenSourceImportDate</key> 9 + <string>2006-05-20</string> 10 + <key>OpenSourceLicense</key> 11 + <string>BSD</string> 12 + <key>OpenSourceLicenseFile</key> 13 + <string>libutil.txt</string> 14 + <key>OpenSourceProject</key> 15 + <string>libutil</string> 16 + <key>OpenSourceVersion</key> 17 + <string>2005-02-13</string> 18 + </dict> 19 + <dict> 20 + <key>OpenSourceImportDate</key> 21 + <string>2006-05-20</string> 22 + <key>OpenSourceLicense</key> 23 + <string>BSD</string> 24 + <key>OpenSourceLicenseFile</key> 25 + <string>libutil.txt</string> 26 + <key>OpenSourceProject</key> 27 + <string>libutil</string> 28 + <key>OpenSourceVersion</key> 29 + <string>1.3</string> 30 + <key>OpenSourceURL</key> 31 + <string>http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/lib/libutil/getmntopts.c?rev=1.3</string> 32 + </dict> 33 + </array> 34 + </plist>
+238
src/libutil/libutil.txt
··· 1 + _secure_path.c: 2 + /*- 3 + * Based on code copyright (c) 1995,1997 by 4 + * Berkeley Software Design, Inc. 5 + * All rights reserved. 6 + * 7 + * Redistribution and use in source and binary forms, with or without 8 + * modification, is permitted provided that the following conditions 9 + * are met: 10 + * 1. Redistributions of source code must retain the above copyright 11 + * notice immediately at the beginning of the file, without modification, 12 + * this list of conditions, and the following disclaimer. 13 + * 2. Redistributions in binary form must reproduce the above copyright 14 + * notice, this list of conditions and the following disclaimer in the 15 + * documentation and/or other materials provided with the distribution. 16 + * 3. This work was done expressly for inclusion into FreeBSD. Other use 17 + * is permitted provided this notation is included. 18 + * 4. Absolutely no warranty of function or purpose is made by the authors. 19 + * 5. Modifications may be freely made to this file providing the above 20 + * conditions are met. 21 + */ 22 + 23 + fparseln.c: 24 + /* 25 + * Copyright (c) 1997 Christos Zoulas. All rights reserved. 26 + * 27 + * Redistribution and use in source and binary forms, with or without 28 + * modification, are permitted provided that the following conditions 29 + * are met: 30 + * 1. Redistributions of source code must retain the above copyright 31 + * notice, this list of conditions and the following disclaimer. 32 + * 2. Redistributions in binary form must reproduce the above copyright 33 + * notice, this list of conditions and the following disclaimer in the 34 + * documentation and/or other materials provided with the distribution. 35 + * 3. All advertising materials mentioning features or use of this software 36 + * must display the following acknowledgement: 37 + * This product includes software developed by Christos Zoulas. 38 + * 4. The name of the author may not be used to endorse or promote products 39 + * derived from this software without specific prior written permission. 40 + * 41 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 42 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 43 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 44 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 45 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 46 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 47 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 48 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 50 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 + */ 52 + 53 + humanize_number.c: 54 + /* 55 + * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc. 56 + * All rights reserved. 57 + * 58 + * This code is derived from software contributed to The NetBSD Foundation 59 + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 60 + * NASA Ames Research Center, by Luke Mewburn and by Tomas Svensson. 61 + * 62 + * Redistribution and use in source and binary forms, with or without 63 + * modification, are permitted provided that the following conditions 64 + * are met: 65 + * 1. Redistributions of source code must retain the above copyright 66 + * notice, this list of conditions and the following disclaimer. 67 + * 2. Redistributions in binary form must reproduce the above copyright 68 + * notice, this list of conditions and the following disclaimer in the 69 + * documentation and/or other materials provided with the distribution. 70 + * 3. All advertising materials mentioning features or use of this software 71 + * must display the following acknowledgement: 72 + * This product includes software developed by the NetBSD 73 + * Foundation, Inc. and its contributors. 74 + * 4. Neither the name of The NetBSD Foundation nor the names of its 75 + * contributors may be used to endorse or promote products derived 76 + * from this software without specific prior written permission. 77 + * 78 + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 79 + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 80 + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 81 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 82 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 83 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 84 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 85 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 86 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 87 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 88 + * POSSIBILITY OF SUCH DAMAGE. 89 + */ 90 + 91 + pidfile.c: 92 + /*- 93 + * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 94 + * All rights reserved. 95 + * 96 + * Redistribution and use in source and binary forms, with or without 97 + * modification, are permitted provided that the following conditions 98 + * are met: 99 + * 1. Redistributions of source code must retain the above copyright 100 + * notice, this list of conditions and the following disclaimer. 101 + * 2. Redistributions in binary form must reproduce the above copyright 102 + * notice, this list of conditions and the following disclaimer in the 103 + * documentation and/or other materials provided with the distribution. 104 + * 105 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 106 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 107 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 108 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 109 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 110 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 111 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 112 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 113 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 114 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 115 + * SUCH DAMAGE. 116 + */ 117 + 118 + property.c: 119 + /* 120 + * 121 + * Simple property list handling code. 122 + * 123 + * Copyright (c) 1998 124 + * Jordan "Perky" Hubbard. All rights reserved. 125 + * 126 + * Redistribution and use in source and binary forms, with or without 127 + * modification, are permitted provided that the following conditions 128 + * are met: 129 + * 1. Redistributions of source code must retain the above copyright 130 + * notice, this list of conditions and the following disclaimer, 131 + * verbatim and that no modifications are made prior to this 132 + * point in the file. 133 + * 2. Redistributions in binary form must reproduce the above copyright 134 + * notice, this list of conditions and the following disclaimer in the 135 + * documentation and/or other materials provided with the distribution. 136 + * 137 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 138 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 139 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 140 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR HIS PETS BE LIABLE 141 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 142 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 143 + * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 144 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 145 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 146 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 147 + * SUCH DAMAGE. 148 + */ 149 + 150 + realhostname.c: 151 + /*- 152 + * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 153 + * All rights reserved. 154 + * 155 + * Redistribution and use in source and binary forms, with or without 156 + * modification, are permitted provided that the following conditions 157 + * are met: 158 + * 1. Redistributions of source code must retain the above copyright 159 + * notice, this list of conditions and the following disclaimer. 160 + * 2. Redistributions in binary form must reproduce the above copyright 161 + * notice, this list of conditions and the following disclaimer in the 162 + * documentation and/or other materials provided with the distribution. 163 + * 164 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 165 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 166 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 167 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 168 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 169 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 170 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 171 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 172 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 173 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 174 + * SUCH DAMAGE. 175 + */ 176 + 177 + trimdomain.c: 178 + /*- 179 + * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org> 180 + * Based on original work by Atsushi Murai <amurai@FreeBSD.org> 181 + * All rights reserved. 182 + * 183 + * Redistribution and use in source and binary forms, with or without 184 + * modification, are permitted provided that the following conditions 185 + * are met: 186 + * 1. Redistributions of source code must retain the above copyright 187 + * notice, this list of conditions and the following disclaimer. 188 + * 2. Redistributions in binary form must reproduce the above copyright 189 + * notice, this list of conditions and the following disclaimer in the 190 + * documentation and/or other materials provided with the distribution. 191 + * 192 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 193 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 194 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 195 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 196 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 197 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 198 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 199 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 200 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 201 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 202 + * SUCH DAMAGE. 203 + * 204 + */ 205 + 206 + uucplock.c: 207 + /* 208 + * Copyright (c) 1988, 1993 209 + * The Regents of the University of California. All rights reserved. 210 + * 211 + * Redistribution and use in source and binary forms, with or without 212 + * modification, are permitted provided that the following conditions 213 + * are met: 214 + * 1. Redistributions of source code must retain the above copyright 215 + * notice, this list of conditions and the following disclaimer. 216 + * 2. Redistributions in binary form must reproduce the above copyright 217 + * notice, this list of conditions and the following disclaimer in the 218 + * documentation and/or other materials provided with the distribution. 219 + * 3. All advertising materials mentioning features or use of this software 220 + * must display the following acknowledgement: 221 + * This product includes software developed by the University of 222 + * California, Berkeley and its contributors. 223 + * 4. Neither the name of the University nor the names of its contributors 224 + * may be used to endorse or promote products derived from this software 225 + * without specific prior written permission. 226 + * 227 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 228 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 229 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 233 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 234 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 235 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 236 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 237 + * SUCH DAMAGE. 238 + */
+575
src/libutil/libutil.xcodeproj/project.pbxproj
··· 1 + // !$*UTF8*$! 2 + { 3 + archiveVersion = 1; 4 + classes = { 5 + }; 6 + objectVersion = 46; 7 + objects = { 8 + 9 + /* Begin PBXAggregateTarget section */ 10 + FDBC26E41741B09300CA4B2B /* osx */ = { 11 + isa = PBXAggregateTarget; 12 + buildConfigurationList = FDBC26E71741B09300CA4B2B /* Build configuration list for PBXAggregateTarget "osx" */; 13 + buildPhases = ( 14 + ); 15 + dependencies = ( 16 + FDBC27001741B1B300CA4B2B /* PBXTargetDependency */, 17 + ); 18 + name = osx; 19 + productName = OSX; 20 + }; 21 + FDBC26E81741B09D00CA4B2B /* ios */ = { 22 + isa = PBXAggregateTarget; 23 + buildConfigurationList = FDBC26E91741B09D00CA4B2B /* Build configuration list for PBXAggregateTarget "ios" */; 24 + buildPhases = ( 25 + ); 26 + dependencies = ( 27 + FDBC27021741B1B500CA4B2B /* PBXTargetDependency */, 28 + FDBC27041741B1B700CA4B2B /* PBXTargetDependency */, 29 + ); 30 + name = ios; 31 + productName = ios; 32 + }; 33 + /* End PBXAggregateTarget section */ 34 + 35 + /* Begin PBXBuildFile section */ 36 + BA79F9CB13BB7207006A292D /* ExtentManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A313BB70FF006A292D /* ExtentManager.cpp */; }; 37 + BA79F9CC13BB7207006A292D /* getmntopts.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A613BB70FF006A292D /* getmntopts.c */; }; 38 + BA79F9CD13BB7207006A292D /* humanize_number.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A813BB70FF006A292D /* humanize_number.c */; }; 39 + BA79F9CE13BB7207006A292D /* pidfile.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B013BB70FF006A292D /* pidfile.c */; }; 40 + BA79F9D013BB7207006A292D /* realhostname.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B513BB70FF006A292D /* realhostname.c */; }; 41 + BA79F9D113BB7207006A292D /* reexec_to_match_kernel.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */; }; 42 + BA79F9D213BB7207006A292D /* trimdomain.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B913BB70FF006A292D /* trimdomain.c */; }; 43 + BA79F9D413BB7207006A292D /* wipefs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9BD13BB70FF006A292D /* wipefs.cpp */; }; 44 + BA79F9D513BB7235006A292D /* libutil.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9AA13BB70FF006A292D /* libutil.h */; settings = {ATTRIBUTES = (Private, ); }; }; 45 + BA79F9D613BB7235006A292D /* mntopts.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9AE13BB70FF006A292D /* mntopts.h */; settings = {ATTRIBUTES = (Private, ); }; }; 46 + BA79F9D713BB7235006A292D /* wipefs.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9BE13BB70FF006A292D /* wipefs.h */; settings = {ATTRIBUTES = (Private, ); }; }; 47 + BA79F9D813BB7243006A292D /* ExtentManager.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9A413BB70FF006A292D /* ExtentManager.h */; }; 48 + BA79F9DD13BB76B0006A292D /* getmntopts.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9A513BB70FF006A292D /* getmntopts.3 */; }; 49 + BA79F9DE13BB76B0006A292D /* humanize_number.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9A713BB70FF006A292D /* humanize_number.3 */; }; 50 + BA79F9DF13BB76B0006A292D /* pidfile.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AF13BB70FF006A292D /* pidfile.3 */; }; 51 + BA79F9E113BB76B0006A292D /* realhostname_sa.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B313BB70FF006A292D /* realhostname_sa.3 */; }; 52 + BA79F9E213BB76B0006A292D /* realhostname.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B413BB70FF006A292D /* realhostname.3 */; }; 53 + BA79F9E313BB76B0006A292D /* reexec_to_match_kernel.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */; }; 54 + BA79F9E413BB76B0006A292D /* trimdomain.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B813BB70FF006A292D /* trimdomain.3 */; }; 55 + BA79F9E613BB76B0006A292D /* wipefs.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9BC13BB70FF006A292D /* wipefs.3 */; }; 56 + BA79F9E913BB77FA006A292D /* libutil.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AB13BB70FF006A292D /* libutil.plist */; }; 57 + BA79F9EA13BB77FF006A292D /* libutil.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AC13BB70FF006A292D /* libutil.txt */; }; 58 + FDBC27051741B1C300CA4B2B /* com.apple.tzlinkd.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = FDBC26FA1741B19000CA4B2B /* com.apple.tzlinkd.plist */; }; 59 + FDBC27061741B1CF00CA4B2B /* tzlinkd.c in Sources */ = {isa = PBXBuildFile; fileRef = FDBC26FE1741B19000CA4B2B /* tzlinkd.c */; }; 60 + FDBC27071741B1D600CA4B2B /* tzlink.c in Sources */ = {isa = PBXBuildFile; fileRef = FDBC26F91741B18500CA4B2B /* tzlink.c */; }; 61 + FDBC270B1741B55400CA4B2B /* tzlink.h in Headers */ = {isa = PBXBuildFile; fileRef = FDBC27091741B47200CA4B2B /* tzlink.h */; settings = {ATTRIBUTES = (Private, ); }; }; 62 + /* End PBXBuildFile section */ 63 + 64 + /* Begin PBXContainerItemProxy section */ 65 + FDBC26FF1741B1B300CA4B2B /* PBXContainerItemProxy */ = { 66 + isa = PBXContainerItemProxy; 67 + containerPortal = BA79F99713BB70D7006A292D /* Project object */; 68 + proxyType = 1; 69 + remoteGlobalIDString = BA79F9C413BB718B006A292D; 70 + remoteInfo = util; 71 + }; 72 + FDBC27011741B1B500CA4B2B /* PBXContainerItemProxy */ = { 73 + isa = PBXContainerItemProxy; 74 + containerPortal = BA79F99713BB70D7006A292D /* Project object */; 75 + proxyType = 1; 76 + remoteGlobalIDString = BA79F9C413BB718B006A292D; 77 + remoteInfo = util; 78 + }; 79 + FDBC27031741B1B700CA4B2B /* PBXContainerItemProxy */ = { 80 + isa = PBXContainerItemProxy; 81 + containerPortal = BA79F99713BB70D7006A292D /* Project object */; 82 + proxyType = 1; 83 + remoteGlobalIDString = FDBC26EF1741B13400CA4B2B; 84 + remoteInfo = tzlinkd; 85 + }; 86 + /* End PBXContainerItemProxy section */ 87 + 88 + /* Begin PBXCopyFilesBuildPhase section */ 89 + BA79F9DB13BB7698006A292D /* CopyFiles */ = { 90 + isa = PBXCopyFilesBuildPhase; 91 + buildActionMask = 8; 92 + dstPath = "$(INSTALL_PATH_PREFIX)/usr/local/share/man/man3"; 93 + dstSubfolderSpec = 0; 94 + files = ( 95 + BA79F9DD13BB76B0006A292D /* getmntopts.3 in CopyFiles */, 96 + BA79F9DE13BB76B0006A292D /* humanize_number.3 in CopyFiles */, 97 + BA79F9DF13BB76B0006A292D /* pidfile.3 in CopyFiles */, 98 + BA79F9E113BB76B0006A292D /* realhostname_sa.3 in CopyFiles */, 99 + BA79F9E213BB76B0006A292D /* realhostname.3 in CopyFiles */, 100 + BA79F9E313BB76B0006A292D /* reexec_to_match_kernel.3 in CopyFiles */, 101 + BA79F9E413BB76B0006A292D /* trimdomain.3 in CopyFiles */, 102 + BA79F9E613BB76B0006A292D /* wipefs.3 in CopyFiles */, 103 + ); 104 + runOnlyForDeploymentPostprocessing = 1; 105 + }; 106 + BA79F9E713BB77BB006A292D /* CopyFiles */ = { 107 + isa = PBXCopyFilesBuildPhase; 108 + buildActionMask = 8; 109 + dstPath = "$(INSTALL_PATH_PREFIX)/usr/local/OpenSourceVersions"; 110 + dstSubfolderSpec = 0; 111 + files = ( 112 + BA79F9E913BB77FA006A292D /* libutil.plist in CopyFiles */, 113 + ); 114 + runOnlyForDeploymentPostprocessing = 1; 115 + }; 116 + BA79F9E813BB77D6006A292D /* CopyFiles */ = { 117 + isa = PBXCopyFilesBuildPhase; 118 + buildActionMask = 8; 119 + dstPath = "$(INSTALL_PATH_PREFIX)/usr/local/OpenSourceLicenses"; 120 + dstSubfolderSpec = 0; 121 + files = ( 122 + BA79F9EA13BB77FF006A292D /* libutil.txt in CopyFiles */, 123 + ); 124 + runOnlyForDeploymentPostprocessing = 1; 125 + }; 126 + FDBC26EE1741B13400CA4B2B /* CopyFiles */ = { 127 + isa = PBXCopyFilesBuildPhase; 128 + buildActionMask = 2147483647; 129 + dstPath = "$(INSTALL_PATH_PREFIX)/System/Library/LaunchDaemons"; 130 + dstSubfolderSpec = 0; 131 + files = ( 132 + FDBC27051741B1C300CA4B2B /* com.apple.tzlinkd.plist in CopyFiles */, 133 + ); 134 + runOnlyForDeploymentPostprocessing = 1; 135 + }; 136 + /* End PBXCopyFilesBuildPhase section */ 137 + 138 + /* Begin PBXFileReference section */ 139 + 3F09C378186D1F73007AF93C /* base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = base.xcconfig; path = xcconfigs/base.xcconfig; sourceTree = "<group>"; }; 140 + BA79F9A313BB70FF006A292D /* ExtentManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ExtentManager.cpp; sourceTree = "<group>"; }; 141 + BA79F9A413BB70FF006A292D /* ExtentManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtentManager.h; sourceTree = "<group>"; }; 142 + BA79F9A513BB70FF006A292D /* getmntopts.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = getmntopts.3; sourceTree = "<group>"; }; 143 + BA79F9A613BB70FF006A292D /* getmntopts.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = getmntopts.c; sourceTree = "<group>"; }; 144 + BA79F9A713BB70FF006A292D /* humanize_number.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = humanize_number.3; sourceTree = "<group>"; }; 145 + BA79F9A813BB70FF006A292D /* humanize_number.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = humanize_number.c; sourceTree = "<group>"; }; 146 + BA79F9A913BB70FF006A292D /* libutil.exports */ = {isa = PBXFileReference; lastKnownFileType = text; path = libutil.exports; sourceTree = "<group>"; }; 147 + BA79F9AA13BB70FF006A292D /* libutil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = libutil.h; sourceTree = "<group>"; }; 148 + BA79F9AB13BB70FF006A292D /* libutil.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = libutil.plist; sourceTree = "<group>"; }; 149 + BA79F9AC13BB70FF006A292D /* libutil.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = libutil.txt; sourceTree = "<group>"; }; 150 + BA79F9AE13BB70FF006A292D /* mntopts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mntopts.h; sourceTree = "<group>"; }; 151 + BA79F9AF13BB70FF006A292D /* pidfile.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = pidfile.3; sourceTree = "<group>"; }; 152 + BA79F9B013BB70FF006A292D /* pidfile.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = pidfile.c; sourceTree = "<group>"; }; 153 + BA79F9B313BB70FF006A292D /* realhostname_sa.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = realhostname_sa.3; sourceTree = "<group>"; }; 154 + BA79F9B413BB70FF006A292D /* realhostname.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = realhostname.3; sourceTree = "<group>"; }; 155 + BA79F9B513BB70FF006A292D /* realhostname.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = realhostname.c; sourceTree = "<group>"; }; 156 + BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = reexec_to_match_kernel.3; sourceTree = "<group>"; }; 157 + BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = reexec_to_match_kernel.c; sourceTree = "<group>"; }; 158 + BA79F9B813BB70FF006A292D /* trimdomain.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = trimdomain.3; sourceTree = "<group>"; }; 159 + BA79F9B913BB70FF006A292D /* trimdomain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = trimdomain.c; sourceTree = "<group>"; }; 160 + BA79F9BC13BB70FF006A292D /* wipefs.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = wipefs.3; sourceTree = "<group>"; }; 161 + BA79F9BD13BB70FF006A292D /* wipefs.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = wipefs.cpp; sourceTree = "<group>"; }; 162 + BA79F9BE13BB70FF006A292D /* wipefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wipefs.h; sourceTree = "<group>"; }; 163 + BA79F9C513BB718B006A292D /* libutil.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libutil.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; 164 + FDBC26F01741B13400CA4B2B /* tzlinkd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = tzlinkd; sourceTree = BUILT_PRODUCTS_DIR; }; 165 + FDBC26F91741B18500CA4B2B /* tzlink.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tzlink.c; sourceTree = "<group>"; }; 166 + FDBC26FA1741B19000CA4B2B /* com.apple.tzlinkd.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = com.apple.tzlinkd.plist; sourceTree = "<group>"; }; 167 + FDBC26FB1741B19000CA4B2B /* com.apple.tzlinkd.sb */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.tzlinkd.sb; sourceTree = "<group>"; }; 168 + FDBC26FE1741B19000CA4B2B /* tzlinkd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tzlinkd.c; sourceTree = "<group>"; }; 169 + FDBC27081741B47200CA4B2B /* tzlink_internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tzlink_internal.h; sourceTree = "<group>"; }; 170 + FDBC27091741B47200CA4B2B /* tzlink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tzlink.h; sourceTree = "<group>"; }; 171 + FDBC270D1741B66500CA4B2B /* tzlinkd.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = tzlinkd.xcconfig; sourceTree = "<group>"; }; 172 + /* End PBXFileReference section */ 173 + 174 + /* Begin PBXFrameworksBuildPhase section */ 175 + BA79F9C213BB718B006A292D /* Frameworks */ = { 176 + isa = PBXFrameworksBuildPhase; 177 + buildActionMask = 2147483647; 178 + files = ( 179 + ); 180 + runOnlyForDeploymentPostprocessing = 0; 181 + }; 182 + FDBC26ED1741B13400CA4B2B /* Frameworks */ = { 183 + isa = PBXFrameworksBuildPhase; 184 + buildActionMask = 2147483647; 185 + files = ( 186 + ); 187 + runOnlyForDeploymentPostprocessing = 0; 188 + }; 189 + /* End PBXFrameworksBuildPhase section */ 190 + 191 + /* Begin PBXGroup section */ 192 + BA79F99513BB70D7006A292D = { 193 + isa = PBXGroup; 194 + children = ( 195 + 3F09C378186D1F73007AF93C /* base.xcconfig */, 196 + BA79F9A313BB70FF006A292D /* ExtentManager.cpp */, 197 + BA79F9A413BB70FF006A292D /* ExtentManager.h */, 198 + BA79F9A513BB70FF006A292D /* getmntopts.3 */, 199 + BA79F9A613BB70FF006A292D /* getmntopts.c */, 200 + BA79F9A713BB70FF006A292D /* humanize_number.3 */, 201 + BA79F9A813BB70FF006A292D /* humanize_number.c */, 202 + BA79F9A913BB70FF006A292D /* libutil.exports */, 203 + BA79F9AA13BB70FF006A292D /* libutil.h */, 204 + BA79F9AB13BB70FF006A292D /* libutil.plist */, 205 + BA79F9AC13BB70FF006A292D /* libutil.txt */, 206 + BA79F9AE13BB70FF006A292D /* mntopts.h */, 207 + BA79F9AF13BB70FF006A292D /* pidfile.3 */, 208 + BA79F9B013BB70FF006A292D /* pidfile.c */, 209 + BA79F9B313BB70FF006A292D /* realhostname_sa.3 */, 210 + BA79F9B413BB70FF006A292D /* realhostname.3 */, 211 + BA79F9B513BB70FF006A292D /* realhostname.c */, 212 + BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */, 213 + BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */, 214 + BA79F9B813BB70FF006A292D /* trimdomain.3 */, 215 + BA79F9B913BB70FF006A292D /* trimdomain.c */, 216 + FDBC26F91741B18500CA4B2B /* tzlink.c */, 217 + FDBC27091741B47200CA4B2B /* tzlink.h */, 218 + FDBC27081741B47200CA4B2B /* tzlink_internal.h */, 219 + FDBC26F11741B13400CA4B2B /* tzlinkd */, 220 + BA79F9BC13BB70FF006A292D /* wipefs.3 */, 221 + BA79F9BD13BB70FF006A292D /* wipefs.cpp */, 222 + BA79F9BE13BB70FF006A292D /* wipefs.h */, 223 + FDBC270C1741B66500CA4B2B /* xcconfigs */, 224 + BA79F9C613BB718B006A292D /* Products */, 225 + ); 226 + sourceTree = "<group>"; 227 + }; 228 + BA79F9C613BB718B006A292D /* Products */ = { 229 + isa = PBXGroup; 230 + children = ( 231 + BA79F9C513BB718B006A292D /* libutil.dylib */, 232 + FDBC26F01741B13400CA4B2B /* tzlinkd */, 233 + ); 234 + name = Products; 235 + sourceTree = "<group>"; 236 + }; 237 + FDBC26F11741B13400CA4B2B /* tzlinkd */ = { 238 + isa = PBXGroup; 239 + children = ( 240 + FDBC26FA1741B19000CA4B2B /* com.apple.tzlinkd.plist */, 241 + FDBC26FB1741B19000CA4B2B /* com.apple.tzlinkd.sb */, 242 + FDBC26FE1741B19000CA4B2B /* tzlinkd.c */, 243 + ); 244 + path = tzlinkd; 245 + sourceTree = "<group>"; 246 + }; 247 + FDBC270C1741B66500CA4B2B /* xcconfigs */ = { 248 + isa = PBXGroup; 249 + children = ( 250 + FDBC270D1741B66500CA4B2B /* tzlinkd.xcconfig */, 251 + ); 252 + path = xcconfigs; 253 + sourceTree = "<group>"; 254 + }; 255 + /* End PBXGroup section */ 256 + 257 + /* Begin PBXHeadersBuildPhase section */ 258 + BA79F9C313BB718B006A292D /* Headers */ = { 259 + isa = PBXHeadersBuildPhase; 260 + buildActionMask = 2147483647; 261 + files = ( 262 + BA79F9D513BB7235006A292D /* libutil.h in Headers */, 263 + BA79F9D613BB7235006A292D /* mntopts.h in Headers */, 264 + FDBC270B1741B55400CA4B2B /* tzlink.h in Headers */, 265 + BA79F9D713BB7235006A292D /* wipefs.h in Headers */, 266 + BA79F9D813BB7243006A292D /* ExtentManager.h in Headers */, 267 + ); 268 + runOnlyForDeploymentPostprocessing = 0; 269 + }; 270 + /* End PBXHeadersBuildPhase section */ 271 + 272 + /* Begin PBXNativeTarget section */ 273 + BA79F9C413BB718B006A292D /* util */ = { 274 + isa = PBXNativeTarget; 275 + buildConfigurationList = BA79F9C713BB718B006A292D /* Build configuration list for PBXNativeTarget "util" */; 276 + buildPhases = ( 277 + BA79F9C113BB718B006A292D /* Sources */, 278 + BA79F9C213BB718B006A292D /* Frameworks */, 279 + BA79F9C313BB718B006A292D /* Headers */, 280 + BA79F9DA13BB750E006A292D /* ShellScript */, 281 + BA79F9EB13BB7864006A292D /* ShellScript */, 282 + BA79F9DB13BB7698006A292D /* CopyFiles */, 283 + BA79F9E713BB77BB006A292D /* CopyFiles */, 284 + BA79F9E813BB77D6006A292D /* CopyFiles */, 285 + ); 286 + buildRules = ( 287 + ); 288 + dependencies = ( 289 + ); 290 + name = util; 291 + productName = util; 292 + productReference = BA79F9C513BB718B006A292D /* libutil.dylib */; 293 + productType = "com.apple.product-type.library.dynamic"; 294 + }; 295 + FDBC26EF1741B13400CA4B2B /* tzlinkd */ = { 296 + isa = PBXNativeTarget; 297 + buildConfigurationList = FDBC26F81741B13400CA4B2B /* Build configuration list for PBXNativeTarget "tzlinkd" */; 298 + buildPhases = ( 299 + FDBC26EC1741B13400CA4B2B /* Sources */, 300 + FDBC26ED1741B13400CA4B2B /* Frameworks */, 301 + FDBC26EE1741B13400CA4B2B /* CopyFiles */, 302 + ); 303 + buildRules = ( 304 + ); 305 + dependencies = ( 306 + ); 307 + name = tzlinkd; 308 + productName = tzlinkd; 309 + productReference = FDBC26F01741B13400CA4B2B /* tzlinkd */; 310 + productType = "com.apple.product-type.tool"; 311 + }; 312 + /* End PBXNativeTarget section */ 313 + 314 + /* Begin PBXProject section */ 315 + BA79F99713BB70D7006A292D /* Project object */ = { 316 + isa = PBXProject; 317 + attributes = { 318 + LastUpgradeCheck = 0420; 319 + }; 320 + buildConfigurationList = BA79F99A13BB70D7006A292D /* Build configuration list for PBXProject "libutil" */; 321 + compatibilityVersion = "Xcode 3.2"; 322 + developmentRegion = English; 323 + hasScannedForEncodings = 0; 324 + knownRegions = ( 325 + en, 326 + ); 327 + mainGroup = BA79F99513BB70D7006A292D; 328 + productRefGroup = BA79F9C613BB718B006A292D /* Products */; 329 + projectDirPath = ""; 330 + projectRoot = ""; 331 + targets = ( 332 + FDBC26E81741B09D00CA4B2B /* ios */, 333 + FDBC26E41741B09300CA4B2B /* osx */, 334 + BA79F9C413BB718B006A292D /* util */, 335 + FDBC26EF1741B13400CA4B2B /* tzlinkd */, 336 + ); 337 + }; 338 + /* End PBXProject section */ 339 + 340 + /* Begin PBXShellScriptBuildPhase section */ 341 + BA79F9DA13BB750E006A292D /* ShellScript */ = { 342 + isa = PBXShellScriptBuildPhase; 343 + buildActionMask = 2147483647; 344 + files = ( 345 + ); 346 + inputPaths = ( 347 + ); 348 + outputPaths = ( 349 + "$(BUILT_PRODUCTS_DIR)/libutil1.0.dylib", 350 + ); 351 + runOnlyForDeploymentPostprocessing = 0; 352 + shellPath = /bin/sh; 353 + shellScript = "set -e\nset -x\n\nln -sf ${EXECUTABLE_NAME} \"${BUILT_PRODUCTS_DIR}/libutil1.0.dylib\"\n"; 354 + }; 355 + BA79F9EB13BB7864006A292D /* ShellScript */ = { 356 + isa = PBXShellScriptBuildPhase; 357 + buildActionMask = 8; 358 + files = ( 359 + ); 360 + inputPaths = ( 361 + ); 362 + outputPaths = ( 363 + "$(DSTROOT)/$(INSTALL_PATH)/libutil1.0.dylib", 364 + ); 365 + runOnlyForDeploymentPostprocessing = 1; 366 + shellPath = /bin/sh; 367 + shellScript = "set -e\nset -x\n\nln -sf ${EXECUTABLE_NAME} \"${DSTROOT}/${INSTALL_PATH}/libutil1.0.dylib\"\n"; 368 + }; 369 + /* End PBXShellScriptBuildPhase section */ 370 + 371 + /* Begin PBXSourcesBuildPhase section */ 372 + BA79F9C113BB718B006A292D /* Sources */ = { 373 + isa = PBXSourcesBuildPhase; 374 + buildActionMask = 2147483647; 375 + files = ( 376 + BA79F9CB13BB7207006A292D /* ExtentManager.cpp in Sources */, 377 + BA79F9CC13BB7207006A292D /* getmntopts.c in Sources */, 378 + BA79F9CD13BB7207006A292D /* humanize_number.c in Sources */, 379 + BA79F9CE13BB7207006A292D /* pidfile.c in Sources */, 380 + BA79F9D013BB7207006A292D /* realhostname.c in Sources */, 381 + BA79F9D113BB7207006A292D /* reexec_to_match_kernel.c in Sources */, 382 + BA79F9D213BB7207006A292D /* trimdomain.c in Sources */, 383 + FDBC27071741B1D600CA4B2B /* tzlink.c in Sources */, 384 + BA79F9D413BB7207006A292D /* wipefs.cpp in Sources */, 385 + ); 386 + runOnlyForDeploymentPostprocessing = 0; 387 + }; 388 + FDBC26EC1741B13400CA4B2B /* Sources */ = { 389 + isa = PBXSourcesBuildPhase; 390 + buildActionMask = 2147483647; 391 + files = ( 392 + FDBC27061741B1CF00CA4B2B /* tzlinkd.c in Sources */, 393 + ); 394 + runOnlyForDeploymentPostprocessing = 0; 395 + }; 396 + /* End PBXSourcesBuildPhase section */ 397 + 398 + /* Begin PBXTargetDependency section */ 399 + FDBC27001741B1B300CA4B2B /* PBXTargetDependency */ = { 400 + isa = PBXTargetDependency; 401 + target = BA79F9C413BB718B006A292D /* util */; 402 + targetProxy = FDBC26FF1741B1B300CA4B2B /* PBXContainerItemProxy */; 403 + }; 404 + FDBC27021741B1B500CA4B2B /* PBXTargetDependency */ = { 405 + isa = PBXTargetDependency; 406 + target = BA79F9C413BB718B006A292D /* util */; 407 + targetProxy = FDBC27011741B1B500CA4B2B /* PBXContainerItemProxy */; 408 + }; 409 + FDBC27041741B1B700CA4B2B /* PBXTargetDependency */ = { 410 + isa = PBXTargetDependency; 411 + target = FDBC26EF1741B13400CA4B2B /* tzlinkd */; 412 + targetProxy = FDBC27031741B1B700CA4B2B /* PBXContainerItemProxy */; 413 + }; 414 + /* End PBXTargetDependency section */ 415 + 416 + /* Begin XCBuildConfiguration section */ 417 + BA79F99C13BB70D7006A292D /* Debug */ = { 418 + isa = XCBuildConfiguration; 419 + baseConfigurationReference = 3F09C378186D1F73007AF93C /* base.xcconfig */; 420 + buildSettings = { 421 + APPLY_RULES_IN_COPY_FILES = YES; 422 + "PLIST_FILE_OUTPUT_FORMAT[sdk=iphoneos*]" = binary; 423 + "PLIST_FILE_OUTPUT_FORMAT[sdk=macosx*]" = XML; 424 + USE_HEADERMAP = NO; 425 + }; 426 + name = Debug; 427 + }; 428 + BA79F99D13BB70D7006A292D /* Release */ = { 429 + isa = XCBuildConfiguration; 430 + baseConfigurationReference = 3F09C378186D1F73007AF93C /* base.xcconfig */; 431 + buildSettings = { 432 + APPLY_RULES_IN_COPY_FILES = YES; 433 + "PLIST_FILE_OUTPUT_FORMAT[sdk=iphoneos*]" = binary; 434 + "PLIST_FILE_OUTPUT_FORMAT[sdk=macosx*]" = XML; 435 + USE_HEADERMAP = NO; 436 + }; 437 + name = Release; 438 + }; 439 + BA79F9C813BB718B006A292D /* Debug */ = { 440 + isa = XCBuildConfiguration; 441 + buildSettings = { 442 + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 443 + DYLIB_COMPATIBILITY_VERSION = 1.0; 444 + DYLIB_CURRENT_VERSION = 1.0; 445 + EXECUTABLE_PREFIX = lib; 446 + EXPORTED_SYMBOLS_FILE = libutil.exports; 447 + GCC_OPTIMIZATION_LEVEL = 0; 448 + GCC_PREPROCESSOR_DEFINITIONS = ( 449 + "DEBUG=1", 450 + "$(inherited)", 451 + ); 452 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 453 + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 454 + GCC_WARN_ABOUT_RETURN_TYPE = YES; 455 + GCC_WARN_UNUSED_VARIABLE = YES; 456 + INSTALL_PATH_ACTUAL = /usr/lib; 457 + PRODUCT_NAME = "$(TARGET_NAME)"; 458 + WARNING_CFLAGS = "-Wall"; 459 + }; 460 + name = Debug; 461 + }; 462 + BA79F9C913BB718B006A292D /* Release */ = { 463 + isa = XCBuildConfiguration; 464 + buildSettings = { 465 + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 466 + DYLIB_COMPATIBILITY_VERSION = 1.0; 467 + DYLIB_CURRENT_VERSION = 1.0; 468 + EXECUTABLE_PREFIX = lib; 469 + EXPORTED_SYMBOLS_FILE = libutil.exports; 470 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 471 + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 472 + GCC_WARN_ABOUT_RETURN_TYPE = YES; 473 + GCC_WARN_UNUSED_VARIABLE = YES; 474 + INSTALL_PATH_ACTUAL = /usr/lib; 475 + PRODUCT_NAME = "$(TARGET_NAME)"; 476 + WARNING_CFLAGS = "-Wall"; 477 + }; 478 + name = Release; 479 + }; 480 + FDBC26E51741B09300CA4B2B /* Debug */ = { 481 + isa = XCBuildConfiguration; 482 + buildSettings = { 483 + PRODUCT_NAME = "$(TARGET_NAME)"; 484 + }; 485 + name = Debug; 486 + }; 487 + FDBC26E61741B09300CA4B2B /* Release */ = { 488 + isa = XCBuildConfiguration; 489 + buildSettings = { 490 + PRODUCT_NAME = "$(TARGET_NAME)"; 491 + }; 492 + name = Release; 493 + }; 494 + FDBC26EA1741B09D00CA4B2B /* Debug */ = { 495 + isa = XCBuildConfiguration; 496 + buildSettings = { 497 + PRODUCT_NAME = "$(TARGET_NAME)"; 498 + }; 499 + name = Debug; 500 + }; 501 + FDBC26EB1741B09D00CA4B2B /* Release */ = { 502 + isa = XCBuildConfiguration; 503 + buildSettings = { 504 + PRODUCT_NAME = "$(TARGET_NAME)"; 505 + }; 506 + name = Release; 507 + }; 508 + FDBC26F61741B13400CA4B2B /* Debug */ = { 509 + isa = XCBuildConfiguration; 510 + baseConfigurationReference = FDBC270D1741B66500CA4B2B /* tzlinkd.xcconfig */; 511 + buildSettings = { 512 + GCC_TREAT_WARNINGS_AS_ERRORS = YES; 513 + }; 514 + name = Debug; 515 + }; 516 + FDBC26F71741B13400CA4B2B /* Release */ = { 517 + isa = XCBuildConfiguration; 518 + baseConfigurationReference = FDBC270D1741B66500CA4B2B /* tzlinkd.xcconfig */; 519 + buildSettings = { 520 + GCC_TREAT_WARNINGS_AS_ERRORS = YES; 521 + }; 522 + name = Release; 523 + }; 524 + /* End XCBuildConfiguration section */ 525 + 526 + /* Begin XCConfigurationList section */ 527 + BA79F99A13BB70D7006A292D /* Build configuration list for PBXProject "libutil" */ = { 528 + isa = XCConfigurationList; 529 + buildConfigurations = ( 530 + BA79F99C13BB70D7006A292D /* Debug */, 531 + BA79F99D13BB70D7006A292D /* Release */, 532 + ); 533 + defaultConfigurationIsVisible = 0; 534 + defaultConfigurationName = Release; 535 + }; 536 + BA79F9C713BB718B006A292D /* Build configuration list for PBXNativeTarget "util" */ = { 537 + isa = XCConfigurationList; 538 + buildConfigurations = ( 539 + BA79F9C813BB718B006A292D /* Debug */, 540 + BA79F9C913BB718B006A292D /* Release */, 541 + ); 542 + defaultConfigurationIsVisible = 0; 543 + defaultConfigurationName = Release; 544 + }; 545 + FDBC26E71741B09300CA4B2B /* Build configuration list for PBXAggregateTarget "osx" */ = { 546 + isa = XCConfigurationList; 547 + buildConfigurations = ( 548 + FDBC26E51741B09300CA4B2B /* Debug */, 549 + FDBC26E61741B09300CA4B2B /* Release */, 550 + ); 551 + defaultConfigurationIsVisible = 0; 552 + defaultConfigurationName = Release; 553 + }; 554 + FDBC26E91741B09D00CA4B2B /* Build configuration list for PBXAggregateTarget "ios" */ = { 555 + isa = XCConfigurationList; 556 + buildConfigurations = ( 557 + FDBC26EA1741B09D00CA4B2B /* Debug */, 558 + FDBC26EB1741B09D00CA4B2B /* Release */, 559 + ); 560 + defaultConfigurationIsVisible = 0; 561 + defaultConfigurationName = Release; 562 + }; 563 + FDBC26F81741B13400CA4B2B /* Build configuration list for PBXNativeTarget "tzlinkd" */ = { 564 + isa = XCConfigurationList; 565 + buildConfigurations = ( 566 + FDBC26F61741B13400CA4B2B /* Debug */, 567 + FDBC26F71741B13400CA4B2B /* Release */, 568 + ); 569 + defaultConfigurationIsVisible = 0; 570 + defaultConfigurationName = Release; 571 + }; 572 + /* End XCConfigurationList section */ 573 + }; 574 + rootObject = BA79F99713BB70D7006A292D /* Project object */; 575 + }
+7
src/libutil/libutil.xcodeproj/project.xcworkspace/contents.xcworkspacedata
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <Workspace 3 + version = "1.0"> 4 + <FileRef 5 + location = "self:libutil.xcodeproj"> 6 + </FileRef> 7 + </Workspace>
+138
src/libutil/mntopts.h
··· 1 + /* 2 + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + 24 + /* $NetBSD: mntopts.h,v 1.7 2006/02/12 01:32:06 chs Exp $ */ 25 + 26 + /*- 27 + * Copyright (c) 1994 28 + * The Regents of the University of California. All rights reserved. 29 + * 30 + * Redistribution and use in source and binary forms, with or without 31 + * modification, are permitted provided that the following conditions 32 + * are met: 33 + * 1. Redistributions of source code must retain the above copyright 34 + * notice, this list of conditions and the following disclaimer. 35 + * 2. Redistributions in binary form must reproduce the above copyright 36 + * notice, this list of conditions and the following disclaimer in the 37 + * documentation and/or other materials provided with the distribution. 38 + * 3. Neither the name of the University nor the names of its contributors 39 + * may be used to endorse or promote products derived from this software 40 + * without specific prior written permission. 41 + * 42 + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 43 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 45 + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 46 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 48 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 50 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 51 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 52 + * SUCH DAMAGE. 53 + * 54 + * @(#)mntopts.h 8.7 (Berkeley) 3/29/95 55 + */ 56 + #ifndef _MNTOPTS_H_ 57 + #define _MNTOPTS_H_ 58 + 59 + #ifdef __cplusplus 60 + extern "C" { 61 + #endif 62 + 63 + struct mntopt { 64 + const char *m_option; /* option name */ 65 + int m_inverse; /* if a negative option, eg "dev" */ 66 + int m_flag; /* bit to set, eg. MNT_RDONLY */ 67 + int m_altloc; /* 1 => set bit in altflags */ 68 + }; 69 + 70 + /* User-visible MNT_ flags. */ 71 + #define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 } 72 + #define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 } 73 + #define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } 74 + #define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } 75 + #define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } 76 + #define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 } 77 + #define MOPT_UNION { "union", 0, MNT_UNION, 0 } 78 + #define MOPT_USERQUOTA { "userquota", 0, 0, 0 } 79 + #define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 } 80 + #define MOPT_BROWSE { "browse", 1, MNT_DONTBROWSE, 0 } 81 + #define MOPT_AUTOMOUNTED { "automounted",0, MNT_AUTOMOUNTED, 0 } 82 + #define MOPT_DEFWRITE { "defwrite", 0, MNT_DEFWRITE, 0} 83 + #define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0} 84 + #define MOPT_IGNORE_OWNERSHIP { "owners", 1, MNT_IGNORE_OWNERSHIP, 0} 85 + /* alias the deprecated name for compatibility */ 86 + #define MOPT_PERMISSIONS { "perm", 1, MNT_IGNORE_OWNERSHIP, 0} 87 + #define MOPT_QUARANTINE { "quarantine", 0, MNT_QUARANTINE, 0} 88 + #define MOPT_CPROTECT { "protect", 0, MNT_CPROTECT, 0 } 89 + 90 + /* Control flags. */ 91 + #define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } 92 + #define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 } 93 + #define MOPT_RELOAD { "reload", 0, MNT_RELOAD, 0 } 94 + 95 + /* Support for old-style "ro", "rw" flags. */ 96 + #define MOPT_RO { "ro", 0, MNT_RDONLY, 0 } 97 + #define MOPT_RW { "rw", 1, MNT_RDONLY, 0 } 98 + 99 + /* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */ 100 + #define MOPT_AUTO { "auto", 0, 0, 0 } 101 + 102 + #define MOPT_FSTAB_COMPAT \ 103 + MOPT_RO, \ 104 + MOPT_RW, \ 105 + MOPT_AUTO 106 + 107 + /* Standard options which all mounts can understand. */ 108 + #define MOPT_STDOPTS \ 109 + MOPT_USERQUOTA, \ 110 + MOPT_GROUPQUOTA, \ 111 + MOPT_FSTAB_COMPAT, \ 112 + MOPT_NODEV, \ 113 + MOPT_NOEXEC, \ 114 + MOPT_NOSUID, \ 115 + MOPT_RDONLY, \ 116 + MOPT_UNION, \ 117 + MOPT_BROWSE, \ 118 + MOPT_AUTOMOUNTED, \ 119 + MOPT_DEFWRITE, \ 120 + MOPT_NOATIME, \ 121 + MOPT_PERMISSIONS, \ 122 + MOPT_IGNORE_OWNERSHIP, \ 123 + MOPT_QUARANTINE, \ 124 + MOPT_CPROTECT 125 + 126 + typedef struct mntoptparse *mntoptparse_t; 127 + mntoptparse_t getmntopts(const char *, const struct mntopt *, int *, int *); 128 + const char *getmntoptstr(mntoptparse_t, const char *); 129 + long getmntoptnum(mntoptparse_t, const char *); 130 + void freemntopts(mntoptparse_t); 131 + 132 + extern int getmnt_silent; 133 + 134 + #ifdef __cplusplus 135 + } 136 + #endif 137 + 138 + #endif /* _MNTOPTS_H_ */
+249
src/libutil/pidfile.3
··· 1 + .\" Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 2 + .\" All rights reserved. 3 + .\" 4 + .\" Redistribution and use in source and binary forms, with or without 5 + .\" modification, are permitted provided that the following conditions 6 + .\" are met: 7 + .\" 1. Redistributions of source code must retain the above copyright 8 + .\" notice, this list of conditions and the following disclaimer. 9 + .\" 2. Redistributions in binary form must reproduce the above copyright 10 + .\" notice, this list of conditions and the following disclaimer in the 11 + .\" documentation and/or other materials provided with the distribution. 12 + .\" 13 + .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 14 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 17 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 + .\" SUCH DAMAGE. 24 + .\" 25 + .\" $FreeBSD: src/lib/libutil/pidfile.3,v 1.5 2006/03/04 15:20:28 keramida Exp $ 26 + .\" 27 + .Dd August 22, 2005 28 + .Dt PIDFILE 3 29 + .Os 30 + .Sh NAME 31 + .Nm pidfile_open , 32 + .Nm pidfile_write , 33 + .Nm pidfile_close , 34 + .Nm pidfile_remove 35 + .Nd "library for PID files handling" 36 + .Sh LIBRARY 37 + .Lb libutil 38 + .Sh SYNOPSIS 39 + .In sys/param.h 40 + .In libutil.h 41 + .Ft "struct pidfh *" 42 + .Fn pidfile_open "const char *path" "mode_t mode" "pid_t *pidptr" 43 + .Ft int 44 + .Fn pidfile_write "struct pidfh *pfh" 45 + .Ft int 46 + .Fn pidfile_close "struct pidfh *pfh" 47 + .Ft int 48 + .Fn pidfile_remove "struct pidfh *pfh" 49 + .Sh DESCRIPTION 50 + The 51 + .Nm pidfile 52 + family of functions allows daemons to handle PID files. 53 + It uses 54 + .Xr flock 2 55 + to lock a pidfile and detect already running daemons. 56 + .Pp 57 + The 58 + .Fn pidfile_open 59 + function opens (or creates) a file specified by the 60 + .Fa path 61 + argument and locks it with the 62 + .Xr flock 2 63 + system call. 64 + If a file can not be locked, a PID of an already running daemon is returned in 65 + the 66 + .Fa pidptr 67 + argument (if it is not 68 + .Dv NULL ) . 69 + The function does not write process' PID into the file here, so it can be 70 + used before 71 + .Fn fork Ns ing 72 + and exit with a proper error message when needed. 73 + If the 74 + .Fa path 75 + argument is 76 + .Dv NULL , 77 + .Pa /var/run/ Ns Ao Va progname Ac Ns Pa .pid 78 + file will be used. 79 + .Pp 80 + The 81 + .Fn pidfile_write 82 + function writes process' PID into a previously opened file. 83 + .Pp 84 + The 85 + .Fn pidfile_close 86 + function closes a pidfile. 87 + It should be used after daemon 88 + .Fn fork Ns s 89 + to start a child process. 90 + .Pp 91 + The 92 + .Fn pidfile_remove 93 + function closes and removes a pidfile. 94 + .Sh RETURN VALUES 95 + The 96 + .Fn pidfile_open 97 + function returns a valid pointer to a 98 + .Vt pidfh 99 + structure on success, or 100 + .Dv NULL 101 + if an error occurs. 102 + If an error occurs, 103 + .Va errno 104 + will be set. 105 + .Rv -std pidfile_write pidfile_close pidfile_remove 106 + .Sh EXAMPLES 107 + The following example shows in which order these functions should be used. 108 + Note that it is safe to pass 109 + .Dv NULL 110 + to 111 + .Fn pidfile_write , 112 + .Fn pidfile_remove 113 + and 114 + .Fn pidfile_close 115 + functions. 116 + .Bd -literal 117 + struct pidfh *pfh; 118 + pid_t otherpid, childpid; 119 + 120 + pfh = pidfile_open("/var/run/daemon.pid", 0600, &otherpid); 121 + if (pfh == NULL) { 122 + if (errno == EEXIST) { 123 + errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", 124 + (intmax_t)otherpid); 125 + } 126 + /* If we cannot create pidfile from other reasons, only warn. */ 127 + warn("Cannot open or create pidfile"); 128 + } 129 + 130 + if (daemon(0, 0) == -1) { 131 + warn("Cannot daemonize"); 132 + pidfile_remove(pfh); 133 + exit(EXIT_FAILURE); 134 + } 135 + 136 + pidfile_write(pfh); 137 + 138 + for (;;) { 139 + /* Do work. */ 140 + childpid = fork(); 141 + switch (childpid) { 142 + case -1: 143 + syslog(LOG_ERR, "Cannot fork(): %s.", strerror(errno)); 144 + break; 145 + case 0: 146 + pidfile_close(pfh); 147 + /* Do child work. */ 148 + break; 149 + default: 150 + syslog(LOG_INFO, "Child %jd started.", (intmax_t)childpid); 151 + break; 152 + } 153 + } 154 + 155 + pidfile_remove(pfh); 156 + exit(EXIT_SUCCESS); 157 + .Ed 158 + .Sh ERRORS 159 + The 160 + .Fn pidfile_open 161 + function will fail if: 162 + .Bl -tag -width Er 163 + .It Bq Er EEXIST 164 + Some process already holds the lock on the given pidfile, meaning that a 165 + daemon is already running. 166 + .It Bq Er ENAMETOOLONG 167 + Specified pidfile's name is too long. 168 + .It Bq Er EINVAL 169 + Some process already holds the lock on the given pidfile, but PID read 170 + from there is invalid. 171 + .El 172 + .Pp 173 + The 174 + .Fn pidfile_open 175 + function may also fail and set 176 + .Va errno 177 + for any errors specified for the 178 + .Xr fstat 2 , 179 + .Xr open 2 , 180 + and 181 + .Xr read 2 182 + calls. 183 + .Pp 184 + The 185 + .Fn pidfile_write 186 + function will fail if: 187 + .Bl -tag -width Er 188 + .It Bq Er EDOOFUS 189 + Improper function use. 190 + Probably called before 191 + .Fn pidfile_open . 192 + .El 193 + .Pp 194 + The 195 + .Fn pidfile_write 196 + function may also fail and set 197 + .Va errno 198 + for any errors specified for the 199 + .Xr fstat 2 , 200 + .Xr ftruncate 2 , 201 + and 202 + .Xr write 2 203 + calls. 204 + .Pp 205 + The 206 + .Fn pidfile_close 207 + function may fail and set 208 + .Va errno 209 + for any errors specified for the 210 + .Xr close 2 211 + and 212 + .Xr fstat 2 213 + calls. 214 + .Pp 215 + The 216 + .Fn pidfile_remove 217 + function will fail if: 218 + .Bl -tag -width Er 219 + .It Bq Er EDOOFUS 220 + Improper function use. 221 + Probably called not from the process which made 222 + .Fn pidfile_write . 223 + .El 224 + .Pp 225 + The 226 + .Fn pidfile_remove 227 + function may also fail and set 228 + .Va errno 229 + for any errors specified for the 230 + .Xr close 2 , 231 + .Xr flock 2 , 232 + .Xr fstat 2 , 233 + .Xr write 2 , 234 + and 235 + .Xr unlink 2 236 + calls. 237 + .Sh SEE ALSO 238 + .Xr flock 2 , 239 + .Xr open 2 , 240 + .Xr daemon 3 241 + .Sh AUTHORS 242 + .An -nosplit 243 + The 244 + .Nm pidfile 245 + functionality is based on ideas from 246 + .An John-Mark Gurney Aq jmg@FreeBSD.org . 247 + .Pp 248 + The code and manual page was written by 249 + .An Pawel Jakub Dawidek Aq pjd@FreeBSD.org .
+243
src/libutil/pidfile.c
··· 1 + /*- 2 + * Copyright (c) 2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 1. Redistributions of source code must retain the above copyright 9 + * notice, this list of conditions and the following disclaimer. 10 + * 2. Redistributions in binary form must reproduce the above copyright 11 + * notice, this list of conditions and the following disclaimer in the 12 + * documentation and/or other materials provided with the distribution. 13 + * 14 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 + * SUCH DAMAGE. 25 + */ 26 + 27 + #include <sys/cdefs.h> 28 + 29 + #include <sys/param.h> 30 + #include <sys/file.h> 31 + #include <sys/stat.h> 32 + 33 + #include <stdio.h> 34 + #include <stdlib.h> 35 + #include <unistd.h> 36 + #include <fcntl.h> 37 + #include <string.h> 38 + #include <err.h> 39 + #include <errno.h> 40 + #include <libutil.h> 41 + 42 + static int _pidfile_remove(struct pidfh *pfh, int freeit); 43 + 44 + static int 45 + pidfile_verify(struct pidfh *pfh) 46 + { 47 + struct stat sb; 48 + 49 + if (pfh == NULL || pfh->pf_fd == -1) 50 + return EINVAL; 51 + /* 52 + * Check remembered descriptor. 53 + */ 54 + if (fstat(pfh->pf_fd, &sb) == -1) 55 + return (errno); 56 + if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino) 57 + return EINVAL; 58 + return (0); 59 + } 60 + 61 + static int 62 + pidfile_read(const char *path, pid_t *pidptr) 63 + { 64 + char buf[16], *endptr; 65 + int error, fd, i; 66 + 67 + fd = open(path, O_RDONLY); 68 + if (fd == -1) 69 + return (errno); 70 + 71 + i = read(fd, buf, sizeof(buf) - 1); 72 + error = errno; /* Remember errno in case close() wants to change it. */ 73 + close(fd); 74 + if (i == -1) 75 + return (error); 76 + buf[i] = '\0'; 77 + 78 + *pidptr = strtol(buf, &endptr, 10); 79 + if (endptr != &buf[i]) 80 + return (EINVAL); 81 + 82 + return (0); 83 + } 84 + 85 + struct pidfh * 86 + pidfile_open(const char *path, mode_t mode, pid_t *pidptr) 87 + { 88 + struct pidfh *pfh; 89 + struct stat sb; 90 + int error, fd; 91 + 92 + pfh = malloc(sizeof(*pfh)); 93 + if (pfh == NULL) 94 + return (NULL); 95 + 96 + if (path == NULL) { 97 + snprintf(pfh->pf_path, sizeof(pfh->pf_path), "/var/run/%s.pid", 98 + getprogname()); 99 + } else { 100 + strlcpy(pfh->pf_path, path, sizeof(pfh->pf_path)); 101 + } 102 + if (strlen(pfh->pf_path) == sizeof(pfh->pf_path) - 1) { 103 + free(pfh); 104 + errno = ENAMETOOLONG; 105 + return (NULL); 106 + } 107 + 108 + /* 109 + * Open the PID file and obtain exclusive lock. 110 + * We truncate PID file here only to remove old PID immediatelly, 111 + * PID file will be truncated again in pidfile_write(), so 112 + * pidfile_write() can be called multiple times. 113 + */ 114 + fd = open(pfh->pf_path, 115 + O_WRONLY | O_CREAT | O_EXLOCK | O_TRUNC | O_NONBLOCK, mode); 116 + if (fd == -1) { 117 + if (errno == EWOULDBLOCK && pidptr != NULL) { 118 + errno = pidfile_read(pfh->pf_path, pidptr); 119 + if (errno == 0) 120 + errno = EEXIST; 121 + } 122 + free(pfh); 123 + return (NULL); 124 + } 125 + /* 126 + * Remember file information, so in pidfile_write() we are sure we write 127 + * to the proper descriptor. 128 + */ 129 + if (fstat(fd, &sb) == -1) { 130 + error = errno; 131 + unlink(pfh->pf_path); 132 + close(fd); 133 + free(pfh); 134 + errno = error; 135 + return (NULL); 136 + } 137 + 138 + pfh->pf_fd = fd; 139 + pfh->pf_dev = sb.st_dev; 140 + pfh->pf_ino = sb.st_ino; 141 + 142 + return (pfh); 143 + } 144 + 145 + int 146 + pidfile_write(struct pidfh *pfh) 147 + { 148 + char pidstr[16]; 149 + int error, fd; 150 + 151 + /* 152 + * Check remembered descriptor, so we don't overwrite some other 153 + * file if pidfile was closed and descriptor reused. 154 + */ 155 + errno = pidfile_verify(pfh); 156 + if (errno != 0) { 157 + /* 158 + * Don't close descriptor, because we are not sure if it's ours. 159 + */ 160 + return (-1); 161 + } 162 + fd = pfh->pf_fd; 163 + 164 + /* 165 + * Truncate PID file, so multiple calls of pidfile_write() are allowed. 166 + */ 167 + if (ftruncate(fd, 0) == -1) { 168 + error = errno; 169 + _pidfile_remove(pfh, 0); 170 + errno = error; 171 + return (-1); 172 + } 173 + 174 + snprintf(pidstr, sizeof(pidstr), "%u", getpid()); 175 + if (pwrite(fd, pidstr, strlen(pidstr), 0) != (ssize_t)strlen(pidstr)) { 176 + error = errno; 177 + _pidfile_remove(pfh, 0); 178 + errno = error; 179 + return (-1); 180 + } 181 + 182 + return (0); 183 + } 184 + 185 + int 186 + pidfile_close(struct pidfh *pfh) 187 + { 188 + int error; 189 + 190 + error = pidfile_verify(pfh); 191 + if (error != 0) { 192 + errno = error; 193 + return (-1); 194 + } 195 + 196 + if (close(pfh->pf_fd) == -1) 197 + error = errno; 198 + free(pfh); 199 + if (error != 0) { 200 + errno = error; 201 + return (-1); 202 + } 203 + return (0); 204 + } 205 + 206 + static int 207 + _pidfile_remove(struct pidfh *pfh, int freeit) 208 + { 209 + int error; 210 + 211 + error = pidfile_verify(pfh); 212 + if (error != 0) { 213 + errno = error; 214 + return (-1); 215 + } 216 + 217 + if (unlink(pfh->pf_path) == -1) 218 + error = errno; 219 + if (flock(pfh->pf_fd, LOCK_UN) == -1) { 220 + if (error == 0) 221 + error = errno; 222 + } 223 + if (close(pfh->pf_fd) == -1) { 224 + if (error == 0) 225 + error = errno; 226 + } 227 + if (freeit) 228 + free(pfh); 229 + else 230 + pfh->pf_fd = -1; 231 + if (error != 0) { 232 + errno = error; 233 + return (-1); 234 + } 235 + return (0); 236 + } 237 + 238 + int 239 + pidfile_remove(struct pidfh *pfh) 240 + { 241 + 242 + return (_pidfile_remove(pfh, 1)); 243 + }
+105
src/libutil/realhostname.3
··· 1 + .\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 2 + .\" All rights reserved. 3 + .\" 4 + .\" Redistribution and use in source and binary forms, with or without 5 + .\" modification, are permitted provided that the following conditions 6 + .\" are met: 7 + .\" 1. Redistributions of source code must retain the above copyright 8 + .\" notice, this list of conditions and the following disclaimer. 9 + .\" 2. Redistributions in binary form must reproduce the above copyright 10 + .\" notice, this list of conditions and the following disclaimer in the 11 + .\" documentation and/or other materials provided with the distribution. 12 + .\" 13 + .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 + .\" SUCH DAMAGE. 24 + .\" 25 + .\" $FreeBSD: src/lib/libutil/realhostname.3,v 1.10 2005/02/13 22:25:14 ru Exp $ 26 + .\" 27 + .Dd April 6, 1999 28 + .Os 29 + .Dt REALHOSTNAME 3 30 + .Sh NAME 31 + .Nm realhostname 32 + .Nd "convert an IP number to the real host name" 33 + .Sh LIBRARY 34 + .Lb libutil 35 + .Sh SYNOPSIS 36 + .In sys/types.h 37 + .In netinet/in.h 38 + .In libutil.h 39 + .Ft int 40 + .Fn realhostname "char *host" "size_t hsize" "const struct in_addr *ip" 41 + .Sh DESCRIPTION 42 + The function 43 + .Fn realhostname 44 + converts 45 + .Ar ip 46 + to the corresponding host name. 47 + This is done by resolving 48 + .Ar ip 49 + to a host name and then ensuring that the host name resolves 50 + back to 51 + .Ar ip . 52 + .Pp 53 + .Ar host 54 + must point to a buffer of at least 55 + .Ar hsize 56 + bytes, and will always be written to by this function. 57 + .Pp 58 + If the name resolution does not work both ways or if the host name is longer 59 + than 60 + .Ar hsize 61 + bytes, 62 + .Xr inet_ntoa 3 63 + is used to convert 64 + .Ar ip 65 + to an ASCII form. 66 + .Pp 67 + If the string written to 68 + .Ar host 69 + is 70 + .Ar hsize 71 + bytes long, 72 + .Ar host 73 + will not be NUL terminated. 74 + .Sh RETURN VALUES 75 + The 76 + .Fn realhostname 77 + function will return one of the following constants which are defined in 78 + .In libutil.h : 79 + .Pp 80 + .Bl -tag -width XXX -offset XXX 81 + .It Li HOSTNAME_FOUND 82 + A valid host name was found. 83 + .It Li HOSTNAME_INCORRECTNAME 84 + A host name was found, but it did not resolve back to the passed 85 + .Ar ip . 86 + .Ar host 87 + now contains the numeric value of 88 + .Ar ip . 89 + .It Li HOSTNAME_INVALIDADDR 90 + .Ar ip 91 + could not be resolved. 92 + .Ar host 93 + now contains the numeric value of 94 + .Ar ip . 95 + .It Li HOSTNAME_INVALIDNAME 96 + A host name was found, but it could not be resolved back to any ip number. 97 + .Ar host 98 + now contains the numeric value of 99 + .Ar ip . 100 + .El 101 + .Sh SEE ALSO 102 + .Xr gethostbyaddr 3 , 103 + .Xr gethostbyname 3 , 104 + .Xr inet_ntoa 3 , 105 + .Xr realhostname_sa 3
+186
src/libutil/realhostname.c
··· 1 + /*- 2 + * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 1. Redistributions of source code must retain the above copyright 9 + * notice, this list of conditions and the following disclaimer. 10 + * 2. Redistributions in binary form must reproduce the above copyright 11 + * notice, this list of conditions and the following disclaimer in the 12 + * documentation and/or other materials provided with the distribution. 13 + * 14 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 + * SUCH DAMAGE. 25 + */ 26 + 27 + #include <sys/cdefs.h> 28 + 29 + #include <sys/param.h> 30 + #include <sys/socket.h> 31 + 32 + #include <netdb.h> 33 + #include <netinet/in.h> 34 + #include <arpa/inet.h> 35 + 36 + #include <stdio.h> 37 + #include <string.h> 38 + 39 + #include "libutil.h" 40 + 41 + struct sockinet { 42 + u_char si_len; 43 + u_char si_family; 44 + u_short si_port; 45 + }; 46 + 47 + void trimdomain(char *_fullhost, size_t _hostsize); 48 + 49 + int 50 + realhostname(char *host, size_t hsize, const struct in_addr *ip) 51 + { 52 + char trimmed[MAXHOSTNAMELEN]; 53 + int result; 54 + struct hostent *hp; 55 + 56 + result = HOSTNAME_INVALIDADDR; 57 + hp = gethostbyaddr((const char *)ip, sizeof(*ip), AF_INET); 58 + 59 + if (hp != NULL) { 60 + strlcpy(trimmed, hp->h_name, sizeof(trimmed)); 61 + trimdomain(trimmed, strlen(trimmed)); 62 + if (strlen(trimmed) <= hsize) { 63 + char lookup[MAXHOSTNAMELEN]; 64 + 65 + strncpy(lookup, hp->h_name, sizeof(lookup) - 1); 66 + lookup[sizeof(lookup) - 1] = '\0'; 67 + hp = gethostbyname(lookup); 68 + if (hp == NULL) 69 + result = HOSTNAME_INVALIDNAME; 70 + else for (; ; hp->h_addr_list++) { 71 + if (*hp->h_addr_list == NULL) { 72 + result = HOSTNAME_INCORRECTNAME; 73 + break; 74 + } 75 + if (!memcmp(*hp->h_addr_list, ip, sizeof(*ip))) { 76 + strncpy(host, trimmed, hsize); 77 + return HOSTNAME_FOUND; 78 + } 79 + } 80 + } 81 + } 82 + 83 + strncpy(host, inet_ntoa(*ip), hsize); 84 + 85 + return result; 86 + } 87 + 88 + int 89 + realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen) 90 + { 91 + int result, error; 92 + char buf[NI_MAXHOST]; 93 + 94 + result = HOSTNAME_INVALIDADDR; 95 + 96 + #ifdef INET6 97 + /* IPv4 mapped IPv6 addr consideraton, specified in rfc2373. */ 98 + if (addr->sa_family == AF_INET6 && 99 + addrlen == sizeof(struct sockaddr_in6) && 100 + IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)addr)->sin6_addr)) { 101 + struct sockaddr_in6 *sin6; 102 + 103 + sin6 = (struct sockaddr_in6 *)addr; 104 + 105 + memset(&lsin, 0, sizeof(lsin)); 106 + lsin.sin_len = sizeof(struct sockaddr_in); 107 + lsin.sin_family = AF_INET; 108 + lsin.sin_port = sin6->sin6_port; 109 + memcpy(&lsin.sin_addr, &sin6->sin6_addr.s6_addr[12], 110 + sizeof(struct in_addr)); 111 + addr = (struct sockaddr *)&lsin; 112 + addrlen = lsin.sin_len; 113 + } 114 + #endif 115 + 116 + error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, 117 + NI_NAMEREQD); 118 + if (error == 0) { 119 + struct addrinfo hints, *res, *ores; 120 + struct sockaddr *sa; 121 + 122 + memset(&hints, 0, sizeof(struct addrinfo)); 123 + hints.ai_family = addr->sa_family; 124 + hints.ai_flags = AI_CANONNAME | AI_PASSIVE; 125 + hints.ai_socktype = SOCK_STREAM; 126 + 127 + error = getaddrinfo(buf, NULL, &hints, &res); 128 + if (error) { 129 + result = HOSTNAME_INVALIDNAME; 130 + goto numeric; 131 + } 132 + for (ores = res; ; res = res->ai_next) { 133 + if (res == NULL) { 134 + freeaddrinfo(ores); 135 + result = HOSTNAME_INCORRECTNAME; 136 + goto numeric; 137 + } 138 + sa = res->ai_addr; 139 + if (sa == NULL) { 140 + freeaddrinfo(ores); 141 + result = HOSTNAME_INCORRECTNAME; 142 + goto numeric; 143 + } 144 + if (sa->sa_len == addrlen && 145 + sa->sa_family == addr->sa_family) { 146 + ((struct sockinet *)sa)->si_port = ((struct sockinet *)addr)->si_port; 147 + #ifdef INET6 148 + /* 149 + * XXX: sin6_socpe_id may not been 150 + * filled by DNS 151 + */ 152 + if (sa->sa_family == AF_INET6 && 153 + ((struct sockaddr_in6 *)sa)->sin6_scope_id == 0) 154 + ((struct sockaddr_in6 *)sa)->sin6_scope_id = ((struct sockaddr_in6 *)addr)->sin6_scope_id; 155 + #endif 156 + if (!memcmp(sa, addr, sa->sa_len)) { 157 + result = HOSTNAME_FOUND; 158 + if (ores->ai_canonname == NULL) { 159 + freeaddrinfo(ores); 160 + goto numeric; 161 + } 162 + strlcpy(buf, ores->ai_canonname, 163 + sizeof(buf)); 164 + trimdomain(buf, hsize); 165 + if (strlen(buf) > hsize && 166 + addr->sa_family == AF_INET) { 167 + freeaddrinfo(ores); 168 + goto numeric; 169 + } 170 + strncpy(host, buf, hsize); 171 + break; 172 + } 173 + } 174 + } 175 + freeaddrinfo(ores); 176 + } else { 177 + numeric: 178 + if (getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, 179 + NI_NUMERICHOST) == 0) 180 + strncpy(host, buf, hsize); 181 + } 182 + 183 + return result; 184 + } 185 + 186 +
+133
src/libutil/realhostname_sa.3
··· 1 + .\" Copyright (C) 1995, 1996, 1997, 1998, 1999, and 2000 WIDE Project. 2 + .\" All rights reserved. 3 + .\" 4 + .\" Redistribution and use in source and binary forms, with or without 5 + .\" modification, are permitted provided that the following conditions 6 + .\" are met: 7 + .\" 1. Redistributions of source code must retain the above copyright 8 + .\" notice, this list of conditions and the following disclaimer. 9 + .\" 2. Redistributions in binary form must reproduce the above copyright 10 + .\" notice, this list of conditions and the following disclaimer in the 11 + .\" documentation and/or other materials provided with the distribution. 12 + .\" 3. Neither the name of the project nor the names of its contributors 13 + .\" may be used to endorse or promote products derived from this software 14 + .\" without specific prior written permission. 15 + .\" 16 + .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 17 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 20 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 + .\" SUCH DAMAGE. 27 + .\" 28 + .\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 29 + .\" All rights reserved. 30 + .\" 31 + .\" Redistribution and use in source and binary forms, with or without 32 + .\" modification, are permitted provided that the following conditions 33 + .\" are met: 34 + .\" 1. Redistributions of source code must retain the above copyright 35 + .\" notice, this list of conditions and the following disclaimer. 36 + .\" 2. Redistributions in binary form must reproduce the above copyright 37 + .\" notice, this list of conditions and the following disclaimer in the 38 + .\" documentation and/or other materials provided with the distribution. 39 + .\" 40 + .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 41 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 + .\" SUCH DAMAGE. 51 + .\" 52 + .\" $FreeBSD: src/lib/libutil/realhostname_sa.3,v 1.11 2005/02/13 22:25:14 ru Exp $ 53 + .\" 54 + .Dd January 11, 2000 55 + .Os 56 + .Dt REALHOSTNAME_SA 3 57 + .Sh NAME 58 + .Nm realhostname_sa 59 + .Nd "convert a" 60 + .Vt "struct sockaddr" 61 + to the real host name 62 + .Sh LIBRARY 63 + .Lb libutil 64 + .Sh SYNOPSIS 65 + .In sys/types.h 66 + .In netinet/in.h 67 + .In libutil.h 68 + .Ft int 69 + .Fn realhostname_sa "char *host" "size_t hsize" "struct sockaddr *addr" "int addrlen" 70 + .Sh DESCRIPTION 71 + The function 72 + .Fn realhostname_sa 73 + converts 74 + .Ar addr 75 + to the corresponding host name. 76 + This is done by resolving 77 + .Ar addr 78 + to a host name and then ensuring that the host name resolves 79 + back to 80 + .Ar addr . 81 + .Pp 82 + .Ar host 83 + must point to a buffer of at least 84 + .Ar hsize 85 + bytes, and will always be written to by this function. 86 + .Pp 87 + If the name resolution does not work both ways or if the host name is longer 88 + than 89 + .Ar hsize 90 + bytes, 91 + .Xr getnameinfo 3 92 + with NI_NUMERICHOST specified, is used to convert 93 + .Ar addr 94 + to an ASCII form. 95 + .Pp 96 + If the string written to 97 + .Ar host 98 + is 99 + .Ar hsize 100 + bytes long, 101 + .Ar host 102 + will not be NUL terminated. 103 + .Sh RETURN VALUES 104 + The 105 + .Fn realhostname_sa 106 + function will return one of the following constants which are defined in 107 + .In libutil.h : 108 + .Pp 109 + .Bl -tag -width XXX -offset XXX 110 + .It Li HOSTNAME_FOUND 111 + A valid host name was found. 112 + .It Li HOSTNAME_INCORRECTNAME 113 + A host name was found, but it did not resolve back to the passed 114 + .Ar ip . 115 + .Ar host 116 + now contains the numeric value of 117 + .Ar ip . 118 + .It Li HOSTNAME_INVALIDADDR 119 + .Ar ip 120 + could not be resolved. 121 + .Ar host 122 + now contains the numeric value of 123 + .Ar ip . 124 + .It Li HOSTNAME_INVALIDNAME 125 + A host name was found, but it could not be resolved back to any ip number. 126 + .Ar host 127 + now contains the numeric value of 128 + .Ar ip . 129 + .El 130 + .Sh SEE ALSO 131 + .Xr getaddrinfo 3 , 132 + .Xr getnameinfo 3 , 133 + .Xr realhostname 3
+50
src/libutil/reexec_to_match_kernel.3
··· 1 + .Dd Apr 14, 2008 2 + .Dt REEXEC_TO_MATCH_KERNEL 3 3 + .Os "Mac OS X" 4 + .Sh NAME 5 + .Nm reexec_to_match_kernel 6 + .Nd Re-exec the current binary to match the ABI of the running kernel 7 + .Sh LIBRARY 8 + .Lb libutil 9 + .Sh SYNOPSIS 10 + .In libutil.h 11 + .Ft int 12 + .Fo reexec_to_match_kernel 13 + .Fa "void" 14 + .Fc 15 + .Ft int 16 + .Fo reexec_to_match_lp64ness 17 + .Fa "bool isLP64" 18 + .Fc 19 + .Sh DESCRIPTION 20 + The 21 + .Fn reexec_to_match_kernel 22 + function re-executes the current binary to match the ABI of the running kernel. 23 + That is, if the current kernel is a 64-bit Intel kernel, it will attempt to 24 + execute the 64-bit x86_64 userspace slice of the universal binary. The API 25 + intentionally does not take arguments because its use should be transparent 26 + to the program and to the user. 27 + .Pp 28 + The 29 + .Fn reexec_to_match_lp64ness 30 + is coarser-grained, and only attempts to match the word width that is requested. 31 + For example, if the current system defaults to executing the 64-bit x86_64 32 + userspace slice, but the program should instead run in 32-bit i386 mode, 33 + this routine can be used. 34 + .Pp 35 + Both 36 + .Fn reexec_to_match_kernel 37 + and 38 + .Fn reexec_to_match_lp64ness 39 + can each be used exactly once in a program's lifetime. In certain circumstances, 40 + it may even be desirable to use one, and then the other. 41 + .Sh RETURN VALUES 42 + The 43 + .Fn reexec_to_match_kernel 44 + and 45 + .Fn reexec_to_match_lp64ness 46 + functions return 0 if re-execution was not required. It returns -1 and 47 + sets errno if there was an error performing the re-execution, for example 48 + if the binary is not universal, or does not contain a slice to match the running 49 + kernel's ABI. If the function succeeds, control never returns to the caller 50 + and the program starts from main() again.
+215
src/libutil/reexec_to_match_kernel.c
··· 1 + /* 2 + * Copyright (c) 2008-2010 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + 24 + #include <sys/cdefs.h> 25 + 26 + #include <spawn.h> 27 + #include <errno.h> 28 + #include <crt_externs.h> 29 + #include <mach/mach.h> 30 + #include <mach-o/loader.h> 31 + #include <mach-o/dyld.h> 32 + #include <sys/sysctl.h> 33 + #include <stdlib.h> 34 + #include <stdio.h> 35 + 36 + #include "libutil.h" 37 + 38 + static cpu_type_t current_program_arch(void); 39 + static cpu_type_t current_kernel_arch(void); 40 + static int reexec(cpu_type_t cputype, const char *guardenv); 41 + 42 + #define kReExecToMatchKernel "REEXEC_TO_MATCH_KERNEL" 43 + #define kReExecToMatchLP64 "REEXEC_TO_MATCH_LP64NESS" 44 + 45 + int reexec_to_match_kernel(void) 46 + { 47 + cpu_type_t kernarch, progarch; 48 + char *alreadyenv; 49 + 50 + alreadyenv = getenv(kReExecToMatchKernel); 51 + if (alreadyenv) { 52 + /* we've done this at least once, assume 53 + another try won't help */ 54 + return 0; 55 + } 56 + 57 + kernarch = current_kernel_arch(); 58 + progarch = current_program_arch(); 59 + 60 + if (kernarch == 0) { 61 + /* could not determine kernel arch */ 62 + errno = EINVAL; 63 + return -1; 64 + } 65 + 66 + if (kernarch == progarch) { 67 + /* nothing to do here */ 68 + return 0; 69 + } 70 + 71 + /* Now we need to re-exec */ 72 + return reexec(kernarch, kReExecToMatchKernel); 73 + } 74 + 75 + int reexec_to_match_lp64ness(bool isLP64) 76 + { 77 + cpu_type_t kernarch, progarch, targetarch; 78 + char *alreadyenv; 79 + 80 + alreadyenv = getenv(kReExecToMatchLP64); 81 + if (alreadyenv) { 82 + /* we've done this at least once, assume 83 + another try won't help */ 84 + return 0; 85 + } 86 + 87 + kernarch = current_kernel_arch(); 88 + progarch = current_program_arch(); 89 + 90 + if (kernarch == 0) { 91 + /* could not determine kernel arch */ 92 + errno = EINVAL; 93 + return -1; 94 + } 95 + 96 + if (isLP64) { 97 + targetarch = kernarch | CPU_ARCH_ABI64; 98 + } else { 99 + targetarch = kernarch & ~CPU_ARCH_ABI64; 100 + } 101 + 102 + if (targetarch == progarch) { 103 + /* nothing to do here */ 104 + return 0; 105 + } 106 + 107 + /* Now we need to re-exec */ 108 + return reexec(targetarch, kReExecToMatchLP64); 109 + } 110 + 111 + static cpu_type_t current_program_arch(void) 112 + { 113 + cpu_type_t current_arch = (_NSGetMachExecuteHeader())->cputype; 114 + 115 + return current_arch; 116 + } 117 + 118 + static cpu_type_t current_kernel_arch(void) 119 + { 120 + struct host_basic_info hi; 121 + unsigned int size; 122 + kern_return_t kret; 123 + cpu_type_t current_arch; 124 + int ret, mib[4]; 125 + size_t len; 126 + struct kinfo_proc kp; 127 + 128 + size = sizeof(hi)/sizeof(int); 129 + kret = host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hi, &size); 130 + if (kret != KERN_SUCCESS) { 131 + return 0; 132 + } 133 + 134 + current_arch = hi.cpu_type; 135 + 136 + /* Now determine if the kernel is running in 64-bit mode */ 137 + mib[0] = CTL_KERN; 138 + mib[1] = KERN_PROC; 139 + mib[2] = KERN_PROC_PID; 140 + mib[3] = 0; /* kernproc, pid 0 */ 141 + len = sizeof(kp); 142 + ret = sysctl(mib, sizeof(mib)/sizeof(mib[0]), &kp, &len, NULL, 0); 143 + if (ret == -1) { 144 + return 0; 145 + } 146 + 147 + if (kp.kp_proc.p_flag & P_LP64) { 148 + current_arch |= CPU_ARCH_ABI64; 149 + } 150 + 151 + return current_arch; 152 + } 153 + 154 + static int reexec(cpu_type_t cputype, const char *guardenv) 155 + { 156 + posix_spawnattr_t attr; 157 + int ret, envcount; 158 + size_t copied = 0; 159 + char **argv, **oldenvp, **newenvp; 160 + char execpath[MAXPATHLEN+1]; 161 + uint32_t execsize; 162 + char guardstr[32]; 163 + 164 + argv = *_NSGetArgv(); 165 + oldenvp = *_NSGetEnviron(); 166 + for (envcount = 0; oldenvp[envcount]; envcount++); 167 + // if there are 4 elements and a NULL, envcount will be 4 168 + 169 + newenvp = calloc(envcount+2, sizeof(newenvp[0])); 170 + for (envcount = 0; oldenvp[envcount]; envcount++) { 171 + newenvp[envcount] = oldenvp[envcount]; 172 + } 173 + 174 + snprintf(guardstr, sizeof(guardstr), "%s=1", guardenv); 175 + newenvp[envcount++] = guardstr; 176 + newenvp[envcount] = NULL; 177 + 178 + execsize = (uint32_t)sizeof(execpath); 179 + ret = _NSGetExecutablePath(execpath, &execsize); 180 + if (ret != 0) { 181 + return -1; 182 + } 183 + 184 + ret = posix_spawnattr_init(&attr); 185 + if (ret != 0) { 186 + return -1; 187 + } 188 + ret = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETEXEC); 189 + if (ret != 0) { 190 + return -1; 191 + } 192 + ret = posix_spawnattr_setbinpref_np(&attr, 1, &cputype, &copied); 193 + if (ret != 0 || copied != 1) { 194 + return -1; 195 + } 196 + 197 + #if 0 198 + fprintf(stderr, "reexec: %s (arch=%d)\n", execpath, cputype); 199 + for (envcount=0; newenvp[envcount]; envcount++) { 200 + fprintf(stderr, "env[%d] = %s\n", envcount, newenvp[envcount]); 201 + } 202 + for (envcount=0; argv[envcount]; envcount++) { 203 + fprintf(stderr, "argv[%d] = %s\n", envcount, argv[envcount]); 204 + } 205 + #endif 206 + 207 + ret = posix_spawn(NULL, execpath, NULL, &attr, argv, newenvp); 208 + if (ret != 0) { 209 + errno = ret; 210 + return -1; 211 + } 212 + 213 + /* should not be reached */ 214 + return 0; 215 + }
+85
src/libutil/trimdomain.3
··· 1 + .\" Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> 2 + .\" All rights reserved. 3 + .\" 4 + .\" Redistribution and use in source and binary forms, with or without 5 + .\" modification, are permitted provided that the following conditions 6 + .\" are met: 7 + .\" 1. Redistributions of source code must retain the above copyright 8 + .\" notice, this list of conditions and the following disclaimer. 9 + .\" 2. Redistributions in binary form must reproduce the above copyright 10 + .\" notice, this list of conditions and the following disclaimer in the 11 + .\" documentation and/or other materials provided with the distribution. 12 + .\" 13 + .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 + .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 + .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 + .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 + .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 + .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 + .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 + .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 + .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 + .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 + .\" SUCH DAMAGE. 24 + .\" 25 + .\" $FreeBSD: src/lib/libutil/trimdomain.3,v 1.8 2004/07/02 23:52:20 ru Exp $ 26 + .\" 27 + .Dd April 7, 1999 28 + .Os 29 + .Dt TRIMDOMAIN 3 30 + .Sh NAME 31 + .Nm trimdomain 32 + .Nd "trim the current domain name from a host name" 33 + .Sh LIBRARY 34 + .Lb libutil 35 + .Sh SYNOPSIS 36 + .In sys/types.h 37 + .In libutil.h 38 + .Ft void 39 + .Fn trimdomain "char *fullhost" "int hostsize" 40 + .Sh DESCRIPTION 41 + The function 42 + .Fn trimdomain 43 + removes the current domain name from the passed 44 + .Ar fullhost 45 + name by writing a 46 + .Dv NUL 47 + character over the first period of the passed name. 48 + The current domain 49 + name is determined by calling 50 + .Xr gethostname 3 51 + and removing everything up to the first period. 52 + The name is determined 53 + the first time this function is called and is cached for future use. 54 + .Pp 55 + The 56 + .Fn trimdomain 57 + function will only trim the domain name if the passed 58 + .Ar fullname 59 + ends with the current domain name and if the length of the resulting host 60 + name does not exceed 61 + .Ar hostsize . 62 + .Pp 63 + If the passed 64 + .Ar fullname 65 + is actually a 66 + .Dv DISPLAY 67 + specification of the form 68 + .Sm off 69 + .Ar host . domain : nn Oo . 70 + .Ar nn 71 + .Oc 72 + .Sm on 73 + and the domain name is the same as the local domain name, 74 + .Fn trimdomain 75 + will remove the embedded domain name, copying the screen and display 76 + numbers to the end of the base host name and resulting in 77 + .Sm off 78 + .Ar host : nn Op . Ar nn . 79 + .Sm on 80 + .Sh RETURN VALUES 81 + The 82 + .Fn trimdomain 83 + function does not return a value. 84 + .Sh SEE ALSO 85 + .Xr gethostname 3
+116
src/libutil/trimdomain.c
··· 1 + /*- 2 + * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org> 3 + * Based on original work by Atsushi Murai <amurai@FreeBSD.org> 4 + * All rights reserved. 5 + * 6 + * Redistribution and use in source and binary forms, with or without 7 + * modification, are permitted provided that the following conditions 8 + * are met: 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 15 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 + * SUCH DAMAGE. 26 + * 27 + */ 28 + 29 + #include <sys/cdefs.h> 30 + 31 + #include <sys/param.h> 32 + 33 + #include <libutil.h> 34 + #include <string.h> 35 + #include <unistd.h> 36 + 37 + void trimdomain(char *_fullhost, size_t _hostsize); 38 + 39 + static int isDISP(const char *); 40 + 41 + /*- 42 + * Trim the current domain name from fullhost, but only if the result 43 + * is less than or equal to hostsize in length. 44 + * 45 + * This function understands $DISPLAY type fullhosts. 46 + * 47 + * For example: 48 + * 49 + * trimdomain("abcde.my.domain", 5) -> "abcde" 50 + * trimdomain("abcde.my.domain", 4) -> "abcde.my.domain" 51 + * trimdomain("abcde.my.domain:0.0", 9) -> "abcde:0.0" 52 + * trimdomain("abcde.my.domain:0.0", 8) -> "abcde.my.domain:0.0" 53 + */ 54 + void 55 + trimdomain(char *fullhost, size_t hostsize) 56 + { 57 + static size_t dlen; 58 + static int first = 1; 59 + static char domain[MAXHOSTNAMELEN]; 60 + char *end, *s; 61 + size_t len; 62 + 63 + if (first) { 64 + /* XXX: Should we assume that our domain is this persistent ? */ 65 + first = 0; 66 + if (gethostname(domain, sizeof(domain) - 1) == 0 && 67 + (s = strchr(domain, '.')) != NULL) 68 + memmove(domain, s + 1, strlen(s + 1) + 1); 69 + else 70 + domain[0] = '\0'; 71 + dlen = strlen(domain); 72 + } 73 + 74 + if (domain[0] == '\0') 75 + return; 76 + 77 + s = fullhost; 78 + end = (char *)((uintptr_t)s + hostsize + 1); 79 + if ((s = memchr(s, '.', (size_t)(end - s))) != NULL) { 80 + if (strncasecmp(s + 1, domain, dlen) == 0) { 81 + if (s[dlen + 1] == '\0') { 82 + /* Found -- lose the domain. */ 83 + *s = '\0'; 84 + } else if (s[dlen + 1] == ':' && 85 + isDISP(s + dlen + 2) && 86 + (len = strlen(s + dlen + 1)) < (size_t)(end - s)) { 87 + /* Found -- shuffle the DISPLAY back. */ 88 + memmove(s, s + dlen + 1, len + 1); 89 + } 90 + } 91 + } 92 + } 93 + 94 + /* 95 + * Is the given string NN or NN.NN where ``NN'' is an all-numeric string ? 96 + */ 97 + static int 98 + isDISP(const char *disp) 99 + { 100 + size_t w; 101 + int res; 102 + 103 + w = strspn(disp, "0123456789"); 104 + res = 0; 105 + if (w > 0) { 106 + if (disp[w] == '\0') 107 + res = 1; /* NN */ 108 + else if (disp[w] == '.') { 109 + disp += w + 1; 110 + w = strspn(disp, "0123456789"); 111 + if (w > 0 && disp[w] == '\0') 112 + res = 1; /* NN.NN */ 113 + } 114 + } 115 + return (res); 116 + }
+70
src/libutil/tzlink.c
··· 1 + // Modified by Lubos Dolezel for Darling build 2 + /* 3 + * Copyright (c) 2013 Apple Inc. All rights reserved. 4 + * 5 + * @APPLE_LICENSE_HEADER_START@ 6 + * 7 + * This file contains Original Code and/or Modifications of Original Code 8 + * as defined in and that are subject to the Apple Public Source License 9 + * Version 2.0 (the 'License'). You may not use this file except in 10 + * compliance with the License. Please obtain a copy of the License at 11 + * http://www.opensource.apple.com/apsl/ and read it before using this 12 + * file. 13 + * 14 + * The Original Code and all software distributed under the License are 15 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 + * Please see the License for the specific language governing rights and 20 + * limitations under the License. 21 + * 22 + * @APPLE_LICENSE_HEADER_END@ 23 + */ 24 + 25 + #include <TargetConditionals.h> 26 + #if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR 27 + # include <xpc/xpc.h> 28 + #endif 29 + #include <errno.h> 30 + 31 + #include "tzlink.h" 32 + #include "tzlink_internal.h" 33 + 34 + errno_t 35 + tzlink(const char *tz) 36 + { 37 + #if TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR 38 + xpc_connection_t connection; 39 + xpc_object_t request, reply; 40 + errno_t e; 41 + 42 + if (tz == NULL) { 43 + return EINVAL; 44 + } 45 + 46 + connection = xpc_connection_create_mach_service(TZLINK_SERVICE_NAME, NULL, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED); 47 + xpc_connection_set_event_handler(connection, ^(__unused xpc_object_t event) { 48 + }); 49 + xpc_connection_resume(connection); 50 + 51 + request = xpc_dictionary_create(NULL, NULL, 0); 52 + xpc_dictionary_set_string(request, TZLINK_KEY_REQUEST_TIMEZONE, tz); 53 + 54 + reply = xpc_connection_send_message_with_reply_sync(connection, request); 55 + if (xpc_get_type(reply) == XPC_TYPE_DICTIONARY) { 56 + e = (errno_t)xpc_dictionary_get_uint64(reply, TZLINK_KEY_REPLY_ERROR); 57 + } else { 58 + e = EIO; 59 + } 60 + 61 + xpc_release(reply); 62 + xpc_release(request); 63 + xpc_release(connection); 64 + 65 + return e; 66 + #else /* !TARGET_OS_IPHONE */ 67 + #pragma unused (tz) 68 + return ENOTSUP; 69 + #endif /* TARGET_OS_IPHONE */ 70 + }
+56
src/libutil/tzlink.h
··· 1 + /* 2 + * Copyright (c) 2013 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + 24 + #ifndef _TZLINK_H_ 25 + #define _TZLINK_H_ 26 + 27 + /*! 28 + * @function tzlink 29 + * Create the timezone link at TZDEFAULT 30 + * 31 + * @param tz 32 + * New timezone, e.g. "America/Los_Angeles". This path is relative to TZDIR, 33 + * and must not contain any relative path components or stray slashes. 34 + * The file must exist and must be a valid timezone file with correct 35 + * ownership (root:wheel) and permissions (0644). 36 + * 37 + * @result 38 + * If the call succeeds, will return zero. Otherwise, returns an error: 39 + * EINVAL: Invalid input, e.g. NULL or a path with relative components. 40 + * ENAMETOOLONG: Input too long (generates a path > PATH_MAX) 41 + * ENOENT: Specified file doesn't exist or fails owner/perm check. 42 + * EPERM: Entitlement check failed. 43 + * EIO: Failed to communicate with backing daemon. 44 + * ENOTSUP: Always returned on OS X. 45 + * And possibly others not documented here. 46 + * 47 + * @discussion 48 + * This call can be used by any sufficiently-entitled client to overwrite 49 + * the timezone link at TZDEFAULT (see <tzfile.h>). It communicates with a 50 + * root daemon that does the necessary validation and file system work. 51 + * Upon success, the "SignificantTimeChangeNotification" notification is 52 + * posted. 53 + */ 54 + errno_t tzlink(const char *tz); 55 + 56 + #endif /* !_TZLINK_H_ */
+26
src/libutil/tzlinkd/com.apple.tzlinkd.plist
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 + <plist version="1.0"> 4 + <dict> 5 + <key>EnableTransactions</key> 6 + <true/> 7 + <key>JetsamProperties</key> 8 + <dict> 9 + <key>JetsamMemoryLimit</key> 10 + <integer>300</integer> 11 + <key>JetsamPriority</key> 12 + <integer>-49</integer> 13 + </dict> 14 + <key>Label</key> 15 + <string>com.apple.tzlinkd</string> 16 + <key>MachServices</key> 17 + <dict> 18 + <key>com.apple.tzlink</key> 19 + <true/> 20 + </dict> 21 + <key>POSIXSpawnType</key> 22 + <string>Adaptive</string> 23 + <key>Program</key> 24 + <string>/usr/libexec/tzlinkd</string> 25 + </dict> 26 + </plist>
+11
src/libutil/tzlinkd/com.apple.tzlinkd.sb
··· 1 + (version 1) 2 + 3 + (deny default) 4 + 5 + (import "system.sb") 6 + 7 + (allow file-write-create file-write-unlink 8 + (literal "/private/var/db/timezone/localtime")) 9 + 10 + (allow file-read* 11 + (literal "/private/var/db/timezone/zoneinfo"))
+10
src/libutil/tzlinkd/entitlements.plist
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 + <plist version="1.0"> 4 + <dict> 5 + <key>seatbelt-profiles</key> 6 + <array> 7 + <string>com.apple.tzlinkd</string> 8 + </array> 9 + </dict> 10 + </plist>
+194
src/libutil/tzlinkd/tzlinkd.c
··· 1 + /* 2 + * Copyright (c) 2013 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + 24 + #include <xpc/xpc.h> 25 + #include <xpc/private.h> 26 + #include <notify.h> 27 + #include <tzfile.h> 28 + 29 + #include "tzlink_internal.h" 30 + 31 + static bool peer_entitled(xpc_connection_t); 32 + static int set_timezone(const char *); 33 + static int build_source_path(char *, size_t, const char *); 34 + static int validate_source_path(const char *); 35 + 36 + int 37 + main(void) 38 + { 39 + dispatch_queue_t queue; 40 + xpc_connection_t listener; 41 + 42 + xpc_track_activity(); 43 + 44 + queue = dispatch_queue_create(TZLINK_SERVICE_NAME, NULL); 45 + 46 + listener = xpc_connection_create_mach_service(TZLINK_SERVICE_NAME, queue, XPC_CONNECTION_MACH_SERVICE_LISTENER); 47 + xpc_connection_set_event_handler(listener, ^(xpc_object_t peer) { 48 + if (xpc_get_type(peer) != XPC_TYPE_CONNECTION) { 49 + return; 50 + } 51 + 52 + xpc_connection_set_target_queue(peer, queue); 53 + xpc_connection_set_event_handler(peer, ^(xpc_object_t request) { 54 + xpc_object_t reply; 55 + const char *tz; 56 + int error; 57 + 58 + if (xpc_get_type(request) != XPC_TYPE_DICTIONARY) { 59 + return; 60 + } 61 + 62 + if (peer_entitled(peer)) { 63 + tz = xpc_dictionary_get_string(request, TZLINK_KEY_REQUEST_TIMEZONE); 64 + error = tz ? set_timezone(tz) : EINVAL; 65 + } else { 66 + error = EPERM; 67 + } 68 + 69 + reply = xpc_dictionary_create_reply(request); 70 + xpc_dictionary_set_uint64(reply, TZLINK_KEY_REPLY_ERROR, (uint64_t)error); 71 + xpc_connection_send_message(peer, reply); 72 + xpc_release(reply); 73 + }); 74 + xpc_connection_resume(peer); 75 + }); 76 + xpc_connection_resume(listener); 77 + 78 + dispatch_main(); 79 + } 80 + 81 + static bool 82 + peer_entitled(xpc_connection_t peer) 83 + { 84 + xpc_object_t val; 85 + bool entitled; 86 + 87 + entitled = false; 88 + 89 + val = xpc_connection_copy_entitlement_value(peer, TZLINK_ENTITLEMENT); 90 + if (val != NULL) { 91 + entitled = xpc_bool_get_value(val); 92 + xpc_release(val); 93 + } 94 + 95 + return entitled; 96 + } 97 + 98 + static int 99 + set_timezone(const char *tz) 100 + { 101 + char srcpath[PATH_MAX]; 102 + int error; 103 + 104 + error = build_source_path(srcpath, sizeof(srcpath), tz); 105 + if (error != 0) { 106 + return error; 107 + } 108 + 109 + error = validate_source_path(srcpath); 110 + if (error != 0) { 111 + return error; 112 + } 113 + 114 + (void)unlink(TZDEFAULT); 115 + if (symlink(srcpath, TZDEFAULT) != 0) { 116 + return errno ? errno : EFAULT; 117 + } 118 + 119 + /* 120 + * notifyd posts "com.apple.system.timezone" automatically, 121 + * but we also need post this. Sigh. 122 + */ 123 + (void)notify_post("SignificantTimeChangeNotification"); 124 + 125 + return 0; 126 + } 127 + 128 + /* Create path from input. */ 129 + static int 130 + build_source_path(char *path, size_t size, const char *tz) 131 + { 132 + char *str, *str0; 133 + char *pathcomp; 134 + int error; 135 + 136 + if (strlcpy(path, TZDIR, size) >= size) { 137 + return ENAMETOOLONG; 138 + } 139 + 140 + error = 0; 141 + 142 + /* Attempt to validate the input; construct a clean path as we go. */ 143 + str0 = str = strdup(tz); 144 + while ((pathcomp = strsep(&str, "/")) != NULL) { 145 + if (pathcomp[0] == '\0' || pathcomp[0] == '.') { 146 + error = EINVAL; 147 + break; 148 + } 149 + if (strlcat(path, "/", size) >= size) { 150 + error = ENAMETOOLONG; 151 + break; 152 + } 153 + if (strlcat(path, pathcomp, size) >= size) { 154 + error = ENAMETOOLONG; 155 + break; 156 + } 157 + } 158 + free(str0); 159 + 160 + return error; 161 + } 162 + 163 + /* Validate path. */ 164 + static int 165 + validate_source_path(const char *path) 166 + { 167 + struct stat sb; 168 + 169 + if (lstat(path, &sb) != 0) { 170 + return errno ? errno : EFAULT; 171 + } 172 + 173 + /* Ensure that the time zone file is... */ 174 + 175 + /* ... a regular file. */ 176 + if (!S_ISREG(sb.st_mode)) { 177 + return ENOENT; 178 + } 179 + 180 + /* ... owned by root:wheel */ 181 + if (sb.st_uid != 0 || sb.st_gid != 0) { 182 + return ENOENT; 183 + } 184 + 185 + /* ... 0644 perms */ 186 + if ((sb.st_mode & ACCESSPERMS) != 0644) { 187 + return ENOENT; 188 + } 189 + 190 + /* ... is a real tzfile (starts with TZif) */ 191 + // TODO: Validate contents of file. 192 + 193 + return 0; 194 + }
+162
src/libutil/wipefs.3
··· 1 + .\" 2 + .\" Copyright (c) 2008,2011 Apple Inc. All rights reserved. 3 + .\" 4 + .\" @APPLE_LICENSE_HEADER_START@ 5 + .\" 6 + .\" This file contains Original Code and/or Modifications of Original Code 7 + .\" as defined in and that are subject to the Apple Public Source License 8 + .\" Version 2.0 (the 'License'). You may not use this file except in 9 + .\" compliance with the License. Please obtain a copy of the License at 10 + .\" http://www.opensource.apple.com/apsl/ and read it before using this 11 + .\" file. 12 + .\" 13 + .\" The Original Code and all software distributed under the License are 14 + .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + .\" Please see the License for the specific language governing rights and 19 + .\" limitations under the License. 20 + .\" 21 + .\" @APPLE_LICENSE_HEADER_END@ 22 + .\" 23 + .Dd 6/30/11 \" DATE 24 + .Dt libutil 3 \" Program name and manual section number 25 + .Os Mac OS X 26 + .Sh NAME \" Section Header - required - don't modify 27 + .\" The following lines are read in generating the apropos(man -k) database. Use only key 28 + .\" words here as the database is built based on the words here and in the .ND line. 29 + .Nm wipefs_alloc , 30 + .Nm wipefs_except_blocks , 31 + .Nm wipefs_wipe , 32 + .Nm wipefs_free 33 + .\" Use .Nm macro to designate other names for the documented program. 34 + .Nd wipes existing file systems on a volume 35 + .Sh LIBRARY \" Section Header - required - don't modify 36 + .Lb libutil 37 + .Sh SYNOPSIS 38 + .In wipefs.h 39 + .Ft int 40 + .Fo wipefs_alloc 41 + .Fa "int fd" 42 + .Fa "size_t block_size" 43 + .Fa "wipefs_ctx *handle" 44 + .Fc 45 + .Ft int 46 + .Fo wipefs_include_blocks 47 + .Fa "wipefs_ctx handle" 48 + .Fa "off_t block_offset" 49 + .Fa "off_t nblocks" 50 + .Fc 51 + .Ft int 52 + .Fo wipefs_except_blocks 53 + .Fa "wipefs_ctx handle" 54 + .Fa "off_t block_offset" 55 + .Fa "off_t nblocks" 56 + .Fc 57 + .Ft int 58 + .Fo wipefs_wipe 59 + .Fa "wipefs_ctx handle" 60 + .Fc 61 + .Ft void 62 + .Fo wipefs_free 63 + .Fa "wipefs_ctx *handle" 64 + .Fc 65 + .Sh DESCRIPTION \" Section Header - required - don't modify 66 + The wipefs family of functions wipe existing file systems on a volume. A 67 + .Li DKIOCUNMAP 68 + ioctl is sent to the device to invalidate all of its content. 69 + Then zeroes are written to various locations that are used by various file systems to recognize their content and mount their volumes. 70 + 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. 71 + .Pp 72 + .Sy NOTE: 73 + These routines do not overwrite all volume structures. 74 + These routines do not securely erase the previous content. 75 + They only overwrite enough to make sure that the normal utilities will no longer recognize any file system content. 76 + It is possible that previous file system content could be recovered by other means. 77 + .Pp 78 + The 79 + .Fn wipefs_alloc 80 + function initializes a 81 + .Fa wipefs_ctx 82 + object (which is an opaque data type). 83 + .Fa file_desc 84 + is the file handle of the volume to be wiped, which can be a block device node, a character device node, or a file. 85 + .Fa file_desc 86 + must be opened with write access. If 87 + .Fa block_size 88 + is 0, this function calls 89 + .Xr ioctl 2 90 + to get the block size. A valid 91 + .Fa block_size 92 + must be supplied if 93 + .Fa file_desc 94 + is a regular file. This function does not write any data to the volume. 95 + .Pp 96 + The 97 + .Fn wipefs_include_blocks 98 + function tells wipefs to write zeroes in the block range provided, in addition to any other ranges 99 + it would normally write. This may be more efficient than if the caller were to write this range 100 + separately, especially if the block range overlaps or is contiguous with other ranges that wipefs 101 + will write. This function does not write any data to the volume. If this function is called 102 + multiple times, the union of all the ranges provided will be written by 103 + .Fn wipefs_wipe . 104 + .Pp 105 + The 106 + .Fn wipefs_except_blocks 107 + function tells wipefs not to write anything in the block range provided. This function is used for performance 108 + optimizations if the caller will write to these blocks. It is the caller's responsibility to write to these blocks. 109 + Otherwise, some file systems may still be recognized on the volume. This function does not write any data to the 110 + volume. If this function is called multiple times, the union of all the ranges provided will be excluded from being 111 + written by 112 + .Fn wipefs_wipe . 113 + .Pp 114 + The 115 + .Fn wipefs_wipe 116 + function sends a 117 + .Li DKIOCUNMAP 118 + ioctl and then writes data to the volume to wipe out existing file systems on it. 119 + .Sy CAUTION: 120 + this function destroys any file system or partition scheme on the volume represented by 121 + .Fa file_desc . 122 + If 123 + .Fa file_desc 124 + represents the entire disk (e.g. /dev/diskX), the partition map of the disk will be destroyed. If 125 + .Fa file_desc 126 + represents a partition (e.g., /dev/diskXsY), only the file system in that partition is destroyed. Although the partition scheme or file system on 127 + .Fa file_desc 128 + may be beyond repair after 129 + .Fn wipefs_wipe , 130 + 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. 131 + .Pp 132 + The 133 + .Fn wipefs_free 134 + function frees the allocated 135 + .Fa wipefs_ctx 136 + handle and set 137 + .Fa *handlep 138 + to NULL. 139 + .Sh RETURN VALUES 140 + The 141 + .Fn wipefs_alloc , 142 + .Fn wipefs_include_blocks , 143 + .Fn wipefs_except_blocks 144 + and 145 + .Fn wipefs_wipe 146 + functions return 0 on success, or will fail and return an error code. 147 + Each function may return 148 + .Fa ENOMEM 149 + if insufficient memory is available. In addition, if 150 + .Fa block_size 151 + is not provided, 152 + .Fn wipefs_alloc 153 + may return any error 154 + .Xr ioctl 2 155 + returns; 156 + .Fn wipefs_wipe 157 + may return any error 158 + .Xr pwrite 2 159 + returns. 160 + .\" .Sh BUGS \" Document known, unremedied bugs 161 + .\".Sh HISTORY \" Document history if command behaves in a unique manner 162 + .\"The wipefs family of functions first appeared in Mac OS X Leopard (10.5.3).
+317
src/libutil/wipefs.cpp
··· 1 + /* 2 + * Copyright (c) 2008 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + // 24 + // wipefs.cpp 25 + // 26 + 27 + #include <fcntl.h> 28 + #include <unistd.h> 29 + #include <sys/uio.h> 30 + #include <sys/ioctl.h> 31 + #include <sys/disk.h> 32 + #include <sys/stat.h> 33 + #include <cstring> 34 + #include <strings.h> 35 + 36 + #include "ExtentManager.h" 37 + #include "wipefs.h" 38 + 39 + #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 40 + 41 + struct __wipefs_ctx { 42 + int fd; 43 + class ExtentManager extMan; 44 + }; 45 + 46 + static void 47 + AddExtentsForFutureFS(class ExtentManager *extMan) 48 + { 49 + // we don't know what blocks future FS will use to recognize itself. But we'd better be safe than sorry and write 50 + // the first and last 2MB of the volume 51 + off_t size = 2 * 1024 * 1024; 52 + extMan->AddByteRangeExtent(0, size); 53 + extMan->AddByteRangeExtent(extMan->totalBytes - size, size); 54 + } 55 + 56 + static void 57 + AddExtentsForHFS(class ExtentManager *extMan) 58 + { 59 + // first 1KB is boot block, last 512B is reserved 60 + // the Volume Header (512B) is after 1KB and before the last 512B 61 + extMan->AddByteRangeExtent(0, 1024 + 512); 62 + extMan->AddByteRangeExtent(extMan->totalBytes - 1024, 1024); 63 + } 64 + 65 + static void 66 + AddExtentsForMSDOS(class ExtentManager *extMan) 67 + { 68 + // MSDOS needs the first block (in theory, up to 32KB) 69 + extMan->AddByteRangeExtent(0, 32 * 1024); 70 + } 71 + 72 + static void 73 + AddExtentsForNTFS(class ExtentManager *extMan) 74 + { 75 + // NTFS supports block size from 256B to 32768B. The first, middle and last block are needed 76 + extMan->AddByteRangeExtent(0, 32 * 1024); 77 + extMan->AddByteRangeExtent(extMan->totalBytes - 32 * 1024, 32 * 1024); 78 + // to be safe, add the rage from (mid_point - 32KB) to (mid_point + 32KB) 79 + extMan->AddByteRangeExtent(extMan->totalBytes / 2 - 32 * 1024, 64 * 1024); 80 + } 81 + 82 + static void 83 + AddExtentsForUDF(class ExtentManager *extMan) 84 + { 85 + off_t lastBlockAddr = extMan->totalBlocks - 1; 86 + 87 + // Volume Recognization Sequence (VRS) starts at 32KB, usually less than 7 Volume Structure Descriptors (2KB each) 88 + extMan->AddByteRangeExtent(32 * 1024, 14 * 1024); 89 + 90 + // AVDP is on 256, 512, last block, last block - 256 91 + extMan->AddBlockRangeExtent(256, 1); 92 + extMan->AddBlockRangeExtent(512, 1); 93 + extMan->AddBlockRangeExtent(lastBlockAddr, 1); 94 + extMan->AddBlockRangeExtent(lastBlockAddr - 256, 1); 95 + 96 + // to be safe, assume the device has 2KB block size and do it again 97 + if (extMan->blockSize != 2048) { 98 + off_t blockSize = 2048; 99 + // AVDP is on 256, 512, last block, last block - 256 100 + extMan->AddByteRangeExtent(256 * blockSize, blockSize); 101 + extMan->AddByteRangeExtent(512 * blockSize, blockSize); 102 + extMan->AddByteRangeExtent(extMan->totalBytes - blockSize, blockSize); 103 + extMan->AddByteRangeExtent(extMan->totalBytes - 256 * blockSize, blockSize); 104 + } 105 + } 106 + 107 + static void 108 + AddExtentsForUFS(class ExtentManager *extMan) 109 + { 110 + // UFS super block is 8KB at offset 8KB 111 + extMan->AddByteRangeExtent(8192, 8192); 112 + } 113 + 114 + static void 115 + AddExtentsForZFS(class ExtentManager *extMan) 116 + { 117 + // ZFS needs the first 512KB and last 512KB for all the 4 disk labels 118 + extMan->AddByteRangeExtent(0, 512 * 1024); 119 + extMan->AddByteRangeExtent(extMan->totalBytes - 512 * 1024, 512 * 1024); 120 + } 121 + 122 + static void 123 + AddExtentsForPartitions(class ExtentManager *extMan) 124 + { 125 + // MBR (Master Boot Record) needs the first sector 126 + // APM (Apple Partition Map) needs the second sector 127 + // GPT (GUID Partition Table) needs the first 34 and last 33 sectors 128 + extMan->AddByteRangeExtent(0, 512 * 34); 129 + extMan->AddByteRangeExtent(extMan->totalBytes - 512 * 33, 512 * 33); 130 + } 131 + 132 + extern "C" int 133 + wipefs_alloc(int fd, size_t block_size, wipefs_ctx *handle) 134 + { 135 + int err = 0; 136 + uint64_t numBlocks = 0; 137 + uint32_t nativeBlockSize = 0; 138 + off_t totalSizeInBytes = 0; 139 + class ExtentManager *extMan = NULL; 140 + struct stat sbuf = { 0 }; 141 + 142 + *handle = NULL; 143 + (void)fstat(fd, &sbuf); 144 + switch (sbuf.st_mode & S_IFMT) { 145 + case S_IFCHR: 146 + case S_IFBLK: 147 + if (ioctl(fd, DKIOCGETBLOCKSIZE, (char *)&nativeBlockSize) < 0) { 148 + err = errno; 149 + goto labelExit; 150 + } 151 + if (ioctl(fd, DKIOCGETBLOCKCOUNT, (char *)&numBlocks) < 0) { 152 + err = errno; 153 + goto labelExit; 154 + } 155 + totalSizeInBytes = numBlocks * nativeBlockSize; 156 + break; 157 + case S_IFREG: 158 + nativeBlockSize = sbuf.st_blksize; 159 + numBlocks = sbuf.st_size / sbuf.st_blksize; 160 + totalSizeInBytes = sbuf.st_size; 161 + break; 162 + default: 163 + errno = EINVAL; 164 + goto labelExit; 165 + } 166 + if (block_size == 0) { 167 + block_size = nativeBlockSize; 168 + } 169 + if (block_size == 0 || totalSizeInBytes == 0) { 170 + err = EINVAL; 171 + goto labelExit; 172 + } 173 + 174 + try { 175 + *handle = new __wipefs_ctx; 176 + if (*handle == NULL) { 177 + bad_alloc e; 178 + throw e; 179 + } 180 + 181 + (*handle)->fd = fd; 182 + extMan = &(*handle)->extMan; 183 + 184 + extMan->Init(block_size, nativeBlockSize, totalSizeInBytes); 185 + AddExtentsForFutureFS(extMan); 186 + AddExtentsForHFS(extMan); 187 + AddExtentsForMSDOS(extMan); 188 + AddExtentsForNTFS(extMan); 189 + AddExtentsForUDF(extMan); 190 + AddExtentsForUFS(extMan); 191 + AddExtentsForZFS(extMan); 192 + AddExtentsForPartitions(extMan); 193 + } 194 + catch (bad_alloc &e) { 195 + err = ENOMEM; 196 + } 197 + catch (...) { // currently only ENOMEM is possible 198 + err = ENOMEM; 199 + } 200 + 201 + labelExit: 202 + if (err != 0) { 203 + wipefs_free(handle); 204 + } 205 + return err; 206 + } // wipefs_alloc 207 + 208 + extern "C" int 209 + wipefs_include_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks) 210 + { 211 + int err = 0; 212 + try { 213 + handle->extMan.AddBlockRangeExtent(block_offset, nblocks); 214 + } 215 + catch (bad_alloc &e) { 216 + err = ENOMEM; 217 + } 218 + catch (...) { // currently only ENOMEM is possible 219 + err = ENOMEM; 220 + } 221 + return err; 222 + } 223 + 224 + extern "C" int 225 + wipefs_except_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks) 226 + { 227 + int err = 0; 228 + try { 229 + handle->extMan.RemoveBlockRangeExtent(block_offset, nblocks); 230 + } 231 + catch (bad_alloc &e) { 232 + err = ENOMEM; 233 + } 234 + catch (...) { // currently only ENOMEM is possible 235 + err = ENOMEM; 236 + } 237 + return err; 238 + } 239 + 240 + extern "C" int 241 + wipefs_wipe(wipefs_ctx handle) 242 + { 243 + int err = 0; 244 + uint8_t *bufZero = NULL; 245 + ListExtIt curExt; 246 + size_t bufSize; 247 + dk_extent_t extent; 248 + dk_unmap_t unmap; 249 + 250 + memset(&extent, 0, sizeof(dk_extent_t)); 251 + extent.length = handle->extMan.totalBytes; 252 + 253 + memset(&unmap, 0, sizeof(dk_unmap_t)); 254 + unmap.extents = &extent; 255 + unmap.extentsCount = 1; 256 + 257 + // 258 + // Don't bother to check the return value since this is mostly 259 + // informational for the lower-level drivers. 260 + // 261 + ioctl(handle->fd, DKIOCUNMAP, (caddr_t)&unmap); 262 + 263 + 264 + bufSize = 128 * 1024; // issue large I/O to get better performance 265 + if (handle->extMan.nativeBlockSize > bufSize) { 266 + bufSize = handle->extMan.nativeBlockSize; 267 + } 268 + bufZero = new uint8_t[bufSize]; 269 + bzero(bufZero, bufSize); 270 + 271 + off_t byteOffset, totalBytes; 272 + size_t numBytes, numBytesToWrite, blockSize; 273 + 274 + blockSize = handle->extMan.blockSize; 275 + totalBytes = handle->extMan.totalBytes; 276 + // write zero to all extents 277 + for (curExt = handle->extMan.extentList.begin(); curExt != handle->extMan.extentList.end(); curExt++) { 278 + byteOffset = curExt->blockAddr * blockSize; 279 + numBytes = curExt->numBlocks * blockSize; 280 + // make both offset and numBytes on native block boundary 281 + if (byteOffset % handle->extMan.nativeBlockSize != 0 || 282 + numBytes % handle->extMan.nativeBlockSize != 0) { 283 + size_t nativeBlockSize = handle->extMan.nativeBlockSize; 284 + off_t newOffset, newEndOffset; 285 + newOffset = byteOffset / nativeBlockSize * nativeBlockSize; 286 + newEndOffset = roundup(byteOffset + numBytes, nativeBlockSize); 287 + byteOffset = newOffset; 288 + numBytes = newEndOffset - newOffset; 289 + } 290 + if (byteOffset + (off_t)numBytes > totalBytes) { 291 + numBytes = totalBytes - byteOffset; 292 + } 293 + while (numBytes > 0) { 294 + numBytesToWrite = min(numBytes, bufSize); 295 + if (pwrite(handle->fd, bufZero, numBytesToWrite, byteOffset) != (ssize_t)numBytesToWrite) { 296 + err = errno; 297 + goto labelExit; 298 + } 299 + numBytes -= numBytesToWrite; 300 + byteOffset += numBytesToWrite; 301 + } 302 + } 303 + 304 + labelExit: 305 + if (bufZero != NULL) 306 + delete[] bufZero; 307 + return err; 308 + } // wipefs_wipe 309 + 310 + extern "C" void 311 + wipefs_free(wipefs_ctx *handle) 312 + { 313 + if (*handle != NULL) { 314 + delete *handle; 315 + *handle = NULL; 316 + } 317 + }
+48
src/libutil/wipefs.h
··· 1 + /* 2 + * Copyright (c) 2008 Apple Inc. All rights reserved. 3 + * 4 + * @APPLE_LICENSE_HEADER_START@ 5 + * 6 + * This file contains Original Code and/or Modifications of Original Code 7 + * as defined in and that are subject to the Apple Public Source License 8 + * Version 2.0 (the 'License'). You may not use this file except in 9 + * compliance with the License. Please obtain a copy of the License at 10 + * http://www.opensource.apple.com/apsl/ and read it before using this 11 + * file. 12 + * 13 + * The Original Code and all software distributed under the License are 14 + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 + * Please see the License for the specific language governing rights and 19 + * limitations under the License. 20 + * 21 + * @APPLE_LICENSE_HEADER_END@ 22 + */ 23 + // 24 + // wipefs.h 25 + // 26 + #ifndef WIPEFS_H 27 + #define WIPEFS_H 28 + 29 + #ifdef __cplusplus 30 + extern "C" { 31 + #endif 32 + 33 + typedef struct __wipefs_ctx *wipefs_ctx; 34 + 35 + __BEGIN_DECLS 36 + extern int wipefs_alloc(int fd, size_t block_size, wipefs_ctx *handle); 37 + extern int wipefs_include_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks); 38 + extern int wipefs_except_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks); 39 + extern int wipefs_wipe(wipefs_ctx handle); 40 + extern void wipefs_free(wipefs_ctx *handle); 41 + __END_DECLS 42 + 43 + #ifdef __cplusplus 44 + } 45 + #endif 46 + 47 + #endif // #ifndef WIPEFS_H 48 +
+11
src/libutil/xcconfigs/base.xcconfig
··· 1 + #include "<DEVELOPER_DIR>/Makefiles/CoreOS/Xcode/BSD.xcconfig" 2 + #include "<DEVELOPER_DIR>/AppleInternal/XcodeConfig/SimulatorSupport.xcconfig" 3 + 4 + // Set INSTALL_PATH[sdk=macosx*] when SimulatorSupport.xcconfig is unavailable 5 + INSTALL_PATH[sdk=macosx*] = $(INSTALL_PATH_ACTUAL) 6 + 7 + // Use $(INSTALL_PATH_PREFIX) instead of $(SDKROOT) as a prefix for other 8 + // variables as appropriate 9 + PUBLIC_HEADERS_FOLDER_PATH = $(INSTALL_PATH_PREFIX)/usr/include 10 + PRIVATE_HEADERS_FOLDER_PATH = $(INSTALL_PATH_PREFIX)/usr/local/include 11 +
+33
src/libutil/xcconfigs/tzlinkd.xcconfig
··· 1 + #include "<DEVELOPER_DIR>/AppleInternal/XcodeConfig/SimulatorSupport.xcconfig" 2 + 3 + // Set INSTALL_PATH_ACTUAL to whatever INSTALL_PATH would normally be 4 + INSTALL_PATH_ACTUAL = /usr/sbin 5 + 6 + INSTALL_PATH_ACTUAL = /usr/libexec 7 + PRODUCT_NAME = tzlinkd 8 + 9 + CODE_SIGN_IDENTITY = - 10 + CODE_SIGN_ENTITLEMENTS = tzlinkd/entitlements.plist 11 + 12 + USER_HEADER_SEARCH_PATHS = $(SRCROOT) 13 + 14 + ALWAYS_SEARCH_USER_PATHS = NO 15 + 16 + GCC_TREAT_WARNINGS_AS_ERRORS = YES 17 + CLANG_WARN_BOOL_CONVERSION = YES 18 + CLANG_WARN_CONSTANT_CONVERSION = YES 19 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR 20 + CLANG_WARN_EMPTY_BODY = YES 21 + CLANG_WARN_ENUM_CONVERSION = YES 22 + CLANG_WARN_INT_CONVERSION = YES 23 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR 24 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 25 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES 26 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR 27 + GCC_WARN_UNDECLARED_SELECTOR = YES 28 + GCC_WARN_UNINITIALIZED_AUTOS = YES 29 + GCC_WARN_UNUSED_FUNCTION = YES 30 + GCC_WARN_UNUSED_VARIABLE = YES 31 + GCC_WARN_UNKNOWN_PRAGMAS = YES 32 + GCC_WARN_UNUSED_LABEL = YES 33 + GCC_WARN_UNUSED_PARAMETER = YES
+2 -2
src/util/CMakeLists.txt
··· 16 16 leb.cpp 17 17 ) 18 18 19 - add_library(util ${util-SRCS}) 20 - set_target_properties(util PROPERTIES COMPILE_FLAGS "-fPIC") 19 + add_library(darling-util ${util-SRCS}) 20 + set_target_properties(darling-util PROPERTIES COMPILE_FLAGS "-fPIC") 21 21