Home » U++ Library support » U++ Core » LoadFile("/sys/devices/virtual/thermal/ ...") does not work
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work [message #58302 is a reply to message #58301] |
Wed, 13 April 2022 20:33 |
Tom1
Messages: 1212 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
OK, the problem is here:
bool FileStream::Open(const char *name, dword mode, mode_t tmode) {
Close();
LLOG("Open " << name);
int iomode = mode & ~SHAREMASK;
handle = open(ToSystemCharset(name), iomode == READ ? O_RDONLY :
iomode == CREATE ? O_CREAT|O_RDWR|O_TRUNC :
O_RDWR|O_CREAT,
tmode);
if(handle >= 0) {
struct stat st[1];
fstat(handle, st);
if(!(st->st_mode & S_IFREG) || // not a regular file, e.g. folder - bad things would happen
(mode & NOWRITESHARE) && flock(handle, LOCK_EX|LOCK_NB) < 0) { // lock if not sharing
close(handle);
handle = -1;
return false;
}
int64 fsz = st->st_size;
The 'st->st_size' returned from fstat() above is zero for e.g. "/proc/meminfo". This causes the contents of the file not being read at all. (I tested with a fake length of five bytes and received the five first characters of "/proc/meminfo", so this explains the behavior.)
Best regards,
Tom
More edit: It turns out that files in "/proc" or "/sys" are not really files. Not on disk, but not even in memory. Their contents is generated by the kernel on the fly. So, there is no way to tell their size and so fstat() returns zero. Only way to read them is to just read() them in until EOF.
Maybe they could be read up to the buffer (page) size and if the EOF is encountered, the filesize becomes determined...?
[Updated on: Wed, 13 April 2022 20:46] Report message to a moderator
|
|
|
|
|
LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 06 April 2022 12:29
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Fri, 08 April 2022 16:11
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Tue, 12 April 2022 08:54
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Tue, 12 April 2022 14:46
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 13 April 2022 09:13
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 13 April 2022 14:44
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Wed, 13 April 2022 17:39
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 13 April 2022 18:45
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 13 April 2022 20:33
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Mon, 16 May 2022 10:48
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 09:05
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Wed, 18 May 2022 09:58
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 10:15
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 10:26
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Wed, 18 May 2022 10:29
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 10:36
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: pvictor on Wed, 18 May 2022 10:50
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Wed, 18 May 2022 10:58
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 10:47
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Wed, 18 May 2022 11:04
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Wed, 18 May 2022 11:10
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: mirek on Thu, 19 May 2022 10:33
|
|
|
Re: LoadFile("/sys/devices/virtual/thermal/ ...") does not work
By: Tom1 on Thu, 19 May 2022 11:04
|
Goto Forum:
Current Time: Sun Apr 28 14:06:34 CEST 2024
Total time taken to generate the page: 0.02882 seconds
|