Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:45:28+00:00 2026-06-17T19:45:28+00:00

I’m currently trying to access a physical hard disk as a stream of binary

  • 0

I’m currently trying to access a physical hard disk as a stream of binary data in C. I’ve mounted an image (.img), and it’s readable from the OS (Win 7).

My C program simply attempts to open the physical drive in read-only binary mode, then read some data from the drive.

However, if I simply read data from the stream without seeking anywhere, all is well, I get back the data that is stored in the drive, and as I’m at offset 0 in the stream, I’m able to read the MBR on the disk.

However, if I try to fseek to any offset from the origin (zero), fseek return -1, indicating that it couldn’t do it.

I’m guessing this might be a permission/ring 3/user level problem with accessing physical disks, and I’m probably going to have to write a driver to get kernel level access to do this, I’m just confused why I can read some data fine from the first sector, but I can’t seek to any other offsets. I’ve included part of the C program I’ve written below.

FILE *disk = fopen("\\\\.\\PhysicalDrive1, "rb+");
if (disk == NULL) {
    **error handle
 }
else { //Opened the drive sucessfully
fread(buffer, 1, 100, disk);
printf("Reading the first byte from buffer, it's:%d\n", buffer[0]);
//This works fine and I can read any byte within the initial buffer
int test = fseek(disk, 100, SEEK_SET);
printf("The value of fseek is:%d\n", test);
//This always returns -1, indicating the seek failed  
fclose(disk);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:45:29+00:00Added an answer on June 17, 2026 at 7:45 pm

    Quote from msdn:

    If successful, fseek returns 0. Otherwise, it returns a nonzero value. On devices incapable of seeking, the return value is undefined. If stream is a null pointer, or if origin is not one of allowed values described below, fseek invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, these functions set errno to EINVAL and return -1.

    Section 7.21.9.2 of the C standard [ISO/IEC 9899:2011] specifies the following behavior for fseek() when opening a binary file in binary mode:

    A binary stream need not meaningfully support fseek calls with a
    whence value of SEEK_END.

    In addition, footnote 268 of Section 7.21.3 has this to say:

    Setting the file position indicator to end-of-file, as with
    fseek(file, 0, SEEK_END), has undefined behavior for a binary stream
    (because of possible trailing null characters) or for any stream with
    state-dependent encoding that does not assuredly end in the initial
    shift state.

    A lot of low-level stuff matters, like sector alignment, file systems,etc. which needs a specific driver program to help navigating through the drives also need to be considered.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.