SFUSE_Documentation
로딩중...
검색중...
일치하는것 없음
bitmap.c 파일 참조
#include "bitmap.h"
#include "block.h"
#include <errno.h>
#include <unistd.h>
bitmap.c에 대한 include 의존 그래프

이 파일의 소스 코드 페이지로 가기

함수

int bitmap_load (int fd, uint32_t start_blk, struct sfuse_bitmaps *bmaps, uint32_t count)
 디스크에서 연속된 비트맵 블록들을 읽어 메모리에 로드
int bitmap_sync (int fd, uint32_t start_blk, const struct sfuse_bitmaps *bmaps, uint32_t count)
 메모리에 있는 비트맵을 디스크에 저장
int alloc_bit (uint8_t *map, uint32_t total_bits)
 비트맵에서 0인 비트를 찾아 1로 설정하고 인덱스를 반환
void free_bit (uint8_t *map, uint32_t idx)
 비트맵에서 지정한 인덱스 비트를 0으로 설정
int alloc_inode (struct sfuse_superblock *sb, struct sfuse_inode_bitmap *imap)
 새로운 아이노드 할당
void free_inode (struct sfuse_superblock *sb, struct sfuse_inode_bitmap *imap, uint32_t ino)
 아이노드 해제
int alloc_block (struct sfuse_superblock *sb, struct sfuse_block_bitmap *bmap)
 새로운 데이터 블록 할당
void free_block (struct sfuse_superblock *sb, struct sfuse_block_bitmap *bmap, uint32_t blk)
 데이터 블록 해제

변수

static const uint32_t BITS_PER_BLOCK = 4096 * 8
 한 블록에 담길 수 있는 비트 수

함수 문서화

◆ alloc_bit()

int alloc_bit ( uint8_t * map,
uint32_t total_bits )

비트맵에서 0인 비트를 찾아 1로 설정하고 인덱스를 반환

비트맵에서 비트를 할당

매개변수
map비트맵 버퍼
total_bits전체 비트 수
반환값
할당된 비트 인덱스, 실패 시 -ENOSPC

bitmap.c 파일의 57 번째 라인에서 정의되었습니다.

57 {
58 uint32_t blocks = (total_bits + BITS_PER_BLOCK - 1) / BITS_PER_BLOCK;
59 for (uint32_t b = 0; b < blocks; ++b) {
60 uint8_t *block_ptr = map + b * SFUSE_BLOCK_SIZE;
61 for (uint32_t byte = 0; byte < SFUSE_BLOCK_SIZE; ++byte) {
62 if (block_ptr[byte] == 0xFF)
63 continue;
64 for (uint32_t bit = 0; bit < 8; ++bit) {
65 if (!(block_ptr[byte] & (1u << bit))) {
66 uint32_t index = b * BITS_PER_BLOCK + byte * 8 + bit;
67 if (index < total_bits) {
68 block_ptr[byte] |= (uint8_t)(1u << bit);
69 return index;
70 }
71 }
72 }
73 }
74 }
75 return -ENOSPC;
76}
static const uint32_t BITS_PER_BLOCK
한 블록에 담길 수 있는 비트 수
Definition bitmap.c:11
#define SFUSE_BLOCK_SIZE
블록 크기 (바이트 단위)
Definition super.h:20
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ alloc_block()

int alloc_block ( struct sfuse_superblock * sb,
struct sfuse_block_bitmap * bmap )

새로운 데이터 블록 할당

슈퍼블록 기반으로 데이터 블록 할당

매개변수
sb슈퍼블록 포인터
bmap블록 비트맵 포인터
반환값
할당된 블록 번호, 실패 시 음수 오류 코드

bitmap.c 파일의 121 번째 라인에서 정의되었습니다.

121 {
122 int blk = alloc_bit(bmap->map, sb->total_blocks);
123 if (blk >= 0) {
124 sb->free_blocks -= 1;
125 }
126 return blk;
127}
int alloc_bit(uint8_t *map, uint32_t total_bits)
비트맵에서 0인 비트를 찾아 1로 설정하고 인덱스를 반환
Definition bitmap.c:57
uint8_t map[4096 *2]
Definition bitmap.h:24
uint32_t free_blocks
Definition super.h:56
uint32_t total_blocks
Definition super.h:54
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ alloc_inode()

int alloc_inode ( struct sfuse_superblock * sb,
struct sfuse_inode_bitmap * imap )

새로운 아이노드 할당

슈퍼블록 기반으로 아이노드 할당

매개변수
sb슈퍼블록 포인터
imap아이노드 비트맵 포인터
반환값
할당된 아이노드 번호, 실패 시 음수 오류 코드

