1*82357f6dSdsl /* $NetBSD: openraw.c,v 1.3 2009/03/14 21:04:06 dsl Exp $ */
23f496a25Sleo
33f496a25Sleo /*
43f496a25Sleo * Copyright (c) 1999 The NetBSD Foundation, Inc.
53f496a25Sleo * All rights reserved.
63f496a25Sleo *
73f496a25Sleo * This code is derived from software contributed to The NetBSD Foundation
83f496a25Sleo * by Julian Coleman, Waldi Ravens and Leo Weppelman.
93f496a25Sleo *
103f496a25Sleo * Redistribution and use in source and binary forms, with or without
113f496a25Sleo * modification, are permitted provided that the following conditions
123f496a25Sleo * are met:
133f496a25Sleo * 1. Redistributions of source code must retain the above copyright
143f496a25Sleo * notice, this list of conditions and the following disclaimer.
153f496a25Sleo * 2. Redistributions in binary form must reproduce the above copyright
163f496a25Sleo * notice, this list of conditions and the following disclaimer in the
173f496a25Sleo * documentation and/or other materials provided with the distribution.
183f496a25Sleo *
193f496a25Sleo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
203f496a25Sleo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
213f496a25Sleo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223f496a25Sleo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
233f496a25Sleo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
243f496a25Sleo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
253f496a25Sleo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
263f496a25Sleo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
273f496a25Sleo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
283f496a25Sleo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
293f496a25Sleo * POSSIBILITY OF SUCH DAMAGE.
303f496a25Sleo */
313f496a25Sleo
323f496a25Sleo #include "privahdi.h"
333f496a25Sleo #include <fcntl.h>
343f496a25Sleo #include <paths.h>
353f496a25Sleo #include <stdio.h>
363f496a25Sleo #include <machine/disklabel.h>
373f496a25Sleo
383f496a25Sleo /*
393f496a25Sleo * Open raw disk partition.
403f496a25Sleo */
413f496a25Sleo int
openraw(const char * name,int flags)42*82357f6dSdsl openraw (const char *name, int flags)
433f496a25Sleo {
443f496a25Sleo char buf[MAXPATHLEN];
453f496a25Sleo int f;
463f496a25Sleo
473f496a25Sleo if ((f = open (name, flags)) != -1)
483f496a25Sleo return (f);
493f496a25Sleo
503f496a25Sleo snprintf (buf, MAXPATHLEN, "r%s%c", name, RAW_PART + 'a');
513f496a25Sleo if ((f = open (buf, flags)) != -1)
523f496a25Sleo return (f);
533f496a25Sleo
543f496a25Sleo snprintf (buf, MAXPATHLEN, "%sr%s%c", _PATH_DEV, name, RAW_PART + 'a');
553f496a25Sleo if ((f = open (buf, flags)) != -1)
563f496a25Sleo return (f);
573f496a25Sleo
583f496a25Sleo return (0);
593f496a25Sleo }
60