ReactOS 0.4.15-dev-7953-g1f49173
boot.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void read_boot (DOS_FS *fs)
 
void write_label (DOS_FS *fs, char *label)
 
off_t find_volume_de (DOS_FS *fs, DIR_ENT *de)
 

Function Documentation

◆ find_volume_de()

off_t find_volume_de ( DOS_FS fs,
DIR_ENT *  de 
)

Definition at line 524 of file boot.c.

525{
526 uint32_t cluster;
528 int i;
529
530 if (fs->root_cluster) {
531 for (cluster = fs->root_cluster;
532 cluster != 0 && cluster != -1;
533 cluster = next_cluster(fs, cluster)) {
534 offset = cluster_start(fs, cluster);
535 for (i = 0; i * sizeof(DIR_ENT) < fs->cluster_size; i++) {
536 fs_read(offset, sizeof(DIR_ENT), de);
537 if (de->attr != VFAT_LN_ATTR && de->attr & ATTR_VOLUME)
538 return offset;
539 offset += sizeof(DIR_ENT);
540 }
541 }
542 } else {
543 for (i = 0; i < fs->root_entries; i++) {
544 offset = fs->root_start + i * sizeof(DIR_ENT);
545 fs_read(offset, sizeof(DIR_ENT), de);
546 if (de->attr != VFAT_LN_ATTR && de->attr & ATTR_VOLUME)
547 return offset;
548 }
549 }
550
551 return 0;
552}
UINT32 uint32_t
Definition: types.h:75
__kernel_off_t off_t
Definition: linux.h:201
#define VFAT_LN_ATTR
Definition: fsck.fat.h:78
GLintptr offset
Definition: glext.h:5920
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ATTR_VOLUME
Definition: mkdosfs.c:369
uint32_t next_cluster(DOS_FS *fs, uint32_t cluster)
Definition: fat.c:276
off_t cluster_start(DOS_FS *fs, uint32_t cluster)
Definition: fat.c:289
void fs_read(off_t pos, int size, void *data)
Definition: io.c:282
Definition: ffs.h:70

Referenced by write_volume_label().

◆ read_boot()

void read_boot ( DOS_FS fs)

Definition at line 334 of file boot.c.

