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 3ff5b22
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 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 @@ -130,10 +131,7 @@ 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];
shortname = basename(argv[i]);

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

Expand Down

0 comments on commit 3ff5b22

Please sign in to comment.