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 *  BLMiscUtilities.c
25 *  bless
26 *
27 *  Created by Shantonu Sen on Sat Apr 19 2003.
28 *  Copyright (c) 2003-2007 Apple Inc. All Rights Reserved.
29 *
30 *  $Id: BLMiscUtilities.c,v 1.7 2006/02/20 22:49:56 ssen Exp $
31 *
32 */
33
34#include "bless.h"
35#include "bless_private.h"
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <sys/mount.h>
42
43char * blostype2string(uint32_t type, char buf[5])
44{
45    bzero(buf, 5);
46    if(type == 0) return buf;
47
48    sprintf(buf, "%c%c%c%c",
49	    (type >> 24)&0xFF,
50	    (type >> 16)&0xFF,
51	    (type >> 8)&0xFF,
52	    (type >> 0)&0xFF);
53
54    return buf;
55}
56
57int blsustatfs(const char *path, struct statfs *buf)
58{
59    int ret;
60    struct stat sb;
61    char *dev = NULL;
62
63    ret = statfs(path, buf);
64    if(ret)
65        return ret;
66
67
68    ret = stat(path, &sb);
69    if(ret)
70        return ret;
71
72    // figure out the true device we live on
73    dev = devname(sb.st_dev, S_IFBLK);
74    if(dev == NULL) {
75        errno = ENOENT;
76        return -1;
77    }
78
79    snprintf(buf->f_mntfromname, sizeof(buf->f_mntfromname), "/dev/%s", dev);
80
81    return 0;
82}
83
84