summaryrefslogtreecommitdiff
path: root/fatfs/fat.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2003-08-02 21:33:35 +0000
committerMarcus Brinkmann <marcus@gnu.org>2003-08-02 21:33:35 +0000
commitacdd8445816fb1068728057ec65a8c6dd61bc1f5 (patch)
tree5131bbcb26d2ccc741bc8b477e63539258db7295 /fatfs/fat.c
parent15dc4468532a00874d2e2e6c180f476b76ba7947 (diff)
2003-08-01 Marco Gerards <metgerards@student.han.nl>
* node-create.c: New file. * Makefile (SRCS): Added node-created.c. * dir.c: Include <hurd/fsys.h>. (diskfs_direnter_hard): Initialize a new block with zeros. Enter direntry and setup the virtual inode. Also handle directories correctly. (diskfs_rewrite_hard): Function rewritten. (diskfs_dirempty): Change logic to test if a file was deleted. * fat.c (fat_extend_chain): Unlock spin_lock when returning from function. Set dn->last to 0 when deallocating the complete file. Update dn->last when not deallocating the complete file. Set dn->first to zero when the complete file was deallocated. Also update dn->length_of_chain to the new amount of clusters in the chain. * main.c (diskfs_hard_readonly): Remove global variable.
Diffstat (limited to 'fatfs/fat.c')
-rw-r--r--fatfs/fat.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/fatfs/fat.c b/fatfs/fat.c
index f2f67aa6..86fe908e 100644
--- a/fatfs/fat.c
+++ b/fatfs/fat.c
@@ -385,14 +385,17 @@ fat_extend_chain (struct node *node, cluster_t new_last_cluster, int create)
dn->last = dn->first = *table;
return 0;
}
-
- spin_lock(&dn->chain_extension_lock);
+ spin_lock(&dn->chain_extension_lock);
+
/* If we already have what we need, or we have all clusters that are
available without allocating new ones, go out. */
if (new_last_cluster < dn->length_of_chain
|| (!create && dn->chain_complete))
- return 0;
+ {
+ spin_unlock(&dn->chain_extension_lock);
+ return 0;
+ }
left = new_last_cluster + 1 - dn->length_of_chain;
@@ -517,6 +520,7 @@ fat_truncate_node (struct node *node, cluster_t clusters_to_keep)
/* Deallocate the complete file. */
node->dn->start_cluster = 0;
pos = count = offs = 0;
+ node->dn->last = 0;
}
else
{
@@ -525,6 +529,11 @@ fat_truncate_node (struct node *node, cluster_t clusters_to_keep)
while (count-- > 0)
{
assert (next);
+
+ /* This cluster is now the last cluster in the chain. */
+ if (count == 0)
+ node->dn->last = next;
+
next = next->next;
}
assert (next);
@@ -566,6 +575,11 @@ fat_truncate_node (struct node *node, cluster_t clusters_to_keep)
free (next);
next = next_next;
}
+
+ if (clusters_to_keep == 0)
+ node->dn->first = 0;
+
+ node->dn->length_of_chain = clusters_to_keep;
}