| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: udf.c,v 1.29 2022/04/26 15:18:08 reinoud Exp $ */ | | 1 | /* $NetBSD: udf.c,v 1.30 2022/05/07 08:54:02 reinoud Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2006, 2008, 2013, 2021, 2022 Reinoud Zandijk | | 4 | * Copyright (c) 2006, 2008, 2013, 2021, 2022 Reinoud Zandijk |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | | 26 | * |
27 | */ | | 27 | */ |
28 | #if HAVE_NBTOOL_CONFIG_H | | 28 | #if HAVE_NBTOOL_CONFIG_H |
29 | #include "nbtool_config.h" | | 29 | #include "nbtool_config.h" |
30 | #endif | | 30 | #endif |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __RCSID("$NetBSD: udf.c,v 1.29 2022/04/26 15:18:08 reinoud Exp $"); | | 33 | __RCSID("$NetBSD: udf.c,v 1.30 2022/05/07 08:54:02 reinoud Exp $"); |
34 | | | 34 | |
35 | #include <stdio.h> | | 35 | #include <stdio.h> |
36 | #include <stdlib.h> | | 36 | #include <stdlib.h> |
37 | #include <string.h> | | 37 | #include <string.h> |
38 | #include <errno.h> | | 38 | #include <errno.h> |
39 | #include <time.h> | | 39 | #include <time.h> |
40 | #include <assert.h> | | 40 | #include <assert.h> |
41 | #include <err.h> | | 41 | #include <err.h> |
42 | #include <unistd.h> | | 42 | #include <unistd.h> |
43 | #include <fcntl.h> | | 43 | #include <fcntl.h> |
44 | #include <math.h> | | 44 | #include <math.h> |
45 | #include <sys/types.h> | | 45 | #include <sys/types.h> |
46 | #include <sys/param.h> | | 46 | #include <sys/param.h> |
| @@ -1120,27 +1120,44 @@ udf_enumerate_and_estimate(const char *d | | | @@ -1120,27 +1120,44 @@ udf_enumerate_and_estimate(const char *d |
1120 | nblk += spareable_blockingnr; /* slack */ | | 1120 | nblk += spareable_blockingnr; /* slack */ |
1121 | } | | 1121 | } |
1122 | | | 1122 | |
1123 | nblk += 256; /* pre-volume space */ | | 1123 | nblk += 256; /* pre-volume space */ |
1124 | nblk += 256; /* post-volume space */ | | 1124 | nblk += 256; /* post-volume space */ |
1125 | nblk += 1024; /* safeguard */ | | 1125 | nblk += 1024; /* safeguard */ |
1126 | | | 1126 | |
1127 | /* try to honour minimum size */ | | 1127 | /* try to honour minimum size */ |
1128 | n = fsopts->minsize / fsopts->sectorsize; | | 1128 | n = fsopts->minsize / fsopts->sectorsize; |
1129 | if (nblk < n) { | | 1129 | if (nblk < n) { |
1130 | stats->ndatablocks += (n - nblk); | | 1130 | stats->ndatablocks += (n - nblk); |
1131 | nblk += n - nblk; | | 1131 | nblk += n - nblk; |
1132 | } | | 1132 | } |
| | | 1133 | |
| | | 1134 | /* keep proposed size a multiple of blockingnr for image creation */ |
| | | 1135 | if (S_ISREG(dev_fd_stat.st_mode)) { |
| | | 1136 | struct mmc_trackinfo ti; |
| | | 1137 | int blockingnr; |
| | | 1138 | int error; |
| | | 1139 | |
| | | 1140 | /* adjust proposed size to be a multiple of the blockingnr */ |
| | | 1141 | udf_update_discinfo(); |
| | | 1142 | ti.tracknr = mmc_discinfo.first_track_last_session; |
| | | 1143 | error = udf_update_trackinfo(&ti); |
| | | 1144 | assert(!error); |
| | | 1145 | blockingnr = udf_get_blockingnr(&ti); |
| | | 1146 | nblk = UDF_ROUNDUP(nblk, blockingnr); |
| | | 1147 | } |
| | | 1148 | |
1133 | proposed_size = (off_t) nblk * fsopts->sectorsize; | | 1149 | proposed_size = (off_t) nblk * fsopts->sectorsize; |
| | | 1150 | |
1134 | /* sanity size */ | | 1151 | /* sanity size */ |
1135 | if (proposed_size < 512*1024) | | 1152 | if (proposed_size < 512*1024) |
1136 | proposed_size = 512*1024; | | 1153 | proposed_size = 512*1024; |
1137 | | | 1154 | |
1138 | if (fsopts->size) { | | 1155 | if (fsopts->size) { |
1139 | if (fsopts->size < proposed_size) | | 1156 | if (fsopts->size < proposed_size) |
1140 | errx(1, "makefs_udf: won't fit on disc!"); | | 1157 | errx(1, "makefs_udf: won't fit on disc!"); |
1141 | } else { | | 1158 | } else { |
1142 | fsopts->size = proposed_size; | | 1159 | fsopts->size = proposed_size; |
1143 | } | | 1160 | } |
1144 | | | 1161 | |
1145 | fsopts->inodes = stats->nfiles + stats->ndirs; | | 1162 | fsopts->inodes = stats->nfiles + stats->ndirs; |
1146 | } | | 1163 | } |