2 * Copyright (c) 2016-2019 The DragonFly Project
3 * Copyright (c) 2016-2019 Tomohiro Kusumi <tkusumi@netbsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <vfs/hammer/hammer_disk.h>
37 static hammer_volume_ondisk_t
40 return (read_buf(fp
, 0, sizeof(struct hammer_volume_ondisk
)));
44 test_ondisk(const hammer_volume_ondisk_t ondisk
)
47 static hammer_uuid_t fsid
, fstype
;
48 static char label
[64];
50 if (ondisk
->vol_signature
!= HAMMER_FSBUF_VOLUME
&&
51 ondisk
->vol_signature
!= HAMMER_FSBUF_VOLUME_REV
)
53 if (ondisk
->vol_rootvol
!= HAMMER_ROOT_VOLNO
)
55 if (ondisk
->vol_no
< 0 || ondisk
->vol_no
> HAMMER_MAX_VOLUMES
- 1)
57 if (ondisk
->vol_count
< 1 || ondisk
->vol_count
> HAMMER_MAX_VOLUMES
)
61 count
= ondisk
->vol_count
;
64 memcpy(&fsid
, &ondisk
->vol_fsid
, sizeof(fsid
));
65 memcpy(&fstype
, &ondisk
->vol_fstype
, sizeof(fstype
));
66 strlcpy(label
, ondisk
->vol_label
, sizeof(label
));
68 if (ondisk
->vol_count
!= count
)
70 if (!uuid_equal(&ondisk
->vol_fsid
, &fsid
, NULL
))
72 if (!uuid_equal(&ondisk
->vol_fstype
, &fstype
, NULL
))
74 if (strcmp(ondisk
->vol_label
, label
))
82 extract_device_name(const char *devpath
)
86 p
= strrchr(devpath
, '/');
98 fstyp_hammer(FILE *fp
, char *label
, size_t size
, const char *devpath
)
100 hammer_volume_ondisk_t ondisk
;
105 ondisk
= read_ondisk(fp
);
108 if (ondisk
->vol_no
!= HAMMER_ROOT_VOLNO
)
110 if (ondisk
->vol_count
!= 1)
112 if (test_ondisk(ondisk
))
116 * fstyp_function in DragonFly takes an additional devpath argument
117 * which doesn't exist in FreeBSD and NetBSD.
120 /* Add device name to help support multiple autofs -media mounts. */
121 p
= extract_device_name(devpath
);
123 snprintf(label
, size
, "%s_%s", ondisk
->vol_label
, p
);
125 strlcpy(label
, ondisk
->vol_label
, size
);
127 strlcpy(label
, ondisk
->vol_label
, size
);
136 test_volume(const char *volpath
)
138 hammer_volume_ondisk_t ondisk
= NULL
;
142 if ((fp
= fopen(volpath
, "r")) == NULL
)
145 ondisk
= read_ondisk(fp
);
148 if (test_ondisk(ondisk
))
151 volno
= ondisk
->vol_no
;
160 __fsvtyp_hammer(const char *blkdevs
, char *label
, size_t size
, int partial
)
162 hammer_volume_ondisk_t ondisk
= NULL
;
164 char *dup
= NULL
, *p
, *volpath
, *rootvolpath
, x
[HAMMER_MAX_VOLUMES
];
165 int i
, volno
, error
= 1;
170 memset(x
, 0, sizeof(x
));
171 dup
= strdup(blkdevs
);
179 if ((p
= strchr(p
, ':')) != NULL
)
181 if ((volno
= test_volume(volpath
)) == -1)
183 if (volno
< 0 || volno
>= HAMMER_MAX_VOLUMES
)
186 if (volno
== HAMMER_ROOT_VOLNO
)
187 rootvolpath
= volpath
;
190 /* If no rootvolpath, proceed only if partial mode with volpath. */
192 volpath
= rootvolpath
;
193 else if (!partial
|| !volpath
)
195 if ((fp
= fopen(volpath
, "r")) == NULL
)
197 ondisk
= read_ondisk(fp
);
206 for (i
= 0; i
< HAMMER_MAX_VOLUMES
; i
++)
209 for (i
= 0; i
< HAMMER_MAX_VOLUMES
; i
++)
212 if (ondisk
->vol_count
!= i
)
214 for (; i
< HAMMER_MAX_VOLUMES
; i
++)
218 /* Add device name to help support multiple autofs -media mounts. */
219 p
= (char*)extract_device_name(volpath
);
221 snprintf(label
, size
, "%s_%s", ondisk
->vol_label
, p
);
223 strlcpy(label
, ondisk
->vol_label
, size
);
234 fsvtyp_hammer(const char *blkdevs
, char *label
, size_t size
)
236 return (__fsvtyp_hammer(blkdevs
, label
, size
, 0));
240 fsvtyp_hammer_partial(const char *blkdevs
, char *label
, size_t size
)
242 return (__fsvtyp_hammer(blkdevs
, label
, size
, 1));