mkfs: move directory entry manipulation

This commit is contained in:
Ben Gras 2012-11-07 18:48:30 +01:00
parent 960c93c6f7
commit 6463554619

View file

@ -750,6 +750,40 @@ d2_inode *get_inoblock(ino_t i, block_t *blockno, d2_inode **ino)
return inoblock; return inoblock;
} }
int dir_try_enter(zone_t z, ino_t child, char *name)
{
char *p1, *p2;
struct direct *dir_entry = alloc_block();
int r = 0;
int i;
get_block(z, (char *) dir_entry);
for (i = 0; i < NR_DIR_ENTRIES(block_size); i++)
if (!dir_entry[i].mfs_d_ino)
break;
if(i < NR_DIR_ENTRIES(block_size)) {
int j;
r = 1;
dir_entry[i].mfs_d_ino = child;
p1 = name;
p2 = dir_entry[i].mfs_d_name;
j = sizeof(dir_entry[i].mfs_d_name);
assert(j == 60);
while (j--) {
*p2++ = *p1;
if (*p1 != 0) p1++;
}
}
put_block(z, (char *) dir_entry);
free(dir_entry);
return r;
}
/*================================================================ /*================================================================
* directory & inode management assist group * directory & inode management assist group
*===============================================================*/ *===============================================================*/
@ -759,47 +793,27 @@ char *name;
{ {
/* Enter child in parent directory */ /* Enter child in parent directory */
/* Works for dir > 1 block and zone > block */ /* Works for dir > 1 block and zone > block */
unsigned int i, j, k; unsigned int k;
block_t b; block_t b;
zone_t z; zone_t z;
char *p1, *p2;
struct direct *dir_entry = alloc_block();
d2_inode *ino; d2_inode *ino;
d2_inode *inoblock = get_inoblock(parent, &b, &ino); d2_inode *inoblock = get_inoblock(parent, &b, &ino);
int nr_dzones;
assert(!(block_size % sizeof(struct direct))); assert(!(block_size % sizeof(struct direct)));
nr_dzones = V2_NR_DZONES; for (k = 0; k < V2_NR_DZONES; k++) {
for (k = 0; k < nr_dzones; k++) {
z = ino->d2_zone[k]; z = ino->d2_zone[k];
if (z == 0) { if (z == 0) {
z = alloc_zone(); z = alloc_zone();
ino->d2_zone[k] = z; ino->d2_zone[k] = z;
} }
{ if(dir_try_enter(z, child, name)) {
get_block(z, (char *) dir_entry);
for (i = 0; i < NR_DIR_ENTRIES(block_size); i++) {
if (dir_entry[i].mfs_d_ino == 0) {
dir_entry[i].mfs_d_ino = child;
p1 = name;
p2 = dir_entry[i].mfs_d_name;
j = sizeof(dir_entry[i].mfs_d_name);
j = 60;
while (j--) {
*p2++ = *p1;
if (*p1 != 0) p1++;
}
put_block(z, (char *) dir_entry);
put_block(b, (char *) inoblock); put_block(b, (char *) inoblock);
free(dir_entry);
free(inoblock); free(inoblock);
return; return;
} }
} }
}
}
printf("Directory-inode %lu beyond direct blocks. Could not enter %s\n", printf("Directory-inode %lu beyond direct blocks. Could not enter %s\n",
parent, name); parent, name);