diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-26 19:22:34 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-05-26 19:22:34 +0000 |
commit | a0fcefa90d39c5510c3f62bdbd3f2f128f211d6b (patch) | |
tree | 1deba65ce2f157d8f25da5498676e306742887e8 /nuttx/fs/fs_seekdir.c | |
parent | f93e30156c033d77182a052549a5e355a5d0a5a0 (diff) | |
download | px4-nuttx-a0fcefa90d39c5510c3f62bdbd3f2f128f211d6b.tar.gz px4-nuttx-a0fcefa90d39c5510c3f62bdbd3f2f128f211d6b.tar.bz2 px4-nuttx-a0fcefa90d39c5510c3f62bdbd3f2f128f211d6b.zip |
Finish FAT directory operations; add option to disable mountpoints; fix ARM compile errors
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@252 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs/fs_seekdir.c')
-rw-r--r-- | nuttx/fs/fs_seekdir.c | 93 |
1 files changed, 83 insertions, 10 deletions
diff --git a/nuttx/fs/fs_seekdir.c b/nuttx/fs/fs_seekdir.c index bdc03d88c..5a4dae6c3 100644 --- a/nuttx/fs/fs_seekdir.c +++ b/nuttx/fs/fs_seekdir.c @@ -50,6 +50,10 @@ #if CONFIG_NFILE_DESCRIPTORS > 0 +/************************************************************ + * Name: seekpsuedodir + ************************************************************/ + static inline void seekpsuedodir(struct internal_dir_s *idir, off_t offset) { struct inode *curr; @@ -62,15 +66,15 @@ static inline void seekpsuedodir(struct internal_dir_s *idir, off_t offset) * "rewind" to the root dir. */ - if ( offset < idir->position ) + if ( offset < idir->fd_position ) { pos = 0; - curr = idir->root; + curr = idir->fd_root; } else { - pos = idir->position; - curr = idir->u.psuedo.next; + pos = idir->fd_position; + curr = idir->u.psuedo.fd_next; } /* Traverse the peer list starting at the 'root' of the @@ -84,9 +88,9 @@ static inline void seekpsuedodir(struct internal_dir_s *idir, off_t offset) /* Now get the inode to vist next time that readdir() is called */ - prev = idir->u.psuedo.next; - idir->u.psuedo.next = curr; /* The next node to visit (might be null) */ - idir->position = pos; /* Might be beyond the last dirent */ + prev = idir->u.psuedo.fd_next; + idir->u.psuedo.fd_next = curr; /* The next node to visit (might be null) */ + idir->fd_position = pos; /* Might be beyond the last dirent */ if (curr) { @@ -104,6 +108,73 @@ static inline void seekpsuedodir(struct internal_dir_s *idir, off_t offset) } /************************************************************ + * Name: seekmountptdir + ************************************************************/ + +#ifndef CONFIG_DISABLE_MOUNTPOUNT +static inline void seekmountptdir(struct internal_dir_s *idir, off_t offset) +{ + struct inode *inode; + off_t pos; + + /* Determine a starting point for the seek. If the seek + * is "forward" from the current position, then we will + * start at the current poisition. Otherwise, we will + * "rewind" to the root dir. + */ + + inode = idir->fd_root; + if ( offset < idir->fd_position ) + { + if (inode->u.i_mops && inode->u.i_mops->rewinddir) + { + /* Perform the rewinddir() operation */ + + inode->u.i_mops->rewinddir(inode, idir); + pos = 0; + } + else + { + /* We can't do the seek and there is no way to return + * an error indication. + */ + + return; + } + } + else + { + pos = idir->fd_position; + } + + /* This is a brute force approach... we will just read + * directory entries until we are at the desired position. + */ + + while (pos < offset) + { + if (!inode->u.i_mops || !inode->u.i_mops->readdir || + inode->u.i_mops->readdir(inode, idir) < 0) + { + /* We can't read the next entry and there is no way to return + * an error indication. + */ + + return; + } + + /* Increment the position on each successful read */ + + pos++; + } + + /* If we get here the the directory position has been successfully set */ + + idir->fd_position = pos; +} +#endif + +/************************************************************ * Public Functions ************************************************************/ @@ -132,7 +203,7 @@ void seekdir(FAR DIR *dirp, off_t offset) /* Sanity checks */ - if (!idir || !idir->root) + if (!idir || !idir->fd_root) { return; } @@ -141,13 +212,15 @@ void seekdir(FAR DIR *dirp, off_t offset) * that we are dealing with. */ - if (INODE_IS_MOUNTPT(idir->root)) +#ifndef CONFIG_DISABLE_MOUNTPOUNT + if (INODE_IS_MOUNTPT(idir->fd_root)) { /* The node is a file system mointpoint */ -#warning "Mountpoint support not implemented" + seekmountptdir(idir, offset); } else +#endif { /* The node is part of the root psuedo file system */ |