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/* Copyright 1998 Apple Computer, Inc.
24 *
25 * Get disk label's sector size  routine.
26 *    Input: pointer to a block device string  ie: "/dev/disk1s1"
27 *    Return: sector size from the disk label
28 *
29 * HISTORY
30 *
31 * 27 May 1998 K. Crippes at Apple
32 *      Rhapsody version created.
33 * 18 Feb 1999 D. Markarian at Apple
34 *      DKIOCGLABEL deprecated;  using DKIOCBLKSIZE instead, which now returns
35 *      the appropriate size for ufs partitions created with wierd block sizes.
36 */
37
38#include <sys/types.h>
39#include <sys/file.h>
40#include <sys/disk.h>
41#include <errno.h>
42#include <stdio.h>
43#include <string.h>
44#include <unistd.h>
45
46char *blockcheck __P((char *));
47
48long dksecsize (dev)
49     char *dev;
50{
51    int    fd;        /* file descriptor for reading device label */
52    char   *cdev;
53    int    devblklen;
54    extern int errno;
55
56    /* Convert block device into a character device string */
57    if ((cdev = blockcheck(dev))) {
58        if ((fd = open(cdev, O_RDONLY)) < 0) {
59  	  fprintf(stderr, "Can't open %s, %s\n", cdev, strerror(errno));
60	  return (0);
61        }
62    }
63    else
64          return (0);
65
66    if (ioctl(fd, DKIOCGETBLOCKSIZE, &devblklen) < 0) {
67	(void)close(fd);
68        return (0);
69    }
70    else {
71	(void)close(fd);
72        return (devblklen);
73    }
74}
75
76