Permalink
Browse files

Fixed #14 All partitions are now backed up. Adjust your black-/whitel…

…ists! Partition numbers are now added to the back of the device identifier.

Also replaced some \ts with four spaces.
  • Loading branch information...
1 parent 4d0702b commit 4e894303a2fe36d35286e7e1d38320d0c3405a90 @TacoSteemers committed Apr 13, 2013
Showing with 150 additions and 134 deletions.
  1. +11 −10 README.md
  2. +1 −1 code/backup.c
  3. +1 −1 code/backup.h
  4. +61 −61 code/bookKeeping.c
  5. +66 −56 code/detection.c
  6. +6 −2 code/detection.h
  7. +1 −0 code/global.h
  8. +3 −3 code/uslist.c
View
@@ -2,8 +2,8 @@ usbud
=====
## USB Storage Back Up Daemon
-The daemon will back up USB storage devices the moment they are plugged in.
-The daemon supports blacklisting and whitelisting. Either list consists of a file that contains one device id on each line. One can use the 'uslist' executable to find the device ids.
+The daemon will back up all mounted partitions on USB storage devices.
+The daemon supports per-partition blacklisting and whitelisting. Either list consists of a file that contains one device id on each line. One can use the 'uslist' executable to find the device ids.
Log output can be found in syslog.
This project is known to work on GNU/Linux systems. usbud depends on the availability of items such as '/sys/block' and '/proc/mounts' and the application 'rsync'.
**Important note: the USB storage back up daemon should not be confused with a 'full' backup solution. It should be used in conjunction with a 'full' backup solution.**
@@ -31,17 +31,18 @@ Please note that re-inserting a device, even in a different slot, does not neces
Here are some examples of identifiers:
- Generic MultiCard Device 00000000000006 USB SD Reader
- InphiCHN Mass Storage Device USB Flash Disk
- Kingston DataTraveler 2.0 899000000000000000000073 DataTraveler 2.0
- Kingston DataTraveler 2.0 899000000000000000000094 DataTraveler 2.0
- Kingston DataTraveler 2.0 8998011620080115142551D9 DataTraveler 2.0
- Generic Mass Storage 0ABE6A52 Flash Disk
- Apple iPod 000A27001CB7AFED iPod
+ Generic MultiCard Device 00000000000006 USB SD Reader1
+ InphiCHN Mass Storage Device USB Flash Disk1
+ Kingston DataTraveler 2.0 899000000000000000000073 DataTraveler 2.01
+ Kingston DataTraveler 2.0 899000000000000000000094 DataTraveler 2.01
+ Kingston DataTraveler 2.0 8998011620080115142551D9 DataTraveler 2.01
+ Generic Mass Storage 0ABE6A52 Flash Disk1
+ Generic Mass Storage 0ABE6A52 Flash Disk2
+ Apple iPod 000A27001CB7AFED iPod1
The first is a card that has been inserted in an 'all-in-one' card reader. This is supported. You may encounter problems when you use several card readers that were created by the same manufacturer. Maybe they would have to be of the same model, before problems occur.
The second is a cheap thumb drive that does not carry any identifying meta data at all. If you plug in a second one that was made by the same manufacturer, the daemon system will become confused. Most likely it will remove the backup that it has for the first drive, and place the backup of the second drive in it's stead.
-The next four items are regular thumb drives that will work quite well.
+The next five items are regular thumb drives that will work quite well. One of them has two partitions on it.
The last item is an iPod shuffle. Not every audio device is supported. To the best of my knowledge, all Creative Zen devices are not and are unlikely to ever be supported, because they use the 'MTP' protocol (Media Transfer Protocol). I have a Zen that I have tested this with. MTP is related to the Picture Transfer Protocol, and as such I'm quite certain that PTP devices are not supported either.
## Notes on device labels and multi-card readers
View
@@ -15,7 +15,7 @@
#include "bookKeeping.h"
#include "backup.h"
-void processDevice(char* mountPoint, char* deviceId)
+void perhapsPerformBackup(char* mountPoint, char* deviceId)
{
int index;
if(checkIfDeviceIsKnown(deviceId)==1)
View
@@ -6,7 +6,7 @@
#ifndef BACKUP_H
#define BACKUP_H
-void processDevice(char *mountPoint, char *deviceId);
+void perhapsPerformBackup(char *mountPoint, char *deviceId);
int needsBackup(char* deviceId);
void createTargetDirectoryString(char* output, char* deviceId);
void doBackup(char *source, char *target);
View
@@ -14,81 +14,81 @@ device* devices[MAXNUMDEVS];
void initializeDeviceBookKeeping(void)
{
- int i = 0;
- for(; i < MAXNUMDEVS; i++)
- {
- devices[i] = malloc(sizeof(device));
- if(!devices[i])
- {
- syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
- exit(EXIT_FAILURE);
- }
- devices[i]->index = i;
- devices[i]->runId = 0;
- devices[i]->id = malloc(sizeof(char) * 256);
- if(!devices[i]->id)
- {
- syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
- exit(EXIT_FAILURE);
- }
- devices[i]->id[0] = '\0';
- }
+ int i = 0;
+ for(; i < MAXNUMDEVS; i++)
+ {
+ devices[i] = malloc(sizeof(device));
+ if(!devices[i])
+ {
+ syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
+ exit(EXIT_FAILURE);
+ }
+ devices[i]->index = i;
+ devices[i]->runId = 0;
+ devices[i]->id = malloc(sizeof(char) * 256);
+ if(!devices[i]->id)
+ {
+ syslog(LOG_ERR, "Exiting with failure: malloc failed during initialization");
+ exit(EXIT_FAILURE);
+ }
+ devices[i]->id[0] = '\0';
+ }
}
void initializeRun(void)
{
- /* Ensure that the previous gCurrentRunId is different
- from the current, and is not equal to zero. */
- gCurrentRunId += 1;
- if(gCurrentRunId > 2)
- {
- gCurrentRunId = 1;
- }
+ /* Ensure that the previous gCurrentRunId is different
+ from the current, and is not equal to zero. */
+ gCurrentRunId += 1;
+ if(gCurrentRunId > 2)
+ {
+ gCurrentRunId = 1;
+ }
}
void finalizeRun(void)
{
- int i = 0;
- /* Here we will remove stale data from bookkeeping */
- for(; i < MAXNUMDEVS; i++)
- {
- if(devices[i]->id[0] == 0)
- continue; /* No data, no need to remove */
- if(devices[i]->runId == gCurrentRunId)
- continue; /* Recent data, no need to remove */
- syslog(LOG_INFO, "Removing stale device \"%s\".", devices[i]->id);
- devices[i]->id[0] = '\0';
- devices[i]->runId = 0;
- }
+ int i = 0;
+ /* Here we will remove stale data from bookkeeping */
+ for(; i < MAXNUMDEVS; i++)
+ {
+ if(devices[i]->id[0] == 0)
+ continue; /* No data, no need to remove */
+ if(devices[i]->runId == gCurrentRunId)
+ continue; /* Recent data, no need to remove */
+ syslog(LOG_INFO, "Removing stale device \"%s\".", devices[i]->id);
+ devices[i]->id[0] = '\0';
+ devices[i]->runId = 0;
+ }
}
int checkIfDeviceIsKnown(char* deviceId)
{
- int i = 0;
- for(; i < MAXNUMDEVS; i++)
- {
- if(strncmp(devices[i]->id, deviceId, strlen(deviceId)) != 0)
- continue; /* Not the same */
- /* This is the same. We will update the runId,
- to show that this device is not stale */
- devices[i]->runId = gCurrentRunId;
- return 1;
- }
- return 0;
+ int i = 0;
+ for(; i < MAXNUMDEVS; i++)
+ {
+ if(strncmp(devices[i]->id, deviceId, strlen(deviceId)) != 0)
+ continue; /* Not the same */
+ /* This is the same. We will update the runId,
+ to show that this device is not stale */
+ devices[i]->runId = gCurrentRunId;
+ return 1;
+ }
+ return 0;
}
int registerDevice(char* deviceId)
{
- int i = 0;
- for(; i < MAXNUMDEVS; i++)
- {
- if(devices[i]->id[0] != '\0')
- continue; /* Not an empty spot */
- memcpy(devices[i]->id, deviceId, strlen(deviceId)+1);
- devices[i]->runId = gCurrentRunId;
- syslog(LOG_INFO, "Device \"%s\" has been registered.", deviceId);
- return i;
- }
- syslog(LOG_INFO, "Device \"%s\" could not be registered. Too many devices have been registered already.", deviceId);
- return -1;
+ int i = 0;
+ for(; i < MAXNUMDEVS; i++)
+ {
+ if(devices[i]->id[0] != '\0')
+ continue; /* Not an empty spot */
+ memcpy(devices[i]->id, deviceId, strlen(deviceId)+1);
+ devices[i]->runId = gCurrentRunId;
+ syslog(LOG_INFO, "Device \"%s\" has been registered.", deviceId);
+ return i;
+ }
+ syslog(LOG_INFO, "Device \"%s\" could not be registered. Too many devices have been registered already.", deviceId);
+ return -1;
}
Oops, something went wrong.

0 comments on commit 4e89430

Please sign in to comment.