3

I have a question about dm-crypt.

Here is my situation. I have an encrypted partition mapped (encrypted in virtual device) using the cryptsetup command in Linux. I am opening the mapped virtual device in a c-program using the open() function.

Can i be sure that when i use the fsync() function all information will be written to the encrypted partition or is there some buffer in the dm-crypt driver?

serv-inc
  • 35,772
  • 9
  • 166
  • 188
mediata
  • 65
  • 1
  • 4
  • Is this a question about dm-crypt in general (whether it buffers before writing even after a `sync`), or do you think that using your own program is different from for example a shell command, say, a `touch crypt/file; sync`? – serv-inc Aug 26 '15 at 12:29
  • I use own program on C. But cryptsetup use dm-crypt kernel module to map crypted partition in /dev/mapper/ witch I open into C program with open() and write and read directly. And my question is when i call fsync() into my C program all info witch i write before will be into real crypted partition after fsync() return or is there a way to be into buffer in dm-crypt module. – mediata Aug 26 '15 at 13:48

1 Answers1

1

I could not find much reference on this. Maybe someone can shed more light on this, as I have not grokked the source, but it seems as though a sync writes to disk.

One point is the questions trim-with-lvm-and-dm-crypt where a sync changes the disk content reliably, yet the cached content is only updated after a echo 1 > /proc/sys/vm/drop_caches.

Another is the issue that sync hangs on a suspended device, which indicates that the sync goes directly to the device.

A third is this Gentoo discussion where luksClose is possible reliably after a sync.

A fourth is this UL answer, which says

the rest of the stuff [dm-crypt] is in kernel and pretty heavily used, so it's probably fine

It may still be that all these are wrong, and it can happen that sync does not write directly to the encrypted disk, but it seems unlikely.

Community
  • 1
  • 1
serv-inc
  • 35,772
  • 9
  • 166
  • 188