From 0ba9dfd7ef5e304bd383f65cea2679984649de21 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Mon, 13 Jan 2020 08:27:02 +0100 Subject: [PATCH] common: Include the recordings' size in the listing. The size is only approximate (i.e. multiples of sectors used). --- src/common/logger.rs | 21 ++++++++++++++++++++- test/logger_test.rs | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/common/logger.rs b/src/common/logger.rs index 2ca2e22..1c982af 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -554,6 +554,17 @@ impl<'a> Logger<'a> { continue; } + let mut num_data_sectors = 0; + + for d in 1..NUM_SECTORS { + let wrapped_index = ((index + d) & (NUM_SECTORS - 1)) as usize; + let other_sector_header = &self.sector_header[wrapped_index]; + + if other_sector_header.belongs_to(sector_header.recording_id) { + num_data_sectors += 1; + } + } + let mut date_time_s = [b' '; 19]; if let Some(tm) = Time::from_unix_time(sector_header.start_time) { @@ -561,6 +572,13 @@ impl<'a> Logger<'a> { tm.fmt_time(&mut date_time_s[11..]); } + let recording_size = (num_data_sectors + 1) * (SECTOR_SIZE >> 10); + + let mut recording_size_s = [b'0'; 9]; + let recording_size_s_len = fmt_u32_pad(&mut recording_size_s, + recording_size as u32, + 8, b' '); + let mut recording_id_s = [b'0'; 9]; let recording_id_s_len = fmt_u32_pad(&mut recording_id_s, @@ -568,7 +586,8 @@ impl<'a> Logger<'a> { 8, b' '); tx_buf.write(&date_time_s); - tx_buf.write(b" "); + tx_buf.write(&recording_size_s[0..recording_size_s_len]); + tx_buf.write(b"K"); tx_buf.write(&recording_id_s[0..recording_id_s_len]); tx_buf.write(b"\n"); diff --git a/test/logger_test.rs b/test/logger_test.rs index b110055..cf4984a 100644 --- a/test/logger_test.rs +++ b/test/logger_test.rs @@ -425,7 +425,7 @@ fn list_recordings1() { let num_bytes_read = file.read(&mut listing_raw).unwrap(); let expected_bytes = b"\ -2020-01-07 19:27:30 1\n"; +2020-01-07 19:27:30 4K 1\n"; assert_eq!(String::from_utf8(expected_bytes.to_vec()).unwrap(), String::from_utf8(listing_raw[0..num_bytes_read].to_vec()).unwrap()); @@ -477,7 +477,7 @@ fn list_recording1_multi_sector() { let num_bytes_read = file.read(&mut listing_raw).unwrap(); let expected_bytes = b"\ -2020-01-09 12:11:33 1\n"; +2020-01-09 12:11:33 8K 1\n"; assert_eq!(String::from_utf8(expected_bytes.to_vec()).unwrap(), String::from_utf8(listing_raw[0..num_bytes_read].to_vec()).unwrap()); -- 2.30.2