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

  • SEARCH
  • Home
  • 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 7671363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:02:09+00:00 2026-05-31T16:02:09+00:00

Using the following code, I’m able to successfully open a raw disk on my

  • 0

Using the following code, I’m able to successfully open a raw disk on my machine, but when I get the disk length I get 0 each time…

// Where "Path" is /dev/rdisk1 -- is rdisk1 versus disk1 the proper way to open a raw disk?
Device = open(Path, O_RDWR);
if (Device == -1)
{
    throw xException("Error opening device");
}

And getting size with both of these methods returns 0:

struct stat st;

if (stat(Path, &st) == 0)
    _Length = st.st_size;

/

_Length = (INT64)lseek(Device, 0, SEEK_END);
        lseek(Device, 0, SEEK_SET);

I’m not totally familiar with programming on non-Windows platforms, so please forgive anything that seems odd. My questions here are:

  1. Is this the proper way to open a raw disk under OS X?
  2. What might be causing the disk size to be returned as 0?

The disk in question is an unformatted disk, but for those wanting the info from Disk Utility (with non-important stuff removed):

Name :  ST920217 AS Media
Type :  Disk

Partition Map Scheme :  Unformatted
Disk Identifier      :  disk1
Media Name           :  ST920217 AS Media
Media Type           :  Generic
Writable             :  Yes
Total Capacity       :  20 GB (20,003,880,960 Bytes)
Disk Number          :  1
Partition Number     :  0
  • 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-05-31T16:02:11+00:00Added an answer on May 31, 2026 at 4:02 pm

    After a little bit of searching through ioctl request codes, I found something that actually works.

    #include <sys/disk.h>
    #include <sys/ioctl.h>
    #include <fcntl.h>
    
    int main()
    {
        // Open disk
        uint32_t dev = open("/dev/disk1", O_RDONLY);
    
        if (dev == -1) {
            perror("Failed to open disk");
            return -1;
        }
    
        uint64_t sector_count = 0;
        // Query the number of sectors on the disk
        ioctl(dev, DKIOCGETBLOCKCOUNT, &sector_count);
    
        uint32_t sector_size = 0;
        // Query the size of each sector
        ioctl(dev, DKIOCGETBLOCKSIZE, &sector_size);
    
        uint64_t disk_size = sector_count * sector_size;
        printf("%ld", disk_size);
        return 0;
    }
    

    Something like that should do the trick. I just copied the code I had into that, so I’m not sure if it would compile alright but it should.

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

Sidebar

Related Questions

I using following code and it is successfully uploading files on my local machine.
I'm using following code but cannot return data from MySQL. This is the output:
I open a pop-up window using following code in main.html function openwindow(url) { window.open(url,
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
i am using following code in android to get IMEI number of phone TelephonyManager
I'm using following code to show loading message in JQuery mobile. But the loading
I am using following code to create a list dynamically. It works fine but
i am using following code to make an httpPost call but it is returning
i am using following code to get GPS location. now i want to get
I am using following code, but my progress bar is not displaying in the

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.