Skip to content

Commit

Permalink
Improve mkfs path handling with basename
Browse files Browse the repository at this point in the history
The mkfs tool previously expected a hardcoded 'user/' prefix, which
limited its usability. This commit switches to using basename to handle
file paths, allowing mkfs to work with any file path.
  • Loading branch information
snoire committed Oct 17, 2024
1 parent de247db commit 79c4098
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mkfs/mkfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include <libgen.h>

#define stat xv6_stat // avoid clash with host struct stat
#include "kernel/types.h"
Expand Down Expand Up @@ -129,12 +130,9 @@ main(int argc, char *argv[])

for(i = 2; i < argc; i++){
// get rid of "user/"
char *shortname;
if(strncmp(argv[i], "user/", 5) == 0)
shortname = argv[i] + 5;
else
shortname = argv[i];

char *filepath = strdup(argv[i]);
char *shortname = basename(filepath);

assert(index(shortname, '/') == 0);

if((fd = open(argv[i], 0)) < 0)
Expand All @@ -160,6 +158,7 @@ main(int argc, char *argv[])
iappend(inum, buf, cc);

close(fd);
free(filepath);
}

// fix size of root inode dir
Expand Down

0 comments on commit 79c4098

Please sign in to comment.