xref: /freebsd/usr.sbin/fstyp/ufs.c (revision 4d65a7c6951cea0333f1a0c1b32c38489cdfa6c5)
1be3a49eeSEdward Tomasz Napierala /*-
2be3a49eeSEdward Tomasz Napierala  * Copyright (c) 2002, 2003 Gordon Tetlow
3be3a49eeSEdward Tomasz Napierala  * Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
4be3a49eeSEdward Tomasz Napierala  * Copyright (c) 2014 The FreeBSD Foundation
5be3a49eeSEdward Tomasz Napierala  * All rights reserved.
6be3a49eeSEdward Tomasz Napierala  *
7be3a49eeSEdward Tomasz Napierala  * This software was developed by Edward Tomasz Napierala under sponsorship
8be3a49eeSEdward Tomasz Napierala  * from the FreeBSD Foundation.
9be3a49eeSEdward Tomasz Napierala  *
10be3a49eeSEdward Tomasz Napierala  * Redistribution and use in source and binary forms, with or without
11be3a49eeSEdward Tomasz Napierala  * modification, are permitted provided that the following conditions
12be3a49eeSEdward Tomasz Napierala  * are met:
13be3a49eeSEdward Tomasz Napierala  * 1. Redistributions of source code must retain the above copyright
14be3a49eeSEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer.
15be3a49eeSEdward Tomasz Napierala  * 2. Redistributions in binary form must reproduce the above copyright
16be3a49eeSEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer in the
17be3a49eeSEdward Tomasz Napierala  *    documentation and/or other materials provided with the distribution.
18be3a49eeSEdward Tomasz Napierala  *
19be3a49eeSEdward Tomasz Napierala  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20be3a49eeSEdward Tomasz Napierala  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21be3a49eeSEdward Tomasz Napierala  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22be3a49eeSEdward Tomasz Napierala  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23be3a49eeSEdward Tomasz Napierala  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24be3a49eeSEdward Tomasz Napierala  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25be3a49eeSEdward Tomasz Napierala  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26be3a49eeSEdward Tomasz Napierala  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27be3a49eeSEdward Tomasz Napierala  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28be3a49eeSEdward Tomasz Napierala  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29be3a49eeSEdward Tomasz Napierala  * SUCH DAMAGE.
30be3a49eeSEdward Tomasz Napierala  */
31be3a49eeSEdward Tomasz Napierala 
32be3a49eeSEdward Tomasz Napierala #include <sys/types.h>
33dffce215SKirk McKusick #include <ufs/ufs/dinode.h>
34dffce215SKirk McKusick #include <ufs/ffs/fs.h>
35dffce215SKirk McKusick 
36dffce215SKirk McKusick #include <errno.h>
37dffce215SKirk McKusick #include <libufs.h>
38be3a49eeSEdward Tomasz Napierala #include <stdint.h>
39be3a49eeSEdward Tomasz Napierala #include <stdio.h>
40be3a49eeSEdward Tomasz Napierala #include <stdlib.h>
41be3a49eeSEdward Tomasz Napierala #include <string.h>
42be3a49eeSEdward Tomasz Napierala 
43be3a49eeSEdward Tomasz Napierala #include "fstyp.h"
44be3a49eeSEdward Tomasz Napierala 
45be3a49eeSEdward Tomasz Napierala int
fstyp_ufs(FILE * fp,char * label,size_t labelsize)46be3a49eeSEdward Tomasz Napierala fstyp_ufs(FILE *fp, char *label, size_t labelsize)
47be3a49eeSEdward Tomasz Napierala {
48be3a49eeSEdward Tomasz Napierala 	struct fs *fs;
49be3a49eeSEdward Tomasz Napierala 
50*b21582eeSKirk McKusick 	switch (sbget(fileno(fp), &fs, UFS_STDSB, UFS_NOCSUM)) {
51dffce215SKirk McKusick 	case 0:
52be3a49eeSEdward Tomasz Napierala 		strlcpy(label, fs->fs_volname, labelsize);
5334816cb9SKirk McKusick 		free(fs);
54be3a49eeSEdward Tomasz Napierala 		return (0);
55dffce215SKirk McKusick 	case ENOENT:
56dffce215SKirk McKusick 		/* Cannot find file system superblock */
57be3a49eeSEdward Tomasz Napierala 		return (1);
58dffce215SKirk McKusick 	default:
59dffce215SKirk McKusick 		/* Unable to read file system superblock */
60dffce215SKirk McKusick 		return (1);
61dffce215SKirk McKusick 	}
62be3a49eeSEdward Tomasz Napierala }
63