Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to TRIM a block on SSD disk?

Tags:

c

linux

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.

like image 744
Nulik Avatar asked Apr 04 '12 19:04

Nulik


1 Answers

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);
like image 139
vcsjones Avatar answered Nov 15 '22 06:11

vcsjones