Code Monkey home page Code Monkey logo

Comments (4)

deitch avatar deitch commented on August 24, 2024

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.

deitch avatar deitch commented on August 24, 2024

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, &sector_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.

deitch avatar deitch commented on August 24, 2024

@mraerino can you try against this branch and see what you get? https://github.com/diskfs/go-diskfs/tree/pbsize

from go-diskfs.

mraerino avatar mraerino commented on August 24, 2024

works! #107 (review)

from go-diskfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.