1

I'm currently working on an App to search file from disk. Till now what I have done is searching files by the snapshot.

I'm wondering if I can read the RAW bytes from the disk, instead of getting volumes and searching files with a high-level API directly. What I want to do is extracting partition or volumes from GPT or MBR manually, indexing files with different policies based on different type of file system, hopefully I could speed up the searching much.

I need to know how to read the RAW bytes from the disk, but unfortunately, I still don't know how to take the first step after some researches.

Could you please share me any idea about it, any help will be appreciated.

Thanks.

102errors
  • 43
  • 3

1 Answers1

1

So i am no expert on anything I am saying but I have some ideas here.

  1. On linux / Unix all devices are just files. Yes your hard drive is a file as well as your printer
  2. You could read that file byte by byte or whatever you want to achieve.

If Swift can't do that than use C. You can use Bridging Headers to interact with c code in your swift code.

int fdes = open("/dev/sda1", O_RDONLY);
if (fdes < 0)
    err(1, "/dev/sda1");
... do more ...

For more information on that code I posted here see this post: Reading Hard Disk Sectors in C++ on Linux The code there is C++ but I will be pretty similar to plain c which you need in order to use the Bridging Headers.

mufumade
  • 400
  • 4
  • 16