bwalex / tc-play

Free and simple TrueCrypt/VeraCrypt Implementation based on dm-crypt
BSD 2-Clause "Simplified" License
551 stars 56 forks source link

Incorrect volume size when creating volume on disk partition #55

Closed ghost closed 10 years ago

ghost commented 10 years ago

System OS is Debian Testing/Jessie 64-bit. tcplay v1.1 from Debian repository. Disk is 500 GB connected via USB with one partition. tcplay -c on the partition creates an approximately 1.8 GB volume. If any other information would be helpful, please ask. Thanks!

[233238.673671] usb 5-4: New USB device found, idVendor=152d, idProduct=2338 [233238.673680] usb 5-4: New USB device strings: Mfr=1, Product=2, SerialNumber=5 [233238.673686] usb 5-4: Product: USB to ATA/ATAPI Bridge [233238.673691] usb 5-4: Manufacturer: JMicron [233238.675506] usb-storage 5-4:1.0: USB Mass Storage device detected [233238.675971] scsi5 : usb-storage 5-4:1.0 [233239.677001] scsi 5:0:0:0: Direct-Access WDC WD50 00AAKS-00YGA0 1C02 PQ: 0 ANSI: 2 CCS [233239.679531] sd 5:0:0:0: Attached scsi generic sg1 type 0 [233239.680967] sd 5:0:0:0: [sdb] 976773168 512-byte logical blocks: (500 GB/465 GiB) [233239.681890] sd 5:0:0:0: [sdb] Write Protect is off [233239.681900] sd 5:0:0:0: [sdb] Mode Sense: 00 38 00 00 [233239.697456] sdb: sdb1

root@dmz1:~# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes 81 heads, 63 sectors/track, 191411 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000098ec

Device Boot Start End Blocks Id System /dev/sdb1 2048 976773167 488385560 83 Linux

Command (m for help): q

root@dmz1:~# tcplay -c -d /dev/sdb1 -z Passphrase: Repeat passphrase: Summary of actions:

bwalex commented 10 years ago

I'm a bit at a loss here. Can you try with the following patch and tell me what it says?

Oh boy, that makes no sense, my patch. not my day. Here is an updated one:

diff --git i/io.c w/io.c
index a862422..998d9d7 100644
--- i/io.c
+++ w/io.c
@@ -294,6 +294,8 @@ get_disk_info(const char *dev, disksz_t *blocks, size_t *bsize)
    *blocks = (disksz_t)(nbytes / blocksz);
    *bsize = (size_t)(blocksz);

+   printf("dev: %s, nbytes: %ju, blocksz: %d, blocks: %ju\n", dev, nbytes, blocksz, (uint64_t)*blocks);
+
    close(fd);
    return 0;
 }
ghost commented 10 years ago

It appears this bug is not present in the latest sources. I downloaded the .zip from github and compiled it with your printf, and that version does the right thing. I also noticed that tcplay v1.1 from the Debian repo states it will "Completely erase EVERYTHING on /dev/sdb1" when -z is specified; the locally compiled tcplay does not. Closing this bug.

root@dmz1:~/bin# fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes 81 heads, 63 sectors/track, 191411 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000098ec

Device Boot Start End Blocks Id System /dev/sdb1 2048 976773167 488385560 83 Linux root@dmz1:~/bin# ./tcplay -c -d /dev/sdb1 -z dev: /dev/sdb1, nbytes: 500106813440, blocksz: 512, blocks: 976771120 Passphrase: Repeat passphrase: Summary of actions:

root@dmz1:~/bin# /usr/sbin/tcplay -c -d /dev/sdb1 -z Passphrase: Repeat passphrase: Summary of actions: