how to TRIM a block on SSD disk?

Go To StackoverFlow.com

5

In a C program, how do I tell the linux kernel to TRIM a block on a SSD disk? I suppose I have to open() the device and fcntl() it something, but what? It needs to be generic (i.e. work with different SSD disks)

Note: there is no ext4 filesystem on the device, just raw data.

2012-04-04 19:04
by Nulik


6

You would send it IOCATADELETE. Something like this:

//header - may already be defined
#define IOCATADELETE _IOW('a', 104, off_t[2])

//code
int fd = open("/dev/abc", O_RDWR | O_DIRECT);
off_t ioarg[2];
ioarg[0] = 0; //block number
ioarg[1] = 0; //size
ioctl(fd, IOCATADELETE, ioarg);
close(fd);
2012-04-04 19:17
by vcsjones
thanks, this is what I neede - Nulik 2012-04-05 21:03
What is that "104"? Is it the number of TRIM command or it consist of multiple numbers - Majid Azimi 2018-01-05 08:15
Ads