Index: uuid.admin.inc
===================================================================
--- uuid.admin.inc
+++ uuid.admin.inc
@@ -80,6 +80,23 @@
     '#description' => t('Should UUIDs be created automatically for comments?'),
   );
 
+  if (module_exists('filefield')) {
+    $form['files'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Files settings'),
+    );
+    $form['files']['uuid_automatic_for_filefield'] = array(
+      '#type' => 'radios',
+      '#title' => t('Automatic UUID generation for filefield  files'),
+      '#default_value' => variable_get('uuid_automatic_for_filefield', FALSE),
+      '#options' => array(
+         TRUE => t('Enabled'),
+         FALSE => t('Disabled'),
+      ),
+      '#description' => t('Should UUIDs be created automatically for filefield uploaded files?'),
+    );
+  }
+
   $form['settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Synchronization'),
@@ -155,5 +172,13 @@
     }
   }
 
+  // Files
+  if (variable_get('uuid_automatic_for_files', FALSE)) {
+    $result = db_query("SELECT fid, status FROM {files} files LEFT JOIN {uuid_files} uuid_files ON files.fid = uuid_files.fid WHERE files.status = 1 AND uuid_files.fid IS NULL");
+    while ($item = db_fetch_object($result)) {
+      _uuid_file_insert_uuid($item);
+    }
+  }
+  
   drupal_set_message(t("UUID tables have been updated."));
 }
Index: uuid.install
===================================================================
--- uuid.install
+++ uuid.install
@@ -33,6 +33,7 @@
     'uuid_vocabulary' => uuid_table_schema('vocabulary', 'vid'),
     'uuid_term_data' => uuid_table_schema('term_data', 'tid'),
     'uuid_comments' => uuid_table_schema('comments', 'cid'),
+    'uuid_files' => uuid_table_schema('files', 'fid'),
   );
   // The uuid_node_revisions table requires an additional column (node id) to
   // support revision deletion upon node delete. No index is needed on this
@@ -183,3 +184,14 @@
 
   return $ret;
 }
+
+/**
+ * Create uuid_files table.
+ */
+function uuid_update_6006() {
+  $ret = array();
+
+  db_create_table($ret, 'uuid_files', uuid_table_schema('files', 'fid'));
+
+  return $ret;
+}
Index: uuid.module
===================================================================
--- uuid.module
+++ uuid.module
@@ -63,7 +63,7 @@
       }
       break;
     case 'update':
-      if (isset($node->revision)) {
+      if (!empty($node->revision)) {
         if (isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid) && $node->revision_uuid != $node->loaded_revision_uuid) {
           db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
@@ -249,6 +249,60 @@
 }
 
 /**
+ * Implementation of hook_file_insert().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_insert(&$file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  _uuid_file_insert_uuid($file);
+}
+
+/**
+ * Implementation of hook_file_update().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_update(&$file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  if (!db_result(db_query("SELECT fid FROM {uuid_files} WHERE fid = %d", $file->fid))) {
+    _uuid_file_insert_uuid($file);
+  }
+}
+
+/**
+ * Implementation of hook_file_delete().
+ *
+ * Support for filefields files.
+ */
+function uuid_file_delete($file) {
+  if (!variable_get('uuid_automatic_for_filefield', FALSE)) {
+    return;
+  }
+
+  db_query("DELETE FROM {uuid_files} WHERE fid = %d", $file->fid);
+}
+
+/**
+ * Insert the uid for a ile.
+ */
+function _uuid_file_insert_uuid(&$file) {
+  if ($file->fid && $file->status) {
+    $uuid = uuid_uuid();
+    db_query("INSERT INTO {uuid_files} (fid, uuid) VALUES (%d, '%s')",
+      $file->fid, $uuid);
+
+    $file->uuid = $uuid;
+  }
+}
+
+/**
  * Determines if a UUID is valid.
  */
 function uuid_is_valid($uuid) {
