Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Nov 2008 20:29:48 -0800
From:      "Xin LI" <delphij@gmail.com>
To:        "Marcel Moolenaar" <marcel@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r185038 - head/sbin/geom/class/part
Message-ID:  <a78074950811172029ndfdbc83h7c3430addaadfa12@mail.gmail.com>
In-Reply-To: <200811180003.mAI03UKc061998@svn.freebsd.org>
References:  <200811180003.mAI03UKc061998@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Thanks!

On Mon, Nov 17, 2008 at 4:03 PM, Marcel Moolenaar <marcel@freebsd.org> wrote:
> Author: marcel
> Date: Tue Nov 18 00:03:30 2008
> New Revision: 185038
> URL: http://svn.freebsd.org/changeset/base/185038
>
> Log:
>  Pad the bootcode we write to the partition to a multiple of the
>  sector size.
>
>  Submitted by: Alexey Shuvaev <shuvaev@physik.uni-wuerzburg.de>
>  Prompted by:  delphij
>  MFC after:    3 days
>
> Modified:
>  head/sbin/geom/class/part/geom_part.c
>
> Modified: head/sbin/geom/class/part/geom_part.c
> ==============================================================================
> --- head/sbin/geom/class/part/geom_part.c       Tue Nov 18 00:01:16 2008        (r185037)
> +++ head/sbin/geom/class/part/geom_part.c       Tue Nov 18 00:03:30 2008        (r185038)
> @@ -393,6 +393,8 @@ gpart_write_partcode(struct gctl_req *re
>        struct ggeom *gp;
>        struct gprovider *pp;
>        const char *s;
> +       char *buf;
> +       off_t bsize;
>        int error, fd;
>
>        s = gctl_get_ascii(req, "class");
> @@ -428,8 +430,21 @@ gpart_write_partcode(struct gctl_req *re
>                        errx(EXIT_FAILURE, "%s: not enough space", dsf);
>                if (lseek(fd, 0, SEEK_SET) != 0)
>                        err(EXIT_FAILURE, "%s", dsf);
> -               if (write(fd, code, size) != size)
> +
> +               /*
> +                * When writing to a disk device, the write must be
> +                * sector aligned and not write to any partial sectors,
> +                * so round up the buffer size to the next sector and zero it.
> +                */
> +               bsize = (size + pp->lg_sectorsize - 1) /
> +                   pp->lg_sectorsize * pp->lg_sectorsize;
> +               buf = calloc(1, bsize);
> +               if (buf == NULL)
> +                       err(EXIT_FAILURE, "%s", dsf);
> +               bcopy(code, buf, size);
> +               if (write(fd, buf, bsize) != bsize)
>                        err(EXIT_FAILURE, "%s", dsf);
> +               free(buf);
>                close(fd);
>        } else
>                errx(EXIT_FAILURE, "invalid partition index");
>



-- 
Xin LI <delphij@delphij.net> http://www.delphij.net



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a78074950811172029ndfdbc83h7c3430addaadfa12>