8 * Convert a relative pathname to an absolute pathname
9 * In the future this might also resolve symlinks...
11 void pm_realpath(com32sys_t
*regs
)
13 const char *src
= MK_PTR(regs
->ds
, regs
->esi
.w
[0]);
14 char *dst
= MK_PTR(regs
->es
, regs
->edi
.w
[0]);
16 realpath(dst
, src
, FILENAME_MAX
);
25 static size_t join_paths(char *dst
, size_t bufsize
,
26 const char *s1
, const char *s2
)
39 for (i
= 0; i
< 2; i
++) {
60 size_t realpath(char *dst
, const char *src
, size_t bufsize
)
62 if (this_fs
->fs_ops
->realpath
) {
63 return this_fs
->fs_ops
->realpath(this_fs
, dst
, src
, bufsize
);
65 /* Filesystems with "common" pathname resolution */
66 return join_paths(dst
, bufsize
,
67 src
[0] == '/' ? "" : this_fs
->cwd_name
,
72 int chdir(const char *src
)
76 char cwd_buf
[CURRENTDIR_MAX
];
78 if (this_fs
->fs_ops
->chdir
)
79 return this_fs
->fs_ops
->chdir(this_fs
, src
);
81 /* Otherwise it is a "conventional filesystem" */
86 file
= handle_to_file(rv
);
87 if (file
->inode
->mode
!= DT_DIR
) {
92 put_inode(this_fs
->cwd
);
93 this_fs
->cwd
= get_inode(file
->inode
);
96 /* Save the current working directory */
97 realpath(cwd_buf
, src
, CURRENTDIR_MAX
);
99 /* Make sure the cwd_name ends in a slash, it's supposed to be a prefix */
100 join_paths(this_fs
->cwd_name
, CURRENTDIR_MAX
, cwd_buf
, "/");