From da006ec3280e0a6997a3e131d2c5ed5fafa7e3af Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Sat, 10 Mar 2018 21:39:12 -0800 Subject: [PATCH] libstand: Const-ify buffer argument of write(2) analog illumos issue #9198 --- usr/src/boot/Makefile.version | 2 +- usr/src/boot/lib/libstand/cd9660.c | 11 +--------- usr/src/boot/lib/libstand/nfs.c | 12 +---------- usr/src/boot/lib/libstand/nullfs.c | 28 ++++++++++++++++---------- usr/src/boot/lib/libstand/stand.h | 8 ++++---- usr/src/boot/lib/libstand/tftp.c | 10 +-------- usr/src/boot/lib/libstand/ufs.c | 13 ++++++------ usr/src/boot/lib/libstand/write.c | 9 +++------ usr/src/boot/sys/boot/userboot/userboot/host.c | 15 ++------------ usr/src/boot/sys/boot/zfs/zfs.c | 13 +----------- 10 files changed, 38 insertions(+), 83 deletions(-) diff --git a/usr/src/boot/Makefile.version b/usr/src/boot/Makefile.version index af557cc15f..6b7ed90fc4 100644 --- a/usr/src/boot/Makefile.version +++ b/usr/src/boot/Makefile.version @@ -33,4 +33,4 @@ LOADER_VERSION = 1.1 # Use date like formatting here, YYYY.MM.DD.XX, without leading zeroes. # The version is processed from left to right, the version number can only # be increased. -BOOT_VERSION = $(LOADER_VERSION)-2018.2.22.1 +BOOT_VERSION = $(LOADER_VERSION)-2018.2.24.1 diff --git a/usr/src/boot/lib/libstand/cd9660.c b/usr/src/boot/lib/libstand/cd9660.c index 3a76331ab7..c5d9327d4d 100644 --- a/usr/src/boot/lib/libstand/cd9660.c +++ b/usr/src/boot/lib/libstand/cd9660.c @@ -32,7 +32,6 @@ */ #include -__FBSDID("$FreeBSD$"); /* * Stand-alone ISO9660 file reading package. @@ -66,8 +65,6 @@ static int cd9660_open(const char *path, struct open_file *f); static int cd9660_close(struct open_file *f); static int cd9660_read(struct open_file *f, void *buf, size_t size, size_t *resid); -static int cd9660_write(struct open_file *f, void *buf, size_t size, - size_t *resid); static off_t cd9660_seek(struct open_file *f, off_t offset, int where); static int cd9660_stat(struct open_file *f, struct stat *sb); static int cd9660_readdir(struct open_file *f, struct dirent *d); @@ -86,7 +83,7 @@ struct fs_ops cd9660_fsops = { cd9660_open, cd9660_close, cd9660_read, - cd9660_write, + null_write, cd9660_seek, cd9660_stat, cd9660_readdir @@ -556,12 +553,6 @@ again: return (0); } -static int -cd9660_write(struct open_file *f __unused, void *start __unused, size_t size __unused, size_t *resid __unused) -{ - return EROFS; -} - static off_t cd9660_seek(struct open_file *f, off_t offset, int where) { diff --git a/usr/src/boot/lib/libstand/nfs.c b/usr/src/boot/lib/libstand/nfs.c index 27f7f182f4..1cf8f5af0b 100644 --- a/usr/src/boot/lib/libstand/nfs.c +++ b/usr/src/boot/lib/libstand/nfs.c @@ -125,7 +125,6 @@ struct nfs_iodesc { int nfs_open(const char *path, struct open_file *f); static int nfs_close(struct open_file *f); static int nfs_read(struct open_file *f, void *buf, size_t size, size_t *resid); -static int nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid); static off_t nfs_seek(struct open_file *f, off_t offset, int where); static int nfs_stat(struct open_file *f, struct stat *sb); static int nfs_readdir(struct open_file *f, struct dirent *d); @@ -137,7 +136,7 @@ struct fs_ops nfs_fsops = { nfs_open, nfs_close, nfs_read, - nfs_write, + null_write, nfs_seek, nfs_stat, nfs_readdir @@ -704,15 +703,6 @@ ret: return (0); } -/* - * Not implemented. - */ -int -nfs_write(struct open_file *f, void *buf, size_t size, size_t *resid) -{ - return (EROFS); -} - off_t nfs_seek(struct open_file *f, off_t offset, int where) { diff --git a/usr/src/boot/lib/libstand/nullfs.c b/usr/src/boot/lib/libstand/nullfs.c index e4c0b7cbc4..78b0940ba8 100644 --- a/usr/src/boot/lib/libstand/nullfs.c +++ b/usr/src/boot/lib/libstand/nullfs.c @@ -1,6 +1,6 @@ /* $NetBSD: nullfs.c,v 1.1 1996/01/13 22:25:39 leo Exp $ */ -/*- +/* * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * @@ -15,7 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -61,45 +61,51 @@ */ #include -__FBSDID("$FreeBSD$"); #include "stand.h" /* * Null filesystem */ -int null_open (const char *path, struct open_file *f) +int +null_open(const char *path, struct open_file *f) { return EINVAL; } -int null_close(struct open_file *f) +int +null_close(struct open_file *f) { return 0; } -int null_read (struct open_file *f, void *buf, size_t size, size_t *resid) +int +null_read(struct open_file *f, void *buf, size_t size, size_t *resid) { return EIO; } -int null_write (struct open_file *f, void *buf, size_t size, size_t *resid) +int +null_write(struct open_file *f, const void *buf, size_t size, size_t *resid) { - return EIO; + return EROFS; } -off_t null_seek (struct open_file *f, off_t offset, int where) +off_t +null_seek(struct open_file *f, off_t offset, int where) { errno = EIO; return -1; } -int null_stat (struct open_file *f, struct stat *sb) +int +null_stat(struct open_file *f, struct stat *sb) { return EIO; } -int null_readdir(struct open_file *f, struct dirent *d) +int +null_readdir(struct open_file *f, struct dirent *d) { return EIO; } diff --git a/usr/src/boot/lib/libstand/stand.h b/usr/src/boot/lib/libstand/stand.h index 40d4d34bcb..c445d684a1 100644 --- a/usr/src/boot/lib/libstand/stand.h +++ b/usr/src/boot/lib/libstand/stand.h @@ -27,7 +27,7 @@ * From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $ */ -/*- +/* * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. * @@ -104,7 +104,7 @@ struct fs_ops { int (*fo_close)(struct open_file *f); int (*fo_read)(struct open_file *f, void *buf, size_t size, size_t *resid); - int (*fo_write)(struct open_file *f, void *buf, + int (*fo_write)(struct open_file *f, const void *buf, size_t size, size_t *resid); off_t (*fo_seek)(struct open_file *f, off_t offset, int where); int (*fo_stat)(struct open_file *f, struct stat *sb); @@ -282,7 +282,7 @@ extern int open(const char *, int); extern int close(int); extern void closeall(void); extern ssize_t read(int, void *, size_t); -extern ssize_t write(int, void *, size_t); +extern ssize_t write(int, const void *, size_t); extern struct dirent *readdirfd(int); extern void srandom(u_long seed); @@ -369,7 +369,7 @@ extern void nullsys(void); extern int null_open(const char *path, struct open_file *f); extern int null_close(struct open_file *f); extern int null_read(struct open_file *f, void *buf, size_t size, size_t *resid); -extern int null_write(struct open_file *f, void *buf, size_t size, size_t *resid); +extern int null_write(struct open_file *f, const void *buf, size_t size, size_t *resid); extern off_t null_seek(struct open_file *f, off_t offset, int where); extern int null_stat(struct open_file *f, struct stat *sb); extern int null_readdir(struct open_file *f, struct dirent *d); diff --git a/usr/src/boot/lib/libstand/tftp.c b/usr/src/boot/lib/libstand/tftp.c index 39cd1466fe..c1ce0e3b80 100644 --- a/usr/src/boot/lib/libstand/tftp.c +++ b/usr/src/boot/lib/libstand/tftp.c @@ -65,7 +65,6 @@ static int tftp_open(const char *path, struct open_file *f); static int tftp_close(struct open_file *f); static int tftp_parse_oack(struct tftp_handle *h, char *buf, size_t len); static int tftp_read(struct open_file *f, void *buf, size_t size, size_t *resid); -static int tftp_write(struct open_file *f, void *buf, size_t size, size_t *resid); static off_t tftp_seek(struct open_file *f, off_t offset, int where); static int tftp_set_blksize(struct tftp_handle *h, const char *str); static int tftp_stat(struct open_file *f, struct stat *sb); @@ -80,7 +79,7 @@ struct fs_ops tftp_fsops = { tftp_open, tftp_close, tftp_read, - tftp_write, + null_write, tftp_seek, tftp_stat, null_readdir @@ -563,13 +562,6 @@ tftp_close(struct open_file *f) return (0); } -static int -tftp_write(struct open_file *f __unused, void *start __unused, size_t size __unused, - size_t *resid __unused /* out */) -{ - return (EROFS); -} - static int tftp_stat(struct open_file *f, struct stat *sb) { diff --git a/usr/src/boot/lib/libstand/ufs.c b/usr/src/boot/lib/libstand/ufs.c index 893d4e5c63..58a7100562 100644 --- a/usr/src/boot/lib/libstand/ufs.c +++ b/usr/src/boot/lib/libstand/ufs.c @@ -1,6 +1,6 @@ /* $NetBSD: ufs.c,v 1.20 1998/03/01 07:15:39 ross Exp $ */ -/*- +/* * Copyright (c) 2002 Networks Associates Technology, Inc. * All rights reserved. * @@ -83,7 +83,8 @@ #include "string.h" static int ufs_open(const char *path, struct open_file *f); -static int ufs_write(struct open_file *f, void *buf, size_t size, size_t *resid); +static int ufs_write(struct open_file *f, const void *buf, size_t size, + size_t *resid); static int ufs_close(struct open_file *f); static int ufs_read(struct open_file *f, void *buf, size_t size, size_t *resid); static off_t ufs_seek(struct open_file *f, off_t offset, int where); @@ -130,7 +131,7 @@ struct file { static int read_inode(ino_t, struct open_file *); static int block_map(struct open_file *, ufs2_daddr_t, ufs2_daddr_t *); static int buf_read_file(struct open_file *, char **, size_t *); -static int buf_write_file(struct open_file *, char *, size_t *); +static int buf_write_file(struct open_file *, const char *, size_t *); static int search_directory(char *, struct open_file *, ino_t *); /* @@ -300,7 +301,7 @@ block_map(f, file_block, disk_block_p) static int buf_write_file(f, buf_p, size_p) struct open_file *f; - char *buf_p; + const char *buf_p; size_t *size_p; /* out */ { struct file *fp = (struct file *)f->f_fsdata; @@ -758,14 +759,14 @@ ufs_read(f, start, size, resid) static int ufs_write(f, start, size, resid) struct open_file *f; - void *start; + const void *start; size_t size; size_t *resid; /* out */ { struct file *fp = (struct file *)f->f_fsdata; size_t csize; int rc = 0; - char *addr = start; + const char *addr = start; csize = size; while ((size != 0) && (csize != 0)) { diff --git a/usr/src/boot/lib/libstand/write.c b/usr/src/boot/lib/libstand/write.c index 9e02f083f2..96fc5c3457 100644 --- a/usr/src/boot/lib/libstand/write.c +++ b/usr/src/boot/lib/libstand/write.c @@ -61,16 +61,12 @@ */ #include -__FBSDID("$FreeBSD$"); #include #include "stand.h" ssize_t -write(fd, dest, bcount) - int fd; - void *dest; - size_t bcount; +write(int fd, const void *dest, size_t bcount) { struct open_file *f = &files[fd]; size_t resid; @@ -82,7 +78,8 @@ write(fd, dest, bcount) if (f->f_flags & F_RAW) { twiddle(4); errno = (f->f_dev->dv_strategy)(f->f_devdata, F_WRITE, - btodb(f->f_offset), bcount, dest, &resid); + btodb(f->f_offset), bcount, __DECONST(void *, dest), + &resid); if (errno) return (-1); f->f_offset += resid; diff --git a/usr/src/boot/sys/boot/userboot/userboot/host.c b/usr/src/boot/sys/boot/userboot/userboot/host.c index db88c61eca..c15d9d7e41 100644 --- a/usr/src/boot/sys/boot/userboot/userboot/host.c +++ b/usr/src/boot/sys/boot/userboot/userboot/host.c @@ -1,4 +1,4 @@ -/*- +/* * Copyright (c) 2011 Google, Inc. * All rights reserved. * @@ -25,7 +25,6 @@ */ #include -__FBSDID("$FreeBSD$"); /* * Read from the host filesystem @@ -74,16 +73,6 @@ host_read(struct open_file *f, void *start, size_t size, size_t *resid) return (CALLBACK(read, f->f_fsdata, start, size, resid)); } -/* - * Don't be silly - the bootstrap has no business writing anything. - */ -static int -host_write(struct open_file *f, void *start, size_t size, size_t *resid) -{ - - return (EROFS); -} - static off_t host_seek(struct open_file *f, off_t offset, int where) { @@ -183,7 +172,7 @@ struct fs_ops host_fsops = { host_open, host_close, host_read, - host_write, + null_write, host_seek, host_stat, host_readdir diff --git a/usr/src/boot/sys/boot/zfs/zfs.c b/usr/src/boot/sys/boot/zfs/zfs.c index 3dbb955e55..3efd491431 100644 --- a/usr/src/boot/sys/boot/zfs/zfs.c +++ b/usr/src/boot/sys/boot/zfs/zfs.c @@ -50,7 +50,6 @@ #define ZFS_BE_LAST 8 static int zfs_open(const char *path, struct open_file *f); -static int zfs_write(struct open_file *f, void *buf, size_t size, size_t *resid); static int zfs_close(struct open_file *f); static int zfs_read(struct open_file *f, void *buf, size_t size, size_t *resid); static off_t zfs_seek(struct open_file *f, off_t offset, int where); @@ -64,7 +63,7 @@ struct fs_ops zfs_fsops = { zfs_open, zfs_close, zfs_read, - zfs_write, + null_write, zfs_seek, zfs_stat, zfs_readdir @@ -170,16 +169,6 @@ zfs_read(struct open_file *f, void *start, size_t size, size_t *resid /* out */) return (0); } -/* - * Don't be silly - the bootstrap has no business writing anything. - */ -static int -zfs_write(struct open_file *f, void *start, size_t size, size_t *resid /* out */) -{ - - return (EROFS); -} - static off_t zfs_seek(struct open_file *f, off_t offset, int where) { -- 2.11.4.GIT