diff --git a/sbin/geom/class/label/glabel.8 b/sbin/geom/class/label/glabel.8 index fff9205..bfa45ca 100644 --- a/sbin/geom/class/label/glabel.8 +++ b/sbin/geom/class/label/glabel.8 @@ -117,6 +117,9 @@ REISERFS (directory .It NTFS (directory .Pa /dev/ntfs/ ) . +.It +XFS (directory +.Pa /dev/xfs ) . .El .Pp Support for partition metadata is implemented for: diff --git a/sys/conf/files b/sys/conf/files index 1abb924..49c12ed 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2222,6 +2222,7 @@ geom/label/g_label_ntfs.c optional geom_label geom/label/g_label_reiserfs.c optional geom_label geom/label/g_label_ufs.c optional geom_label geom/label/g_label_gpt.c optional geom_label +geom/label/g_label_xfs.c optional geom_label geom/linux_lvm/g_linux_lvm.c optional geom_linux_lvm geom/mirror/g_mirror.c optional geom_mirror geom/mirror/g_mirror_ctl.c optional geom_mirror diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c index 0d8a3b4..179509a 100644 --- a/sys/geom/label/g_label.c +++ b/sys/geom/label/g_label.c @@ -87,6 +87,7 @@ const struct g_label_desc *g_labels[] = { &g_label_ntfs, &g_label_gpt, &g_label_gpt_uuid, + &g_label_xfs, NULL }; diff --git a/sys/geom/label/g_label.h b/sys/geom/label/g_label.h index 06ba2f5..e0d78e8 100644 --- a/sys/geom/label/g_label.h +++ b/sys/geom/label/g_label.h @@ -87,6 +87,7 @@ extern struct g_label_desc g_label_reiserfs; extern struct g_label_desc g_label_ntfs; extern struct g_label_desc g_label_gpt; extern struct g_label_desc g_label_gpt_uuid; +extern struct g_label_desc g_label_xfs; #endif /* _KERNEL */ struct g_label_metadata { diff --git a/sys/geom/label/g_label_xfs.c b/sys/geom/label/g_label_xfs.c new file mode 100644 index 0000000..69db15f --- /dev/null +++ b/sys/geom/label/g_label_xfs.c @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2010 Arne Meyer + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#define XFS_MAGIC 0x58465342 + +typedef struct xfs_sb { + uint32_t sb_magicnum; + char fake[104]; + char sb_fname[12]; +} xfs_sb_t; + +static void +g_label_xfs_taste(struct g_consumer *cp, char *label, size_t size) +{ + struct g_provider *pp; + xfs_sb_t *fs; + + g_topology_assert_not(); + pp = cp->provider; + label[0] = '\0'; + + fs = (xfs_sb_t *)g_read_data(cp, 0, pp->sectorsize, NULL); + if(fs == NULL) + return; + + /* Check for xfs magic */ + if (be32toh(fs->sb_magicnum) == XFS_MAGIC) { + G_LABEL_DEBUG(1, "xfs file system detected on %s.", + pp->name); + } else { + goto exit_free; + } + + /* Check for volume label */ + if (fs->sb_fname[0] == '\0') + goto exit_free; + + /* Terminate label */ + fs->sb_fname[sizeof(fs->sb_fname) - 1] = '\0'; + strlcpy(label, fs->sb_fname, size); + +exit_free: + g_free(fs); +} + +struct g_label_desc g_label_xfs = { + .ld_taste = g_label_xfs_taste, + .ld_dir = "xfs", + .ld_enabled = 1 +}; + +G_LABEL_INIT(xfs, g_label_xfs, "Create device nodes for XFS volumes"); diff --git a/sys/modules/geom/geom_label/Makefile b/sys/modules/geom/geom_label/Makefile index 300606a..87d8ec0 100644 --- a/sys/modules/geom/geom_label/Makefile +++ b/sys/modules/geom/geom_label/Makefile @@ -11,5 +11,6 @@ SRCS+= g_label_msdosfs.c SRCS+= g_label_ntfs.c SRCS+= g_label_reiserfs.c SRCS+= g_label_ufs.c +SRCS+= g_label_xfs.c .include