2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Alex Hornung <ahornung@gmail.com
6 * and Ákos Kovács <akoskovacs@gmx.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <vfs/msdosfs/bootsect.h>
38 #define MSDOS_BOOT_BLOCK_SIZE 512
40 static char buffer[MSDOS_BOOT_BLOCK_SIZE * 4];
41 static char *get_volname(char *buf);
44 msdosfs_probe(const char *dev)
46 if (fsid_dev_read(dev, 0L, sizeof(buffer), buffer) != 0)
49 if (get_volname(buffer) != NULL)
55 msdosfs_volname(const char *dev)
59 if (fsid_dev_read(dev, 0L, sizeof(buffer), buffer) != 0)
62 volname = get_volname(buffer);
66 if (volname[0] == '\0')
74 * This function used to get the offset address of
75 * the volume name, of the FAT partition.
76 * It also checks, that is a real FAT partition.
79 get_volname(char *buff)
81 struct bootsector710 *bpb7;
82 struct bootsector50 *bpb4;
85 bpb7 = (struct bootsector710 *)buff;
86 bpb4 = (struct bootsector50 *)buff;
89 * First, assume BPB v7
91 extb = (struct extboot *)bpb7->bsExt;
92 if ((extb->exBootSignature == 0x28 || extb->exBootSignature == 0x29) &&
93 strncmp(extb->exFileSysType, "FAT", 3) == 0)
94 return extb->exVolumeLabel;
97 * If this is not a BPB v7, try it as a bpb v4.
99 extb = (struct extboot *)bpb4->bsExt;
100 if ((extb->exBootSignature == 0x28 || extb->exBootSignature == 0x29) &&
101 strncmp(extb->exFileSysType, "FAT", 3) == 0)
102 return extb->exVolumeLabel;
105 * If previous checks failed, it may not a FAT filesystem, or
106 * it may an older one without a volume name.