bugGNUstep - Bugs: bug #29920, problem when opening a file in...

Group
 
 

bug #29920: problem when opening a file in /sys using NSString stringWithContentsOfFile

Submitter:  Riccardo Mottola <rmottola>
Submitted:  Wed 19 May 2010 09:59:03 PM UTC
   
 
Category:  Base/Foundation Severity:  3 - Normal
Item Group:  Bug Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 05 Mar 2011 03:14:42 PM UTC, comment #5: 

assumed fixed

Richard Frith-Macdonald <CaS>
Group Member
Sat 29 May 2010 08:07:05 AM UTC, comment #4: 

I changed the code so that it doesn't treat it as an error if a read from a file fails before we have read the expected number of bytes.

Richard Frith-Macdonald <CaS>
Group Member
Mon 24 May 2010 08:48:16 AM UTC, comment #3: 

The error message is surely a bit misleading.

I think it should be possible to read files on synthesized virtual filesystem. I have checked and different Linux installations on diffrent computers share the same "problem". I'd say it is currently a "bug-feature" instead of just an error.

I can try to add additional code to handle this special case. Maybe it is just sensible to remove the check for certain files.

The first question is, however, how to recognize we are treating a special file? Could checking for the first path element to be /sys a possible idea? It is a bit "broad" perhaps?
I don't see a property on the file itself to identify it, however!

Riccardo Mottola <rmottola>
Group Member
Thu 20 May 2010 10:43:34 AM UTC, comment #2: 

Sounds like it's reasonable to not read the file (there's a filesystem error with the operating system reporting the wrong size for the file) ... but the error message is wrong.
It should possible say something like 'file truncated while reading'
or 'not a regular file'.
Or perhaps you want to add extra code to handle special files?

Richard Frith-Macdonald <CaS>
Group Member
Wed 19 May 2010 11:55:21 PM UTC, comment #1: 

Debugging shows that gnustep relies on seeking the file from beginning to the end, determining the filesize first. Then it reads the file, if the sizes to not match, it returns error.


Apparently on these syhnthesized files, the filesize is bogus (even ls -l reports it wrongly to 4096, even if it has 1 byte)

Riccardo Mottola <rmottola>
Group Member
Wed 19 May 2010 09:59:03 PM UTC, original submission:  

File NSData.m: 265. In readContentsOfFile read of file (/sys/class/power_supply/BAT0/present) contents failed - No such file or directory

however the same file can be read using "cat" from the command line and fopen() works just fine on it.

It is not due to the content either, I copied the file with a copy with the same permissions and it works just fine:
-r--r--r-- 1 root root 4096 May 19 23:22 /sys/class/power_supply/BAT0/present
-r--r--r-- 1 root root 2 May 19 23:32 /home/multix/present

the second file reads fine into a string, the first not.

Riccardo Mottola <rmottola>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by CaS (Posted a comment)
  • -email is unavailable- added by rmottola (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-03-05 CaS Open/ClosedIn Test Closed
    2010-05-29 CaS StatusNone Fixed
        Open/ClosedOpen In Test

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code