Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is FILE_FLAG_BACKUP_SEMANTICS needed to open a directory with CreateFile()?

Tags:

windows

winapi

The documentation for CreateFile() specifies that:

To open a directory using CreateFile, specify the FILE_FLAG_BACKUP_SEMANTICS flag as part of dwFlagsAndAttributes.

What I don't understand is why this flag is needed.

The documented meaning of the flag is:

The file is being opened or created for a backup or restore operation. The system ensures that the calling process overrides file security checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME privileges.

How is this related to directories?

I've been looking for an answer to this for a while now.

like image 620
KillStealKS Avatar asked Oct 16 '25 19:10

KillStealKS


1 Answers

Look at the operations you can perform on a directory handle. They're all backup-related. This isn't Unix, you don't use a directory handle for readdir or openat It's used for BackupRead, BackupWrite, and change notification (which is also something a backup tool wants, to get a consistent snapshot).

like image 108
hobbs Avatar answered Oct 18 '25 12:10

hobbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!