2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Ákos Kovács <akoskovacs@gmx.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 static struct fs_type fs_types[] = {
42 { "HAMMER", hammer_probe, hammer_volname },
43 { "UFS", ufs_probe, ufs_volname },
44 { "CD9660", cd9660_probe, cd9660_volname },
45 { "EXT2", ext2_probe, ext2_volname },
46 { "MSDOSFS",msdosfs_probe, msdosfs_volname },
51 fsid_fsname(fsid_t id)
56 return fs_types[id-1].fs_name;
64 for (count = 0; fs_types[count].fs_name != NULL; count++)
71 fsid_probe(const char *dev, const char *fs_type)
75 if (dev == NULL || fs_type == NULL)
78 for (i = 0; fs_types[i].fs_name != NULL; i++) {
79 if ((strcmp(fs_type, fs_types[i].fs_name)) == 0)
80 return fs_types[i].fs_probe(dev);
86 fsid_probe_all(const char *dev)
94 for (i = 0; fs_types[i].fs_name != NULL; i++) {
95 if ((ret = fs_types[i].fs_probe(dev)) != FSID_UNKNOWN)
102 fsid_volname(const char *dev, const char *fs_type)
106 if (dev == NULL || fs_type == NULL)
109 for (i = 0; fs_types[i].fs_name != NULL; i++) {
110 if ((strcmp(fs_type, fs_types[i].fs_name)) == 0) {
111 return fs_types[i].fs_volname(dev);
118 fsid_volname_all(const char *dev)
125 if ((fs_id = fsid_probe_all(dev)) != 0)
126 return fs_types[fs_id - 1].fs_volname(dev);
132 fsid_dev_read(const char *dev, off_t off, size_t len, char *buf)
136 if ((fd = open(dev, O_RDONLY)) < 0)
139 if ((lseek(fd, off, SEEK_SET)) < 0) {
145 if ((read(fd, buf, len)) < 0) {