make_test_disk.py 718 B

12345678910111213141516171819
  1. # Copyright (c) 2017 Alison Chaiken
  2. #
  3. # SPDX-License-Identifier: GPL-2.0
  4. #
  5. # Create a block device for testing of 'gpt' and 'part' commands.
  6. import os
  7. def makeDisk():
  8. if (os.path.exists("testdisk.raw")):
  9. os.remove("testdisk.raw")
  10. fd = os.open("testdisk.raw", os.O_RDWR|os.O_CREAT )
  11. os.ftruncate(fd, 4194304)
  12. os.close(fd)
  13. os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "-U",
  14. "375a56f7-d6c9-4e81-b5f0-09d41ca89efe", "testdisk.raw")
  15. os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "--new=1:2048:2560", "testdisk.raw")
  16. os.spawnl(os.P_WAIT, "/sbin/sgdisk", "sgdisk", "--new=2:4096:4608", "testdisk.raw")
  17. os.spawnl(os.P_WAIT, "/sbin/gdisk", "sgdisk", "-l", "testdisk.raw")