ft-lib: add discard()
This commit is contained in:
parent
c1e6adc72c
commit
498057d00e
@ -487,8 +487,6 @@ int dm_load(struct dm_interface *dmi, const char *name,
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
|
||||||
// returns false if control buffer too small.
|
|
||||||
static bool get_status(struct dm_interface *dmi, struct dm_ioctl *ctl,
|
static bool get_status(struct dm_interface *dmi, struct dm_ioctl *ctl,
|
||||||
const char *name, unsigned flags,
|
const char *name, unsigned flags,
|
||||||
int *result)
|
int *result)
|
||||||
@ -611,4 +609,24 @@ int get_dev_size(const char *path, uint64_t *sectors)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int discard(const char *path, uint64_t sector_b, uint64_t sector_e)
|
||||||
|
{
|
||||||
|
int r, fd;
|
||||||
|
uint64_t payload[2];
|
||||||
|
|
||||||
|
fd = open(path, O_RDWR);
|
||||||
|
if (fd < 0) {
|
||||||
|
fprintf(stderr, "couldn't open %s", path);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
payload[0] = sector_b;
|
||||||
|
payload[1] = sector_e;
|
||||||
|
|
||||||
|
r = ioctl(fd, BLKDISCARD, payload);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
@ -44,7 +44,8 @@
|
|||||||
|
|
||||||
message
|
message
|
||||||
|
|
||||||
get-dev-size)
|
get-dev-size
|
||||||
|
discard)
|
||||||
|
|
||||||
(import (chezscheme)
|
(import (chezscheme)
|
||||||
(disk-units)
|
(disk-units)
|
||||||
@ -393,4 +394,10 @@
|
|||||||
(if (zero? r)
|
(if (zero? r)
|
||||||
(sectors result)
|
(sectors result)
|
||||||
(fail (fmt #f "get-dev-size failed: " r))))))
|
(fail (fmt #f "get-dev-size failed: " r))))))
|
||||||
)
|
|
||||||
|
(define (discard dev sb se)
|
||||||
|
(define c-discard
|
||||||
|
(foreign-procedure "discard" (string unsigned-64 unsigned-64) int))
|
||||||
|
(unless (zero? (c-discard dev sb se))
|
||||||
|
(fail (fmt #f "discard ioctl failed"))))
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user