PKUOS - Pintos
Pintos source browser for PKU Operating System course
Data Structures | Functions | Variables
partition.c File Reference
#include "devices/partition.h"
#include <packed.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "devices/block.h"
#include "threads/malloc.h"
Include dependency graph for partition.c:

Go to the source code of this file.

Data Structures

struct  partition
 A partition of a block device. More...
 

Functions

static void read_partition_table (struct block *block, block_sector_t sector, block_sector_t primary_extended_sector, int *part_nr)
 Reads the partition table in the given SECTOR of BLOCK and scans it for partitions of interest to Pintos. More...
 
static void found_partition (struct block *block, uint8_t part_type, block_sector_t start, block_sector_t size, int part_nr)
 We have found a primary or logical partition of the given TYPE on BLOCK, starting at sector START and continuing for SIZE sectors, which we are giving the partition number PART_NR. More...
 
static const char * partition_type_name (uint8_t type)
 Returns a human-readable name for the given partition TYPE. More...
 
void partition_scan (struct block *block)
 Scans BLOCK for partitions of interest to Pintos. More...
 
static void partition_read (void *p_, block_sector_t sector, void *buffer)
 Reads sector SECTOR from partition P into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes. More...
 
static void partition_write (void *p_, block_sector_t sector, const void *buffer)
 Write sector SECTOR to partition P from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes. More...
 

Variables

static struct block_operations partition_operations
 

Function Documentation

◆ found_partition()

static void found_partition ( struct block block,
uint8_t  part_type,
block_sector_t  start,
block_sector_t  size,
int  part_nr 
)
static

We have found a primary or logical partition of the given TYPE on BLOCK, starting at sector START and continuing for SIZE sectors, which we are giving the partition number PART_NR.

Check whether this is a partition of interest to Pintos, and if so then add it to the proper element of partitions[].

Definition at line 154 of file partition.c.

References partition::block, BLOCK_FILESYS, BLOCK_FOREIGN, BLOCK_KERNEL, block_name(), block_register(), BLOCK_SCRATCH, block_size(), BLOCK_SWAP, malloc(), name, NULL, PANIC, partition_operations, partition_type_name(), PRDSNu, printf(), snprintf(), partition::start, and start.

Referenced by read_partition_table().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ partition_read()

static void partition_read ( void *  p_,
block_sector_t  sector,
void *  buffer 
)
static

Reads sector SECTOR from partition P into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.

Definition at line 304 of file partition.c.

References partition::block, block_read(), buffer, and partition::start.

Here is the call graph for this function:

◆ partition_scan()

void partition_scan ( struct block block)

Scans BLOCK for partitions of interest to Pintos.

devices/partition.h

Definition at line 28 of file partition.c.

References block_name(), printf(), and read_partition_table().

Referenced by identify_ata_device().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ partition_type_name()

static const char * partition_type_name ( uint8_t  type)
static

Returns a human-readable name for the given partition TYPE.

Definition at line 190 of file partition.c.

References NULL.

Referenced by found_partition().

Here is the caller graph for this function:

◆ partition_write()

static void partition_write ( void *  p_,
block_sector_t  sector,
const void *  buffer 
)
static

Write sector SECTOR to partition P from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.

Returns after the block has acknowledged receiving the data.

Definition at line 314 of file partition.c.

References partition::block, block_write(), buffer, and partition::start.

Here is the call graph for this function:

◆ read_partition_table()

static void read_partition_table ( struct block block,
block_sector_t  sector,
block_sector_t  primary_extended_sector,
int *  part_nr 
)
static

Reads the partition table in the given SECTOR of BLOCK and scans it for partitions of interest to Pintos.

If SECTOR is 0, so that this is the top-level partition table on BLOCK, then PRIMARY_EXTENDED_SECTOR is not meaningful; otherwise, it should designate the sector of the top-level extended partition table that was traversed to arrive at SECTOR, for use in finding logical partitions (see the large comment below).

PART_NR points to the number of non-empty primary or logical partitions already encountered on BLOCK. It is incremented as partitions are found.

< 0x00=not bootable, 0x80=bootable.

< Encoded starting cylinder, head, sector.

< Partition type (see partition_type_name).

< Encoded ending cylinder, head, sector.

< Start sector offset from partition table.

< Number of sectors.

< Loader, in top-level partition table.

< Table entries.

< Should be 0xaa55.

< Extended partition.

< Windows 98 extended partition.

< Linux extended partition.

< DR-DOS extended partition.

Definition at line 50 of file partition.c.

References ASSERT, block_name(), block_read(), BLOCK_SECTOR_SIZE, block_size(), found_partition(), free(), malloc(), NULL, PACKED, PANIC, PRDSNu, printf(), read_partition_table(), and block::type.

Referenced by partition_scan(), and read_partition_table().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ partition_operations

static struct block_operations partition_operations
static
Initial value:
=
{
}
static void partition_write(void *p_, block_sector_t sector, const void *buffer)
Write sector SECTOR to partition P from BUFFER, which must contain BLOCK_SECTOR_SIZE bytes.
Definition: partition.c:314
static void partition_read(void *p_, block_sector_t sector, void *buffer)
Reads sector SECTOR from partition P into BUFFER, which must have room for BLOCK_SECTOR_SIZE bytes.
Definition: partition.c:304

Definition at line 16 of file partition.c.

Referenced by found_partition().