summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1997-08-11 20:29:22 +0000
committerTheodore Ts'o <tytso@mit.edu>1997-08-11 20:29:22 +0000
commit3cb6c5021d722e17b7105d1bc090880671f6fc6d (patch)
tree7753483488fc1f68272993f38d727dfd041cbf63 /lib
parent4cbe8af4b0d0c72fb28bb500c1bd8a46b00fdde3 (diff)
downloade2fsprogs-3cb6c5021d722e17b7105d1bc090880671f6fc6d.tar.gz
Many files:
dosio.c: New file to do DOS/BIOS disk accesses. namei.c (open_namei): Make pathlen be of type size_t. llseek.c: Always #include stdlib.h since it's need to define size_t. io.h: Use errcode_t for magic numbers. icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c (dir_block_cmp): Use size_t where appropriate. read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c (ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t where appropriate. closefs.c (ext2fs_flush): Use dgrp_t instead of int where appropriate. openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t instead of int where appropriate. rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode), initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be 16-bit safe. link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc), ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func): Add #pragma argsused for Turbo C.
Diffstat (limited to 'lib')
-rw-r--r--lib/ext2fs/ChangeLog39
-rw-r--r--lib/ext2fs/block.c3
-rw-r--r--lib/ext2fs/brel_ma.c24
-rw-r--r--lib/ext2fs/check_desc.c4
-rw-r--r--lib/ext2fs/closefs.c10
-rw-r--r--lib/ext2fs/cmp_bitmaps.c10
-rw-r--r--lib/ext2fs/dblist.c18
-rw-r--r--lib/ext2fs/dosio.c457
-rw-r--r--lib/ext2fs/dosio.h153
-rw-r--r--lib/ext2fs/dupfs.c4
-rw-r--r--lib/ext2fs/getsize.c2
-rw-r--r--lib/ext2fs/icount.c20
-rw-r--r--lib/ext2fs/initialize.c14
-rw-r--r--lib/ext2fs/inode.c38
-rw-r--r--lib/ext2fs/io.h4
-rw-r--r--lib/ext2fs/irel_ma.c76
-rw-r--r--lib/ext2fs/ismounted.c3
-rw-r--r--lib/ext2fs/link.c3
-rw-r--r--lib/ext2fs/llseek.c4
-rw-r--r--lib/ext2fs/lookup.c3
-rw-r--r--lib/ext2fs/namei.c4
-rw-r--r--lib/ext2fs/openfs.c5
-rw-r--r--lib/ext2fs/read_bb.c5
-rw-r--r--lib/ext2fs/rw_bitmaps.c14
-rw-r--r--lib/ext2fs/unlink.c6
25 files changed, 808 insertions, 115 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 8d463da0..68e9ed02 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,42 @@
+Mon Aug 11 03:30:48 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * dosio.c: New file to do DOS/BIOS disk accesses.
+
+ * namei.c (open_namei): Make pathlen be of type size_t.
+
+ * llseek.c: Always #include stdlib.h since it's need to define
+ size_t.
+
+ * io.h: Use errcode_t for magic numbers.
+
+ * icount.c (get_icount_el): Use size_t where appropriate
+
+ * dupfs.c (ext2fs_dup_handle):
+ * dblist.c (dir_block_cmp): Use size_t where appropriate.
+
+ * read_bb.c (ext2fs_read_bb_inode):
+ * cmp_bitmaps.c (ext2fs_compare_inode_bitmap): Use blk_t, ino_t
+ and size_t where appropriate.
+
+ * closefs.c (ext2fs_flush): Use dgrp_t instead of int where
+ appropriate.
+
+ * openfs.c (ext2fs_open):
+ * check_desc.c (ext2fs_check_desc): Use blk_t instead of int where
+ appropriate.
+
+ * rw_bitmaps.c (read_bitmaps):
+ * irel_ma.c:
+ * inode.c (ext2fs_write_inode):
+ * initialize.c (ext2fs_initialize):
+ * brel_ma.c: Fix to make be 16-bit safe.
+
+ * link.c (ext2fs_link):
+ * unlink.c (ext2fs_unlink):
+ * lookup.c (lookup_proc):
+ * ismounted.c (ext2fs_check_if_mounted):
+ * block.c (xlate_func): Add #pragma argsused for Turbo C.
+
Sun Aug 10 10:05:22 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>
* block.c (ext2fs_block_iterate2): Use retval which is a errcode_t
diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c
index c1709d9b..0a3e32f7 100644
--- a/lib/ext2fs/block.c
+++ b/lib/ext2fs/block.c
@@ -419,6 +419,9 @@ struct xlate {
void *real_private;
};
+#ifdef __TURBOC__
+#pragma argsused
+#endif
static int xlate_func(ext2_filsys fs, blk_t *blocknr, int blockcnt,
blk_t ref_block, int ref_offset, void *private)
{
diff --git a/lib/ext2fs/brel_ma.c b/lib/ext2fs/brel_ma.c
index aadd4f4f..583ee852 100644
--- a/lib/ext2fs/brel_ma.c
+++ b/lib/ext2fs/brel_ma.c
@@ -3,6 +3,9 @@
*
* Copyright (C) 1996, 1997 Theodore Ts'o.
*
+ * TODO: rewrite to not use a direct array!!! (Fortunately this
+ * module isn't really used yet.)
+ *
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
@@ -72,7 +75,8 @@ errcode_t ext2fs_brel_memarray_create(char *name, blk_t max_block,
memset(ma, 0, sizeof(struct brel_ma));
brel->private = ma;
- size = sizeof(struct ext2_block_relocate_entry) * (max_block+1);
+ size = (size_t) (sizeof(struct ext2_block_relocate_entry) *
+ (max_block+1));
ma->entries = malloc(size);
if (!ma->entries)
goto errout;
@@ -106,7 +110,7 @@ static errcode_t bma_put(ext2_brel brel, blk_t old,
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
- ma->entries[old] = *ent;
+ ma->entries[(unsigned)old] = *ent;
return 0;
}
@@ -118,7 +122,7 @@ static errcode_t bma_get(ext2_brel brel, blk_t old,
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
*ent = ma->entries[old];
return 0;
@@ -137,10 +141,10 @@ static errcode_t bma_next(ext2_brel brel, blk_t *old,
ma = brel->private;
while (++brel->current < ma->max_block) {
- if (ma->entries[brel->current].new == 0)
+ if (ma->entries[(unsigned)brel->current].new == 0)
continue;
*old = brel->current;
- *ent = ma->entries[brel->current];
+ *ent = ma->entries[(unsigned)brel->current];
return 0;
}
*old = 0;
@@ -154,10 +158,10 @@ static errcode_t bma_move(ext2_brel brel, blk_t old, blk_t new)
ma = brel->private;
if ((old > ma->max_block) || (new > ma->max_block))
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
- ma->entries[new] = ma->entries[old];
- ma->entries[old].new = 0;
+ ma->entries[(unsigned)new] = ma->entries[old];
+ ma->entries[(unsigned)old].new = 0;
return 0;
}
@@ -168,9 +172,9 @@ static errcode_t bma_delete(ext2_brel brel, blk_t old)
ma = brel->private;
if (old > ma->max_block)
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned)old].new == 0)
return ENOENT;
- ma->entries[old].new = 0;
+ ma->entries[(unsigned)old].new = 0;
return 0;
}
diff --git a/lib/ext2fs/check_desc.c b/lib/ext2fs/check_desc.c
index fca0bb46..6a75b08e 100644
--- a/lib/ext2fs/check_desc.c
+++ b/lib/ext2fs/check_desc.c
@@ -30,8 +30,8 @@
errcode_t ext2fs_check_desc(ext2_filsys fs)
{
int i;
- int block = fs->super->s_first_data_block;
- int next;
+ blk_t block = fs->super->s_first_data_block;
+ blk_t next;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 3883055c..cdc8597c 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -58,8 +58,8 @@ int ext2fs_bg_has_super(ext2_filsys fs, int group_block)
errcode_t ext2fs_flush(ext2_filsys fs)
{
- int i,j,maxgroup;
- int group_block;
+ dgrp_t i,j,maxgroup;
+ blk_t group_block;
errcode_t retval;
char *group_ptr;
unsigned long fs_state;
@@ -76,9 +76,11 @@ errcode_t ext2fs_flush(ext2_filsys fs)
retval = ENOMEM;
if (!(super_shadow = malloc(SUPERBLOCK_SIZE)))
goto errout;
- if (!(group_shadow = malloc(fs->blocksize*fs->desc_blocks)))
+ if (!(group_shadow = malloc((size_t) fs->blocksize *
+ fs->desc_blocks)))
goto errout;
- memset(group_shadow, 0, fs->blocksize*fs->desc_blocks);
+ memset(group_shadow, 0, (size_t) fs->blocksize *
+ fs->desc_blocks);
/* swap the superblock */
*super_shadow = *fs->super;
diff --git a/lib/ext2fs/cmp_bitmaps.c b/lib/ext2fs/cmp_bitmaps.c
index 21fe42aa..638315f8 100644
--- a/lib/ext2fs/cmp_bitmaps.c
+++ b/lib/ext2fs/cmp_bitmaps.c
@@ -30,14 +30,15 @@
errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
ext2fs_block_bitmap bm2)
{
- int i;
+ blk_t i;
EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_BLOCK_BITMAP);
EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_BLOCK_BITMAP);
if ((bm1->start != bm2->start) ||
(bm1->end != bm2->end) ||
- (memcmp(bm1->bitmap, bm2->bitmap, (bm1->end - bm1->start)/8)))
+ (memcmp(bm1->bitmap, bm2->bitmap,
+ (size_t) (bm1->end - bm1->start)/8)))
return EXT2_ET_NEQ_BLOCK_BITMAP;
for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
@@ -51,14 +52,15 @@ errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
ext2fs_inode_bitmap bm2)
{
- int i;
+ ino_t i;
EXT2_CHECK_MAGIC(bm1, EXT2_ET_MAGIC_INODE_BITMAP);
EXT2_CHECK_MAGIC(bm2, EXT2_ET_MAGIC_INODE_BITMAP);
if ((bm1->start != bm2->start) ||
(bm1->end != bm2->end) ||
- (memcmp(bm1->bitmap, bm2->bitmap, (bm1->end - bm1->start)/8)))
+ (memcmp(bm1->bitmap, bm2->bitmap,
+ (size_t) (bm1->end - bm1->start)/8)))
return EXT2_ET_NEQ_INODE_BITMAP;
for (i = bm1->end - ((bm1->end - bm1->start) % 8); i <= bm1->end; i++)
diff --git a/lib/ext2fs/dblist.c b/lib/ext2fs/dblist.c
index 62739358..7c83c69c 100644
--- a/lib/ext2fs/dblist.c
+++ b/lib/ext2fs/dblist.c
@@ -81,7 +81,7 @@ static errcode_t make_dblist(ext2_filsys fs, ino_t size, ino_t count,
goto cleanup;
dblist->size = (dblist->size * 2) + 12;
}
- len = sizeof(struct ext2_db_entry) * dblist->size;
+ len = (size_t) sizeof(struct ext2_db_entry) * dblist->size;
dblist->count = count;
dblist->list = malloc(len);
if (dblist->list == NULL) {
@@ -157,15 +157,15 @@ errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ino_t ino, blk_t blk,
if (dblist->count >= dblist->size) {
dblist->size += 100;
- nlist = realloc(dblist->list,
- dblist->size * sizeof(struct ext2_db_entry));
+ nlist = realloc(dblist->list, (size_t) dblist->size *
+ sizeof(struct ext2_db_entry));
if (nlist == 0) {
dblist->size -= 100;
return ENOMEM;
}
dblist->list = nlist;
}
- new = dblist->list + dblist->count++;
+ new = dblist->list + ( (int) dblist->count++);
new->blk = blk;
new->ino = ino;
new->blockcnt = blockcnt;
@@ -211,12 +211,12 @@ errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
EXT2_CHECK_MAGIC(dblist, EXT2_ET_MAGIC_DBLIST);
if (!dblist->sorted) {
- qsort(dblist->list, dblist->count,
+ qsort(dblist->list, (size_t) dblist->count,
sizeof(struct ext2_db_entry), dir_block_cmp);
dblist->sorted = 1;
}
for (i=0; i < dblist->count; i++) {
- ret = (*func)(dblist->fs, &dblist->list[i], private);
+ ret = (*func)(dblist->fs, &dblist->list[(int)i], private);
if (ret & DBLIST_ABORT)
return 0;
}
@@ -232,12 +232,12 @@ static int dir_block_cmp(const void *a, const void *b)
(const struct ext2_db_entry *) b;
if (db_a->blk != db_b->blk)
- return (db_a->blk - db_b->blk);
+ return (int) (db_a->blk - db_b->blk);
if (db_a->ino != db_b->ino)
- return (db_a->ino - db_b->ino);
+ return (int) (db_a->ino - db_b->ino);
- return (db_a->blockcnt - db_b->blockcnt);
+ return (int) (db_a->blockcnt - db_b->blockcnt);
}
int ext2fs_dblist_count(ext2_dblist dblist)
diff --git a/lib/ext2fs/dosio.c b/lib/ext2fs/dosio.c
new file mode 100644
index 00000000..b1d79711
--- /dev/null
+++ b/lib/ext2fs/dosio.c
@@ -0,0 +1,457 @@
+/*
+ * dosio.c -- Disk I/O module for the ext2fs/DOS library.
+ *
+ * Copyright (c) 1997 by Theodore Ts'o.
+ *
+ * Copyright (c) 1997 Mark Habersack
+ * This file may be distributed under the terms of the GNU Public License.
+ *
+ */
+
+#include <stdio.h>
+#include <bios.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <io.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <linux/types.h>
+#include "utils.h"
+#include "dosio.h"
+#include "et/com_err.h"
+#include "ext2_err.h"
+#include "ext2fs/io.h"
+
+/*
+ * Some helper macros
+ */
+#define LINUX_EXT2FS 0x83
+#define LINUX_SWAP 0x82
+#define WRITE_ERR(_msg_) write(2, _msg_, strlen(_msg_))
+#define WRITE_ERR_S(_msg_) write(2, _msg_, sizeof(_msg_))
+
+/*
+ * Exported variables
+ */
+unsigned long _dio_error;
+unsigned long _dio_hw_error;
+
+/*
+ * Array of all opened partitions
+ */
+static PARTITION **partitions = NULL;
+static unsigned short npart = 0; /* Number of mapped partitions */
+static PARTITION *active = NULL;
+
+/*
+ * I/O Manager routine prototypes
+ */
+static errcode_t dos_open(const char *dev, int flags, io_channel *channel);
+static errcode_t dos_close(io_channel channel);
+static errcode_t dos_set_blksize(io_channel channel, int blksize);
+static errcode_t dos_read_blk(io_channel channel, unsigned long block,
+ int count, void *buf);
+static errcode_t dos_write_blk(io_channel channel, unsigned long block,
+ int count, const void *buf);
+static errcode_t dos_flush(io_channel channel);
+
+static struct struct_io_manager struct_dos_manager = {
+ EXT2_ET_MAGIC_IO_MANAGER,
+ "DOS I/O Manager",
+ dos_open,
+ dos_close,
+ dos_set_blksize,
+ dos_read_blk,
+ dos_write_blk,
+ dos_flush
+};
+io_manager dos_io_manager = &struct_dos_manager;
+
+/*
+ * Macro taken from unix_io.c
+ */
+/*
+ * For checking structure magic numbers...
+ */
+
+#define EXT2_CHECK_MAGIC(struct, code) \
+ if ((struct)->magic != (code)) return (code)
+
+/*
+ * Calculates a CHS address of a sector from its LBA
+ * offset for the given partition.
+ */
+static void lba2chs(unsigned long lba_addr, CHS *chs, PARTITION *part)
+{
+ unsigned long abss;
+
+ chs->offset = lba_addr & 0x000001FF;
+ abss = (lba_addr >> 9) + part->start;
+ chs->cyl = abss / (part->sects * part->heads);
+ chs->head = (abss / part->sects) % part->heads;
+ chs->sector = (abss % part->sects) + 1;
+}
+
+#ifdef __TURBOC__
+#pragma argsused
+#endif
+/*
+ * Scans the passed partition table looking for *pno partition
+ * that has LINUX_EXT2FS type.
+ *
+ * TODO:
+ * For partition numbers >5 Linux uses DOS extended partitions -
+ * dive into them an return an appropriate entry. Also dive into
+ * extended partitions when scanning for a first Linux/ext2fs.
+ */
+static PTABLE_ENTRY *scan_partition_table(PTABLE_ENTRY *pentry,
+ unsigned short phys,
+ unsigned char *pno)
+{
+ unsigned i;
+
+ if(*pno != 0xFF && *pno >= 5)
+ return NULL; /* We don't support extended partitions for now */
+
+ if(*pno != 0xFF)
+ {
+ if(pentry[*pno].type == LINUX_EXT2FS)
+ return &pentry[*pno];
+ else
+ {
+ if(!pentry[*pno].type)
+ *pno = 0xFE;
+ else if(pentry[*pno].type == LINUX_SWAP)
+ *pno = 0xFD;
+ return NULL;
+ }
+ }
+
+ for(i = 0; i < 4; i++)
+ if(pentry[i].type == LINUX_EXT2FS)
+ {
+ *pno = i;
+ return &pentry[i];
+ }
+
+ return NULL;
+}
+
+/*
+ * Allocate libext2fs structures associated with I/O manager
+ */
+static io_channel alloc_io_channel(PARTITION *part)
+{
+ io_channel ioch;
+
+ ioch = (io_channel)malloc(sizeof(struct struct_io_channel));
+ if (!ioch)
+ return NULL;
+ memset(ioch, 0, sizeof(struct struct_io_channel));
+ ioch->magic = EXT2_ET_MAGIC_IO_CHANNEL;
+ ioch->manager = dos_io_manager;
+ ioch->name = (char *)malloc(strlen(part->dev)+1);
+ if (!ioch->name) {
+ free(ioch);
+ return NULL;
+ }
+ strcpy(ioch->name, part->dev);
+ ioch->private_data = part;
+ ioch->block_size = 1024; /* The smallest ext2fs block size */
+ ioch->read_error = 0;
+ ioch->write_error = 0;
+
+ return ioch;
+}
+
+#ifdef __TURBOC__
+#pragma argsused
+#endif
+/*
+ * Open the 'name' partition, initialize all information structures
+ * we need to keep and create libext2fs I/O manager.
+ */
+static errcode_t dos_open(const char *dev, int flags, io_channel *channel)
+{
+ unsigned char *tmp, sec[512];
+ PARTITION *part;
+ PTABLE_ENTRY *pent;
+ PARTITION **newparts;
+
+ if(!dev)
+ {
+ _dio_error = ERR_BADDEV;
+ return EXT2_ET_BAD_DEVICE_NAME;
+ }
+
+ /*
+ * First check whether the dev name is OK
+ */
+ tmp = (unsigned char*)strrchr(dev, '/');
+ if(!tmp)
+ {
+ _dio_error = ERR_BADDEV;
+ return EXT2_ET_BAD_DEVICE_NAME;
+ }
+ *tmp = 0;
+ if(strcmp(dev, "/dev"))
+ {
+ _dio_error = ERR_BADDEV;
+ return EXT2_ET_BAD_DEVICE_NAME;
+ }
+ *tmp++ = '/';
+
+ /*
+ * Check whether the partition data is already in cache
+ */
+
+ part = (PARTITION*)malloc(sizeof(PARTITION));
+ if (!part)
+ return ENOMEM;
+ {
+ int i = 0;
+
+ for(;i < npart; i++)
+ if(!strcmp(partitions[i]->dev, dev))
+ {
+ /* Found it! Make it the active one */
+ active = partitions[i];
+ *channel = alloc_io_channel(active);
+ if (!*channel)
+ return ENOMEM;
+ return 0;
+ }
+ }
+
+ /*
+ * Drive number & optionally partn number
+ */
+ switch(tmp[0])
+ {
+ case 'h':
+ case 's':
+ part->phys = 0x80;
+ part->phys += toupper(tmp[2]) - 'A';
+ /*
+ * Do we have the partition number?
+ */
+ if(tmp[3])
+ part->pno = isdigit((int)tmp[3]) ? tmp[3] - '0' - 1: 0;
+ else
+ part->pno = 0xFF;
+ break;
+
+ case 'f':
+ if(tmp[2])
+ part->phys = isdigit((int)tmp[2]) ? tmp[2] - '0' : 0;
+ else
+ part->phys = 0x00; /* We'll assume /dev/fd0 */
+ break;
+
+ default:
+ _dio_error = ERR_BADDEV;
+ return ENODEV;
+ }
+
+ if(part->phys < 0x80)
+ {
+ /* We don't support floppies for now */
+ _dio_error = ERR_NOTSUPP;
+ return EINVAL;
+ }
+
+ part->dev = strdup(dev);
+
+ /*
+ * Get drive's geometry
+ */
+ _dio_hw_error = biosdisk(DISK_GET_GEOMETRY,
+ part->phys,
+ 0, /* head */
+ 0, /* cylinder */
+ 1, /* sector */
+ 1, /* just one sector */
+ sec);
+
+ if(!HW_OK())
+ {
+ _dio_error = ERR_HARDWARE;
+ if (part)
+ free(part);
+ return EFAULT;
+ }
+
+ /*
+ * Calculate the geometry
+ */
+ part->cyls = (unsigned short)(((sec[0] >> 6) << 8) + sec[1] + 1);
+ part->heads = sec[3] + 1;
+ part->sects = sec[0] & 0x3F;
+
+ /*
+ * Now that we know all we need, let's look for the partition
+ */
+ _dio_hw_error = biosdisk(DISK_READ, part->phys, 0, 0, 1, 1, sec);
+
+ if(!HW_OK())
+ {
+ _dio_error = ERR_HARDWARE;
+ if (part)
+ free(part);
+ return EFAULT;
+ }
+
+ pent = (PTABLE_ENTRY*)&sec[0x1BE];
+ pent = scan_partition_table(pent, part->phys, &part->pno);
+
+ if(!pent)
+ {
+ _dio_error = part->pno == 0xFE ? ERR_EMPTYPART :
+ part->pno == 0xFD ? ERR_LINUXSWAP : ERR_NOTEXT2FS;
+ if (part)
+ free(part);
+ return ENODEV;
+ }
+
+ /*
+ * Calculate the remaining figures
+ */
+ {
+ unsigned long fsec, fhead, fcyl;
+
+ fsec = (unsigned long)(pent->start_sec & 0x3F);
+ fhead = (unsigned long)pent->start_head;
+ fcyl = ((pent->start_sec >> 6) << 8) + pent->start_cyl;
+ part->start = fsec + fhead * part->sects + fcyl *
+ (part->heads * part->sects) - 1;
+ part->len = pent->size;
+ }
+
+ /*
+ * Add the partition to the table
+ */
+ newparts = (PARTITION**)realloc(partitions, sizeof(PARTITION) * npart);
+ if (!newparts) {
+ free(part);
+ return ENOMEM;
+ }
+ partitions = newparts;
+ partitions[npart++] = active = part;
+
+ /*
+ * Now alloc all libe2fs structures
+ */
+ *channel = alloc_io_channel(active);
+ if (!*channel)
+ return ENOMEM;
+
+ return 0;
+}
+
+static errcode_t dos_close(io_channel channel)
+{
+ if (channel->name)
+ free(channel->name);
+ if (channel)
+ free(channel);
+
+ return 0;
+}
+
+static errcode_t dos_set_blksize(io_channel channel, int blksize)
+{
+ channel->block_size = blksize;
+
+ return 0;
+}
+
+static errcode_t dos_read_blk(io_channel channel, unsigned long block,
+ int count, void *buf)
+{
+ PARTITION *part;
+ size_t size;
+ ext2_loff_t loc;
+ CHS chs;
+
+ EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+ part = (PARTITION*)channel->private_data;
+
+ size = (size_t)((count < 0) ? -count : count * channel->block_size);
+ loc = (ext2_loff_t) block * channel->block_size;
+
+ lba2chs(loc, &chs, part);
+ /*
+ * Potential bug here:
+ * If DJGPP is used then reads of >18 sectors will fail!
+ * Have to rewrite biosdisk.
+ */
+ _dio_hw_error = biosdisk(DISK_READ,
+ part->phys,
+ chs.head,
+ chs.cyl,
+ chs.sector,
+ size < 512 ? 1 : size/512,
+ buf);
+
+ if(!HW_OK())
+ {
+ _dio_error = ERR_HARDWARE;
+ return EFAULT;
+ }
+
+ return 0;
+}
+
+static errcode_t dos_write_blk(io_channel channel, unsigned long block,
+ int count, const void *buf)
+{
+ PARTITION *part;
+ size_t size;
+ ext2_loff_t loc;
+ CHS chs;
+
+ EXT2_CHECK_MAGIC(channel, EXT2_ET_MAGIC_IO_CHANNEL);
+ part = (PARTITION*)channel->private_data;
+
+ if(count == 1)
+ size = (size_t)channel->block_size;
+ else
+ {
+ if (count < 0)
+ size = (size_t)-count;
+ else
+ size = (size_t)(count * channel->block_size);
+ }
+
+ loc = (ext2_loff_t)block * channel->block_size;
+ lba2chs(loc, &chs, part);
+ _dio_hw_error = biosdisk(DISK_WRITE,
+ part->phys,
+ chs.head,
+ chs.cyl,
+ chs.sector,
+ size < 512 ? 1 : size/512,
+ (void*)buf);
+
+ if(!HW_OK())
+ {
+ _dio_error = ERR_HARDWARE;
+ return EFAULT;
+ }
+
+ return 0;
+}
+
+#ifdef __TURBOC__
+#pragma argsused
+#endif
+static errcode_t dos_flush(io_channel channel)
+{
+ /*
+ * No buffers, no flush...
+ */
+ return 0;
+}
diff --git a/lib/ext2fs/dosio.h b/lib/ext2fs/dosio.h
new file mode 100644
index 00000000..a0d652d5
--- /dev/null
+++ b/lib/ext2fs/dosio.h
@@ -0,0 +1,153 @@
+/*
+ * v1.0
+ *
+ * Disk I/O include file for the ext2fs/DOS library.
+ *
+ * Copyright (c) 1997 Mark Habersack
+ * This file may be distributed under the terms of the GNU Public License.
+ *
+ */
+#ifndef __diskio_h
+#define __diskio_h
+#ifdef __TURBOC__
+#ifndef __LARGE__
+# error "ext2fs/DOS library requires LARGE model!"
+#endif
+#endif
+
+#ifdef __TURBOC__
+#include "msdos.h"
+#endif
+
+/*
+ * A helper structure used in LBA => CHS conversion
+ */
+typedef struct
+{
+ unsigned short cyl; /* Cylinder (or track) */
+ unsigned short head;
+ unsigned short sector;
+ unsigned short offset; /* Offset of byte within the sector */
+} CHS;
+
+/*
+ * All partition data we need is here
+ */
+typedef struct
+{
+ char *dev; /* _Linux_ device name (like "/dev/hda1") */
+ unsigned char phys; /* Physical DOS drive number */
+ unsigned long start; /* LBA address of partition start */
+ unsigned long len; /* length of partition in sectors */
+ unsigned char pno; /* Partition number (read from *dev) */
+
+ /* This partition's drive geometry */
+ unsigned short cyls;
+ unsigned short heads;
+ unsigned short sects;
+} PARTITION;
+
+/*
+ * PC partition table entry format
+ */
+#ifdef __DJGPP__
+#pragma pack(1)
+#endif
+typedef struct
+{
+ unsigned char active;
+ unsigned char start_head;
+ unsigned char start_sec;
+ unsigned char start_cyl;
+ unsigned char type;
+ unsigned char end_head;
+ unsigned char end_sec;
+ unsigned char end_cyl;
+ unsigned long first_sec_rel;
+ unsigned long size;
+} PTABLE_ENTRY;
+#ifdef __DJGPP__
+#pragma pack()
+#endif
+
+/*
+ * INT 0x13 operation codes
+ */
+#define DISK_READ 0x02
+#define DISK_WRITE 0x03
+#define DISK_GET_GEOMETRY 0x08
+#define DISK_READY 0x10
+
+/*
+ * Errors to put in _dio_error
+ */
+#define ERR_BADDEV 0x00000001L
+#define ERR_HARDWARE 0x00000002L
+#define ERR_NOTSUPP 0x00000003L
+#define ERR_NOTEXT2FS 0x00000004L
+#define ERR_EMPTYPART 0x00000005L
+#define ERR_LINUXSWAP 0x00000006L
+
+/*
+ * Functions in diskio.c
+ */
+
+/*
+ * Variable contains last module's error
+ */
+extern unsigned long _dio_error;
+
+/*
+ * This one contains last hardware error (if _dio_error == ERR_HARDWARE)
+ */
+extern unsigned long _dio_hw_error;
+
+/*
+ * Macros to check for disk hardware errors
+ */
+#define HW_OK() ((unsigned char)_dio_hw_error == 0x00)
+#define HW_BAD_CMD() ((unsigned char)_dio_hw_error == 0x01)
+#define HW_NO_ADDR_MARK() ((unsigned char)_dio_hw_error == 0x02)
+#define HW_WRITE_PROT() ((unsigned char)_dio_hw_error == 0x03)
+#define HW_NO_SECTOR() ((unsigned char)_dio_hw_error == 0x04)
+#define HW_RESET_FAIL() ((unsigned char)_dio_hw_error == 0x05)
+#define HW_DISK_CHANGED() ((unsigned char)_dio_hw_error == 0x06)
+#define HW_DRIVE_FAIL() ((unsigned char)_dio_hw_error == 0x07)
+#define HW_DMA_OVERRUN() ((unsigned char)_dio_hw_error == 0x08)
+#define HW_DMA_BOUNDARY() ((unsigned char)_dio_hw_error == 0x09)
+#define HW_BAD_SECTOR() ((unsigned char)_dio_hw_error == 0x0A)
+#define HW_BAD_TRACK() ((unsigned char)_dio_hw_error == 0x0B)
+#define HW_UNSUPP_TRACK() ((unsigned char)_dio_hw_error == 0x0C)
+#define HW_BAD_CRC_ECC() ((unsigned char)_dio_hw_error == 0x10)
+#define HW_CRC_ECC_CORR() ((unsigned char)_dio_hw_error == 0x11)
+#define HW_CONTR_FAIL() ((unsigned char)_dio_hw_error == 0x20)
+#define HW_SEEK_FAIL() ((unsigned char)_dio_hw_error == 0x40)
+#define HW_ATTACH_FAIL() ((unsigned char)_dio_hw_error == 0x80)
+#define HW_DRIVE_NREADY() ((unsigned char)_dio_hw_error == 0xAA)
+#define HW_UNDEF_ERROR() ((unsigned char)_dio_hw_error == 0xBB)
+#define HW_WRITE_FAULT() ((unsigned char)_dio_hw_error == 0xCC)
+#define HW_STATUS_ERROR() ((unsigned char)_dio_hw_error == 0xE0)
+#define HW_SENSE_FAIL() ((unsigned char)_dio_hw_error == 0xFF)
+
+
+/*
+ * Open the specified partition.
+ * String 'dev' must have a format:
+ *
+ * /dev/{sd|hd|fd}[X]
+ *
+ * where,
+ *
+ * only one of the option in curly braces can be used and X is an optional
+ * partition number for the given device. If X is not specified, function
+ * scans the drive's partition table in search for the first Linux ext2fs
+ * partition (signature 0x83). Along the way it dives into every extended
+ * partition encountered.
+ * Scan ends if either (a) there are no more used partition entries, or
+ * (b) there is no Xth partition.
+ *
+ * Routine returns 0 on success and !=0 otherwise.
+ */
+int open_partition(char *dev);
+
+#endif /* __diskio_h */
diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c
index f7edd839..8f9787cd 100644
--- a/lib/ext2fs/dupfs.c
+++ b/lib/ext2fs/dupfs.c
@@ -59,11 +59,11 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
goto errout;
memcpy(fs->super, src->super, SUPERBLOCK_SIZE);
- fs->group_desc = malloc(fs->desc_blocks * fs->blocksize);
+ fs->group_desc = malloc((size_t) fs->desc_blocks * fs->blocksize);
if (!fs->group_desc)
goto errout;
memcpy(fs->group_desc, src->group_desc,
- fs->desc_blocks * fs->blocksize);
+ (size_t) fs->desc_blocks * fs->blocksize);
if (src->inode_map) {
retval = ext2fs_copy_bitmap(src->inode_map, &fs->inode_map);
diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c
index c9fc00ae..0246545c 100644
--- a/lib/ext2fs/getsize.c
+++ b/lib/ext2fs/getsize.c
@@ -53,7 +53,9 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks)
{
int fd;
+#ifdef BLKGETSIZE
long size;
+#endif
ext2_loff_t high, low;
#ifdef FDGETPRM
struct floppy_struct this_floppy;
diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c
index 5bffc18a..a91496a2 100644
--- a/lib/ext2fs/icount.c
+++ b/lib/ext2fs/icount.c
@@ -48,7 +48,7 @@ struct ext2_icount_el {
};
struct ext2_icount {
- int magic;
+ errcode_t magic;
ext2fs_inode_bitmap single;
ext2fs_inode_bitmap multiple;
ino_t count;
@@ -84,7 +84,7 @@ errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
if (hint) {
EXT2_CHECK_MAGIC(hint, EXT2_ET_MAGIC_ICOUNT);
if (hint->size > size)
- size = hint->size;
+ size = (size_t) hint->size;
}
icount = malloc(sizeof(struct ext2_icount));
@@ -119,7 +119,7 @@ errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
icount->size += fs->super->s_inodes_count / 50;
}
- bytes = icount->size * sizeof(struct ext2_icount_el);
+ bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el));
#if 0
printf("Icount allocated %d entries, %d bytes.\n",
icount->size, bytes);
@@ -172,7 +172,7 @@ static struct ext2_icount_el *insert_icount_el(ext2_icount_t icount,
if (icount->count >= icount->size) {
if (icount->count) {
- new_size = icount->list[icount->count-1].ino;
+ new_size = icount->list[(unsigned)icount->count-1].ino;
new_size = icount->count *
((float) new_size / icount->num_inodes);
}
@@ -181,14 +181,14 @@ static struct ext2_icount_el *insert_icount_el(ext2_icount_t icount,
#if 0
printf("Reallocating icount %d entries...\n", new_size);
#endif
- new_list = realloc(icount->list,
- new_size * sizeof(struct ext2_icount_el));
+ new_list = realloc(icount->list, (size_t) new_size *
+ sizeof(struct ext2_icount_el));
if (!new_list)
return 0;
icount->size = new_size;
icount->list = new_list;
}
- num = icount->count - pos;
+ num = (int) icount->count - pos;
if (num < 0)
return 0; /* should never happen */
if (num) {
@@ -218,8 +218,8 @@ static struct ext2_icount_el *get_icount_el(ext2_icount_t icount,
return 0;
if (create && ((icount->count == 0) ||
- (ino > icount->list[icount->count-1].ino))) {
- return insert_icount_el(icount, ino, icount->count);
+ (ino > icount->list[(unsigned)icount->count-1].ino))) {
+ return insert_icount_el(icount, ino, (unsigned) icount->count);
}
if (icount->count == 0)
return 0;
@@ -232,7 +232,7 @@ static struct ext2_icount_el *get_icount_el(ext2_icount_t icount,
printf("Non-cursor get_icount_el: %u\n", ino);
#endif
low = 0;
- high = icount->count-1;
+ high = (int) icount->count-1;
while (low <= high) {
#if 0
mid = (low+high)/2;
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index c1f3608f..3e6028b0 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -51,7 +51,7 @@
#ifdef EXT2_DFL_CHECKINTERVAL
#undef EXT2_DFL_CHECKINTERVAL
#endif
-#define EXT2_DFL_CHECKINTERVAL (86400 * 180)
+#define EXT2_DFL_CHECKINTERVAL (86400L * 180L)
errcode_t ext2fs_initialize(const char *name, int flags,
struct ext2_super_block *param,
@@ -65,7 +65,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
int overhead = 0;
blk_t group_block;
int i, j;
- int numblocks;
+ blk_t numblocks;
char *buf;
if (!param || !param->s_blocks_count)
@@ -205,15 +205,15 @@ retry:
* XXX Not all block groups need the descriptor blocks, but
* being clever is tricky...
*/
- overhead = 3 + fs->desc_blocks + fs->inode_blocks_per_group;
+ overhead = (int) (3 + fs->desc_blocks + fs->inode_blocks_per_group);
/*
* See if the last group is big enough to support the
* necessary data structures. If not, we need to get rid of
* it.
*/
- rem = (super->s_blocks_count - super->s_first_data_block) %
- super->s_blocks_per_group;
+ rem = (int) ((super->s_blocks_count - super->s_first_data_block) %
+ super->s_blocks_per_group);
if ((fs->group_desc_count == 1) && rem && (rem < overhead))
return EXT2_ET_TOOSMALL;
if (rem && (rem < overhead+50)) {
@@ -245,12 +245,12 @@ retry:
free(buf);
- fs->group_desc = malloc(fs->desc_blocks * fs->blocksize);
+ fs->group_desc = malloc((size_t) fs->desc_blocks * fs->blocksize);
if (!fs->group_desc) {
retval = ENOMEM;
goto cleanup;
}
- memset(fs->group_desc, 0, fs->desc_blocks * fs->blocksize);
+ memset(fs->group_desc, 0, (size_t) fs->desc_blocks * fs->blocksize);
/*
* Reserve the superblock and group descriptors for each
diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index ddca41c7..37c47c42 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -26,13 +26,15 @@
#include "ext2fsP.h"
struct ext2_struct_inode_scan {
- int magic;
+ errcode_t magic;
ext2_filsys fs;
ino_t current_inode;
blk_t current_block;
dgrp_t current_group;
- int inodes_left, blocks_left, groups_left;
- int inode_buffer_blocks;
+ ino_t inodes_left;
+ blk_t blocks_left;
+ dgrp_t groups_left;
+ blk_t inode_buffer_blocks;
char * inode_buffer;
int inode_size;
char * ptr;
@@ -117,7 +119,8 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
scan->current_group = -1;
scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : 8;
scan->groups_left = fs->group_desc_count;
- scan->inode_buffer = malloc(scan->inode_buffer_blocks * fs->blocksize);
+ scan->inode_buffer = malloc((size_t) (scan->inode_buffer_blocks *
+ fs->blocksize));
scan->done_group = 0;
scan->done_group_data = 0;
scan->bad_block_ptr = 0;
@@ -213,7 +216,7 @@ errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
* increasing order.
*/
static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
- int *num_blocks)
+ blk_t *num_blocks)
{
blk_t blk = scan->current_block;
badblocks_list bb = scan->fs->badblocks;
@@ -261,7 +264,7 @@ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
* will be the bad block, which is handled in the above case.)
*/
if ((blk + *num_blocks) > bb->list[scan->bad_block_ptr])
- *num_blocks = bb->list[scan->bad_block_ptr] - blk;
+ *num_blocks = (int) (bb->list[scan->bad_block_ptr] - blk);
return 0;
}
@@ -272,7 +275,7 @@ static errcode_t check_for_inode_bad_blocks(ext2_inode_scan scan,
*/
static errcode_t get_next_blocks(ext2_inode_scan scan)
{
- int num_blocks;
+ blk_t num_blocks;
errcode_t retval;
/*
@@ -306,11 +309,12 @@ static errcode_t get_next_blocks(ext2_inode_scan scan)
if ((scan->scan_flags & EXT2_SF_BAD_INODE_BLK) ||
(scan->current_block == 0)) {
memset(scan->inode_buffer, 0,
- num_blocks * scan->fs->blocksize);
+ (size_t) num_blocks * scan->fs->blocksize);
} else {
retval = io_channel_read_blk(scan->fs->io,
scan->current_block,
- num_blocks, scan->inode_buffer);
+ (int) num_blocks,
+ scan->inode_buffer);
if (retval)
return EXT2_ET_NEXT_INODE_READ;
}
@@ -444,9 +448,9 @@ errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
EXT2_INODE_SIZE(fs->super);
block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
- if (!fs->group_desc[group].bg_inode_table)
+ if (!fs->group_desc[(unsigned)group].bg_inode_table)
return EXT2_ET_MISSING_INODE_TABLE;
- block_nr = fs->group_desc[group].bg_inode_table + block;
+ block_nr = fs->group_desc[(unsigned)group].bg_inode_table + block;
if (block_nr != fs->icache->buffer_blk) {
retval = io_channel_read_blk(fs->io, block_nr, 1,
fs->icache->buffer);
@@ -455,7 +459,7 @@ errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
fs->icache->buffer_blk = block_nr;
}
offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
- ptr = ((char *) fs->icache->buffer) + offset;
+ ptr = ((char *) fs->icache->buffer) + (unsigned) offset;
memset(inode, 0, sizeof(struct ext2_inode));
length = EXT2_INODE_SIZE(fs->super);
@@ -463,7 +467,7 @@ errcode_t ext2fs_read_inode (ext2_filsys fs, ino_t ino,
length = sizeof(struct ext2_inode);
if ((offset + length) > EXT2_BLOCK_SIZE(fs->super)) {
- clen = EXT2_BLOCK_SIZE(fs->super) - offset;
+ clen = (int) (EXT2_BLOCK_SIZE(fs->super) - offset);
memcpy((char *) inode, ptr, clen);
length -= clen;
@@ -541,11 +545,11 @@ errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
EXT2_INODE_SIZE(fs->super);
block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
- if (!fs->group_desc[group].bg_inode_table)
+ if (!fs->group_desc[(unsigned) group].bg_inode_table)
return EXT2_ET_MISSING_INODE_TABLE;
- block_nr = fs->group_desc[group].bg_inode_table + block;
+ block_nr = fs->group_desc[(unsigned) group].bg_inode_table + block;
offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
- ptr = (char *) fs->icache->buffer + offset;
+ ptr = (char *) fs->icache->buffer + (unsigned) offset;
length = EXT2_INODE_SIZE(fs->super);
clen = length;
@@ -561,7 +565,7 @@ errcode_t ext2fs_write_inode(ext2_filsys fs, ino_t ino,
}
if ((offset + length) > EXT2_BLOCK_SIZE(fs->super)) {
- clen = EXT2_BLOCK_SIZE(fs->super) - offset;
+ clen = (int) (EXT2_BLOCK_SIZE(fs->super) - offset);
length -= clen;
} else {
length = 0;
diff --git a/lib/ext2fs/io.h b/lib/ext2fs/io.h
index fcd1a01f..efc8ff8e 100644
--- a/lib/ext2fs/io.h
+++ b/lib/ext2fs/io.h
@@ -25,7 +25,7 @@ typedef struct struct_io_manager *io_manager;
typedef struct struct_io_channel *io_channel;
struct struct_io_channel {
- int magic;
+ errcode_t magic;
io_manager manager;
char *name;
int block_size;
@@ -49,7 +49,7 @@ struct struct_io_channel {
};
struct struct_io_manager {
- int magic;
+ errcode_t magic;
const char *name;
errcode_t (*open)(const char *name, int flags, io_channel *channel);
errcode_t (*close)(io_channel channel);
diff --git a/lib/ext2fs/irel_ma.c b/lib/ext2fs/irel_ma.c
index 3a8538ca..8a9ac748 100644
--- a/lib/ext2fs/irel_ma.c
+++ b/lib/ext2fs/irel_ma.c
@@ -91,19 +91,21 @@ errcode_t ext2fs_irel_memarray_create(char *name, ino_t max_inode,
memset(ma, 0, sizeof(struct irel_ma));
irel->private = ma;
- size = sizeof(ino_t) * (max_inode+1);
+ size = (size_t) (sizeof(ino_t) * (max_inode+1));
ma->orig_map = malloc(size);
if (!ma->orig_map)
goto errout;
memset(ma->orig_map, 0, size);
- size = sizeof(struct ext2_inode_relocate_entry) * (max_inode+1);
+ size = (size_t) (sizeof(struct ext2_inode_relocate_entry) *
+ (max_inode+1));
ma->entries = malloc(size);
if (!ma->entries)
goto errout;
memset(ma->entries, 0, size);
- size = sizeof(struct inode_reference_entry) * (max_inode+1);
+ size = (size_t) (sizeof(struct inode_reference_entry) *
+ (max_inode+1));
ma->ref_entries = malloc(size);
if (!ma->ref_entries)
goto errout;
@@ -149,16 +151,17 @@ static errcode_t ima_put(ext2_irel irel, ino_t old,
* Force the orig field to the correct value; the application
* program shouldn't be messing with this field.
*/
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned) old].new == 0)
ent->orig = old;
else
- ent->orig = ma->entries[old].orig;
+ ent->orig = ma->entries[(unsigned) old].orig;
/*
* If max_refs has changed, reallocate the refs array
*/
- ref_ent = ma->ref_entries + old;
- if (ref_ent->refs && ent->max_refs != ma->entries[old].max_refs) {
+ ref_ent = ma->ref_entries + (unsigned) old;
+ if (ref_ent->refs && ent->max_refs !=
+ ma->entries[(unsigned) old].max_refs) {
size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
new_refs = realloc(ref_ent->refs, size);
if (!new_refs)
@@ -166,8 +169,8 @@ static errcode_t ima_put(ext2_irel irel, ino_t old,
ref_ent->refs = new_refs;
}
- ma->entries[old] = *ent;
- ma->orig_map[ent->orig] = old;
+ ma->entries[(unsigned) old] = *ent;
+ ma->orig_map[(unsigned) ent->orig] = old;
return 0;
}
@@ -179,9 +182,9 @@ static errcode_t ima_get(ext2_irel irel, ino_t old,
ma = irel->private;
if (old > ma->max_inode)
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned) old].new == 0)
return ENOENT;
- *ent = ma->entries[old];
+ *ent = ma->entries[(unsigned) old];
return 0;
}
@@ -194,11 +197,11 @@ static errcode_t ima_get_by_orig(ext2_irel irel, ino_t orig, ino_t *old,
ma = irel->private;
if (orig > ma->max_inode)
return EINVAL;
- ino = ma->orig_map[orig];
+ ino = ma->orig_map[(unsigned) orig];
if (ino == 0)
return ENOENT;
*old = ino;
- *ent = ma->entries[ino];
+ *ent = ma->entries[(unsigned) ino];
return 0;
}
@@ -215,10 +218,10 @@ static errcode_t ima_next(ext2_irel irel, ino_t *old,
ma = irel->private;
while (++irel->current < ma->max_inode) {
- if (ma->entries[irel->current].new == 0)
+ if (ma->entries[(unsigned) irel->current].new == 0)
continue;
*old = irel->current;
- *ent = ma->entries[irel->current];
+ *ent = ma->entries[(unsigned) irel->current];
return 0;
}
*old = 0;
@@ -237,14 +240,15 @@ static errcode_t ima_add_ref(ext2_irel irel, ino_t ino,
if (ino > ma->max_inode)
return EINVAL;
- ref_ent = ma->ref_entries + ino;
- ent = ma->entries + ino;
+ ref_ent = ma->ref_entries + (unsigned) ino;
+ ent = ma->entries + (unsigned) ino;
/*
* If the inode reference array doesn't exist, create it.
*/
if (ref_ent->refs == 0) {
- size = (sizeof(struct ext2_inode_reference) * ent->max_refs);
+ size = (size_t) ((sizeof(struct ext2_inode_reference) *
+ ent->max_refs));
ref_ent->refs = malloc(size);
if (ref_ent->refs == 0)
return ENOMEM;
@@ -255,7 +259,7 @@ static errcode_t ima_add_ref(ext2_irel irel, ino_t ino,
if (ref_ent->num >= ent->max_refs)
return ENOSPC;
- ref_ent->refs[ref_ent->num++] = *ref;
+ ref_ent->refs[(unsigned) ref_ent->num++] = *ref;
return 0;
}
@@ -266,7 +270,7 @@ static errcode_t ima_start_iter_ref(ext2_irel irel, ino_t ino)
ma = irel->private;
if (ino > ma->max_inode)
return EINVAL;
- if (ma->entries[ino].new == 0)
+ if (ma->entries[(unsigned) ino].new == 0)
return ENOENT;
ma->ref_current = ino;
ma->ref_iter = 0;
@@ -301,17 +305,17 @@ static errcode_t ima_move(ext2_irel irel, ino_t old, ino_t new)
ma = irel->private;
if ((old > ma->max_inode) || (new > ma->max_inode))
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned) old].new == 0)
return ENOENT;
- ma->entries[new] = ma->entries[old];
- if (ma->ref_entries[new].refs)
- free(ma->ref_entries[new].refs);
- ma->ref_entries[new] = ma->ref_entries[old];
+ ma->entries[(unsigned) new] = ma->entries[(unsigned) old];
+ if (ma->ref_entries[(unsigned) new].refs)
+ free(ma->ref_entries[(unsigned) new].refs);
+ ma->ref_entries[(unsigned) new] = ma->ref_entries[(unsigned) old];
- ma->entries[old].new = 0;
- ma->ref_entries[old].num = 0;
- ma->ref_entries[old].refs = 0;
+ ma->entries[(unsigned) old].new = 0;
+ ma->ref_entries[(unsigned) old].num = 0;
+ ma->ref_entries[(unsigned) old].refs = 0;
ma->orig_map[ma->entries[new].orig] = new;
return 0;
@@ -324,16 +328,16 @@ static errcode_t ima_delete(ext2_irel irel, ino_t old)
ma = irel->private;
if (old > ma->max_inode)
return EINVAL;
- if (ma->entries[old].new == 0)
+ if (ma->entries[(unsigned) old].new == 0)
return ENOENT;
ma->entries[old].new = 0;
- if (ma->ref_entries[old].refs)
- free(ma->ref_entries[old].refs);
- ma->orig_map[ma->entries[old].orig] = 0;
+ if (ma->ref_entries[(unsigned) old].refs)
+ free(ma->ref_entries[(unsigned) old].refs);
+ ma->orig_map[ma->entries[(unsigned) old].orig] = 0;
- ma->ref_entries[old].num = 0;
- ma->ref_entries[old].refs = 0;
+ ma->ref_entries[(unsinged) old].num = 0;
+ ma->ref_entries[(unsigned) old].refs = 0;
return 0;
}
@@ -354,8 +358,8 @@ static errcode_t ima_free(ext2_irel irel)
free (ma->entries);
if (ma->ref_entries) {
for (ino = 0; ino <= ma->max_inode; ino++) {
- if (ma->ref_entries[ino].refs)
- free(ma->ref_entries[ino].refs);
+ if (ma->ref_entries[(unsigned) ino].refs)
+ free(ma->ref_entries[(unsigned) ino].refs);
}
free(ma->ref_entries);
}
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c
index 9c2593cc..ad4c7369 100644
--- a/lib/ext2fs/ismounted.c
+++ b/lib/ext2fs/ismounted.c
@@ -110,6 +110,9 @@ static errcode_t check_getmntinfo(const char *file, int *mount_flags)
/*
* Is_mounted is set to 1 if the device is mounted, 0 otherwise
*/
+#ifdef __TURBOC__
+#pragma argsused
+#endif
errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags)
{
#ifdef HAVE_MNTENT_H
diff --git a/lib/ext2fs/link.c b/lib/ext2fs/link.c
index 63b11b45..a8e51506 100644
--- a/lib/ext2fs/link.c
+++ b/lib/ext2fs/link.c
@@ -86,6 +86,9 @@ static int link_proc(struct ext2_dir_entry *dirent,
return DIRENT_ABORT|DIRENT_CHANGED;
}
+#ifdef __TURBOC__
+#pragma argsused
+#endif
errcode_t ext2fs_link(ext2_filsys fs, ino_t dir, const char *name, ino_t ino,
int flags)
{
diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c
index 986bf0be..9e9d4841 100644
--- a/lib/ext2fs/llseek.c
+++ b/lib/ext2fs/llseek.c
@@ -12,9 +12,13 @@
#include <sys/types.h>
#include <errno.h>
+#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef __MSDOS__
+#include <io.h>
+#endif
#include "et/com_err.h"
#include "ext2fs/io.h"
diff --git a/lib/ext2fs/lookup.c b/lib/ext2fs/lookup.c
index 575806e1..cedaa04c 100644
--- a/lib/ext2fs/lookup.c
+++ b/lib/ext2fs/lookup.c
@@ -30,6 +30,9 @@ struct lookup_struct {
int found;
};
+#ifdef __TURBOC__
+#pragma argsused
+#endif
static int lookup_proc(struct ext2_dir_entry *dirent,
int offset,
int blocksize,
diff --git a/lib/ext2fs/namei.c b/lib/ext2fs/namei.c
index 9824977c..a79cc728 100644
--- a/lib/ext2fs/namei.c
+++ b/lib/ext2fs/namei.c
@@ -26,7 +26,7 @@
#include "ext2fs.h"
static errcode_t open_namei(ext2_filsys fs, ino_t root, ino_t base,
- const char *pathname, int pathlen, int follow,
+ const char *pathname, size_t pathlen, int follow,
int link_count, char *buf, ino_t *res_inode);
static errcode_t follow_link(ext2_filsys fs, ino_t root, ino_t dir,
@@ -115,7 +115,7 @@ static errcode_t dir_namei(ext2_filsys fs, ino_t root, ino_t dir,
}
static errcode_t open_namei(ext2_filsys fs, ino_t root, ino_t base,
- const char *pathname, int pathlen, int follow,
+ const char *pathname, size_t pathlen, int follow,
int link_count, char *buf, ino_t *res_inode)
{
const char *basename;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index a1c0d5bc..73a1da61 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -44,7 +44,8 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
{
ext2_filsys fs;
errcode_t retval;
- int i, j, group_block, groups_per_block;
+ int i, j, groups_per_block;
+ blk_t group_block;
char *dest;
struct ext2_group_desc *gdp;
struct ext2fs_sb *s;
@@ -169,7 +170,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
fs->desc_blocks = (fs->group_desc_count +
EXT2_DESC_PER_BLOCK(fs->super) - 1)
/ EXT2_DESC_PER_BLOCK(fs->super);
- fs->group_desc = malloc(fs->desc_blocks * fs->blocksize);
+ fs->group_desc = malloc((size_t) (fs->desc_blocks * fs->blocksize));
if (!fs->group_desc) {
retval = ENOMEM;
goto cleanup;
diff --git a/lib/ext2fs/read_bb.c b/lib/ext2fs/read_bb.c
index 6934ab9e..7379bbdf 100644
--- a/lib/ext2fs/read_bb.c
+++ b/lib/ext2fs/read_bb.c
@@ -32,6 +32,9 @@ struct read_bb_record {
/*
* Helper function for ext2fs_read_bb_inode()
*/
+#ifdef __TURBOC__
+#pragma argsused
+#endif
static int mark_bad_block(ext2_filsys fs, blk_t *block_nr,
int blockcnt, void *private)
{
@@ -54,7 +57,7 @@ errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list)
errcode_t retval;
struct read_bb_record rb;
struct ext2_inode inode;
- int numblocks;
+ blk_t numblocks;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index bbde132a..5deca2c2 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -30,7 +30,7 @@
errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
{
int i;
- int nbytes;
+ size_t nbytes;
errcode_t retval;
char * inode_bitmap = fs->inode_map->bitmap;
char * bitmap_block = NULL;
@@ -42,7 +42,7 @@ errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
return EXT2_ET_RO_FILSYS;
if (!inode_bitmap)
return 0;
- nbytes = (EXT2_INODES_PER_GROUP(fs->super)+7) / 8;
+ nbytes = (size_t) ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
bitmap_block = malloc(fs->blocksize);
if (!bitmap_block)
@@ -91,9 +91,9 @@ errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
memcpy(bitmap_block, block_bitmap, nbytes);
if (i == fs->group_desc_count - 1) {
/* Force bitmap padding for the last group */
- nbits = (fs->super->s_blocks_count
- - fs->super->s_first_data_block)
- % EXT2_BLOCKS_PER_GROUP(fs->super);
+ nbits = (int) ((fs->super->s_blocks_count
+ - fs->super->s_first_data_block)
+ % EXT2_BLOCKS_PER_GROUP(fs->super));
if (nbits)
for (j = nbits; j < fs->blocksize * 8; j++)
ext2fs_set_bit(j, bitmap_block);
@@ -119,8 +119,8 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
char *block_bitmap = 0, *inode_bitmap = 0;
char *buf;
errcode_t retval;
- int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
- int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
+ int block_nbytes = (int) EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
+ int inode_nbytes = (int) EXT2_INODES_PER_GROUP(fs->super) / 8;
blk_t blk;
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
diff --git a/lib/ext2fs/unlink.c b/lib/ext2fs/unlink.c
index 9c554232..d880c471 100644
--- a/lib/ext2fs/unlink.c
+++ b/lib/ext2fs/unlink.c
@@ -28,6 +28,9 @@ struct link_struct {
int done;
};
+#ifdef __TURBOC__
+#pragma argsused
+#endif
static int unlink_proc(struct ext2_dir_entry *dirent,
int offset,
int blocksize,
@@ -48,6 +51,9 @@ static int unlink_proc(struct ext2_dir_entry *dirent,
return DIRENT_ABORT|DIRENT_CHANGED;
}
+#ifdef __TURBOC__
+#pragma argsused
+#endif
errcode_t ext2fs_unlink(ext2_filsys fs, ino_t dir, const char *name, ino_t ino,
int flags)
{