feat(tools): list file in root dir
This commit is contained in:
parent
c5f4b5878b
commit
7043ece1c3
|
@ -97,7 +97,13 @@ stpdfs_brelse(struct stpdfs_buffer *buff)
|
|||
struct stpdfs_buffer *tmp;
|
||||
|
||||
buff->refcount--;
|
||||
if (buff->refcount <= 0)
|
||||
if (buff->refcount > 0) return;
|
||||
|
||||
if (buff == head)
|
||||
{
|
||||
head = buff->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (tmp = head; tmp != NULL; tmp = tmp->next)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,8 @@ struct stpdfs_inode_info *
|
|||
stpdfs_inode_get(struct stpdfs_super_info *sbi, uint32_t inum)
|
||||
{
|
||||
struct stpdfs_inode_info *empty;
|
||||
struct stpdfs_buffer *buff;
|
||||
struct stpdfs_inode *dinode;
|
||||
int idx;
|
||||
|
||||
empty = NULL;
|
||||
|
@ -38,7 +40,12 @@ stpdfs_inode_get(struct stpdfs_super_info *sbi, uint32_t inum)
|
|||
empty->sbi = sbi;
|
||||
empty->inum = inum;
|
||||
empty->refcount = 1;
|
||||
empty->valid = 0;
|
||||
|
||||
empty->valid = 1;
|
||||
buff = stpdfs_bread(sbi->fd, IBLOCK(inum));
|
||||
dinode = (struct stpdfs_inode *)buff->data + inum % STPDFS_INODES_PER_BLOCK;
|
||||
memcpy(&empty->inode, dinode, sizeof(struct stpdfs_inode));
|
||||
stpdfs_brelse(buff);
|
||||
|
||||
return (empty);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ void stpdfs_brelse(struct stpdfs_buffer *buff);
|
|||
void stpdfs_bpin(struct stpdfs_buffer *buff);
|
||||
|
||||
/* super.c */
|
||||
int stpdfs_super_open(struct stpdfs_super_info *sbi, const char *fname);
|
||||
int stpdfs_read_super(struct stpdfs_super_info *sbi, int fd);
|
||||
int stpdfs_super_validate(struct stpdfs_sb *sb);
|
||||
int stpdfs_super_kill(struct stpdfs_super_info *sbi);
|
||||
|
@ -58,4 +59,7 @@ int stpdfs_super_bfreee(struct stpdfs_super_info *sbi, uint32_t blocknum);
|
|||
uint32_t stpdfs_alloc_block(int fd, struct stpdfs_sb *sb);
|
||||
int stpdfs_free_block(int fd, struct stpdfs_sb *sb, uint32_t blocknum);
|
||||
|
||||
struct stpdfs_inode_info *stpdfs_inode_get(struct stpdfs_super_info *sbi, uint32_t inum);
|
||||
int stpdfs_inode_read(struct stpdfs_inode_info *ip, uint8_t *dest, size_t offset, size_t size);
|
||||
|
||||
#endif /* !STPDFS_H */
|
|
@ -7,8 +7,7 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stupidfs.h>
|
||||
#include <stpdfs.h>
|
||||
#include <libstpdfs/stpdfs.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
|
||||
#include "stupidfs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -9,16 +11,88 @@
|
|||
#ifdef HAVE_GETOPT_H
|
||||
# include <getopt.h>
|
||||
#endif /* HAVE_GETOPT_H */
|
||||
#include <libstpdfs/stpdfs.h>
|
||||
|
||||
#ifdef HAVE_STRUCT_OPTION
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"image", required_argument, 0, 'i'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
#endif /* HAVE_STRUCT_OPTION */
|
||||
|
||||
static char *path = "/";
|
||||
static char *image = NULL;
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
usage(int retval)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
do_ls(void)
|
||||
{
|
||||
struct stpdfs_super_info sbi;
|
||||
struct stpdfs_inode_info *ip;
|
||||
struct stpdfs_dirent dirent;
|
||||
size_t idx;
|
||||
|
||||
if (stpdfs_super_open(&sbi, image))
|
||||
{
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ip = stpdfs_inode_get(&sbi, STPDFS_ROOTINO);
|
||||
for (idx = 0; idx < ip->inode.size; idx += STPDFS_DIRENT_SIZE)
|
||||
{
|
||||
stpdfs_inode_read(ip, (uint8_t *)&dirent, idx, STPDFS_DIRENT_SIZE);
|
||||
printf("%s\n", dirent.filename);
|
||||
}
|
||||
|
||||
|
||||
stpdfs_super_kill(&sbi);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int
|
||||
ls(int argc, char **argv)
|
||||
{
|
||||
int idx;
|
||||
int c;
|
||||
|
||||
return (EXIT_SUCCESS);
|
||||
#if defined(HAVE_GETOPT_LONG) && defined(HAVE_STRUCT_OPTION)
|
||||
while ((c = getopt_long(argc, argv, "hi:", long_options, &idx)) != EOF)
|
||||
#else
|
||||
while ((c = getopt(argc, argv, "hi:")) != EOF)
|
||||
#endif
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
image = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (image == NULL)
|
||||
{
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
path = argv[optind];
|
||||
}
|
||||
|
||||
|
||||
return (do_ls());
|
||||
}
|
Loading…
Reference in a new issue