mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-13 10:02:38 +00:00
Prepare to fix checkdirty() by moving it from check.c to fat.c. It is
identical to a subset of readfat(), so it belongs near readfat() if not in it.
This commit is contained in:
parent
cb10cbc878
commit
a270f31ebd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=125469
@ -199,46 +199,3 @@ checkfilesys(const char *fname)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
checkdirty(int fs, struct bootblock *boot)
|
||||
{
|
||||
off_t off;
|
||||
u_char *buffer;
|
||||
int ret = 0;
|
||||
|
||||
if (boot->ClustMask == CLUST12_MASK)
|
||||
return 0;
|
||||
|
||||
off = boot->ResSectors;
|
||||
off *= boot->BytesPerSec;
|
||||
|
||||
buffer = malloc(boot->BytesPerSec);
|
||||
if (buffer == NULL) {
|
||||
perror("No space for FAT");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (lseek(fs, off, SEEK_SET) != off) {
|
||||
perror("Unable to read FAT");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (read(fs, buffer, boot->BytesPerSec) != boot->BytesPerSec) {
|
||||
perror("Unable to read FAT");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (buffer[0] == boot->Media && buffer[1] == 0xff && buffer[2] == 0xff
|
||||
&& ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f)
|
||||
|| (boot->ClustMask == CLUST32_MASK && buffer[3] == 0x0f
|
||||
&& buffer[4] == 0xff && buffer[5] == 0xff
|
||||
&& buffer[6] == 0xff && buffer[7] == 0x07)))
|
||||
ret = 0;
|
||||
else
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
@ -52,6 +52,49 @@ static int clustdiffer(cl_t, cl_t *, cl_t *, int);
|
||||
static int tryclear(struct bootblock *, struct fatEntry *, cl_t, cl_t *);
|
||||
static int _readfat(int, struct bootblock *, int, u_char **);
|
||||
|
||||
int
|
||||
checkdirty(int fs, struct bootblock *boot)
|
||||
{
|
||||
off_t off;
|
||||
u_char *buffer;
|
||||
int ret = 0;
|
||||
|
||||
if (boot->ClustMask == CLUST12_MASK)
|
||||
return 0;
|
||||
|
||||
off = boot->ResSectors;
|
||||
off *= boot->BytesPerSec;
|
||||
|
||||
buffer = malloc(boot->BytesPerSec);
|
||||
if (buffer == NULL) {
|
||||
perror("No space for FAT");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (lseek(fs, off, SEEK_SET) != off) {
|
||||
perror("Unable to read FAT");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (read(fs, buffer, boot->BytesPerSec) != boot->BytesPerSec) {
|
||||
perror("Unable to read FAT");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (buffer[0] == boot->Media && buffer[1] == 0xff && buffer[2] == 0xff
|
||||
&& ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f)
|
||||
|| (boot->ClustMask == CLUST32_MASK && buffer[3] == 0x0f
|
||||
&& buffer[4] == 0xff && buffer[5] == 0xff
|
||||
&& buffer[6] == 0xff && buffer[7] == 0x07)))
|
||||
ret = 0;
|
||||
else
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check a cluster number for valid value
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user