Check USB Content - c++

I have developed an C++ algorithm, which saves the contents of a USB key in a database. In the Database, as well as save the file names are saved on the USB device info: free blocks and vendors.
So when I put more control keys free blocks.
If the comparison were to change, the database must be recreated. So if I remove or add files to the USB key, the database is rebuilt from scratch. But when I rename a file, nothing happens.
You can find out the changes without having to check each file in the database?
How can I better control of the entire contents of a USB device? Some help!
Thanks!
P.s.: I used ioctl for vendor name and free blocks!!

You could create a hash value from the folder file listing and store that in your DB.
Each time the USB stick is inserted perform the hash calculation of the folder listing and compare to the value stored. If they are different you can assume files have been removed, added or renamed and perform a refresh of your DB.

If you control the OS and the USB key, you can use NTFS. It has a change log feature. This contains an Update Sequence Number (USN). Any change to the key will change the USN. So, you only need to save the old value in your database. If you see a new value, reread the whole file system and update the USN in your database.

Related

clusters the file is occupying [duplicate]

I need to get any information about where the file is physically located on the NTFS disk. Absolute offset, cluster ID..anything.
I need to scan the disk twice, once to get allocated files and one more time I'll need to open partition directly in RAW mode and try to find the rest of data (from deleted files). I need a way to understand that the data I found is the same as the data I've already handled previously as file. As I'm scanning disk in raw mode, the offset of the data I found can be somehow converted to the offset of the file (having information about disk geometry). Is there any way to do this? Other solutions are accepted as well.
Now I'm playing with FSCTL_GET_NTFS_FILE_RECORD, but can't make it work at the moment and I'm not really sure it will help.
UPDATE
I found the following function
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364952(v=vs.85).aspx
It returns structure that contains nFileIndexHigh and nFileIndexLow variables.
Documentation says
The identifier that is stored in the nFileIndexHigh and nFileIndexLow members is called the file ID. Support for file IDs is file system-specific. File IDs are not guaranteed to be unique over time, because file systems are free to reuse them. In some cases, the file ID for a file can change over time.
I don't really understand what is this. I can't connect it to the physical location of file. Is it possible later to extract this file ID from MFT?
UPDATE
Found this:
This identifier and the volume serial number uniquely identify a file. This number can change when the system is restarted or when the file is opened.
This doesn't satisfy my requirements, because I'm going to open the file and the fact that ID might change doesn't make me happy.
Any ideas?
Use the Defragmentation IOCTLs. For example, FSCTL_GET_RETRIEVAL_POINTERS will tell you the extents which contain file data.

how to give a version to mdb files

I am using a .mdb file as a database for a dialog based application. For the each Release I want to give a version to the mdb file if there are more entries added. using C++ i want to read the version and display it in the application.
Can you please tell me if it is possible to give a version to mdb file ?
You can add a table to MDB and track releases there. If MDB should change release number automatically after some data changes, you can use Data Macro (this is for Access 2010+)
You can create a custom property:
db.CreateProperty("VersionId", dbText, "1.0.0")
then add this to the database, but there is no way to read this without opening the database file.
There is no easy way to do that and its probably best to do it as a db.property like #Gustav proposed.
If for some reason it is important to have a version information that you can read without opening the file as access file there are still some options:
There is the Windows Shell Property System that I think allows you to add Properties to every File/Folder.
You could change the Creation Date for the file to fit your need.
You could perhaps even read/change the file content itself in a binary stream if you research it thouroughly enough.
and you can of course have an external .txt (or .ver or whatever) file that you update automatically from the db.property whenever you open the db.

OSX- Auto Delete file after x-time

Can we add metadata to unlink/remove a file after x-time automatically. That is system automatically removes that file, if it finds that particular metadata attached with that file
Note- file can be present at any location, and user may move that file anywhere on their system, but based on that metadata file should get deleted(i.e system should call unlink/remove) for that file.
Is there a cocoa/objective-c/c++ api to set such metadata/attributes of a file?
The main point is i am creating an application through which i am providing some trial files to the user, and those files are also usable by other application which recognises them. After trial expiry, i want to delete those files, but user can always move my files to a different location and use them forever, how to protect those files from permanent use?
No, there is no built-in mechanism to auto-delete a file based on some metadata.
You could add the feature yourself, with an accompanying agent that would trawl for files with the metadata and delete them when the time came.
If you are doing this for good housekeeping you can follow #Petesh answer.
If you are doing this because you really want those files gone then no. The user could move the file to a USB stick and remove it, or edit the metadata, etc.
Your earlier question "Completely restricting all types of access to a folder" seems to addressing the same issue and the suggestions are the same as given there - use encryption or implement your own file system.
E.g. have a special "trial file" format which is the same as the ordinary format - which is readable by other apps - but encrypted and includes an expiry date. Your app then decrypts the file, checks the date, and either does its thing or reports to the user the file is out of date.
The system isn't unbreakable, but its a reasonable barrier - easy for you to do, too hard for the average user to break.

How to find folder changes without touching the files in that directory (Using Windows and C++)

Well I am stuck with this, and I have a few questions:
How will you check whether the folder has been modified without touching the files?
"Last Modified" changes when a file is created/deleted, when a subfolder is created/deleted, but doesn't change when a file is modified (For example, when its size changes).
If a file size changes then folder size will also vary, but there is no API to find the folder size in Windows without touching the file.
Say I give some values to every folder, now when its size changes will that value change by default? (An expected example may be, its hash value?)
or what will change by default in windows when a folder is modified? (Other than its size.)
Thanks in advance.
If you want to monitor a folder for changes, you can use the api ReadDirectoryChangesW. However, if you want to check it offline then you would need to scan the complete directory & check each file modified date, folder creation date etc. Compare it with the last scan time.
You can stop scanning whenever you find at least one change to save time when scanning.
If your app has administrator's rights then you can find changes in a folder by reading the NTFS change journal.

Debug iCloud key-value data in the cloud

I have been banging my head against the wall trying to figure out how to determine what is actually in the key-value store for a given app. Using the api to detect data seems dubious to me as I am afraid of getting false positives. Also I would have to guess at what else might be there (i.e. from previous versions of the app or whatever). So far as I can tell, the developer test website only shows files in the cloud, and not the key-value store. Does anyone know how to access this data, or where in the filesystem the local .plist file is stored (I assume it is in a .plist anyway)?
I finally found it. There is a circuitous route to get there. ~/Library/SyncedPreferences/com.apple.syncedpreferences.plist has a dictionary entry for each application bundle. Inside that dictionary is the key plistPath. This points to the actual plist file that contains the key-value data for your app (on the local device anyway). This file is stored in your app's container at ~/Library/Containers/<bundleName>/Data/Library/SyncedPreferences and appears to be named <bundleName>.plist. Still don't know how to view what is actually in the cloud, so I guess I will have to trust what is in the local file. :)
I know this question is old but shows up in google search so it may help others.
In case that the device is a simulator the path are as follows:
Directory for application bundle list is:
~/Library/Developer/CoreSimulator/Devices/<Device-ID>/data/Library/SyncedPreferences/com.apple.syncedpreferences.plist
File with key-value data for your app:
~/Library/Developer/CoreSimulator/Devices/<Device-ID>/data/Containers/Data/Application/<App-ID>/Library/SyncedPreferences/<bundleName>.plist