Re: newfs_msdos and DVD-RAM

From: Andriy Gapon <avg_at_freebsd.org>
Date: Fri, 02 Apr 2010 22:31:33 +0300
on 02/04/2010 22:26 Andriy Gapon said the following:
> 
> OK, I did it again.
> I tested the below patch using the scenario described above.
> Could you please review and/or test this patch?
> If you like it and it works, I can commit it.
> Thanks!
> 
> --- a/sbin/newfs_msdos/newfs_msdos.c
> +++ b/sbin/newfs_msdos/newfs_msdos.c
> _at__at_ -427,6 +427,9 _at__at_ main(int argc, char *argv[])
>      if (bpb.bpbBytesPerSec < MINBPS)
>  	errx(1, "bytes/sector (%u) is too small; minimum is %u",
>  	     bpb.bpbBytesPerSec, MINBPS);
> +    bpb.bpbSecPerClust /= (bpb.bpbBytesPerSec / MINBPS);
> +    if (bpb.bpbSecPerClust == 0)
> +	bpb.bpbSecPerClust = 1;
>      if (!(fat = opt_F)) {
>  	if (opt_f)
>  	    fat = 12;
> 

And here is a safer one (in case of a huge sector size > 32KB).
I will appreciate any testing with real media that you might have.

diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c
index 955c3a5..3f2778d 100644
--- a/sbin/newfs_msdos/newfs_msdos.c
+++ b/sbin/newfs_msdos/newfs_msdos.c
_at__at_ -427,6 +427,12 _at__at_ main(int argc, char *argv[])
     if (bpb.bpbBytesPerSec < MINBPS)
 	errx(1, "bytes/sector (%u) is too small; minimum is %u",
 	     bpb.bpbBytesPerSec, MINBPS);
+    bpb.bpbSecPerClust /= (bpb.bpbBytesPerSec / MINBPS);
+    if (bpb.bpbSecPerClust == 0)
+	bpb.bpbSecPerClust = 1;
+    if (bpb.bpbSecPerClust * bpb.bpbBytesPerSec > 32 * 1024)
+	errx(1, "bytes per sector (%u) is greater than 32k",
+	    bpb.bpbSecPerClust * bpb.bpbBytesPerSec);
     if (!(fat = opt_F)) {
 	if (opt_f)
 	    fat = 12;


-- 
Andriy Gapon
Received on Fri Apr 02 2010 - 17:31:37 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:02 UTC