bitmap.c 파일의 95 번째 라인에서 정의되었습니다.

95 {
96 int ino = alloc_bit(imap->map, sb->total_inodes);
97 if (ino >= 0) {
98 sb->free_inodes -= 1;
99 }
100 return ino;
101}
uint8_t map[4096]
Definition bitmap.h:17
uint32_t total_inodes
Definition super.h:53
uint32_t free_inodes
Definition super.h:55
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ bitmap_load()

int bitmap_load ( int fd,
uint32_t start_blk,
struct sfuse_bitmaps * bmaps,
uint32_t count )

디스크에서 연속된 비트맵 블록들을 읽어 메모리에 로드

비트맵을 디스크에서 읽어 메모리에 로드

매개변수
fd파일 디스크립터
start_blk시작 블록 번호
bmaps비트맵 구조체 포인터
count읽을 블록 수
반환값
성공 시 0, 실패 시 -EIO

bitmap.c 파일의 21 번째 라인에서 정의되었습니다.

22 {
23 uint8_t *buffer = (uint8_t *)bmaps;
24 for (uint32_t i = 0; i < count; ++i) {
25 if (read_block(fd, start_blk + i, buffer + i * SFUSE_BLOCK_SIZE) < 0) {
26 return -EIO;
27 }
28 }
29 return 0;
30}
ssize_t read_block(int fd, uint32_t blk, void *out_buf)
지정한 블록 번호의 데이터를 읽어 버퍼에 저장
Definition block.c:15
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ bitmap_sync()

int bitmap_sync ( int fd,
uint32_t start_blk,
const struct sfuse_bitmaps * bmaps,
uint32_t count )

메모리에 있는 비트맵을 디스크에 저장

메모리 비트맵을 디스크에 동기화

매개변수
fd파일 디스크립터
start_blk시작 블록 번호
bmaps비트맵 구조체 포인터 (읽기 전용)
count기록할 블록 수
반환값
성공 시 0, 실패 시 -EIO

bitmap.c 파일의 40 번째 라인에서 정의되었습니다.

41 {
42 const uint8_t *buffer = (const uint8_t *)bmaps;
43 for (uint32_t i = 0; i < count; ++i) {
44 if (write_block(fd, start_blk + i, buffer + i * SFUSE_BLOCK_SIZE) < 0) {
45 return -EIO;
46 }
47 }
48 return 0;
49}
ssize_t write_block(int fd, uint32_t blk, const void *buf)
버퍼의 내용을 지정한 블록 번호에 기록
Definition block.c:31
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ free_bit()

void free_bit ( uint8_t * map,
uint32_t idx )

비트맵에서 지정한 인덱스 비트를 0으로 설정

비트맵에서 비트를 해제

매개변수
map비트맵 버퍼
idx해제할 비트 인덱스

bitmap.c 파일의 83 번째 라인에서 정의되었습니다.

83 {
84 uint32_t byte_index = idx / 8;
85 uint32_t bit_offset = idx % 8;
86 map[byte_index] &= (uint8_t)~(1u << bit_offset);
87}
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ free_block()

void free_block ( struct sfuse_superblock * sb,
struct sfuse_block_bitmap * bmap,
uint32_t blk )

데이터 블록 해제

슈퍼블록 기반으로 데이터 블록 해제

매개변수
sb슈퍼블록 포인터
bmap블록 비트맵 포인터
blk해제할 블록 번호

bitmap.c 파일의 135 번째 라인에서 정의되었습니다.

136 {
137 free_bit(bmap->map, blk);
138 sb->free_blocks += 1;
139}
void free_bit(uint8_t *map, uint32_t idx)
비트맵에서 지정한 인덱스 비트를 0으로 설정
Definition bitmap.c:83
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ free_inode()

void free_inode ( struct sfuse_superblock * sb,
struct sfuse_inode_bitmap * imap,
uint32_t ino )

아이노드 해제

슈퍼블록 기반으로 아이노드 해제

매개변수
sb슈퍼블록 포인터
imap아이노드 비트맵 포인터
ino해제할 아이노드 번호

bitmap.c 파일의 109 번째 라인에서 정의되었습니다.

110 {
111 free_bit(imap->map, ino);
112 sb->free_inodes += 1;
113}
이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

변수 문서화

◆ BITS_PER_BLOCK

const uint32_t BITS_PER_BLOCK = 4096 * 8
static

한 블록에 담길 수 있는 비트 수

bitmap.c 파일의 11 번째 라인에서 정의되었습니다.