473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fread() on a bad disk?

3
Hi all, my program does the following:

mbr = fopen(fullpath, "r");
if (!mbr) {
fprintf(stderr, "VxVM ERROR V-5-3-000: Can't open device %s
\n",
fullpath);
return 0;
}

count = fread(buffer, 1, 512, mbr);
if (count < 512) {
return and print error
}


the problem is when a disk has been pulled from the system, my call to fread() on linux never returns, it just hangs (got this from gdb debugger).

Any ideas???
Apr 28 '07 #1
4 1902
Hi all, my program does the following:

mbr = fopen(fullpath, "r");
if (!mbr) {
fprintf(stderr, "VxVM ERROR V-5-3-000: Can't open device %s
\n",
fullpath);
return 0;
}

count = fread(buffer, 1, 512, mbr);
if (count < 512) {
return and print error
}


the problem is when a disk has been pulled from the system, my call to fread() on linux never returns, it just hangs (got this from gdb debugger).

Any ideas???
Expand|Select|Wrap|Line Numbers
  1. mbr = fopen(fullpath, "r");
  2.         if (!mbr) {
  3.                 fprintf(stderr, "VxVM ERROR V-5-3-000: Can't open device %s
  4. \n",
  5.                         fullpath);
  6.                 return 0;
  7.         }
  8.  
  9.         count = fread(buffer, 1, 512, mbr);
  10.         if (count < 512) {
  11.                   return and print error
  12.         }
  13.  
Remember the code brackets

Why don't you try:

Expand|Select|Wrap|Line Numbers
  1. mbr.read(buffer, 512);
  2.  
Apr 28 '07 #2
annied
3
why mbr.read() as opposed to

read(mbr, buf, sizeof(buf)) ?

will read() solve the problem of hanging? Any idea why?
Apr 28 '07 #3
annied
3
tried using read() instead. Got the same result....hang
Apr 28 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
fread() is part of the C file system which dates to 1972. Back then you didn't have removable disks. fread() expects the disk to be ready and waits until it is.

Being able to pop a disk in or out (Windows Plug-and-Play) required all new code for the file system so that the program could continue if the disk were removed unexpectedly.
Apr 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Alain Lafon | last post by:
Helas, I got something that should be a minor problem, but anyhow it isn't to me right now. A little code fragment: fread(&file_qn, x, 1, fp_q); The corresponding text file looks like...
6
by: Patrice Kadionik | last post by:
Hi all, I want to make a brief comparison between read() and fread() (under a Linux OS). 1. Family read and Co: open, close, read, write, ioctl... 2. Family fread and Co: fopen, fclose,...
2
by: John | last post by:
I have a file open using fopen and am reaing using fread. Does this mean that the OS (linux) already buffers this file? What is the buffer size? Can I change it? Thanks, --j
2
by: joel.washburn | last post by:
I'm looking for some information on why fread calls max out CPU usage on SSL connections in windows. I've tried upgrading PHP (now at 5.1.2) and OpenSSL (now 9.8) but cannot stop fread() from...
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
13
by: 010 010 | last post by:
I found this very odd and maybe someone can explain it to me. I was using fread to scan through a binary file and pull bytes out. In the middle of a while loop, for no reason that i could...
5
by: David Mathog | last post by:
When reading a binary input stream with fread() one can read N bytes in two ways : count=fread(buffer,1,N,fin); /* N bytes at a time */ or count=fread(buffer,N,1,fin); /* 1 buffer at a...
5
by: howa | last post by:
are there any advantage in replacing all fread() operations with file_get_contents() ? i.e. file_get_contents("/usr/local/something.txt") VS $filename = "/usr/local/something.txt";
20
by: ericunfuk | last post by:
If fseek() always clears EOF, is there a way for me to fread() from an offset of a file and still be able to detect EOF?i.e. withouting using fseek(). I also need to seek to an offset in the file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.