Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f09d4bf9 authored by Vincent Zvikaramba's avatar Vincent Zvikaramba
Browse files

Revert "fs: sdfat: Update to version 2.0.6-lineage"

This reverts commit f32030da.
parent 5e059ae6
Loading
Loading
Loading
Loading
+34 −43
Original line number Diff line number Diff line
@@ -367,7 +367,7 @@ int amap_create(struct super_block *sb, u32 pack_ratio, u32 sect_per_au, u32 hid
	/* data start sector must be a multiple of clu_size */
	if (fsi->data_start_sector & (fsi->sect_per_clus - 1)) {
		sdfat_msg(sb, KERN_ERR,
			"misaligned data area (start sect : %llu, "
			"misaligned data area (start sect : %u, "
			"sect_per_clus : %u) "
			"please re-format for performance.",
			fsi->data_start_sector, fsi->sect_per_clus);
@@ -882,7 +882,7 @@ ret_new_cold:
}

/* Put and update target AU */
void amap_put_target_au(AMAP_T *amap, TARGET_AU_T *cur, unsigned int num_allocated)
void amap_put_target_au(AMAP_T *amap, TARGET_AU_T *cur, int num_allocated)
{
	/* Update AMAP info vars. */
	if (num_allocated > 0 &&
@@ -973,33 +973,37 @@ static inline int amap_skip_cluster(struct super_block *sb, TARGET_AU_T *cur, in


/* AMAP-based allocation function for FAT32 */
s32 amap_fat_alloc_cluster(struct super_block *sb, u32 num_alloc, CHAIN_T *p_chain, s32 dest)
s32 amap_fat_alloc_cluster(struct super_block *sb, s32 num_alloc, CHAIN_T *p_chain, int dest)
{
	AMAP_T *amap = SDFAT_SB(sb)->fsi.amap;
	TARGET_AU_T *cur = NULL;
	AU_INFO_T *target_au = NULL;				/* Allocation target AU */
	s32 ret = -ENOSPC;
	u32 last_clu = CLUS_EOF, read_clu;
	u32 new_clu, total_cnt;
	u32 num_allocated = 0, num_allocated_each = 0;
	s32 new_clu; // Max. 2G 개의 clusters
	s32 num_allocated = 0, num_allocated_each = 0;
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	BUG_ON(!amap);
	BUG_ON(IS_CLUS_EOF(fsi->used_clusters));

	total_cnt = fsi->num_clusters - CLUS_BASE;
	p_chain->dir = CLUS_EOF;

	if ((fsi->used_clusters + num_alloc) > (fsi->num_clusters - CLUS_BASE)) {
		/* Reserved count management error
		 * or called by dir. management function on fully filled disk
		 */
		num_alloc = fsi->num_clusters - fsi->used_clusters - CLUS_BASE;

	if (unlikely(total_cnt < fsi->used_clusters)) {
		if (unlikely(num_alloc < 0)) {
			sdfat_fs_error_ratelimit(sb,
				"AMAP(%s): invalid used clusters(t:%u,u:%u)\n",
				__func__, total_cnt, fsi->used_clusters);
				__func__, fsi->num_clusters, fsi->used_clusters);
			return -EIO;
		}

	if (num_alloc > total_cnt - fsi->used_clusters)
		return -ENOSPC;

	p_chain->dir = CLUS_EOF;
		if (!num_alloc)
			return 0;
	}

	set_sb_dirty(sb);

@@ -1011,15 +1015,13 @@ retry_alloc:
	if (unlikely(!cur)) {
		// There is no available AU (only ignored-AU are left)
		sdfat_msg(sb, KERN_ERR, "AMAP Allocator: no avaialble AU.");
		goto error;
		return 0;
	}

	/* If there are clusters to skip */
	if (cur->clu_to_skip > 0) {
		if (amap_skip_cluster(sb, &amap->cur_cold, cur->clu_to_skip)) {
			ret = -EIO;
			goto error;
		}
		if (amap_skip_cluster(sb, &amap->cur_cold, cur->clu_to_skip))
			return -EIO;
		cur->clu_to_skip = 0;
	}

@@ -1039,31 +1041,24 @@ retry_alloc:
	do {
		/* Allocate at the target AU */
		if ((new_clu >= CLUS_BASE) && (new_clu < fsi->num_clusters)) {
			if (fat_ent_get(sb, new_clu, &read_clu)) {
			if (fat_ent_get(sb, new_clu, &read_clu))
				// spin_unlock(&amap->amap_lock);
				ret = -EIO;
				goto error;
			}
				return -EIO;	// goto err_and_return

			if (IS_CLUS_FREE(read_clu)) {
				BUG_ON(GET_AU(amap, i_AU_of_CLU(amap, new_clu)) != target_au);

				/* Free cluster found */
				if (fat_ent_set(sb, new_clu, CLUS_EOF)) {
					ret = -EIO;
					goto error;
				}
				if (fat_ent_set(sb, new_clu, CLUS_EOF))
					return -EIO;

				num_allocated_each++;

				if (IS_CLUS_EOF(p_chain->dir)) {
				if (IS_CLUS_EOF(p_chain->dir))
					p_chain->dir = new_clu;
				} else {
					if (fat_ent_set(sb, last_clu, new_clu)) {
						ret = -EIO;
						goto error;
					}
				}
				else
					if (fat_ent_set(sb, last_clu, new_clu))
						return -EIO;
				last_clu = new_clu;

				/* Update au info */
@@ -1093,11 +1088,7 @@ retry_alloc:
		goto retry_alloc;

	// spin_unlock(&amap->amap_lock);
	return 0;
error:
	if (num_allocated)
		fsi->fs_func->free_cluster(sb, p_chain, 0);
	return ret;
	return num_allocated;
}


@@ -1126,8 +1117,8 @@ s32 amap_release_cluster(struct super_block *sb, u32 clu)
	au = GET_AU(amap, i_au);
	if (au->free_clusters >= amap->clusters_per_au) {
		sdfat_fs_error(sb, "%s, au->free_clusters(%hd) is "
			"greater than or equal to amap->clusters_per_au(%hd)",
			__func__, au->free_clusters, amap->clusters_per_au);
			"greater than or equal to amap->clusters_per_au(%hd)"
			, __func__, au->free_clusters, amap->clusters_per_au);
		return -EIO;
	}

+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ typedef struct __AMAP_T {
	int fclu_hint;			/* maximum # of free clusters in an AU */

	/* Hot AU list */
	unsigned int total_fclu_hot;	/* Free clusters in hot list */
	int total_fclu_hot;		/* Free clusters in hot list */
	struct slist_head slist_hot;	/* Hot AU list */

	/* Ignored AU list */
+1 −1
Original line number Diff line number Diff line
@@ -328,7 +328,7 @@ s32 fsapi_write_inode(struct inode *inode, DIR_ENTRY_T *info, int sync)
EXPORT_SYMBOL(fsapi_write_inode);

/* return the cluster number in the given cluster offset */
s32 fsapi_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest)
s32 fsapi_map_clus(struct inode *inode, s32 clu_offset, u32 *clu, int dest)
{
	s32 err;
	struct super_block *sb = inode->i_sb;
+13 −13
Original line number Diff line number Diff line
@@ -119,13 +119,13 @@ typedef struct {
} DATE_TIME_T;

typedef struct {
	u64      Offset;    // start sector number of the partition
	u64      Size;      // in sectors
	u32      Offset;    // start sector number of the partition
	u32      Size;      // in sectors
} PART_INFO_T;

typedef struct {
	u32      SecSize;    // sector size in bytes
	u64      DevSize;    // block device size in sectors
	u32      DevSize;    // block device size in sectors
} DEV_INFO_T;

typedef struct {
@@ -139,7 +139,7 @@ typedef struct {
/* directory structure */
typedef struct {
	u32      dir;
	u32      size;
	s32      size;
	u8       flags;
} CHAIN_T;

@@ -147,7 +147,7 @@ typedef struct {
typedef struct {
	u32      clu;
	union {
		u32 off;     // cluster offset
		s32 off;     // cluster offset
		s32 eidx;    // entry index
	};
} HINT_T;
@@ -209,7 +209,7 @@ typedef struct __cache_entry {
		struct __cache_entry *next;
		struct __cache_entry *prev;
	} hash;
	u64 sec;
	u32 sec;
	u32 flag;
	struct buffer_head   *bh;
} cache_ent_t;
@@ -223,7 +223,7 @@ typedef struct __FATENT_OPS_T {
} FATENT_OPS_T;

typedef struct {
	s32      (*alloc_cluster)(struct super_block *, u32, CHAIN_T *, s32);
	s32      (*alloc_cluster)(struct super_block *, s32, CHAIN_T *, int);
	s32      (*free_cluster)(struct super_block *, CHAIN_T *, s32);
	s32      (*count_used_clusters)(struct super_block *, u32 *);
	s32      (*init_dir_entry)(struct super_block *, CHAIN_T *, s32, u32, u32, u64);
@@ -253,16 +253,16 @@ typedef struct __FS_INFO_T {
	s32	 bd_opened;              // opened or not
	u32      vol_type;               // volume FAT type
	u32      vol_id;                 // volume serial number
	u64      num_sectors;            // num of sectors in volume
	u32      num_sectors;            // num of sectors in volume
	u32      num_clusters;           // num of clusters in volume
	u32      cluster_size;           // cluster size in bytes
	u32      cluster_size_bits;
	u32      sect_per_clus;        // cluster size in sectors
	u32      sect_per_clus_bits;
	u64      FAT1_start_sector;      // FAT1 start sector
	u64      FAT2_start_sector;      // FAT2 start sector
	u64      root_start_sector;      // root dir start sector
	u64      data_start_sector;      // data area start sector
	u32      FAT1_start_sector;      // FAT1 start sector
	u32      FAT2_start_sector;      // FAT2 start sector
	u32      root_start_sector;      // root dir start sector
	u32      data_start_sector;      // data area start sector
	u32      num_FAT_sectors;        // num of FAT sectors
	u32      root_dir;               // root dir cluster
	u32      dentries_in_root;       // num of dentries in root dir
@@ -337,7 +337,7 @@ s32 fsapi_rename(struct inode *old_parent_inode, FILE_ID_T *fid,
s32 fsapi_unlink(struct inode *inode, FILE_ID_T *fid);
s32 fsapi_read_inode(struct inode *inode, DIR_ENTRY_T *info);
s32 fsapi_write_inode(struct inode *inode, DIR_ENTRY_T *info, int sync);
s32 fsapi_map_clus(struct inode *inode, u32 clu_offset, u32 *clu, int dest);
s32 fsapi_map_clus(struct inode *inode, s32 clu_offset, u32 *clu, int dest);
s32 fsapi_reserve_clus(struct inode *inode);

/* directory management functions */
+27 −27
Original line number Diff line number Diff line
@@ -106,12 +106,12 @@ s32 bdev_check_bdi_valid(struct super_block *sb)


/* Make a readahead request */
s32 bdev_readahead(struct super_block *sb, u64 secno, u64 num_secs)
s32 bdev_readahead(struct super_block *sb, u32 secno, u32 num_secs)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);
	u32 sects_per_page = (PAGE_SIZE >> sb->s_blocksize_bits);
	struct blk_plug plug;
	u64 i;
	u32 i;

	if (!fsi->bd_opened)
		return -EIO;
@@ -120,14 +120,14 @@ s32 bdev_readahead(struct super_block *sb, u64 secno, u64 num_secs)
	for (i = 0; i < num_secs; i++) {
		if (i && !(i & (sects_per_page - 1)))
			blk_flush_plug(current);
		sb_breadahead(sb, (sector_t)(secno + i));
		sb_breadahead(sb, secno + i);
	}
	blk_finish_plug(&plug);

	return 0;
}

s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 num_secs, s32 read)
s32 bdev_mread(struct super_block *sb, u32 secno, struct buffer_head **bh, u32 num_secs, s32 read)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);
	u8 blksize_bits = sb->s_blocksize_bits;
@@ -145,9 +145,9 @@ s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 n
	brelse(*bh);

	if (read)
		*bh = __bread(sb->s_bdev, (sector_t)secno, num_secs << blksize_bits);
		*bh = __bread(sb->s_bdev, secno, num_secs << blksize_bits);
	else
		*bh = __getblk(sb->s_bdev, (sector_t)secno, num_secs << blksize_bits);
		*bh = __getblk(sb->s_bdev, secno, num_secs << blksize_bits);

	/* read successfully */
	if (*bh)
@@ -165,9 +165,9 @@ s32 bdev_mread(struct super_block *sb, u64 secno, struct buffer_head **bh, u64 n
	return -EIO;
}

s32 bdev_mwrite(struct super_block *sb, u64 secno, struct buffer_head *bh, u64 num_secs, s32 sync)
s32 bdev_mwrite(struct super_block *sb, u32 secno, struct buffer_head *bh, u32 num_secs, s32 sync)
{
	u64 count;
	s32 count;
	struct buffer_head *bh2;
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);
#ifdef CONFIG_SDFAT_DBG_IOCTL
@@ -189,7 +189,7 @@ s32 bdev_mwrite(struct super_block *sb, u64 secno, struct buffer_head *bh, u64 n
	} else {
		count = num_secs << sb->s_blocksize_bits;

		bh2 = __getblk(sb->s_bdev, (sector_t)secno, count);
		bh2 = __getblk(sb->s_bdev, secno, count);

		if (!bh2)
			goto no_bh;
@@ -239,39 +239,39 @@ s32 bdev_sync_all(struct super_block *sb)
/*
 *  Sector Read/Write Functions
 */
s32 read_sect(struct super_block *sb, u64 sec, struct buffer_head **bh, s32 read)
s32 read_sect(struct super_block *sb, u32 sec, struct buffer_head **bh, s32 read)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	BUG_ON(!bh);
	if ((sec >= fsi->num_sectors) && (fsi->num_sectors > 0)) {
		sdfat_fs_error_ratelimit(sb,
				"%s: out of range (sect:%llu)", __func__, sec);
				"%s: out of range (sect:%u)", __func__, sec);
		return -EIO;
	}

	if (bdev_mread(sb, sec, bh, 1, read)) {
		sdfat_fs_error_ratelimit(sb,
				"%s: I/O error (sect:%llu)", __func__, sec);
				"%s: I/O error (sect:%u)", __func__, sec);
		return -EIO;
	}

	return 0;
}

s32 write_sect(struct super_block *sb, u64 sec, struct buffer_head *bh, s32 sync)
s32 write_sect(struct super_block *sb, u32 sec, struct buffer_head *bh, s32 sync)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	BUG_ON(!bh);
	if ((sec >= fsi->num_sectors) && (fsi->num_sectors > 0)) {
		sdfat_fs_error_ratelimit(sb,
				"%s: out of range (sect:%llu)", __func__, sec);
				"%s: out of range (sect:%u)", __func__, sec);
		return -EIO;
	}

	if (bdev_mwrite(sb, sec, bh, 1, sync)) {
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%u)",
						__func__, sec);
		return -EIO;
	}
@@ -279,19 +279,19 @@ s32 write_sect(struct super_block *sb, u64 sec, struct buffer_head *bh, s32 sync
	return 0;
}

s32 read_msect(struct super_block *sb, u64 sec, struct buffer_head **bh, u64 num_secs, s32 read)
s32 read_msect(struct super_block *sb, u32 sec, struct buffer_head **bh, s32 num_secs, s32 read)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	BUG_ON(!bh);
	if (((sec+num_secs) > fsi->num_sectors) && (fsi->num_sectors > 0)) {
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%llu len:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%u len:%d)",
						__func__, sec, num_secs);
		return -EIO;
	}

	if (bdev_mread(sb, sec, bh, num_secs, read)) {
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%llu len:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%u len:%d)",
						__func__, sec, num_secs);
		return -EIO;
	}
