chore: sync repo
This commit is contained in:
parent
bde4397caa
commit
1c5ba90296
|
@ -6,7 +6,7 @@ bin_PROGRAMS = mkfs.stpd tools.stpd inspect.stpd
|
|||
mkfs_stpd_SOURCES = mkfs/main.c
|
||||
mkfs_stpd_LDADD = ../libfs/libfs.a mkfs/bootsector.o
|
||||
|
||||
tools_stpd_SOURCES = tools/main.c tools/ls.c tools/copy.c
|
||||
tools_stpd_SOURCES = tools/main.c tools/ls.c tools/copy.c tools/mkdir.c
|
||||
|
||||
inspect_stpd_SOURCES = inspect/main.c
|
||||
|
||||
|
|
|
@ -105,6 +105,10 @@ inspect(void)
|
|||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
printf("%02x ", buff->data[idx+j]);
|
||||
if (j == 3)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
}
|
||||
printf(" | ");
|
||||
for (j = 0; j < 8; j++)
|
||||
|
@ -185,7 +189,7 @@ main(int argc, char **argv)
|
|||
break;
|
||||
|
||||
case 'b':
|
||||
block = atoi(optarg);
|
||||
block = strtol(optarg, NULL, 0);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
|
|
|
@ -161,7 +161,9 @@ start:
|
|||
|
||||
mov eax, [eax]
|
||||
mov cx, 1
|
||||
push edx
|
||||
call disk_read_sectors
|
||||
pop edx
|
||||
|
||||
add ebx, BLOCK_SIZE
|
||||
inc edx
|
||||
|
|
|
@ -108,7 +108,7 @@ do_copy(void)
|
|||
}
|
||||
|
||||
int
|
||||
copy(int argc, char **argv)
|
||||
cmd_copy(int argc, char **argv)
|
||||
{
|
||||
int idx;
|
||||
int c;
|
||||
|
|
|
@ -25,6 +25,7 @@ static struct option long_options[] = {
|
|||
|
||||
static char *path = "/";
|
||||
static char *image = NULL;
|
||||
static int all = 0;
|
||||
|
||||
extern char *prg_name;
|
||||
|
||||
|
@ -37,7 +38,11 @@ usage(int retval)
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("Usage: %s ls -i /dev/name [path]\n", prg_name);
|
||||
printf("Usage: %s ls -i /dev/name [OPTIONS]... FILE...\n", prg_name);
|
||||
printf("Options:\n");
|
||||
printf(" -i, --image <image> specify disk image.\n");
|
||||
printf(" -a, --all do not ignore entries starting with .\n");
|
||||
printf(" -h, --help display this menu\n");
|
||||
}
|
||||
|
||||
exit(retval);
|
||||
|
@ -65,7 +70,14 @@ do_ls(void)
|
|||
for (idx = 0; idx < ip->inode.size; idx += STPDFS_DIRENT_SIZE)
|
||||
{
|
||||
fs_read(ip, (uint8_t *)&dirent, idx, STPDFS_DIRENT_SIZE);
|
||||
printf("%s\n", dirent.filename);
|
||||
if (dirent.filename[0] == '.')
|
||||
{
|
||||
if (all) printf("%s\n", dirent.filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", dirent.filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -74,15 +86,15 @@ do_ls(void)
|
|||
}
|
||||
|
||||
int
|
||||
ls(int argc, char **argv)
|
||||
cmd_ls(int argc, char **argv)
|
||||
{
|
||||
int idx;
|
||||
int c;
|
||||
|
||||
#if defined(HAVE_GETOPT_LONG) && defined(HAVE_STRUCT_OPTION)
|
||||
while ((c = getopt_long(argc, argv, "hi:", long_options, &idx)) != EOF)
|
||||
while ((c = getopt_long(argc, argv, "hi:a", long_options, &idx)) != EOF)
|
||||
#else
|
||||
while ((c = getopt(argc, argv, "hi:")) != EOF)
|
||||
while ((c = getopt(argc, argv, "hi:a")) != EOF)
|
||||
#endif
|
||||
{
|
||||
switch (c)
|
||||
|
@ -95,6 +107,10 @@ ls(int argc, char **argv)
|
|||
image = optarg;
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
all = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
break;
|
||||
|
|
|
@ -18,8 +18,9 @@ struct command {
|
|||
};
|
||||
|
||||
struct command commands[] = {
|
||||
{"ls", &ls},
|
||||
{"copy", ©},
|
||||
{"ls", &cmd_ls},
|
||||
{"copy", &cmd_copy},
|
||||
{"mkdir", &cmd_mkdir},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
155
tools/tools/mkdir.c
Normal file
155
tools/tools/mkdir.c
Normal file
|
@ -0,0 +1,155 @@
|
|||
#include "libfs/inode.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
# include <libgen.h>
|
||||
#endif /* HAVE_LIBGEN_H */
|
||||
#ifdef HAVE_GETOPT_H
|
||||
# include <getopt.h>
|
||||
#endif /* HAVE_GETOPT_H */
|
||||
#include <stupidfs.h>
|
||||
#include <libfs/fs.h>
|
||||
|
||||
#ifdef HAVE_STRUCT_OPTION
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"image", required_argument, 0, 'i'},
|
||||
{"mode", required_argument, 0, 'm'},
|
||||
{"parents", no_argument, 0, 'p'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
#endif /* HAVE_STRUCT_OPTION */
|
||||
|
||||
static char *image = NULL;
|
||||
static mode_t mode = STPDFS_S_IFDIR | STPDFS_S_IRUSR | STPDFS_S_IWUSR | STPDFS_S_IXUSR | STPDFS_S_IRGRP | STPDFS_S_IXGRP | STPDFS_S_IXOTH;
|
||||
static int parents = 0;
|
||||
static int verbose = 0;
|
||||
|
||||
extern char *prg_name;
|
||||
|
||||
static void
|
||||
usage(int retval)
|
||||
{
|
||||
if (retval == EXIT_FAILURE)
|
||||
{
|
||||
printf("Try '%s mkdir -h' for more informations.\n", prg_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Usage: %s mkdir -i /dev/name [OPTION]... DIRECTORY...\n", prg_name);
|
||||
printf("Options:\n");
|
||||
printf(" -i, --image <image> specify disk image.\n");
|
||||
printf(" -m, --mode <mode> set file mode\n");
|
||||
printf(" -p, --parents no error if existing, make parent directories as needed\n");
|
||||
printf(" -v, --verbose print a message for each created directory\n");
|
||||
printf(" -h, --help display this help\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
do_mkdir(struct fs_inode *root, char *path)
|
||||
{
|
||||
char *dir;
|
||||
char *tmp;
|
||||
struct fs_inode *dp;
|
||||
struct fs_inode *subdp;
|
||||
|
||||
dir = strtok(path, "/");
|
||||
while (dir != NULL)
|
||||
{
|
||||
tmp = strtok(NULL, "/");
|
||||
printf("%s\n", dir);
|
||||
dir = tmp;
|
||||
}
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_mkdir(int argc, char **argv)
|
||||
{
|
||||
int idx;
|
||||
int c;
|
||||
struct fs_super super;
|
||||
struct fs_inode *root;
|
||||
int status;
|
||||
|
||||
#if defined(HAVE_GETOPT_LONG) && defined(HAVE_STRUCT_OPTION)
|
||||
while ((c = getopt_long(argc, argv, "hi:m:pv", long_options, &idx)) != EOF)
|
||||
#else
|
||||
while ((c = getopt(argc, argv, "hi:m:pv")) != EOF)
|
||||
#endif
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
image = optarg;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
mode = strtol(optarg, NULL, 8);
|
||||
mode |= STPDFS_S_IFDIR;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
parents = 1;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (image == NULL)
|
||||
{
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (optind >= argc)
|
||||
{
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (fs_super_open(&super, image))
|
||||
{
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
root = fs_inode_get(&super, STPDFS_ROOTINO);
|
||||
if (root->valid == 0)
|
||||
{
|
||||
fs_inode_read(root);
|
||||
}
|
||||
|
||||
status = EXIT_SUCCESS;
|
||||
|
||||
while (optind < argc)
|
||||
{
|
||||
if (do_mkdir(root, argv[optind++]))
|
||||
{
|
||||
status = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fs_super_kill(&super);
|
||||
|
||||
|
||||
return (status);
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef TOOLS_H
|
||||
# define TOOLS_H 1
|
||||
|
||||
int ls(int argc, char **argv);
|
||||
int copy(int argc, char **argv);
|
||||
int cmd_ls(int argc, char **argv);
|
||||
int cmd_copy(int argc, char **argv);
|
||||
int cmd_mkdir(int argc, char **argv);
|
||||
|
||||
#endif /* !TOOLS_H */
|
Loading…
Reference in a new issue