335{
336 struct boot_sector b;
337 unsigned total_sectors;
338 unsigned int logical_sector_size, sectors;
340 unsigned total_fat_entries;
341 off_t data_size;
342
343 fs_read(0, sizeof(b), &b);
344 logical_sector_size = GET_UNALIGNED_W(b.sector_size);
345 if (!logical_sector_size)
346 die("Logical sector size is zero.");
347
348 /* This was moved up because it's the first thing that will fail */
349 /* if the platform needs special handling of unaligned multibyte accesses */
350 /* but such handling isn't being provided. See GET_UNALIGNED_W() above. */
351 if (logical_sector_size & (SECTOR_SIZE - 1))
352 die("Logical sector size (%d bytes) is not a multiple of the physical "
353 "sector size.", logical_sector_size);
354
355 fs->cluster_size = b.cluster_size * logical_sector_size;
356 if (!fs->cluster_size)
357 die("Cluster size is zero.");
358 if (b.fats != 2 && b.fats != 1)
359 die("Currently, only 1 or 2 FATs are supported, not %d.\n", b.fats);
360 fs->nfats = b.fats;
361 sectors = GET_UNALIGNED_W(b.sectors);
362 total_sectors = sectors ? sectors : le32toh(b.total_sect);
363 if (verbose)
364 printf("Checking we can access the last sector of the filesystem\n");
365 /* Can't access last odd sector anyway, so round down */
366 fs_test((off_t)((total_sectors & ~1) - 1) * logical_sector_size,
367 logical_sector_size);
368
369 fat_length = le16toh(b.fat_length) ?
370 le16toh(b.fat_length) : le32toh(b.fat32_length);
371 if (!fat_length)
372 die("FAT size is zero.");
373
374 fs->fat_start = (off_t)le16toh(b.reserved) * logical_sector_size;
375 fs->root_start = ((off_t)le16toh(b.reserved) + b.fats * fat_length) *
376 logical_sector_size;
377 fs->root_entries = GET_UNALIGNED_W(b.dir_entries);
378 fs->data_start = fs->root_start + ROUND_TO_MULTIPLE(fs->root_entries <<
380 logical_sector_size);
381
382 data_size = (off_t)total_sectors * logical_sector_size - fs->data_start;
383 if (data_size < fs->cluster_size)
384 die("Filesystem has no space for any data clusters");
385
386 fs->data_clusters = data_size / fs->cluster_size;
387 fs->root_cluster = 0; /* indicates standard, pre-FAT32 root dir */
388 fs->fsinfo_start = 0; /* no FSINFO structure */
389 fs->free_clusters = -1; /* unknown */
390 if (!b.fat_length && b.fat32_length) {
391 fs->fat_bits = 32;
392 fs->root_cluster = le32toh(b.root_cluster);
393 if (!fs->root_cluster && fs->root_entries)
394 /* M$ hasn't specified this, but it looks reasonable: If
395 * root_cluster is 0 but there is a separate root dir
396 * (root_entries != 0), we handle the root dir the old way. Give a
397 * warning, but convertig to a root dir in a cluster chain seems
398 * to complex for now... */
399 printf("Warning: FAT32 root dir not in cluster chain! "
400 "Compatibility mode...\n");
401 else if (!fs->root_cluster && !fs->root_entries)
402 die("No root directory!");
403 else if (fs->root_cluster && fs->root_entries)
404 printf("Warning: FAT32 root dir is in a cluster chain, but "
405 "a separate root dir\n"
406 " area is defined. Cannot fix this easily.\n");
407 if (fs->data_clusters < FAT16_THRESHOLD)
408 printf("Warning: Filesystem is FAT32 according to fat_length "
409 "and fat32_length fields,\n"
410 " but has only %lu clusters, less than the required "
411 "minimum of %d.\n"
412 " This may lead to problems on some systems.\n",
413 (unsigned long)fs->data_clusters, FAT16_THRESHOLD);
414
416 fs->backupboot_start = le16toh(b.backup_boot) * logical_sector_size;
417 check_backup_boot(fs, &b, logical_sector_size);
418
419 read_fsinfo(fs, &b, logical_sector_size);
420 } else if (!atari_format) {
421 /* On real MS-DOS, a 16 bit FAT is used whenever there would be too
422 * much clusers otherwise. */
423 fs->fat_bits = (fs->data_clusters >= FAT12_THRESHOLD) ? 16 : 12;
424 if (fs->data_clusters >= FAT16_THRESHOLD)
425 die("Too many clusters (%lu) for FAT16 filesystem.",
426 (unsigned long)fs->data_clusters);
428 } else {
429 /* On Atari, things are more difficult: GEMDOS always uses 12bit FATs
430 * on floppies, and always 16 bit on harddisks. */
431 fs->fat_bits = 16; /* assume 16 bit FAT for now */
432 /* If more clusters than fat entries in 16-bit fat, we assume
433 * it's a real MSDOS FS with 12-bit fat. */
434 if (fs->data_clusters + 2 > fat_length * logical_sector_size * 8 / 16 ||
435 /* if it has one of the usual floppy sizes -> 12bit FAT */
436 (total_sectors == 720 || total_sectors == 1440 ||
437 total_sectors == 2880))
438 fs->fat_bits = 12;
439 }
440 /* On FAT32, the high 4 bits of a FAT entry are reserved */
441 fs->eff_fat_bits = (fs->fat_bits == 32) ? 28 : fs->fat_bits;
442 fs->fat_size = fat_length * logical_sector_size;
443
444 fs->label = calloc(12, sizeof(uint8_t));
445 if (fs->fat_bits == 12 || fs->fat_bits == 16) {
446 struct boot_sector_16 *b16 = (struct boot_sector_16 *)&b;
447 if (b16->extended_sig == 0x29)
448 memmove(fs->label, b16->label, 11);
449 else
450#ifdef __REACTOS__
451 {
452 free(fs->label);
453#endif
454 fs->label = NULL;
455#ifdef __REACTOS__
456 }
457#endif
458 } else if (fs->fat_bits == 32) {
459 if (b.extended_sig == 0x29)
460 memmove(fs->label, &b.label, 11);
461 else
462#ifdef __REACTOS__
463 {
464 free(fs->label);
465#endif
466 fs->label = NULL;
467#ifdef __REACTOS__
468 }
469#endif
470 }
471
472 total_fat_entries = (uint64_t)fs->fat_size * 8 / fs->fat_bits;
473 if (fs->data_clusters > total_fat_entries - 2)
474 die("Filesystem has %u clusters but only space for %u FAT entries.",
475 fs->data_clusters, total_fat_entries - 2);
476 if (!fs->root_entries && !fs->root_cluster)
477 die("Root directory has zero size.");
478 if (fs->root_entries & (MSDOS_DPS - 1))
479 die("Root directory (%d entries) doesn't span an integral number of "
480 "sectors.", fs->root_entries);
481 if (logical_sector_size & (SECTOR_SIZE - 1))
482 die("Logical sector size (%u bytes) is not a multiple of the physical "
483 "sector size.", logical_sector_size);
484#if 0 /* linux kernel doesn't check that either */
485 /* ++roman: On Atari, these two fields are often left uninitialized */
486 if (!atari_format && (!b.secs_track || !b.heads))
487 die("Invalid disk format in boot sector.");
488#endif
489 if (verbose)
490 dump_boot(fs, &b, logical_sector_size);
491}
#define SECTOR_SIZE
Definition: fs.h:22
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define off_t
Definition: dosfsck.h:5
#define printf
Definition: freeldr.h:97
uint32_t fat32_length
Definition: fsck.fat.h:17
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
if(dx< 0)
Definition: linetemp.h:194
__u16 fat_length
Definition: mkdosfs.c:10
__u8 cluster_size
Definition: mkdosfs.c:4
#define die(str)
Definition: mkdosfs.c:347
__u8 sectors[2]
Definition: mkdosfs.c:8
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define MSDOS_DPS
Definition: msdos_fs.h:28
#define MSDOS_DIR_BITS
Definition: msdos_fs.h:30
BYTE uint8_t
Definition: msvideo1.c:66
#define uint64_t
Definition: nsiface.idl:62
#define atari_format
Definition: rosglue.h:41
#define calloc
Definition: rosglue.h:14
#define verbose
Definition: rosglue.h:36
#define FAT16_THRESHOLD
Definition: boot.c:41
static void read_fsinfo(DOS_FS *fs, struct boot_sector *b, unsigned int lss)
Definition: boot.c:219
static void check_backup_boot(DOS_FS *fs, struct boot_sector *b, unsigned int lss)
Definition: boot.c:127
#define FAT12_THRESHOLD
Definition: boot.c:40
#define ROUND_TO_MULTIPLE(n, m)
Definition: boot.c:36
#define GET_UNALIGNED_W(f)
Definition: boot.c:60
static void check_fat_state_bit(DOS_FS *fs, void *b)
Definition: boot.c:309
static void dump_boot(DOS_FS *fs, struct boot_sector *b, unsigned lss)
Definition: boot.c:74
int fs_test(off_t pos, int size)
Definition: io.c:322
uint8_t extended_sig
Definition: fsck.fat.h:146
uint8_t label[11]
Definition: fsck.fat.h:148

Referenced by VfatChkdsk().

◆ write_label()

void write_label ( DOS_FS fs,
char label 
)

Definition at line 589 of file boot.c.

590{
591 int l = strlen(label);
592
593 while (l < 11)
594 label[l++] = ' ';
595
598}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
r l[0]
Definition: byte_order.h:168
static const WCHAR label[]
Definition: itemdlg.c:1546
static void write_boot_label(DOS_FS *fs, char *label)
Definition: boot.c:494
static void write_volume_label(DOS_FS *fs, char *label)
Definition: boot.c:554