From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by sourceware.org (Postfix) with ESMTP id 7BF07385DC14 for ; Thu, 4 Jun 2020 18:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7BF07385DC14 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-305-NzssNr86MG2Bd_m-ZKvCnA-1; Thu, 04 Jun 2020 14:41:49 -0400 X-MC-Unique: NzssNr86MG2Bd_m-ZKvCnA-1 Received: by mail-pg1-f199.google.com with SMTP id p4so5706761pgf.10 for ; Thu, 04 Jun 2020 11:41:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DUQlCBZeFfp++yTXbaH3VyLe7lFpUa5ScOjlVpUzKts=; b=r4Ce0hsbX+TfJGP4sldLghQkk7cIHmk3RTnApsifuPKQ3Oqyp6Ikp0YbKFCXr8OHqN CROJ48XcTO+zyA/hFmp/EXhU5fG0svoC9ZXcnou+fPqj2BsEXt7NQVoP77/z8T1q9ejx Ck4Z1sODhCQWazzXQF6iornDq/PkogAwe8oMdTNtSLlVasjRyfda2rAXrH+ckOLPNGBk sqz260DaN4KperkWC6qXVZh/ZQGuoIPe/Dkh1616h59B/C5D7CEygH+MliK6gQhT436H HcRp4mCJLNf/BhLAw0F58ZemfH20IT1fAw61dmifeC0Nsuq2/S+mrLPTakgtQ1IxJxni yCKw== X-Gm-Message-State: AOAM533awezWItNMiqyIZ8OXuUSFBW/B10QQaN7VR1/HiKbNd5j1dQeJ KleqZVMVmqvTd16NcpvSplo24oFTF7YUb12QTCzLUl7BtPbEwbdxGu57bD4obZQbQlFpPrGJLAs SChVVCnUK6oVNF+JLc/jbFsD7yQhSrnY= X-Received: by 2002:a17:90a:1a17:: with SMTP id 23mr7200867pjk.95.1591296107988; Thu, 04 Jun 2020 11:41:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD7OtznvSF2OJ4RM+h6wxPVW27unGO0YIdmEeCK1h+bc+d5Px/auQYL/V1C2PXAK35Im7YQbpatk1nxMKEf7U= X-Received: by 2002:a17:90a:1a17:: with SMTP id 23mr7200853pjk.95.1591296107737; Thu, 04 Jun 2020 11:41:47 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jeff Johnston Date: Thu, 4 Jun 2020 14:41:36 -0400 Message-ID: Subject: Re: [PATCH] Support regular file type in _swistat for ARM To: Joe Ramsay Cc: "newlib@sourceware.org" , "Richard Earnshaw (lists)" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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, 04 Jun 2020 18:41:52 -0000 cc'ing Richard. On Thu, Jun 4, 2020 at 5:53 AM 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 | 43 +++++++++++++++++++++++++++++-------------- > 1 file changed, 29 insertions(+), 14 deletions(-) > > diff --git a/libgloss/arm/syscalls.c b/libgloss/arm/syscalls.c > index fc394f9..b4bd329 100644 > --- a/libgloss/arm/syscalls.c > +++ b/libgloss/arm/syscalls.c > @@ -728,33 +728,48 @@ _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, flen; > #ifdef ARM_RDI_MONITOR > - res = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &pfd->handle)); > + isCharDevice = checkerror (do_AngelSWI (AngelSWI_Reason_IsTTY, > &pfd->handle)); > + flen = checkerror (do_AngelSWI (AngelSWI_Reason_FLen, &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); > + 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) > + > + if (isCharDevice != 0 && isCharDevice != 1) > + return error(-1); > + > + if (flen == -1) > return -1; > - /* Return the file size. */ > - st->st_size = res; > + > + st->st_size = flen; > + /* Always assume 1024 byte blocks */ > + st->st_blksize = 1024; > + > + if (isCharDevice) > + st->st_mode |= S_IFCHR; > + else > + { > + st->st_mode |= S_IFREG; > + st->st_blocks = (flen + 1023) / 1024; > + } > + > return 0; > } > > -- > 2.7.4 > >