|
|
Строка 2: |
Строка 2: |
| === 2020-08 === | | === 2020-08 === |
| | | |
| + | * 2020-08-07, 15:54:09: [https://www.virtualbox.org/ticket/19086 #19086 (rm / rmdir not working correctly in shared folders) – Oracle VM VirtualBox] |
| * 2020-08-05, 12:30:58: [https://stackoverflow.com/questions/4193514/how-to-get-hard-disk-serial-number-using-python/4194146#4194146 linux - How to get hard disk serial number using Python - Stack Overflow] | | * 2020-08-05, 12:30:58: [https://stackoverflow.com/questions/4193514/how-to-get-hard-disk-serial-number-using-python/4194146#4194146 linux - How to get hard disk serial number using Python - Stack Overflow] |
| *: <html><span class="kwd">with</span><span class="pln"> open</span><span class="pun">(</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv</span><span class="pun">[</span><span class="lit">1</span><span class="pun">],</span><span class="pln"> </span><span class="str">"rb"</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">as</span><span class="pln"> fd</span><span class="pun">:</span><span class="pln"> </span><span class="com"># tediously derived from the monster struct defined in <hdreg.h></span><span class="pln"> </span><span class="com"># see comment at end of file to verify</span><span class="pln"> hd_driveid_format_str </span><span class="pun">=</span><span class="pln"> </span><span class="str">"@ 10H 20s 3H 8s 40s 2B H 2B H 4B 6H 2B I 36H I Q 152H"</span><span class="pln"> </span><span class="com"># Also from <hdreg.h></span><span class="pln"> HDIO_GET_IDENTITY </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0x030d</span><span class="pln"> </span><span class="com"># How big a buffer do we need?</span><span class="pln"> sizeof_hd_driveid </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">calcsize</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">)</span><span class="pln"> </span><span class="com"># ensure our format string is the correct size</span><span class="pln"> </span><span class="com"># 512 is extracted using sizeof(struct hd_id) in the c code</span><span class="pln"> </span><span class="kwd">assert</span><span class="pln"> sizeof_hd_driveid </span><span class="pun">==</span><span class="pln"> </span><span class="lit">512</span><span class="pln"> </span><span class="com"># Call native function</span><span class="pln"> buf </span><span class="pun">=</span><span class="pln"> fcntl</span><span class="pun">.</span><span class="pln">ioctl</span><span class="pun">(</span><span class="pln">fd</span><span class="pun">,</span><span class="pln"> HDIO_GET_IDENTITY</span><span class="pun">,</span><span class="pln"> </span><span class="str">" "</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> sizeof_hd_driveid</span><span class="pun">)</span><span class="pln"> fields </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">unpack</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">,</span><span class="pln"> buf</span><span class="pun">)</span><span class="pln"> serial_no </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">10</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln"> model </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">15</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln"> </span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hard Disk Model: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> model</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">print</span><span class="pun">(</span><span class="str">" Serial Number: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> serial_no</span><span class="pun">)</span></html> | | *: <html><span class="kwd">with</span><span class="pln"> open</span><span class="pun">(</span><span class="pln">sys</span><span class="pun">.</span><span class="pln">argv</span><span class="pun">[</span><span class="lit">1</span><span class="pun">],</span><span class="pln"> </span><span class="str">"rb"</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">as</span><span class="pln"> fd</span><span class="pun">:</span><span class="pln"> </span><span class="com"># tediously derived from the monster struct defined in <hdreg.h></span><span class="pln"> </span><span class="com"># see comment at end of file to verify</span><span class="pln"> hd_driveid_format_str </span><span class="pun">=</span><span class="pln"> </span><span class="str">"@ 10H 20s 3H 8s 40s 2B H 2B H 4B 6H 2B I 36H I Q 152H"</span><span class="pln"> </span><span class="com"># Also from <hdreg.h></span><span class="pln"> HDIO_GET_IDENTITY </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0x030d</span><span class="pln"> </span><span class="com"># How big a buffer do we need?</span><span class="pln"> sizeof_hd_driveid </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">calcsize</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">)</span><span class="pln"> </span><span class="com"># ensure our format string is the correct size</span><span class="pln"> </span><span class="com"># 512 is extracted using sizeof(struct hd_id) in the c code</span><span class="pln"> </span><span class="kwd">assert</span><span class="pln"> sizeof_hd_driveid </span><span class="pun">==</span><span class="pln"> </span><span class="lit">512</span><span class="pln"> </span><span class="com"># Call native function</span><span class="pln"> buf </span><span class="pun">=</span><span class="pln"> fcntl</span><span class="pun">.</span><span class="pln">ioctl</span><span class="pun">(</span><span class="pln">fd</span><span class="pun">,</span><span class="pln"> HDIO_GET_IDENTITY</span><span class="pun">,</span><span class="pln"> </span><span class="str">" "</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> sizeof_hd_driveid</span><span class="pun">)</span><span class="pln"> fields </span><span class="pun">=</span><span class="pln"> struct</span><span class="pun">.</span><span class="pln">unpack</span><span class="pun">(</span><span class="pln">hd_driveid_format_str</span><span class="pun">,</span><span class="pln"> buf</span><span class="pun">)</span><span class="pln"> serial_no </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">10</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln"> model </span><span class="pun">=</span><span class="pln"> fields</span><span class="pun">[</span><span class="lit">15</span><span class="pun">].</span><span class="pln">strip</span><span class="pun">()</span><span class="pln"> </span><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hard Disk Model: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> model</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">print</span><span class="pun">(</span><span class="str">" Serial Number: %s"</span><span class="pln"> </span><span class="pun">%</span><span class="pln"> serial_no</span><span class="pun">)</span></html> |