Determine block size for quota on Linux

The limit set on the disk quota in Linux is counted in blocks. However, I did not find a reliable way to determine the block size. The tutorials I found relate to block size as 512 bytes, and sometimes 1024 bytes.

I was embarrassed to read a post on LinuxForum.org , which means block size. Therefore, I tried to find this value in the context of quotas.

I found a "Determine the block size on a hard disk file system for disk quota" review on NixCraft in which the command was suggested:

dumpe2fs /dev/sdXN | grep -i 'Block size' 

or

 blockdev --getbsz /dev/sdXN 

But on my system, these commands returned 4096, and when I checked the size of the real quota size on the same system, I got a block size of 1024 bytes.

Is there a script for determining the size of the quota block on the device, except for creating a file with a known size and checking its use of quotas?

+7
linux scripting quota
source share
1 answer

File system lock and quota lock are potentially different. Quota blocking is set by the BLOCK_SIZE macro defined in <sys/mount.h> (/usr/include/sys/mount.h):

 #ifndef _SYS_MOUNT_H #define _SYS_MOUNT_H 1 #include <features.h> #include <sys/ioctl.h> #define BLOCK_SIZE 1024 #define BLOCK_SIZE_BITS 10 ... 

A file system lock for a given file system is returned by calling statvfs :

 #include <stdio.h> #include <sys/statvfs.h> int main(int argc, char *argv[]) { char *fn; struct statvfs vfs; if (argc > 1) fn = argv[1]; else fn = argv[0]; if (statvfs(fn, &vfs)) { perror("statvfs"); return 1; } printf("(%s) bsize: %lu\n", fn, vfs.f_bsize); return 0; } 

The <sys/quota.h> includes a convenient macro for converting file system blocks to disk quota blocks:

 /* * Convert count of filesystem blocks to diskquota blocks, meant * for filesystems where i_blksize != BLOCK_SIZE */ #define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE) 
+7
source share

All Articles