[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Easymint filesystem checks
On Thu, 2011-01-13 at 12:37 +0100, Jo Even Skarstein wrote:
> On Wed, 2011-01-12 at 17:02 -0500, Jeff Mitchell wrote:
> > I woudl assume the norm is to go through fstab (or hd driver) and
> > fsck all the devices with a known fs type; if its an unknwon fs, skip it
> > and do not consider it an error?
>
> I made a small test-program last night (in C). It does a
> Dcntl(FS_INFO...) on all drives, partition types are correctly
> idenfified. It should be easy to run the correct fsck on each partition.
Here's a tiny program that checks the filesystem-type on each partition
and runs e2fsck.ttp on each ext2-partition. No fstab is needed, just
this program and e2fsck. It's a pretty crude hack, but illustrates how
this can be done. It doesn't check the return value of e2fsck, so
booting will continue even if an unrecoverable error is found.
I compiled this with PureC, and it doesn't use any libraries except the
GEMDOS bindings. If somebody wants to make something useful out of this
please go ahead :)
Jo Even
#include <tos.h>
#define FS_INFO 0xf100
struct fs_info
{
char name [32]; /* name of the xfs */
long version; /* upper word: major version; lower word: minor version */
long type; /* upper word: major type; lower word: minor type */
char type_asc[32]; /* human readable version of type */
};
#define FAT 1
#define VFAT 3
#define EXT2 5
int main(int argc, const char *argv[])
{
struct fs_info info;
long drive_bits = Dsetdrv(Dgetdrv()) & ~3; /* Don't check floppies */
int i;
char drv[] = "C:\\";
Cconws("\x1bpCheck filesystems\x1bq\n\r");
for (i = 0; i < 32; i++)
{
if (drive_bits & (1L << i))
{
drv[0] = 'a' + i;
Dcntl(FS_INFO, drv, (long) &info);
Cconws("Drive "); Cconws(drv); Cconws(" "); Cconws(info.type_asc); Cconws("\n\r");
switch ((short int)(info.type >> 16))
{
case FAT:
case VFAT:
break;
case EXT2:
{
static char cmd[] = {127,0};
static char env[32] = {'A','R','G','V','=',0,'-','p',0,'-','C',0,'-',0,'x',':',0,0};
long ret;
env[14] = drv[0];
ret = Pexec(0, "e2fsck.ttp", cmd, env);
break;
}
}
}
}
return 0;
}