1/* 2 * Copyright (c) 2001-2007 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 * unbless.c 25 * bless 26 * 27 * Created by Shantonu Sen <ssen@apple.com> on Sun Mar 6, 2005. 28 * Copyright (c) 2005-2007 Apple Inc. All Rights Reserved. 29 * 30 * $Id: unbless.c,v 1.2 2005/09/12 22:09:06 ssen Exp $ 31 * 32 * 33 */ 34 35#include <stdlib.h> 36#include <stdio.h> 37#include <unistd.h> 38#include <sys/stat.h> 39#include <sys/mount.h> 40#include <sys/param.h> 41#include <err.h> 42 43#include "bless.h" 44 45int unbless(char *mountpoint); 46 47int main(int argc, char *argv[]) { 48 49 char *mntpnt = NULL; 50 struct statfs sb; 51 int ret; 52 53 if (argc != 2) { 54 fprintf(stderr, "Usage: %s /Volumes/foo\n", getprogname()); 55 exit(1); 56 } 57 58 mntpnt = argv[1]; 59 60 ret = statfs(mntpnt, &sb); 61 if(ret) 62 err(1, "statfs(%s)", mntpnt); 63 64 if(0 != strcmp(mntpnt, sb.f_mntonname)) 65 errx(1, "Path is not a mount point"); 66 67 ret = unbless(mntpnt); 68 69 return ret; 70} 71 72 73int unbless(char *mountpoint) { 74 75 int ret; 76 int isHFS; 77 uint32_t oldwords[8]; 78 79 ret = BLIsMountHFS(NULL, mountpoint, &isHFS); 80 if(ret) 81 errx(1, "Could not determine filesystem of %s", mountpoint); 82 83 if(!isHFS) 84 errx(1, "%s is not HFS+", mountpoint); 85 86 ret = BLGetVolumeFinderInfo(NULL, mountpoint, oldwords); 87 if(ret) 88 err(1, "Could not get finder info for %s", mountpoint); 89 90 oldwords[0] = 0; 91 oldwords[1] = 0; 92 oldwords[2] = 0; 93 oldwords[3] = 0; 94 oldwords[5] = 0; 95 96 /* bless! bless */ 97 98 ret = BLSetVolumeFinderInfo(NULL, mountpoint, oldwords); 99 if(ret) 100 err(1, "Can't set finder info for %s", mountpoint); 101 102 return 0; 103} 104 105