2 * Generic utility routines for the Common Access Method layer.
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * 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
28 * $FreeBSD: src/sys/cam/cam.c,v 1.3 1999/08/28 00:40:38 peter Exp $
29 * $DragonFly: src/sys/bus/cam/cam.c,v 1.3 2003/08/07 21:16:44 dillon Exp $
31 #include <sys/param.h>
36 cam_strvis(u_int8_t *dst, const u_int8_t *src, int srclen, int dstlen)
39 /* Trim leading/trailing spaces, nulls. */
40 while (srclen > 0 && src[0] == ' ')
43 && (src[srclen-1] == ' ' || src[srclen-1] == '\0'))
46 while (srclen > 0 && dstlen > 1) {
47 u_int8_t *cur_pos = dst;
49 if (*src < 0x20 || *src >= 0x80) {
50 /* SCSI-II Specifies that these should never occur. */
51 /* non-printable character */
54 *cur_pos++ = ((*src & 0300) >> 6) + '0';
55 *cur_pos++ = ((*src & 0070) >> 3) + '0';
56 *cur_pos++ = ((*src & 0007) >> 0) + '0';
61 /* normal character */
66 dstlen -= cur_pos - dst;
73 * Compare string with pattern, returning 0 on match.
74 * Short pattern matches trailing blanks in name,
75 * wildcard '*' in pattern matches rest of name,
76 * wildcard '?' matches a single non-space character.
79 cam_strmatch(const u_int8_t *str, const u_int8_t *pattern, int str_len)
82 while (*pattern != '\0'&& str_len > 0) {
84 if (*pattern == '*') {
87 if ((*pattern != *str)
88 && (*pattern != '?' || *str == ' ')) {
95 while (str_len > 0 && *str++ == ' ')
102 cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries,
103 int entry_size, cam_quirkmatch_t *comp_func)
105 for (; num_entries > 0; num_entries--, quirk_table += entry_size) {
106 if ((*comp_func)(target, quirk_table) == 0)
107 return (quirk_table);