* [PATCH 00/18 v3] fs: add symlink and readlink support @ 2012-09-03 14:50 Jean-Christophe PLAGNIOL-VILLARD 2012-09-03 14:53 ` [PATCH 01/18 v4] fs: add " Jean-Christophe PLAGNIOL-VILLARD 2012-09-04 7:58 ` [PATCH 00/18 v3] fs: add symlink and " Sascha Hauer 0 siblings, 2 replies; 6+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 14:50 UTC (permalink / raw) To: barebox HI, v4: drop the mounted path added to absolute symlink v3: - fix support mkdir mymount mount -t ramfs none mymount/ ln /env/boot/net /mymount/link - addres comments v2: addres comments please pull The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f: command/mount: add autodetection support (2012-08-21 18:53:00 +0800) are available in the git repository at: git://git.jcrosoft.org/barebox.git tags/fs-symlink for you to fetch changes up to 9919df3e6c53db0edca9f0a9297b7a9e335575de: defautenv: add support of symlink (2012-09-03 22:46:05 +0800) ---------------------------------------------------------------- fs: add symlink and readlink support This patch series introduce the support of symlink and readlink at 1) vfs level 2) libc API - symlink - readlink 3) commands - ln - readlink 3) filesystem - ramfs - nfs - envfs Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> ---------------------------------------------------------------- Jean-Christophe PLAGNIOL-VILLARD (18): fs: add readlink support fs: rename stat to lstat as we implement lstat fs: add symlink support fs: implement stat fs: open: add symlink support fs: introduce get_mounted_path to get the path where a file is mounted ramfs: add symlink and readlink support nfs: add readlink support test: add -L support to test if it's a symbolic link command: add readlink support command: add ln support ls: add symlink support to -l dirname: add -V option to return only path related to the mountpoint recursive_action: add ACTION_FOLLOWLINKS support envfs: introduce version major and minor envfs: add support of variable inode size envfs: add support of symlink defautenv: add support of symlink MAKEALL | 1 + commands/Kconfig | 10 ++++++++ commands/Makefile | 2 ++ commands/dirname.c | 24 +++++++++++++++--- commands/ln.c | 51 +++++++++++++++++++++++++++++++++++++++ commands/ls.c | 31 ++++++++++++++++-------- commands/readlink.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ commands/test.c | 11 +++++++-- common/Makefile | 2 +- common/environment.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- fs/fs.c | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ fs/nfs.c | 86 ++++++++++++++++++++++++++++++++++++++++++++--------------------- fs/ramfs.c | 61 +++++++++++++++++++++++++++++++++++++++++----- include/envfs.h | 15 ++++++++++-- include/fs.h | 12 +++++++++ include/libbb.h | 2 +- lib/recursive_action.c | 7 +++++- scripts/bareboxenv.c | 2 +- 18 files changed, 670 insertions(+), 100 deletions(-) create mode 100644 commands/ln.c create mode 100644 commands/readlink.c Best Regards, J. _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 01/18 v4] fs: add readlink support 2012-09-03 14:50 [PATCH 00/18 v3] fs: add symlink and readlink support Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 14:53 ` Jean-Christophe PLAGNIOL-VILLARD 2012-09-04 7:58 ` [PATCH 00/18 v3] fs: add symlink and " Sascha Hauer 1 sibling, 0 replies; 6+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 14:53 UTC (permalink / raw) To: barebox Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> --- fs/fs.c | 37 +++++++++++++++++++++++++++++++++++++ include/fs.h | 5 +++++ 2 files changed, 42 insertions(+) diff --git a/fs/fs.c b/fs/fs.c index 8ab1a3a..2320c3c 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -890,6 +890,43 @@ int close(int fd) } EXPORT_SYMBOL(close); +int readlink(const char *pathname, char *buf, size_t bufsiz) +{ + struct fs_driver_d *fsdrv; + struct fs_device_d *fsdev; + char *p = normalise_path(pathname); + char *freep = p; + int ret; + + ret = path_check_prereq(pathname, S_IFLNK); + if (ret) + goto out; + + fsdev = get_fs_device_and_root_path(&p); + if (!fsdev) { + ret = -ENODEV; + goto out; + } + fsdrv = fsdev->driver; + + if (fsdrv->readlink) + ret = fsdrv->readlink(&fsdev->dev, p, buf, bufsiz); + else + ret = -ENOSYS; + + if (ret) + goto out; + +out: + free(freep); + + if (ret) + errno = -ret; + + return ret; +} +EXPORT_SYMBOL(readlink); + static int fs_match(struct device_d *dev, struct driver_d *drv) { return strcmp(dev->name, drv->name) ? -1 : 0; diff --git a/include/fs.h b/include/fs.h index 22470e6..96fe9be 100644 --- a/include/fs.h +++ b/include/fs.h @@ -51,6 +51,9 @@ struct fs_driver_d { /* Truncate a file to given size */ int (*truncate)(struct device_d *dev, FILE *f, ulong size); + int (*readlink)(struct device_d *dev, const char *pathname, char *name, + size_t size); + int (*open)(struct device_d *dev, FILE *f, const char *pathname); int (*close)(struct device_d *dev, FILE *f); int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size); @@ -129,6 +132,8 @@ DIR *opendir(const char *pathname); struct dirent *readdir(DIR *dir); int closedir(DIR *dir); +int readlink(const char *path, char *buf, size_t bufsiz); + int mount (const char *device, const char *fsname, const char *path); int umount(const char *pathname); -- 1.7.10.4 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 00/18 v3] fs: add symlink and readlink support 2012-09-03 14:50 [PATCH 00/18 v3] fs: add symlink and readlink support Jean-Christophe PLAGNIOL-VILLARD 2012-09-03 14:53 ` [PATCH 01/18 v4] fs: add " Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-04 7:58 ` Sascha Hauer 1 sibling, 0 replies; 6+ messages in thread From: Sascha Hauer @ 2012-09-04 7:58 UTC (permalink / raw) To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox On Mon, Sep 03, 2012 at 04:50:42PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote: > HI, > > v4: > drop the mounted path added to absolute symlink > > v3: > - fix support > mkdir mymount > mount -t ramfs none mymount/ > ln /env/boot/net /mymount/link > > - addres comments > > v2: > addres comments > > please pull > The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f: > > command/mount: add autodetection support (2012-08-21 18:53:00 +0800) > > are available in the git repository at: > > git://git.jcrosoft.org/barebox.git tags/fs-symlink It gets better. Now we still have: # ln bla link # ln bla link # ls -l lrwxrwxrwx 3 link -> bla lrwxrwxrwx 3 link -> bla # ln a b # rmdir b unable to handle NULL pointer dereference at address 0x00000008 pc : [<a7f25fd0>] lr : [<a7f25fb4>] sp : a6eff948 ip : 00000003 fp : 00000000 r10: a6ffbddc r9 : 00000000 r8 : 00000002 r7 : 00000000 r6 : 00000000 r5 : a6fe0e98 r4 : a6ffbb44 r3 : 00000000 r2 : 00000000 r1 : a6ffbdc7 r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 [<a7f25fd0>] (ramfs_rmdir+0x48/0x78) from [<a7f28660>] (rmdir+0x5c/0x88) [<a7f28660>] (rmdir+0x5c/0x88) from [<a7f18628>] (do_rmdir+0x28/0x6c) [<a7f18628>] (do_rmdir+0x28/0x6c) from [<a7f050b4>] (execute_command+0x38/0x7c) [<a7f050b4>] (execute_command+0x38/0x7c) from [<a7f01efc>] (run_list_real+0x8dc/0x9dc) [<a7f01efc>] (run_list_real+0x8dc/0x9dc) from [<a7f02144>] (parse_stream_outer+0x148/0x238) [<a7f02144>] (parse_stream_outer+0x148/0x238) from [<a7f024cc>] (run_shell+0x3c/0x7c) [<a7f024cc>] (run_shell+0x3c/0x7c) from [<a7f050b4>] (execute_command+0x38/0x7c) [<a7f050b4>] (execute_command+0x38/0x7c) from [<a7f01efc>] (run_list_real+0x8dc/0x9dc) [<a7f01efc>] (run_list_real+0x8dc/0x9dc) from [<a7f01a58>] (run_list_real+0x438/0x9dc) [<a7f2c524>] (unwind_backtrace+0x0/0x9c) from [<a7f1bce0>] (panic+0x28/0x3c) [<a7f1bce0>] (panic+0x28/0x3c) from [<a7f2c97c>] (do_exception+0x10/0x14) [<a7f2c97c>] (do_exception+0x10/0x14) from [<a7f2ca08>] (do_data_abort+0x2c/0x38) [<a7f2ca08>] (do_data_abort+0x2c/0x38) from [<a7f2c750>] (data_abort+0x50/0x60) While you are at it, the 'ln' command should be under "file commands", not under "scripting commands". For links to directories I agree, this is nontrivial and can be added later. I don't see though why links to links shouldn't be supported from the start. All it takes is the following, right? 8<------------------------------------------------ diff --git a/fs/fs.c b/fs/fs.c index 7c59126..447b56f 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -580,13 +580,13 @@ EXPORT_SYMBOL(unlink); static char *realfile(const char *pathname, struct stat *s) { char *path = normalise_path(pathname); - int ret; + int ret, recursive = 16; ret = lstat(path, s); if (ret) goto out; - if (S_ISLNK(s->st_mode)) { + while (S_ISLNK(s->st_mode)) { char tmp[PATH_MAX]; char *new_path; @@ -603,10 +603,16 @@ static char *realfile(const char *pathname, struct stat *s) path = new_path; ret = lstat(path, s); + if (ret) + goto out; + + if (!recursive--) { + ret = -ELOOP; + goto out; + } } - if (!ret) - return path; + return path; out: free(path); -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 00/18 v3] fs: add symlink and readlink support @ 2012-09-03 10:04 Jean-Christophe PLAGNIOL-VILLARD 2012-09-03 13:04 ` Sascha Hauer 0 siblings, 1 reply; 6+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 10:04 UTC (permalink / raw) To: barebox HI, v3: - fix support mkdir mymount mount -t ramfs none mymount/ ln /env/boot/net /mymount/link - addres comments v2: addres comments please pull The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f: command/mount: add autodetection support (2012-08-21 18:53:00 +0800) are available in the git repository at: git://git.jcrosoft.org/barebox.git tags/fs-symlink for you to fetch changes up to dbae117ee78df0e4110db3a3acf4f9a8bee658d0: defautenv: add support of symlink (2012-09-03 17:57:23 +0800) ---------------------------------------------------------------- fs: add symlink and readlink support This patch series introduce the support of symlink and readlink at 1) vfs level 2) libc API - symlink - readlink 3) commands - ln - readlink 3) filesystem - ramfs - nfs - envfs Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> ---------------------------------------------------------------- Jean-Christophe PLAGNIOL-VILLARD (18): fs: add readlink support fs: rename stat to lstat as we implement lstat fs: add symlink support fs: implement stat fs: open: add symlink support fs: introduce get_mounted_path to get the path where a file is mounted ramfs: add symlink and readlink support nfs: add readlink support test: add -L support to test if it's a symbolic link command: add readlink support command: add ln support ls: add symlink support to -l dirname: add -V option to return only path related to the mountpoint recursive_action: add ACTION_FOLLOWLINKS support envfs: introduce version major and minor envfs: add support of variable inode size envfs: add support of symlink defautenv: add support of symlink MAKEALL | 1 + commands/Kconfig | 10 +++++++ commands/Makefile | 2 ++ commands/dirname.c | 24 ++++++++++++++--- commands/ln.c | 51 +++++++++++++++++++++++++++++++++++ commands/ls.c | 31 +++++++++++++++------- commands/readlink.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ commands/test.c | 11 ++++++-- common/Makefile | 2 +- common/environment.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- fs/fs.c | 244 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- fs/nfs.c | 86 +++++++++++++++++++++++++++++++++++++++-------------------- fs/ramfs.c | 61 +++++++++++++++++++++++++++++++++++++----- include/envfs.h | 15 +++++++++-- include/fs.h | 12 +++++++++ include/libbb.h | 2 +- lib/recursive_action.c | 7 ++++- scripts/bareboxenv.c | 2 +- 18 files changed, 691 insertions(+), 100 deletions(-) create mode 100644 commands/ln.c create mode 100644 commands/readlink.c Best Regards, J. _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 00/18 v3] fs: add symlink and readlink support 2012-09-03 10:04 Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 13:04 ` Sascha Hauer 2012-09-03 14:47 ` Jean-Christophe PLAGNIOL-VILLARD 0 siblings, 1 reply; 6+ messages in thread From: Sascha Hauer @ 2012-09-03 13:04 UTC (permalink / raw) To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox On Mon, Sep 03, 2012 at 12:04:09PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote: > HI, > > v3: > - fix support > mkdir mymount > mount -t ramfs none mymount/ > ln /env/boot/net /mymount/link > > - addres comments > > v2: > addres comments > > please pull > The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f: > > command/mount: add autodetection support (2012-08-21 18:53:00 +0800) > > are available in the git repository at: > > git://git.jcrosoft.org/barebox.git tags/fs-symlink > > for you to fetch changes up to dbae117ee78df0e4110db3a3acf4f9a8bee658d0: > > defautenv: add support of symlink (2012-09-03 17:57:23 +0800) > > ---------------------------------------------------------------- > fs: add symlink and readlink support Now we have: > # mkdir ram > # mount -t ramfs none /ram/ > # ln /env/boot/initrd ram/link > # ls -l ram/ > lrwxrwxrwx 16 link -> /ram/env/boot/initrd > # cat ram/link > could not open ram/link: No such file or directory The link should point to /env/boot/initrd instead. This is probably related to your comment to nfs link support: >> There is something wrong here. I do not understand what you do here, but >> symlinks are not supposed to bash on them with dirname/basename until >> you get something which fits your needs. > here the issue is that on nfs you need to mount the correct path >otherwise you > can not get the real file > > so we need to detect it and mount the correct path This is wrong. If you put an absolute link somewhere and mount the filesystem a somewhere else as NFS, then yes, the link will be broken if the mountpoints do not match. A symbolic link is basically just a text file, there is no magic behind it that fixes pathes according to mount pathes. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 00/18 v3] fs: add symlink and readlink support 2012-09-03 13:04 ` Sascha Hauer @ 2012-09-03 14:47 ` Jean-Christophe PLAGNIOL-VILLARD 0 siblings, 0 replies; 6+ messages in thread From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-03 14:47 UTC (permalink / raw) To: Sascha Hauer; +Cc: barebox On 15:04 Mon 03 Sep , Sascha Hauer wrote: > On Mon, Sep 03, 2012 at 12:04:09PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote: > > HI, > > > > v3: > > - fix support > > mkdir mymount > > mount -t ramfs none mymount/ > > ln /env/boot/net /mymount/link > > > > - addres comments > > > > v2: > > addres comments > > > > please pull > > The following changes since commit b77300ac6c6bbbc7eac774ff0076c7c05d39735f: > > > > command/mount: add autodetection support (2012-08-21 18:53:00 +0800) > > > > are available in the git repository at: > > > > git://git.jcrosoft.org/barebox.git tags/fs-symlink > > > > for you to fetch changes up to dbae117ee78df0e4110db3a3acf4f9a8bee658d0: > > > > defautenv: add support of symlink (2012-09-03 17:57:23 +0800) > > > > ---------------------------------------------------------------- > > fs: add symlink and readlink support > > Now we have: > > > # mkdir ram > > # mount -t ramfs none /ram/ > > # ln /env/boot/initrd ram/link > > # ls -l ram/ > > lrwxrwxrwx 16 link -> /ram/env/boot/initrd > > # cat ram/link > > could not open ram/link: No such file or directory > > The link should point to /env/boot/initrd instead. > > This is probably related to your comment to nfs link support: > > >> There is something wrong here. I do not understand what you do here, but > >> symlinks are not supposed to bash on them with dirname/basename until > >> you get something which fits your needs. > > here the issue is that on nfs you need to mount the correct path >otherwise you > > can not get the real file > > > > so we need to detect it and mount the correct path > > This is wrong. If you put an absolute link somewhere and mount the > filesystem a somewhere else as NFS, then yes, the link will be broken if > the mountpoints do not match. > > A symbolic link is basically just a text file, there is no magic behind > it that fixes pathes according to mount pathes. yes a symlink is just a file containing the path I found why I have this on my linux ( I use a special mount to have this feature so by default th obsolute symlink should act like this) # mkdir ram # mount -t ramfs none /ram/ # ln /env/boot/net ram/link # ls -l ram/ lrwxrwxrwx 16 link -> /env/boot/net # cat ram/link #!/bin/sh if [ "$1" = menu ]; then boot-menu-add-entry "$0" "network (tftp, nfs)" exit fi path="/mnt/tftp" # to get the dhcp info (global.dhcp.rootpath, global.dhcp.bootfile, global.dhcp.oftree_file) ifup eth0 global.bootm.image="${path}/${global.user}-linux-${global.hostname}" #global.bootm.oftree="${path}/${global.user}-oftree-${global.hostname}" if [ -n "${global.dhcp.rootpath}" ]; then bootp=1 nfsroot="${global.dhcp.rootpath}" else nfsroot="/home/${global.user}/nfsroot/${global.hostname}" fi if [ -n "${global.dhcp.bootfile}" -o -n "${global.dhcp.oftree_file}" ]; then bootp=1 path="/mnt/dhcp" if [ -d "${path}" ]; then umount "${path}" else mkdir "${path}" fi mount -t tftp $eth0.serverip "${path}" [ -n "${global.dhcp.bootfile}" ] && global.bootm.image="${path}/${global.dhcp.bootfile}" [ -n "${global.dhcp.oftree_file}" ] && global.bootm.oftree="${path}/${global.dhcp.oftree_file}" fi if [ x${bootp} = x1 ]; then echo "Boot via bootp/dhcp on server ${eth0.serverip}" [ -n "${global.dhcp.bootfile}" ] && echo "bootm.image => ${global.dhcp.bootfile}" [ -n "${global.dhcp.oftree_file}" ] && echo "bootm.oftree => ${global.dhcp.oftree_file}" [ -n "${global.dhcp.rootpath}" ] && echo "nfsroot => ${global.dhcp.rootpath}" fi bootargs-ip bootargs-root-nfs -n "$nfsroot" I update the patch series with this patch to act as suppsoed --- diff --git a/fs/fs.c b/fs/fs.c index 53d8316..7c59126 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -1005,12 +1005,6 @@ int readlink(const char *pathname, char *buf, size_t bufsiz) char *p = normalise_path(pathname); char *freep = p; int ret; - size_t len = 0; - char tmp[PATH_MAX]; - - memset(tmp, 0, PATH_MAX); - - buf[0] = 0; ret = path_check_prereq(pathname, S_IFLNK); if (ret) @@ -1023,29 +1017,14 @@ int readlink(const char *pathname, char *buf, size_t bufsiz) } fsdrv = fsdev->driver; - len = min(bufsiz, (size_t)(PATH_MAX - 1)); if (fsdrv->readlink) - ret = fsdrv->readlink(&fsdev->dev, p, tmp, len); + ret = fsdrv->readlink(&fsdev->dev, p, buf, bufsiz); else ret = -ENOSYS; if (ret) goto out; - if (tmp[0] == '/') { - int l = strlen(fsdev->path); - - if (fsdev->path[l - 1] == '/') - l--; - - if (l) { - len -= l; - strncat(buf, fsdev->path, l); - } - } - - strncat(buf, tmp, len); - out: free(freep); Best Regards, J. _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-09-04 7:58 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-09-03 14:50 [PATCH 00/18 v3] fs: add symlink and readlink support Jean-Christophe PLAGNIOL-VILLARD 2012-09-03 14:53 ` [PATCH 01/18 v4] fs: add " Jean-Christophe PLAGNIOL-VILLARD 2012-09-04 7:58 ` [PATCH 00/18 v3] fs: add symlink and " Sascha Hauer -- strict thread matches above, loose matches on Subject: below -- 2012-09-03 10:04 Jean-Christophe PLAGNIOL-VILLARD 2012-09-03 13:04 ` Sascha Hauer 2012-09-03 14:47 ` Jean-Christophe PLAGNIOL-VILLARD
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox