/* * Test program to trigger the precache ioctl */ #include #include #include #include #include #include typedef unsigned long u32; struct ext4_encrypted_metadata { u32 len; char metadata[288]; }; #ifndef EXT4_IOC_GET_ENCRYPTION_METADATA #define EXT4_IOC_GET_ENCRYPTION_METADATA _IOWR('f', 22, struct ext4_encrypted_metadata) #endif #ifndef EXT4_IOC_SET_ENCRYPTION_METADATA #define EXT4_IOC_SET_ENCRYPTION_METADATA _IOR('f', 23, struct ext4_encrypted_metadata) #endif #ifndef EXT4_IOC_GET_ENCRYPTED_FILENAME #define EXT4_IOC_GET_ENCRYPTED_FILENAME _IOWR('f', 24, struct ext4_encrypted_metadata) #endif void print_mdata(const char *s, struct ext4_encrypted_metadata *mdata) { int i; printf("%s len %d: \n", s, mdata->len); for (i = 0; i < mdata->len; i++) printf("%02x ", mdata->metadata[i] & 0xFF); printf("\n"); } int main(int argc, char **argv) { int s_fd, d_fd = -1; int oflags = O_RDONLY; struct ext4_encrypted_metadata f_mdata, fn_mdata; if (argc < 2 || argc > 3) { fprintf(stderr, "Usage: %s source [destination]\n", argv[0]); exit(1); } s_fd = open(argv[1], O_RDONLY); if (s_fd < 0) { perror(argv[1]); exit(1); } if (argc > 2) { d_fd = open(argv[2], O_RDONLY); if (d_fd < 0) { perror(argv[2]); exit(1); } } f_mdata.len = sizeof(f_mdata.metadata); if (ioctl(s_fd, EXT4_IOC_GET_ENCRYPTION_METADATA, &f_mdata)) { perror("EXT4_IOC_GET_ENCRYPTION_METADATA"); f_mdata.len = 0; } else { print_mdata("file", &f_mdata); } fn_mdata.len = sizeof(fn_mdata.metadata); if (ioctl(s_fd, EXT4_IOC_GET_ENCRYPTED_FILENAME, &fn_mdata)) { perror("EXT4_IOC_GET_ENCRYPTED_FILENAME"); } else { print_mdata("filename", &fn_mdata); } if (d_fd >= 0 && f_mdata.len > 0) { if (ioctl(d_fd, EXT4_IOC_SET_ENCRYPTION_METADATA, &f_mdata)) { perror("EXT4_IOC_SET_ENCRYPTION_METADATA"); } } return 0; }