xref: /freebsd/usr.sbin/fstyp/ufs.c (revision b21582ee03ec1394e08173e276df311979856e54)
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/cdefs.h>
33be3a49eeSEdward Tomasz Napierala __FBSDID("$FreeBSD$");
34be3a49eeSEdward Tomasz Napierala 
35be3a49eeSEdward Tomasz Napierala #include <sys/types.h>
36dffce215SKirk McKusick #include <ufs/ufs/dinode.h>
37dffce215SKirk McKusick #include <ufs/ffs/fs.h>
38dffce215SKirk McKusick 
39dffce215SKirk McKusick #include <errno.h>
40dffce215SKirk McKusick #include <libufs.h>
41be3a49eeSEdward Tomasz Napierala #include <stdint.h>
42be3a49eeSEdward Tomasz Napierala #include <stdio.h>
43be3a49eeSEdward Tomasz Napierala #include <stdlib.h>
44be3a49eeSEdward Tomasz Napierala #include <string.h>
45be3a49eeSEdward Tomasz Napierala 
46be3a49eeSEdward Tomasz Napierala #include "fstyp.h"
47be3a49eeSEdward Tomasz Napierala 
48be3a49eeSEdward Tomasz Napierala int
49be3a49eeSEdward Tomasz Napierala fstyp_ufs(FILE *fp, char *label, size_t labelsize)
50be3a49eeSEdward Tomasz Napierala {
51be3a49eeSEdward Tomasz Napierala 	struct fs *fs;
52be3a49eeSEdward Tomasz Napierala 
53*b21582eeSKirk McKusick 	switch (sbget(fileno(fp), &fs, UFS_STDSB, UFS_NOCSUM)) {
54dffce215SKirk McKusick 	case 0:
55be3a49eeSEdward Tomasz Napierala 		strlcpy(label, fs->fs_volname, labelsize);
5634816cb9SKirk McKusick 		free(fs);
57be3a49eeSEdward Tomasz Napierala 		return (0);
58dffce215SKirk McKusick 	case ENOENT:
59dffce215SKirk McKusick 		/* Cannot find file system superblock */
60be3a49eeSEdward Tomasz Napierala 		return (1);
61dffce215SKirk McKusick 	default:
62dffce215SKirk McKusick 		/* Unable to read file system superblock */
63dffce215SKirk McKusick 		return (1);
64dffce215SKirk McKusick 	}
65be3a49eeSEdward Tomasz Napierala }
66