How to TRIM block an SSD?

In a C program, how can I tell the linux kernel to TRIM a block on an SSD? I suppose I need a open()device and fcntl()something, but what? It must be shared (i.e. work with different SSDs)

Note: on the device there is no ext4 file system, but only raw data.

+5
source share
1 answer

You would send it IOCATADELETE. Something like that:

//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);
+6
source

All Articles