Disk operations for Windows 6-obtain the physical disk NUMBER OF THE SYSTEM

Source: Internet
Author: User
Original Works are allowed to be reprinted. During reprinting, please mark the article in hyperlink form
Original source, author information, and this statement. Otherwise, legal liability will be held. Http://cutebunny.blog.51cto.com/301216/624609

In many cases, we need to know in the program which partition or physical disk the operating system is installed on, and then perform some operations or avoid some operations on it. For example, to avoid deletion of the system disk partition table. This section describes how to obtain the logical Partition Number and physical drive Number of the operating system.

Or code first. /*************************************** **************************************** Function: get the number of disk which the system installed on * input: N/A * output: N/A * return: succeed, disk Number * fail, -1 ************************************** **************************************** /DWORD getsystemdiskphysicalnumber (void) {char syspath [disk_path_len]; char diskletter; DWORD disknumber; DWORD ret = getsystemdirectory (syspath, sizeof (syspath); If (ret = 0) {fprintf (stderr, "getsystemdirectory () error: % LD \ n", getlasterror (); Return (DWORD)-1;} diskletter = syspath [0]; disknumber = getphysicaldrivefrompartitionletter (diskletter ); return disknumber;} code analysis: 1. call getsystemdirectory first
Function to obtain the Windows path. The path stored in syspath is c: \ windows \ system32. 2. Extract the first character of the syspath string to obtain the partition drive letter of the system. 3. Call Section 4 partition based on the Logical Partition Number.

This article is from the "bunny Technology Workshop" blog, please be sure to keep this source http://cutebunny.blog.51cto.com/301216/624609

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.