-1

Could anyone please tell me is there any utility to detect if there are any changes in file system of connected USB? or can any one provide sample code for inotify recursively.

  • What does "changes in size" means? AFAIK USB devices have a fixed size. Or do you care about some filesystem on some USB storage device? Please **edit your question** to improve it a lot. – Basile Starynkevitch Apr 02 '18 at 06:06
  • changes in size means , suppose you have 2 GB data on your USB and you deleted 1GB or you have added 1 GB.so is there any way to get notification on this kind of size changes. –  Apr 02 '18 at 06:11
  • 1
    That should go into your question. Don't comment your own question but edit it to improve it. And without any filesystem on the USB storage, your question does not make any sense. And you need to tell which filesystem is used on the key. – Basile Starynkevitch Apr 02 '18 at 06:14
  • Also, I don't really understand what "will notify me" means in your question and what that means to you. I guess you want `incron`, but it is unclear. You are confused and need to understand more about file systems. Your question stays unclear. – Basile Starynkevitch Apr 02 '18 at 06:49
  • Why the `C` and `C++` tags? Why the `linux kernel` tag? Please read [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) and [How to Ask?](https://stackoverflow.com/help/how-to-ask) and provide some [MCVE] – Basile Starynkevitch Apr 02 '18 at 06:53
  • What does "get notified" *precisely* mean in your question? – Basile Starynkevitch Apr 02 '18 at 07:04
  • Explain in a few paragraphs (both here and in your other questions) some motivation and context. Give the real-life problem you want to solve, and the kind of application you want to code (in what industrial domain? Neurosurgery robots is not the same as software embedded in a toy, for example). So **edit your question** (and other ones) to improve it! Your questions smell badly like some [XY problem](http://xyproblem.info/) – Basile Starynkevitch Apr 09 '18 at 07:39

1 Answers1

2

A USB storage device don't contain "files" in the abstract.

But it usually has some file system (often VFAT, but that could be something else; I do format USB keys with ext4 FS sometimes, and I do have a USB disk with both a VFAT and an ext4 file systems on it). That file system should be mounted for you to read or write files on it.

I want a utility which will notify me if there is any change in file system too.

Maybe you want to use inotify(7) facilities on such a mounted file system; the question then is unrelated to USB devices, it is the same for SATA disks and file systems on them; some file systems -notably remote ones like NFS- don't work well with inotify.

Notice that a USB storage could be used as a raw disk as a block device (even if it is usually not used that way). In that case, your question don't makes any sense. Also, a USB storage could have several partitions, so several file systems. You may need to determine which file system and partition you deal with.

You might want to first determine what file system is mounted from your USB storage (e.g. with proc(5), perhaps /proc/mounts...), and later to use inotify to see the changes in it.

If i will add or delete 1 GB from it ,Is there any utility to get notified ?

You add files (thru inode(7)-s) into your VFAT file systems (you can't add 1Gb without files). You could use df(1) to measure its occupation (and you might use watch(1) or crontab(5) to repeat that measure). You could also use inotify thru incron command. You could even format your USB disk with ext4 file system and use disk quota facilities on that.

You might want to read more about operating systems in general. I strongly recommend Operating Systems: Three Easy Pieces. If you are interested in C or C++ system programming on Linux, read some book on that (perhaps the old ALP, or something newer) then read intro(2) and syscalls(2).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Suppose i have two folders in my USB src and dest. If i copy any data from src to dest folder, will i get notifiy ? or if i delete any data from src folder , will i get notify. –  Apr 02 '18 at 06:54
  • 1
    Again, don't comment here. But **improve a lot your question** (you probably need to add several paragraphs in it). We don't even understand why you are asking it. Are you coding some program? Do you want a script? How do you want to be notified? What should happen when you are logged out? BTW, Linux has [directories](https://en.wikipedia.org/wiki/Directory_(computing)) -not folders-. And what is the relation with C or C++ ? Why can't you use [inotify(7)](http://man7.org/linux/man-pages/man7/inotify.7.html) ? – Basile Starynkevitch Apr 02 '18 at 06:56