Bash: Determine free space on cd/dvd
From FVue
Contents
Problem
How do I determine — from within bash — the amount of free space on my cd?
Solution
cdrecord dev=/dev/hdc -atip | sed -rn 's/^ ATIP start of lead out: ([0-9]+).*/\1/ p'
Journal
Lots of useful scripts & information at Joergs LinuxPages: - Writing CDs: "don't let the image file to grow bigger than 332500 blocks (each 2048 bytes, makes 680960000 bytes in total)"
Found 2 retrieval commands: cdrecord -toc and cdrecord -atip.
%> sudo cdrecord dev=/dev/hdc -atip Device type : Removable CD-ROM Version : 0 Response Format: 1 Vendor_info : 'SONY ' Identifikation : 'CD-RW CRX100E ' Revision : '1.0j' Device seems to be: Generic mmc CD-RW. Using generic SCSI-3/mmc CD-R/CD-RW driver (mmc_cdr). Driver flags : MMC SWABAUDIO Supported modes: TAO PACKET SAO ATIP start of lead out: 335100 (74:30/00)
%> sudo cdrecord dev=/dev/hdc -toc Device type : Removable CD-ROM Version : 0 Response Format: 1 Vendor_info : 'SONY ' Identifikation : 'CD-RW CRX100E ' Revision : '1.0j' Device seems to be: Generic mmc CD-RW. Using generic SCSI-3/mmc CD-R/CD-RW driver (mmc_cdr). Driver flags : MMC SWABAUDIO Supported modes: TAO PACKET SAO first: 1 last 1 track: 1 lba: 0 ( 0) 00:02:00 adr: 1 control: 4 mode: 2 track:lout lba: 32499 ( 129996) 07:15:24 adr: 1 control: 4 mode: -1
Since I can't find any other solution, maybe I can use the 'atip' number (335100) as an indication for the last possible block?
Yes, it seems I can: CD-Recordable FAQ - section 2: What's an ATIP?
cdrecord dev=/dev/hdc -atip | sed -rn 's/^ ATIP start of lead out: ([0-9]+).*/\1/ p'
Creating multi-session CD's Mini Howto FAQ - Joerg Schilling. This links tells me I need to take into account additional sectors for lead out/in:
session 0: 11400 sectors session 1: 11400 sectors session 2: 6900 sectors : : session n: 6900 sectors (n = max 44 on a 74 min cd)
Advertisement