From owner-dev-commits-src-main@freebsd.org Sun Aug 1 07:11:37 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 55DB7656739; Sun, 1 Aug 2021 07:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gcskd21dFz51lQ; Sun, 1 Aug 2021 07:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2D9AB2796E; Sun, 1 Aug 2021 07:11:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1717Bb3G017408; Sun, 1 Aug 2021 07:11:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1717Bbuv017407; Sun, 1 Aug 2021 07:11:37 GMT (envelope-from git) Date: Sun, 1 Aug 2021 07:11:37 GMT Message-Id: <202108010711.1717Bbuv017407@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Toomas Soome Subject: git: bbb539b83cec - main - loader: cstyle cleanup of libsa/lseek.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tsoome X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bbb539b83ceced2d355893ead5987193737833fd Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Aug 2021 07:11:37 -0000 The branch main has been updated by tsoome: URL: https://cgit.FreeBSD.org/src/commit/?id=bbb539b83ceced2d355893ead5987193737833fd commit bbb539b83ceced2d355893ead5987193737833fd Author: Toomas Soome AuthorDate: 2021-08-01 07:07:32 +0000 Commit: Toomas Soome CommitDate: 2021-08-01 07:11:17 +0000 loader: cstyle cleanup of libsa/lseek.c Clean up lseek.c, no functional changes intended. This is pre-patch for open file list rewrite. MFC after: 1 week --- stand/libsa/lseek.c | 137 ++++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/stand/libsa/lseek.c b/stand/libsa/lseek.c index df2591acd76d..1a39eb31421b 100644 --- a/stand/libsa/lseek.c +++ b/stand/libsa/lseek.c @@ -32,30 +32,30 @@ * SUCH DAMAGE. * * @(#)lseek.c 8.1 (Berkeley) 6/11/93 - * + * * * Copyright (c) 1989, 1990, 1991 Carnegie Mellon University * All Rights Reserved. * * Author: Alessandro Forin - * + * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. - * + * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. - * + * * Carnegie Mellon requests users of this software to return to - * + * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 - * + * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. */ @@ -68,74 +68,75 @@ __FBSDID("$FreeBSD$"); off_t lseek(int fd, off_t offset, int where) { - off_t bufpos, filepos, target; - struct open_file *f = &files[fd]; + off_t bufpos, filepos, target; + struct open_file *f = &files[fd]; - if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) { - errno = EBADF; - return (-1); - } - - if (f->f_flags & F_RAW) { - /* - * On RAW devices, update internal offset. - */ - switch (where) { - case SEEK_SET: - f->f_offset = offset; - break; - case SEEK_CUR: - f->f_offset += offset; - break; - default: - errno = EOFFSET; - return (-1); + if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) { + errno = EBADF; + return (-1); } - return (f->f_offset); - } - /* - * If there is some unconsumed data in the readahead buffer and it - * contains the desired offset, simply adjust the buffer offset and - * length. We don't bother with SEEK_END here, since the code to - * handle it would fail in the same cases where the non-readahead - * code fails (namely, for streams which cannot seek backward and whose - * size isn't known in advance). - */ - if (f->f_ralen != 0 && where != SEEK_END) { - if ((filepos = (f->f_ops->fo_seek)(f, (off_t)0, SEEK_CUR)) == -1) - return (-1); - bufpos = filepos - f->f_ralen; - switch (where) { - case SEEK_SET: - target = offset; - break; - case SEEK_CUR: - target = bufpos + offset; - break; - default: - errno = EINVAL; - return (-1); + if (f->f_flags & F_RAW) { + /* + * On RAW devices, update internal offset. + */ + switch (where) { + case SEEK_SET: + f->f_offset = offset; + break; + case SEEK_CUR: + f->f_offset += offset; + break; + default: + errno = EOFFSET; + return (-1); + } + return (f->f_offset); } - if (bufpos <= target && target < filepos) { - f->f_raoffset += target - bufpos; - f->f_ralen -= target - bufpos; - return (target); + + /* + * If there is some unconsumed data in the readahead buffer and it + * contains the desired offset, simply adjust the buffer offset and + * length. We don't bother with SEEK_END here, since the code to + * handle it would fail in the same cases where the non-readahead + * code fails (namely, for streams which cannot seek backward and whose + * size isn't known in advance). + */ + if (f->f_ralen != 0 && where != SEEK_END) { + filepos = (f->f_ops->fo_seek)(f, 0, SEEK_CUR); + if (filepos == -1) + return (-1); + bufpos = filepos - f->f_ralen; + switch (where) { + case SEEK_SET: + target = offset; + break; + case SEEK_CUR: + target = bufpos + offset; + break; + default: + errno = EINVAL; + return (-1); + } + if (bufpos <= target && target < filepos) { + f->f_raoffset += target - bufpos; + f->f_ralen -= target - bufpos; + return (target); + } } - } - /* - * If this is a relative seek, we need to correct the offset for - * bytes that we have already read but the caller doesn't know - * about. - */ - if (where == SEEK_CUR) - offset -= f->f_ralen; + /* + * If this is a relative seek, we need to correct the offset for + * bytes that we have already read but the caller doesn't know + * about. + */ + if (where == SEEK_CUR) + offset -= f->f_ralen; - /* - * Invalidate the readahead buffer. - */ - f->f_ralen = 0; + /* + * Invalidate the readahead buffer. + */ + f->f_ralen = 0; - return (f->f_ops->fo_seek)(f, offset, where); + return (f->f_ops->fo_seek)(f, offset, where); }