2 * Copyright (c) 2005 Takanori Watanabe
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
35 #include <fs/ntfs/ntfs.h>
37 #include <geom/geom.h>
38 #include <geom/label/g_label.h>
40 #define G_LABEL_NTFS_DIR "ntfs"
44 g_label_ntfs_taste(struct g_consumer *cp, char *label, size_t size)
46 struct g_provider *pp;
52 char mftrecsz, vnchar;
55 g_topology_assert_not();
61 bf = (struct bootfile *)g_read_data(cp, 0, pp->sectorsize, NULL);
62 if (bf == NULL || strncmp(bf->bf_sysid, "NTFS ", 8) != 0)
65 mftrecsz = (char)bf->bf_mftrecsz;
66 recsize = (mftrecsz > 0) ? (mftrecsz * bf->bf_bps * bf->bf_spc) : (1 << -mftrecsz);
67 if (recsize % pp->sectorsize != 0)
70 voloff = bf->bf_mftcn * bf->bf_spc * bf->bf_bps +
71 recsize * NTFS_VOLUMEINO;
72 if (voloff % pp->sectorsize != 0)
75 filerecp = g_read_data(cp, voloff, recsize, NULL);
78 fr = (struct filerec *)filerecp;
80 if (fr->fr_fixup.fh_magic != NTFS_FILEMAGIC)
83 for (ap = filerecp + fr->fr_attroff;
84 atr = (struct attr *)ap, atr->a_hdr.a_type != -1;
85 ap += atr->a_hdr.reclen) {
86 if (atr->a_hdr.a_type == NTFS_A_VOLUMENAME) {
87 if(atr->a_r.a_datalen >= size *2){
93 * Should we need to use iconv(9)?
95 for (j = 0; j < atr->a_r.a_datalen; j++) {
96 vnchar = *(ap + atr->a_r.a_dataoff + j);
103 label[j / 2] = vnchar;
113 if (filerecp != NULL)
117 const struct g_label_desc g_label_ntfs = {
118 .ld_taste = g_label_ntfs_taste,
119 .ld_dir = G_LABEL_NTFS_DIR