mirror of
				https://github.com/Zygo/bees.git
				synced 2025-11-03 19:50:34 +01:00 
			
		
		
		
	fs: fix FIEMAP_MAX_OFFSET type silliness in fiemap.h
In fiemap.h the members of struct fiemap are declared as __u64, but the
FIEMAP_MAX_OFFSET macro is an unsigned long long value:
	$ grep FIEMAP_MAX_OFFSET -r /usr/include/
	/usr/include/linux/fiemap.h:#define FIEMAP_MAX_OFFSET   (~0ULL)
	$ grep fe_length -r /usr/include/
	/usr/include/linux/fiemap.h:    __u64 fe_length;   /* length in bytes for this extent */
This results in a type mismatch error on architectures like ppc64le:
	fiemap.cc:31:35: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'long long unsigned int')
	    31 |                 fm.fm_length = min(fm.fm_length, FIEMAP_MAX_OFFSET - fm.fm_start);
	       |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Work around this by copying the macro into a uint64_t constant,
and not using the macro any more.
Fixes: https://github.com/Zygo/bees/issues/194
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
			
			
This commit is contained in:
		@@ -143,8 +143,12 @@ namespace crucible {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	struct Fiemap : public fiemap {
 | 
						struct Fiemap : public fiemap {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// because fiemap.h insists on giving FIEMAP_MAX_OFFSET
 | 
				
			||||||
 | 
							// a different type from the struct fiemap members
 | 
				
			||||||
 | 
							static const uint64_t s_fiemap_max_offset = FIEMAP_MAX_OFFSET;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get entire file
 | 
							// Get entire file
 | 
				
			||||||
		Fiemap(uint64_t start = 0, uint64_t length = FIEMAP_MAX_OFFSET);
 | 
							Fiemap(uint64_t start = 0, uint64_t length = s_fiemap_max_offset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		void do_ioctl(int fd);
 | 
							void do_ioctl(int fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,13 +28,13 @@ main(int argc, char **argv)
 | 
				
			|||||||
		if (argc > 2) { fm.fm_start = stoull(argv[2], nullptr, 0); }
 | 
							if (argc > 2) { fm.fm_start = stoull(argv[2], nullptr, 0); }
 | 
				
			||||||
		if (argc > 3) { fm.fm_length = stoull(argv[3], nullptr, 0); }
 | 
							if (argc > 3) { fm.fm_length = stoull(argv[3], nullptr, 0); }
 | 
				
			||||||
		if (argc > 4) { fm.fm_flags = stoull(argv[4], nullptr, 0); }
 | 
							if (argc > 4) { fm.fm_flags = stoull(argv[4], nullptr, 0); }
 | 
				
			||||||
		fm.fm_length = min(fm.fm_length, FIEMAP_MAX_OFFSET - fm.fm_start);
 | 
							fm.fm_length = min(fm.fm_length, Fiemap::s_fiemap_max_offset - fm.fm_start);
 | 
				
			||||||
		uint64_t stop_at = fm.fm_start + fm.fm_length;
 | 
							uint64_t stop_at = fm.fm_start + fm.fm_length;
 | 
				
			||||||
		uint64_t last_byte = fm.fm_start;
 | 
							uint64_t last_byte = fm.fm_start;
 | 
				
			||||||
		do {
 | 
							do {
 | 
				
			||||||
			fm.do_ioctl(fd);
 | 
								fm.do_ioctl(fd);
 | 
				
			||||||
			// cerr << fm;
 | 
								// cerr << fm;
 | 
				
			||||||
			uint64_t last_logical = FIEMAP_MAX_OFFSET;
 | 
								uint64_t last_logical = Fiemap::s_fiemap_max_offset;
 | 
				
			||||||
			for (auto &extent : fm.m_extents) {
 | 
								for (auto &extent : fm.m_extents) {
 | 
				
			||||||
				if (extent.fe_logical > last_byte) {
 | 
									if (extent.fe_logical > last_byte) {
 | 
				
			||||||
					cout << "Log " << to_hex(last_byte) << ".." << to_hex(extent.fe_logical) << " Hole" << endl;
 | 
										cout << "Log " << to_hex(last_byte) << ".." << to_hex(extent.fe_logical) << " Hole" << endl;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user