Return-Path: lccheung@usc.edu Delivery-Date: Mon Sep 8 22:23:34 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,HTML_MESSAGE autolearn=ham version=3.2.3 Received: from msg-scanner3.usc.edu (msg-scanner3.usc.edu [128.125.137.212]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m895NXDh031672 for ; Mon, 8 Sep 2008 22:23:33 -0700 Received: from msg-mx3.usc.edu ([128.125.137.8]) by msg-scanner3.usc.edu (Sun Java System Messaging Server 6.2-3.04 (built Jul 15 2005)) with ESMTP id <0K6W006WFXRMBTN0@msg-scanner3.usc.edu> for cs551@merlot.usc.edu; Mon, 08 Sep 2008 22:26:33 -0700 (PDT) Received: from wf-out-1314.google.com (wf-out-1314.google.com [209.85.200.168]) by msg-mx3.usc.edu (Postfix) with ESMTP id 6B15E31F88 for ; Mon, 08 Sep 2008 22:26:31 -0700 (PDT) Received: by wf-out-1314.google.com with SMTP id 28so1994044wfa.27 for ; Mon, 08 Sep 2008 22:26:29 -0700 (PDT) Received: by 10.142.229.5 with SMTP id b5mr5600656wfh.50.1220937989792; Mon, 08 Sep 2008 22:26:29 -0700 (PDT) Received: by 10.142.158.11 with HTTP; Mon, 08 Sep 2008 22:26:29 -0700 (PDT) Date: Mon, 08 Sep 2008 22:26:29 -0700 From: Leslie Cheung Subject: Re: Stat(1) for filesize In-reply-to: <64d09c810809081738i2300ffe3t85a88c70c4e08bb2@mail.gmail.com> To: cs551@merlot.usc.edu Message-id: MIME-version: 1.0 Content-type: multipart/alternative; boundary="----=_Part_1162_1596498.1220937989776" References: <200809080153.m881rH8X021678@bourbon.usc.edu> <64d09c810809081731o394df205h3191a75b3a6a0b5d@mail.gmail.com> <64d09c810809081738i2300ffe3t85a88c70c4e08bb2@mail.gmail.com> ------=_Part_1162_1596498.1220937989776 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline In the case you can read the file's metadata but not the file itself, the FSZ request should give you the filesize, while the GET request should fail. In general, if you can open a file (for example, using a text editor), your GET request should succeed. If you can see the filesize using, for example, the "ls" command in a shell, your FSZ request should succeed. --Leslie Someone wrote: > But still the Get req for [removed filename] will fail as we cannot read > the file. So do we only have to printf the filesize for this file as we > cannot get the MD5 or print nothing ? > > > Someone wrote: > >> I think you are talking about the [removed filename] file which doesn't >> even have a read permission for non-root users. But in that case, fopen will >> also fail and we will have to simply use stat() irrespective of whether >> fopen is successful or not. Am i right? >> >> Thanks >> >> >> On Mon, Sep 8, 2008 at 4:19 PM, Leslie Cheung wrote: >> >>> Hi class, >>> >>> fseek and stat are different, in that fseek reads the file while stat >>> does not (stat reads only the file's metadata). If you do not have read >>> permission, fseek would fail, but stat may give you the filesize if you have >>> permission to read the file's metadata. >>> >>> I have just looked at the grading guidelines, and you can't get the >>> filesize using fseek in at least one test case. >>> >>> Regards, >>> Leslie >>> >>> On Sun, Sep 7, 2008 at 6:53 PM, Bill Cheng wrote: >>> >>>> Someone wrote: >>>> >>>> > You have emphasized to use stat(1) for filesize. But I have used >>>> other >>>> > method such as 'Fseek' to know the filesize. Is that ok? Or should I >>>> > change it? >>>> >>>> Anything equivalent would be fine. Please make sure that the >>>> value it gives is correct and that it also works for directories. >>>> -- >>>> Bill Cheng // bill.cheng@usc.edu >>> http://merlot.usc.edu/william/usc/> >>>> >>>> >>> >> > ------=_Part_1162_1596498.1220937989776 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
In the case you can read the file's metadata but not the file itself, the FSZ request should give you the filesize, while the GET request should fail.

In general, if you can open a file (for example, using a text editor), your GET request should succeed. If you can see the filesize using, for example, the "ls" command in a shell, your FSZ request should succeed.


--Leslie

Someone wrote:
But still the Get req for [removed filename] will fail as we cannot read the file. So do we only have to printf the filesize for this file as we cannot get the MD5 or print nothing ?


Someone wrote:
I think you are talking about the [removed filename] file which doesn't even have a read permission for non-root users. But in that case, fopen will also fail and we will have to simply use stat() irrespective of whether fopen is successful or not. Am i right?

Thanks


On Mon, Sep 8, 2008 at 4:19 PM, Leslie Cheung <lccheung@usc.edu> wrote:
Hi class,
 
fseek and stat are different, in that fseek reads the file while stat does not (stat reads only the file's metadata).  If you do not have read permission, fseek would fail, but stat may give you the filesize if you have permission to read the file's metadata.
 
I have just looked at the grading guidelines, and you can't get the filesize using fseek in at least one test case.
 
Regards,
Leslie

On Sun, Sep 7, 2008 at 6:53 PM, Bill Cheng <william@bourbon.usc.edu> wrote:
Someone wrote:

 > You have emphasized to use stat(1) for filesize. But I have used other
 > method such as 'Fseek' to know the filesize. Is that ok? Or should I
 > change it?

Anything equivalent would be fine.  Please make sure that the
value it gives is correct and that it also works for directories.
--
Bill Cheng // bill.cheng@usc.edu <URL:http://merlot.usc.edu/william/usc/>





------=_Part_1162_1596498.1220937989776--