create_inode: whitespace fixes

Fix a ton of whitespace issues.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
crypto
Darrick J. Wong 2014-03-11 23:26:58 -04:00 committed by Theodore Ts'o
parent 8f8d8a575b
commit 9c891f7e6b
1 changed files with 110 additions and 88 deletions

View File

@ -25,7 +25,8 @@
int hdlink_cnt = HDLINK_CNT; int hdlink_cnt = HDLINK_CNT;
/* Link an inode number to a directory */ /* Link an inode number to a directory */
static errcode_t add_link(ext2_ino_t parent_ino, ext2_ino_t ino, const char *name) static errcode_t add_link(ext2_ino_t parent_ino, ext2_ino_t ino,
const char *name)
{ {
struct ext2_inode inode; struct ext2_inode inode;
errcode_t retval; errcode_t retval;
@ -43,7 +44,8 @@ static errcode_t add_link(ext2_ino_t parent_ino, ext2_ino_t ino, const char *nam
com_err(__func__, retval, "while expanding directory"); com_err(__func__, retval, "while expanding directory");
return retval; return retval;
} }
retval = ext2fs_link(current_fs, parent_ino, name, ino, inode.i_flags); retval = ext2fs_link(current_fs, parent_ino, name, ino,
inode.i_flags);
} }
if (retval) { if (retval) {
com_err(__func__, retval, "while linking %s", name); com_err(__func__, retval, "while linking %s", name);
@ -103,18 +105,18 @@ errcode_t do_mknod_internal(ext2_ino_t cwd, const char *name, struct stat *st)
int filetype; int filetype;
switch(st->st_mode & S_IFMT) { switch(st->st_mode & S_IFMT) {
case S_IFCHR: case S_IFCHR:
mode = LINUX_S_IFCHR; mode = LINUX_S_IFCHR;
filetype = EXT2_FT_CHRDEV; filetype = EXT2_FT_CHRDEV;
break; break;
case S_IFBLK: case S_IFBLK:
mode = LINUX_S_IFBLK; mode = LINUX_S_IFBLK;
filetype = EXT2_FT_BLKDEV; filetype = EXT2_FT_BLKDEV;
break; break;
case S_IFIFO: case S_IFIFO:
mode = LINUX_S_IFIFO; mode = LINUX_S_IFIFO;
filetype = EXT2_FT_FIFO; filetype = EXT2_FT_FIFO;
break; break;
} }
if (!(current_fs->flags & EXT2_FLAG_RW)) { if (!(current_fs->flags & EXT2_FLAG_RW)) {
@ -143,7 +145,7 @@ errcode_t do_mknod_internal(ext2_ino_t cwd, const char *name, struct stat *st)
com_err(name, retval, 0); com_err(name, retval, 0);
return -1; return -1;
} }
if (ext2fs_test_inode_bitmap2(current_fs->inode_map, ino)) if (ext2fs_test_inode_bitmap2(current_fs->inode_map, ino))
com_err(__func__, 0, "Warning: inode already set"); com_err(__func__, 0, "Warning: inode already set");
ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0); ext2fs_inode_alloc_stats2(current_fs, ino, +1, 0);
memset(&inode, 0, sizeof(inode)); memset(&inode, 0, sizeof(inode));
@ -159,7 +161,8 @@ errcode_t do_mknod_internal(ext2_ino_t cwd, const char *name, struct stat *st)
inode.i_block[1] = 0; inode.i_block[1] = 0;
} else { } else {
inode.i_block[0] = 0; inode.i_block[0] = 0;
inode.i_block[1] = (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); inode.i_block[1] = (minor & 0xff) | (major << 8) |
((minor & ~0xff) << 12);
} }
inode.i_links_count = 1; inode.i_links_count = 1;
@ -182,7 +185,8 @@ errcode_t do_symlink_internal(ext2_ino_t cwd, const char *name, char *target)
cp = strrchr(name, '/'); cp = strrchr(name, '/');
if (cp) { if (cp) {
*cp = 0; *cp = 0;
retval = ext2fs_namei(current_fs, root, cwd, name, &parent_ino); retval = ext2fs_namei(current_fs, root, cwd, name,
&parent_ino);
if (retval) { if (retval) {
com_err(name, retval, 0); com_err(name, retval, 0);
return retval; return retval;
@ -196,7 +200,8 @@ try_again:
if (retval == EXT2_ET_DIR_NO_SPACE) { if (retval == EXT2_ET_DIR_NO_SPACE) {
retval = ext2fs_expand_dir(current_fs, parent_ino); retval = ext2fs_expand_dir(current_fs, parent_ino);
if (retval) { if (retval) {
com_err("do_symlink_internal", retval, "while expanding directory"); com_err("do_symlink_internal", retval,
"while expanding directory");
return retval; return retval;
} }
goto try_again; goto try_again;
@ -220,7 +225,8 @@ errcode_t do_mkdir_internal(ext2_ino_t cwd, const char *name, struct stat *st)
cp = strrchr(name, '/'); cp = strrchr(name, '/');
if (cp) { if (cp) {
*cp = 0; *cp = 0;
retval = ext2fs_namei(current_fs, root, cwd, name, &parent_ino); retval = ext2fs_namei(current_fs, root, cwd, name,
&parent_ino);
if (retval) { if (retval) {
com_err(name, retval, 0); com_err(name, retval, 0);
return retval; return retval;
@ -245,7 +251,8 @@ try_again:
} }
} }
static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_holes) static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize,
int make_holes)
{ {
ext2_file_t e2_file; ext2_file_t e2_file;
errcode_t retval; errcode_t retval;
@ -291,7 +298,9 @@ static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_hol
cmp = memcmp(ptr, zero_buf, got); cmp = memcmp(ptr, zero_buf, got);
if (cmp == 0) { if (cmp == 0) {
/* The whole block is zero, make a hole */ /* The whole block is zero, make a hole */
retval = ext2fs_file_lseek(e2_file, got, EXT2_SEEK_CUR, NULL); retval = ext2fs_file_lseek(e2_file, got,
EXT2_SEEK_CUR,
NULL);
if (retval) if (retval)
goto fail; goto fail;
got = 0; got = 0;
@ -386,7 +395,7 @@ errcode_t do_write_internal(ext2_ino_t cwd, const char *src, const char *dest)
close(fd); close(fd);
return errno; return errno;
} }
if (ext2fs_test_inode_bitmap2(current_fs->inode_map, newfile)) if (ext2fs_test_inode_bitmap2(current_fs->inode_map, newfile))
com_err(__func__, 0, "Warning: inode already set"); com_err(__func__, 0, "Warning: inode already set");
ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0); ext2fs_inode_alloc_stats2(current_fs, newfile, +1, 0);
memset(&inode, 0, sizeof(inode)); memset(&inode, 0, sizeof(inode));
@ -463,7 +472,8 @@ errcode_t populate_fs(ext2_ino_t parent_ino, const char *source_dir)
if (chdir(source_dir) < 0) { if (chdir(source_dir) < 0) {
com_err(__func__, errno, com_err(__func__, errno,
_("while changing working directory to \"%s\""), source_dir); _("while changing working directory to \"%s\""),
source_dir);
return errno; return errno;
} }
@ -474,20 +484,24 @@ errcode_t populate_fs(ext2_ino_t parent_ino, const char *source_dir)
} }
while ((dent = readdir(dh))) { while ((dent = readdir(dh))) {
if ((!strcmp(dent->d_name, ".")) || (!strcmp(dent->d_name, ".."))) if ((!strcmp(dent->d_name, ".")) ||
(!strcmp(dent->d_name, "..")))
continue; continue;
lstat(dent->d_name, &st); lstat(dent->d_name, &st);
name = dent->d_name; name = dent->d_name;
/* Check for hardlinks */ /* Check for hardlinks */
save_inode = 0; save_inode = 0;
if (!S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode) && st.st_nlink > 1) { if (!S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode) &&
st.st_nlink > 1) {
hdlink = is_hardlink(st.st_ino); hdlink = is_hardlink(st.st_ino);
if (hdlink >= 0) { if (hdlink >= 0) {
retval = add_link(parent_ino, retval = add_link(parent_ino,
hdlinks.hdl[hdlink].dst_ino, name); hdlinks.hdl[hdlink].dst_ino,
name);
if (retval) { if (retval) {
com_err(__func__, retval, "while linking %s", name); com_err(__func__, retval,
"while linking %s", name);
return retval; return retval;
} }
continue; continue;
@ -496,70 +510,78 @@ errcode_t populate_fs(ext2_ino_t parent_ino, const char *source_dir)
} }
switch(st.st_mode & S_IFMT) { switch(st.st_mode & S_IFMT) {
case S_IFCHR: case S_IFCHR:
case S_IFBLK: case S_IFBLK:
case S_IFIFO: case S_IFIFO:
retval = do_mknod_internal(parent_ino, name, &st); retval = do_mknod_internal(parent_ino, name, &st);
if (retval) { if (retval) {
com_err(__func__, retval, com_err(__func__, retval,
_("while creating special file \"%s\""), name); _("while creating special file "
"\"%s\""), name);
return retval;
}
break;
case S_IFSOCK:
/* FIXME: there is no make socket function atm. */
com_err(__func__, 0,
_("ignoring socket file \"%s\""), name);
continue;
case S_IFLNK:
read_cnt = readlink(name, ln_target,
sizeof(ln_target));
if (read_cnt == -1) {
com_err(__func__, errno,
_("while trying to readlink \"%s\""),
name);
return errno;
}
ln_target[read_cnt] = '\0';
retval = do_symlink_internal(parent_ino, name,
ln_target);
if (retval) {
com_err(__func__, retval,
_("while writing symlink\"%s\""),
name);
return retval;
}
break;
case S_IFREG:
retval = do_write_internal(parent_ino, name, name);
if (retval) {
com_err(__func__, retval,
_("while writing file \"%s\""), name);
return retval;
}
break;
case S_IFDIR:
retval = do_mkdir_internal(parent_ino, name, &st);
if (retval) {
com_err(__func__, retval,
_("while making dir \"%s\""), name);
return retval;
}
retval = ext2fs_namei(current_fs, root, parent_ino,
name, &ino);
if (retval) {
com_err(name, retval, 0);
return retval; return retval;
} }
break; /* Populate the dir recursively*/
case S_IFSOCK: retval = populate_fs(ino, name);
/* FIXME: there is no make socket function atm. */ if (retval) {
com_err(__func__, 0, com_err(__func__, retval,
_("ignoring socket file \"%s\""), name); _("while adding dir \"%s\""), name);
continue; return retval;
case S_IFLNK: }
read_cnt = readlink(name, ln_target, sizeof(ln_target)); chdir("..");
if (read_cnt == -1) { break;
com_err(__func__, errno, default:
_("while trying to readlink \"%s\""), name); com_err(__func__, 0,
return errno; _("ignoring entry \"%s\""), name);
}
ln_target[read_cnt] = '\0';
retval = do_symlink_internal(parent_ino, name, ln_target);
if (retval) {
com_err(__func__, retval,
_("while writing symlink\"%s\""), name);
return retval;
}
break;
case S_IFREG:
retval = do_write_internal(parent_ino, name, name);
if (retval) {
com_err(__func__, retval,
_("while writing file \"%s\""), name);
return retval;
}
break;
case S_IFDIR:
retval = do_mkdir_internal(parent_ino, name, &st);
if (retval) {
com_err(__func__, retval,
_("while making dir \"%s\""), name);
return retval;
}
retval = ext2fs_namei(current_fs, root, parent_ino, name, &ino);
if (retval) {
com_err(name, retval, 0);
return retval;
}
/* Populate the dir recursively*/
retval = populate_fs(ino, name);
if (retval) {
com_err(__func__, retval, _("while adding dir \"%s\""), name);
return retval;
}
chdir("..");
break;
default:
com_err(__func__, 0,
_("ignoring entry \"%s\""), name);
} }
retval = ext2fs_namei(current_fs, root, parent_ino, name, &ino); retval = ext2fs_namei(current_fs, root, parent_ino,
name, &ino);
if (retval) { if (retval) {
com_err(name, retval, 0); com_err(name, retval, 0);
return retval; return retval;