kern
changeset 95:ec62cbe00b55
whatever
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 11 Dec 2011 21:15:35 +0200 |
parents | b3351d018ac6 |
children | 07fe6a614185 |
files | src/fs.c src/fs.h |
diffstat | 2 files changed, 42 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/src/fs.c Sun Dec 11 11:12:30 2011 +0200 1.2 +++ b/src/fs.c Sun Dec 11 21:15:35 2011 +0200 1.3 @@ -10,6 +10,13 @@ 1.4 #include "fs.h" 1.5 #include "bdev.h" 1.6 1.7 +#define BM_IDX(x) ((x) / 32) 1.8 +#define BM_BIT(x) ((x) & 0x1f) 1.9 + 1.10 +#define BM_ISFREE(bm, x) (((bm)[BM_IDX(x)] & (1 << BM_BIT(x))) == 0) 1.11 +#define BM_SET(bm, x) ((bm)[BM_IDX(x)] |= (1 << BM_BIT(x))) 1.12 +#define BM_CLR(bm, x) ((bm)[BM_IDX(x)] &= ~(1 << BM_BIT(x))) 1.13 + 1.14 1.15 int openfs(struct filesys *fs, dev_t dev); 1.16 static int read_superblock(struct filesys *fs); 1.17 @@ -156,3 +163,35 @@ 1.18 free(buf); 1.19 return 0; 1.20 } 1.21 + 1.22 +static int find_free(uint32_t *bm, int sz) 1.23 +{ 1.24 + int i; 1.25 + uint32_t ent; 1.26 + 1.27 + for(i=0; i<=sz/32; i++) { 1.28 + if(bm[i] != 0xffffffff) { 1.29 + ent = i * 32; 1.30 + for(j=0; j<32; j++) { 1.31 + if(BM_ISFREE(bm, ent)) { 1.32 + return ent; 1.33 + } 1.34 + } 1.35 + 1.36 + panic("shouldn't happen (in find_free:fs.c)"); 1.37 + } 1.38 + } 1.39 + 1.40 + return -1; 1.41 +} 1.42 + 1.43 +static int alloc_inode(struct filesys *fs) 1.44 +{ 1.45 + int ino; 1.46 + 1.47 + if((ino = find_free(fs->ibm, fs->ibm_count)) == -1) { 1.48 + return -1; 1.49 + } 1.50 + BM_SET(fs->ibm, ino); 1.51 + return 0; 1.52 +}
2.1 --- a/src/fs.h Sun Dec 11 11:12:30 2011 +0200 2.2 +++ b/src/fs.h Sun Dec 11 21:15:35 2011 +0200 2.3 @@ -40,6 +40,9 @@ 2.4 2.5 /* total number of blocks */ 2.6 unsigned int num_blocks; 2.7 + /* total number of inodes */ 2.8 + unsigned int num_inodes; 2.9 + 2.10 /* inode allocation bitmap start and count */ 2.11 blkid ibm_start; 2.12 unsigned int ibm_count;