From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id EABD73858D34 for ; Thu, 2 Jul 2020 09:06:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EABD73858D34 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-aRvh_ODJPlWlSkeCEcb6FQ-1; Thu, 02 Jul 2020 05:06:20 -0400 X-MC-Unique: aRvh_ODJPlWlSkeCEcb6FQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91F67800597; Thu, 2 Jul 2020 09:06:19 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-112-158.ams2.redhat.com [10.36.112.158]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3997419C66; Thu, 2 Jul 2020 09:06:19 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id C8698A80926; Thu, 2 Jul 2020 11:06:17 +0200 (CEST) Date: Thu, 2 Jul 2020 11:06:17 +0200 From: Corinna Vinschen To: newlib@sourceware.org Cc: "Richard Earnshaw (lists)" Subject: Re: [PATCH v2] Support regular file type in _swistat for ARM Message-ID: <20200702090617.GU3499@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org, "Richard Earnshaw (lists)" References: <2E6FEF23-0F1D-42A1-B0CF-09307A2E08A0@arm.com> MIME-Version: 1.0 In-Reply-To: <2E6FEF23-0F1D-42A1-B0CF-09307A2E08A0@arm.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jul 2020 09:06:24 -0000 CC'ing Richard. On Jun 23 10:30, Joe Ramsay wrote: > Hi! > > Previously, the implementation of _swistat() for ARM assumed all files > to be of type character device. This change adds support for stat-ing > regular files. Tested with arm-none-eabi > --- > libgloss/arm/syscalls.c | 44 +++++++++++++++++++----------- > newlib/libc/sys/arm/syscalls.c | 61 ++++++++++++++++++++++++++++++++++++------ > 2 files changed, 82 insertions(+), 23 deletions(-) > > diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c > index fc394f9..652301c 100644 > --- a/libgloss/arm/syscalls.c > +++ b/libgloss/arm/syscalls.c > @@ -59,6 +59,7 @@ struct fdent > }; > #define MAX_OPEN_FILES 20 > +#define DEFAULT_BLOCK_SIZE 1024 > /* User file descriptors (fd) are integer indexes into > the openfiles[] array. Error checking is done by using > @@ -728,33 +729,46 @@ _sbrk (ptrdiff_t incr) > int > _swistat (int fd, struct stat * st) > { > - struct fdent *pfd; > - int res; > - > - pfd = findslot (fd); > + struct fdent *pfd = findslot (fd); > if (pfd == NULL) > { > errno = EBADF; > return -1; > } > - /* Always assume a character device, > - with 1024 byte blocks. */ > - st->st_mode |= S_IFCHR; > - st->st_blksize = 1024; > + int isCharDevice; > #ifdef ARM_RDI_MONITOR > - res = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &pfd->handle)); > + isCharDevice = checkerror (do_AngelSWI (AngelSWI_Reason_IsTTY, &pfd->handle)); > #else > asm ("mov r0, %2; swi %a1; mov %0, r0" > - : "=r" (res) > + : "=r" (isCharDevice) > + : "i" (SWI_IsTTY), "r" (pfd->handle) > + : "r0"); > + checkerror(isCharDevice); > +#endif > + > + int flen; > +#ifdef ARM_RDI_MONITOR > + flen = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &pfd->handle)); > +#else > + asm ("mov r0, %2; swi %a1; mov %0, r0" > + : "=r" (flen) > : "i" (SWI_Flen), "r" (pfd->handle) > : "r0"); > - checkerror (res); > + checkerror(flen); > #endif > - if (res == -1) > - return -1; > - /* Return the file size. */ > - st->st_size = res; > + > + st->st_size = flen; > + st->st_blksize = DEFAULT_BLOCK_SIZE; > + > + if (isCharDevice) > + st->st_mode |= S_IFCHR; > + else > + { > + st->st_mode |= S_IFREG; > + st->st_blocks = (flen + DEFAULT_BLOCK_SIZE - 1) / DEFAULT_BLOCK_SIZE; > + } > + > return 0; > } > diff --git a/newlib/libc/sys/arm/syscalls.c b/newlib/libc/sys/arm/syscalls.c > index 1f72229..5156f1a 100644 > --- a/newlib/libc/sys/arm/syscalls.c > +++ b/newlib/libc/sys/arm/syscalls.c > @@ -28,6 +28,7 @@ int _unlink (const char *); > int _link (const char *, const char *); > int _stat (const char *, struct stat *); > int _fstat (int, struct stat *); > +int _swistat (int fd, struct stat * st); > void * _sbrk (ptrdiff_t); > pid_t _getpid (void); > int _kill (int, int); > @@ -84,6 +85,8 @@ poslog; > #define MAX_OPEN_FILES 20 > static poslog openfiles [MAX_OPEN_FILES]; > +#define DEFAULT_BLOCK_SIZE 1024 > + > static int > findslot (int fh) > { > @@ -543,33 +546,75 @@ _sbrk (ptrdiff_t incr) > return (void *) prev_heap_end; > } > +int > +_swistat (int fd, struct stat * st) > +{ > + struct fdent *pfd = findslot (fd); > + if (pfd == NULL) > + { > + errno = EBADF; > + return -1; > + } > + > + int isCharDevice; > +#ifdef ARM_RDI_MONITOR > + isCharDevice = checkerror (do_AngelSWI (AngelSWI_Reason_IsTTY, &pfd->handle)); > +#else > + asm ("mov r0, %2; swi %a1; mov %0, r0" > + : "=r" (isCharDevice) > + : "i" (SWI_IsTTY), "r" (pfd->handle) > + : "r0"); > + checkerror(isCharDevice); > +#endif > + > + int flen; > +#ifdef ARM_RDI_MONITOR > + flen = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &pfd->handle)); > +#else > + asm ("mov r0, %2; swi %a1; mov %0, r0" > + : "=r" (flen) > + : "i" (SWI_Flen), "r" (pfd->handle) > + : "r0"); > + checkerror(flen); > +#endif > + > + st->st_size = flen; > + st->st_blksize = DEFAULT_BLOCK_SIZE; > + > + if (isCharDevice) > + st->st_mode |= S_IFCHR; > + else > + { > + st->st_mode |= S_IFREG; > + st->st_blocks = (flen + DEFAULT_BLOCK_SIZE - 1) / DEFAULT_BLOCK_SIZE; > + } > + > + return 0; > +} > + > extern void memset (struct stat *, int, unsigned int); > int __attribute__((weak)) > _fstat (int file, struct stat * st) > { > memset (st, 0, sizeof (* st)); > - st->st_mode = S_IFCHR; > - st->st_blksize = 1024; > - return 0; > - file = file; > + return _swistat (file, st); > } > int __attribute__((weak)) > _stat (const char *fname, struct stat *st) > { > int file; > - > + memset (st, 0, sizeof (* st)); > /* The best we can do is try to open the file readonly. If it exists, > then we can guess a few things about it. */ > if ((file = _open (fname, O_RDONLY)) < 0) > return -1; > - memset (st, 0, sizeof (* st)); > st->st_mode = S_IFREG | S_IREAD; > - st->st_blksize = 1024; > + res = _swistat (file, st); > _swiclose (file); /* Not interested in the error. */ > - return 0; > + return res; > } > int __attribute__((weak)) > -- > 2.7.4 > -- Corinna Vinschen Cygwin Maintainer Red Hat