@@ -299,20 +299,20 @@ s32 read_msect(struct super_block *sb, u64 sec, struct buffer_head **bh, u64 num
	return 0;
}

s32 write_msect(struct super_block *sb, u64 sec, struct buffer_head *bh, u64 num_secs, s32 sync)
s32 write_msect(struct super_block *sb, u32 sec, struct buffer_head *bh, s32 num_secs, s32 sync)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	BUG_ON(!bh);
	if (((sec+num_secs) > fsi->num_sectors) && (fsi->num_sectors > 0)) {
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%llu len:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%u len:%d)",
						__func__, sec, num_secs);
		return -EIO;
	}


	if (bdev_mwrite(sb, sec, bh, num_secs, sync)) {
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%llu len:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: I/O error (sect:%u len:%d)",
						__func__, sec, num_secs);
		return -EIO;
	}
@@ -340,11 +340,11 @@ static inline s32 __blkdev_sync_bhs(struct buffer_head **bhs, s32 nr_bhs)
	return err;
}

static inline s32 __buffer_zeroed(struct super_block *sb, u64 blknr, u64 num_secs)
static inline s32 __buffer_zeroed(struct super_block *sb, u32 blknr, s32 num_secs)
{
	struct buffer_head *bhs[MAX_BUF_PER_PAGE];
	s32 nr_bhs = MAX_BUF_PER_PAGE;
	u64 last_blknr = blknr + num_secs;
	u32 last_blknr = blknr + num_secs;
	s32 err, i, n;
	struct blk_plug plug;

@@ -352,7 +352,7 @@ static inline s32 __buffer_zeroed(struct super_block *sb, u64 blknr, u64 num_sec
	n = 0;
	blk_start_plug(&plug);
	while (blknr < last_blknr) {
		bhs[n] = sb_getblk(sb, (sector_t)blknr);
		bhs[n] = sb_getblk(sb, blknr);
		if (!bhs[n]) {
			err = -ENOMEM;
			blk_finish_plug(&plug);
@@ -389,19 +389,19 @@ static inline s32 __buffer_zeroed(struct super_block *sb, u64 blknr, u64 num_sec
	return 0;

error:
	EMSG("%s: failed zeroed sect %llu\n", __func__, blknr);
	EMSG("%s: failed zeroed sect %u\n", __func__, blknr);
	for (i = 0; i < n; i++)
		bforget(bhs[i]);

	return err;
}

s32 write_msect_zero(struct super_block *sb, u64 sec, u64 num_secs)
s32 write_msect_zero(struct super_block *sb, u32 sec, s32 num_secs)
{
	FS_INFO_T *fsi = &(SDFAT_SB(sb)->fsi);

	if (((sec+num_secs) > fsi->num_sectors) && (fsi->num_sectors > 0)) {
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%llu len:%llu)",
		sdfat_fs_error_ratelimit(sb, "%s: out of range(sect:%u len:%d)",
						__func__, sec, num_secs);
		return -EIO;
	}
Loading