summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/ext4_common.c41
-rw-r--r--fs/ext4/ext4_write.c57
-rw-r--r--fs/fat/fat_write.c31
-rw-r--r--fs/ubifs/super.c1
4 files changed, 77 insertions, 53 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 02da75c084..1c1172163c 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -904,10 +904,8 @@ long int ext4fs_get_new_blk_no(void)
restart:
fs->curr_blkno++;
/* get the blockbitmap index respective to blockno */
- if (fs->blksz != 1024) {
- bg_idx = fs->curr_blkno / blk_per_grp;
- } else {
- bg_idx = fs->curr_blkno / blk_per_grp;
+ bg_idx = fs->curr_blkno / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = fs->curr_blkno % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -1843,16 +1841,20 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
return blknr;
}
-void ext4fs_close(void)
+/**
+ * ext4fs_reinit_global() - Reinitialize values of ext4 write implementation's
+ * global pointers
+ *
+ * This function assures that for a file with the same name but different size
+ * the sequential store on the ext4 filesystem will be correct.
+ *
+ * In this function the global data, responsible for internal representation
+ * of the ext4 data are initialized to the reset state. Without this, during
+ * replacement of the smaller file with the bigger truncation of new file was
+ * performed.
+ */
+void ext4fs_reinit_global(void)
{
- if ((ext4fs_file != NULL) && (ext4fs_root != NULL)) {
- ext4fs_free_node(ext4fs_file, &ext4fs_root->diropen);
- ext4fs_file = NULL;
- }
- if (ext4fs_root != NULL) {
- free(ext4fs_root);
- ext4fs_root = NULL;
- }
if (ext4fs_indir1_block != NULL) {
free(ext4fs_indir1_block);
ext4fs_indir1_block = NULL;
@@ -1872,6 +1874,19 @@ void ext4fs_close(void)
ext4fs_indir3_blkno = -1;
}
}
+void ext4fs_close(void)
+{
+ if ((ext4fs_file != NULL) && (ext4fs_root != NULL)) {
+ ext4fs_free_node(ext4fs_file, &ext4fs_root->diropen);
+ ext4fs_file = NULL;
+ }
+ if (ext4fs_root != NULL) {
+ free(ext4fs_root);
+ ext4fs_root = NULL;
+ }
+
+ ext4fs_reinit_global();
+}
int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
struct ext2fs_node **fnode, int *ftype)
diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index b674b6faeb..c42add9a7e 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -116,10 +116,8 @@ static void delete_single_indirect_block(struct ext2_inode *inode)
if (inode->b.blocks.indir_block != 0) {
debug("SIPB releasing %u\n", inode->b.blocks.indir_block);
blknr = inode->b.blocks.indir_block;
- if (fs->blksz != 1024) {
- bg_idx = blknr / blk_per_grp;
- } else {
- bg_idx = blknr / blk_per_grp;
+ bg_idx = blknr / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = blknr % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -181,11 +179,9 @@ static void delete_double_indirect_block(struct ext2_inode *inode)
break;
debug("DICB releasing %u\n", *di_buffer);
- if (fs->blksz != 1024) {
- bg_idx = (*di_buffer) / blk_per_grp;
- } else {
- bg_idx = (*di_buffer) / blk_per_grp;
- remainder = (*di_buffer) % blk_per_grp;
+ bg_idx = *di_buffer / blk_per_grp;
+ if (fs->blksz == 1024) {
+ remainder = *di_buffer % blk_per_grp;
if (!remainder)
bg_idx--;
}
@@ -213,10 +209,8 @@ static void delete_double_indirect_block(struct ext2_inode *inode)
/* removing the parent double indirect block */
blknr = inode->b.blocks.double_indir_block;
- if (fs->blksz != 1024) {
- bg_idx = blknr / blk_per_grp;
- } else {
- bg_idx = blknr / blk_per_grp;
+ bg_idx = blknr / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = blknr % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -293,12 +287,9 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
for (j = 0; j < fs->blksz / sizeof(int); j++) {
if (*tip_buffer == 0)
break;
- if (fs->blksz != 1024) {
- bg_idx = (*tip_buffer) / blk_per_grp;
- } else {
- bg_idx = (*tip_buffer) / blk_per_grp;
-
- remainder = (*tip_buffer) % blk_per_grp;
+ bg_idx = *tip_buffer / blk_per_grp;
+ if (fs->blksz == 1024) {
+ remainder = *tip_buffer % blk_per_grp;
if (!remainder)
bg_idx--;
}
@@ -336,12 +327,9 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
* removing the grand parent blocks
* which is connected to inode
*/
- if (fs->blksz != 1024) {
- bg_idx = (*tigp_buffer) / blk_per_grp;
- } else {
- bg_idx = (*tigp_buffer) / blk_per_grp;
-
- remainder = (*tigp_buffer) % blk_per_grp;
+ bg_idx = *tigp_buffer / blk_per_grp;
+ if (fs->blksz == 1024) {
+ remainder = *tigp_buffer % blk_per_grp;
if (!remainder)
bg_idx--;
}
@@ -371,10 +359,8 @@ static void delete_triple_indirect_block(struct ext2_inode *inode)
/* removing the grand parent triple indirect block */
blknr = inode->b.blocks.triple_indir_block;
- if (fs->blksz != 1024) {
- bg_idx = blknr / blk_per_grp;
- } else {
- bg_idx = blknr / blk_per_grp;
+ bg_idx = blknr / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = blknr % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -452,10 +438,8 @@ static int ext4fs_delete_file(int inodeno)
for (i = 0; i < no_blocks; i++) {
blknr = read_allocated_block(&(node_inode->inode), i);
- if (fs->blksz != 1024) {
- bg_idx = blknr / blk_per_grp;
- } else {
- bg_idx = blknr / blk_per_grp;
+ bg_idx = blknr / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = blknr % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -499,10 +483,8 @@ static int ext4fs_delete_file(int inodeno)
no_blocks++;
for (i = 0; i < no_blocks; i++) {
blknr = read_allocated_block(&inode, i);
- if (fs->blksz != 1024) {
- bg_idx = blknr / blk_per_grp;
- } else {
- bg_idx = blknr / blk_per_grp;
+ bg_idx = blknr / blk_per_grp;
+ if (fs->blksz == 1024) {
remainder = blknr % blk_per_grp;
if (!remainder)
bg_idx--;
@@ -580,6 +562,7 @@ static int ext4fs_delete_file(int inodeno)
ext4fs_update();
ext4fs_deinit();
+ ext4fs_reinit_global();
if (ext4fs_init() != 0) {
printf("error in File System init\n");
diff --git a/fs/fat/fat_write.c b/fs/fat/fat_write.c
index 9f5e911852..ba7e3aeb0b 100644
--- a/fs/fat/fat_write.c
+++ b/fs/fat/fat_write.c
@@ -139,6 +139,11 @@ static __u32 get_fatent_value(fsdata *mydata, __u32 entry)
__u32 ret = 0x00;
__u16 val1, val2;
+ if (CHECK_CLUST(entry, mydata->fatsize)) {
+ printf("Error: Invalid FAT entry: 0x%08x\n", entry);
+ return ret;
+ }
+
switch (mydata->fatsize) {
case 32:
bufnum = entry / FAT32BUFSIZE;
@@ -881,8 +886,30 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
return dentptr;
}
+ /*
+ * In FAT16/12, the root dir is locate before data area, shows
+ * in following:
+ * -------------------------------------------------------------
+ * | Boot | FAT1 & 2 | Root dir | Data (start from cluster #2) |
+ * -------------------------------------------------------------
+ *
+ * As a result if curclust is in Root dir, it is a negative
+ * number or 0, 1.
+ *
+ */
+ if (mydata->fatsize != 32 && (int)curclust <= 1) {
+ /* Current clust is in root dir, set to next clust */
+ curclust++;
+ if ((int)curclust <= 1)
+ continue; /* continue to find */
+
+ /* Reach the end of root dir */
+ empty_dentptr = dentptr;
+ return NULL;
+ }
+
curclust = get_fatent_value(mydata, dir_curclust);
- if ((curclust >= 0xffffff8) || (curclust >= 0xfff8)) {
+ if (IS_LAST_CLUST(curclust, mydata->fatsize)) {
empty_dentptr = dentptr;
return NULL;
}
@@ -952,7 +979,7 @@ static int do_fat_write(const char *filename, void *buffer,
}
mydata->fatbufnum = -1;
- mydata->fatbuf = malloc(FATBUFSIZE);
+ mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE);
if (mydata->fatbuf == NULL) {
debug("Error: allocating memory\n");
return -1;
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 67f115f2e8..748ab6792d 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -734,7 +734,6 @@ static int mount_ubifs(struct ubifs_info *c)
ubifs_msg("reserved for root: %llu bytes (%llu KiB)",
c->report_rp_size, c->report_rp_size >> 10);
- dbg_msg("compiled on: " __DATE__ " at " __TIME__);
dbg_msg("min. I/O unit size: %d bytes", c->min_io_size);
dbg_msg("LEB size: %d bytes (%d KiB)",
c->leb_size, c->leb_size >> 10);
OpenPOWER on IntegriCloud