Comments (4)
The sector sizes are determined here. If you dig in, you can see that it determines the device type (correctly, a block device, when you give it /dev/sr0
), and then it calls getSectorSizes (I linked to the Unix one, since, as far as I can tell, you are running on a Unix-like system):
func getSectorSizes(f *os.File) (int64, int64, error) {
fd := f.Fd()
logicalSectorSize, err := unix.IoctlGetInt(int(fd), blksszGet)
if err != nil {
return 0, 0, fmt.Errorf("Unable to get device logical sector size: %v", err)
}
physicalSectorSize, err := unix.IoctlGetInt(int(fd), blkbszGet)
if err != nil {
return 0, 0, fmt.Errorf("Unable to get device physical sector size: %v", err)
}
return int64(logicalSectorSize), int64(physicalSectorSize), nil
}
I find it interesting that fdisk
returned a different value than the ioctl calls, as I think that fdisk does those ioctl calls. It is worth looking into their source code.
The source for fdisk listing (fdisk -l
) is here
from go-diskfs.
Yup, code starts here:
/*
* Get physical block device size. The BLKPBSZGET is supported since Linux
* 2.6.32. For old kernels is probably the best to assume that physical sector
* size is the same as logical sector size.
*
* Example:
*
* rc = blkdev_get_physector_size(fd, &physec);
* if (rc || physec == 0) {
* rc = blkdev_get_sector_size(fd, &physec);
* if (rc)
* physec = DEFAULT_SECTOR_SIZE;
* }
*/
#ifdef BLKPBSZGET
int blkdev_get_physector_size(int fd, int *sector_size)
{
if (ioctl(fd, BLKPBSZGET, §or_size) >= 0)
return 0;
return -1;
}
#else
int blkdev_get_physector_size(int fd __attribute__((__unused__)), int *sector_size)
{
*sector_size = DEFAULT_SECTOR_SIZE;
return 0;
}
#endif
And the definitions here:
/* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
# ifndef BLKIOMIN
# define BLKIOMIN _IO(0x12,120)
# define BLKIOOPT _IO(0x12,121)
# define BLKALIGNOFF _IO(0x12,122)
# define BLKPBSZGET _IO(0x12,123)
# endif
I wonder if it is being misset on different platforms, because we have it fixed here:
blkbszGet = 0x80081270
It is possible, especially in a virtualized environment (I saw you are running in qemu).
Hmm, oh hold on. Even with a fixed number, I am seeing it as we set it to the value of BLKBSZGET
and not BLKPBSZGET
, which are different values.
Let's start with a branch that sets it to the "right" fixed value for now, then let's see about getting it dynamically determined.
from go-diskfs.
@mraerino can you try against this branch and see what you get? https://github.com/diskfs/go-diskfs/tree/pbsize
from go-diskfs.
works! #107 (review)
from go-diskfs.
Related Issues (20)
- minimal gpt partition size is wrong HOT 3
- Is there a golang util to manage RAID(0, 1, 5 6, 10...)? HOT 2
- Where is the type `PartitionTable` defined? HOT 9
- How to close the disk? HOT 1
- gpt can have size larger than minimum size
- Partitions not created HOT 15
- SectorSizeDefault not declared by package diskfs HOT 3
- Is 0o666 a typo? HOT 1
- Can't seem to read fat32 partition HOT 1
- Any plans for a release version? HOT 3
- Implement standard fs.FS interface and friends HOT 3
- Support status for solaris, aix, freebsd, illumos, netbsd, openbsd and plan9 HOT 3
- Incorrect number of partitions reported for the Ubuntu 22.04.02 Server ISO HOT 4
- corrupt GPT with examples/efi_create.go HOT 10
- Create ISO from existing image files with Rock Ridge enabled still errors on filenames longer than 30 characters HOT 11
- Support to remove files HOT 3
- squashfs: read target of symlinks HOT 5
- squashfs: caching of metadata and fragment blocks HOT 8
- Be able to compile to webassembly wasm HOT 3
- need help with finding resourses HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-diskfs.