Changeset 23a0368 in mainline for uspace/lib/c
- Timestamp:
- 2017-03-30T19:52:23Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ae7bfbbd
- Parents:
- b5b5d84
- Location:
- uspace/lib/c
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/io.c
rb5b5d84 r23a0368 41 41 #include <stdbool.h> 42 42 #include <malloc.h> 43 #include <sys/stat.h>44 43 #include <async.h> 45 44 #include <io/kio.h> … … 765 764 int fseek(FILE *stream, off64_t offset, int whence) 766 765 { 766 int rc; 767 767 768 if (stream->error) 768 769 return -1; … … 785 786 break; 786 787 case SEEK_END: 787 if (fstat(stream->fd, &st) != EOK) { 788 /* errno was set by fstat() */ 788 rc = vfs_stat(stream->fd, &st); 789 if (rc != EOK) { 790 errno = rc; 789 791 stream->error = true; 790 792 return -1; -
uspace/lib/c/generic/vfs/vfs.c
rb5b5d84 r23a0368 641 641 /** Get file status. 642 642 * 643 * @param fil desFile descriptor643 * @param file File descriptor 644 644 * @param stat Place to store file information 645 645 * 646 * @return 0 on success, -1 on error and sets errno.647 */ 648 int fstat(int fildes, struct stat *stat)646 * @return EOK on success or a negative error code otherwise. 647 */ 648 int vfs_stat(int file, struct stat *stat) 649 649 { 650 650 sysarg_t rc; … … 653 653 async_exch_t *exch = vfs_exchange_begin(); 654 654 655 req = async_send_1(exch, VFS_IN_STAT, fil des, NULL);655 req = async_send_1(exch, VFS_IN_STAT, file, NULL); 656 656 rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat)); 657 657 if (rc != EOK) { … … 663 663 if (rc_orig != EOK) 664 664 rc = rc_orig; 665 if (rc != EOK) {666 errno = rc;667 return -1;668 }669 665 670 return 0;666 return rc; 671 667 } 672 668 … … 674 670 async_wait_for(req, &rc); 675 671 676 if (rc != EOK) { 677 errno = rc; 678 return -1; 679 } 680 681 return 0; 672 return rc; 682 673 } 683 674 … … 687 678 * @param stat Place to store file information 688 679 * 689 * @return 0 on success, -1 on error and sets errno. 690 */ 691 int stat(const char *path, struct stat *stat) 692 { 693 int fd = vfs_lookup(path, 0); 694 if (fd < 0) { 695 errno = fd; 696 return -1; 697 } 698 699 int rc = fstat(fd, stat); 700 if (rc != EOK) { 701 close(fd); 702 errno = rc; 703 rc = -1; 704 } else 705 rc = close(fd); 680 * @return EOK on success or a negative error code otherwise. 681 */ 682 int vfs_stat_path(const char *path, struct stat *stat) 683 { 684 int file = vfs_lookup(path, 0); 685 if (file < 0) 686 return file; 687 688 int rc = vfs_stat(file, stat); 689 690 close(file); 706 691 707 692 return rc; … … 1057 1042 * @return On success returns session pointer. On error returns @c NULL. 1058 1043 */ 1059 async_sess_t *vfs_fd_session(int fil des, iface_t iface)1044 async_sess_t *vfs_fd_session(int file, iface_t iface) 1060 1045 { 1061 1046 struct stat stat; 1062 int rc = fstat(fildes, &stat);1047 int rc = vfs_stat(file, &stat); 1063 1048 if (rc != 0) 1064 1049 return NULL; … … 1122 1107 child = pa; 1123 1108 1124 rc = stat(child, &st);1109 rc = vfs_stat_path(child, &st); 1125 1110 if (rc != 0) { 1126 1111 free(child); … … 1152 1137 struct stat st; 1153 1138 1154 int rc = stat("/", &st);1139 int rc = vfs_stat_path("/", &st); 1155 1140 if (rc != 0) 1156 1141 return rc; … … 1165 1150 * @param file File located on the queried file system 1166 1151 * @param st Buffer for storing information 1167 * @return 0 on success. On error -1 is returned and errno is set.1152 * @return EOK on success or a negative error code otherwise. 1168 1153 */ 1169 1154 int vfs_statfs(int file, struct statfs *st) -
uspace/lib/c/include/sys/stat.h
rb5b5d84 r23a0368 36 36 #define LIBC_SYS_STAT_H_ 37 37 38 #include <sys/types.h>39 #include <stdbool.h>40 38 #include <ipc/vfs.h> 41 #include <ipc/loc.h>42 39 43 struct stat {44 fs_handle_t fs_handle;45 service_id_t service_id;46 fs_index_t index;47 unsigned int lnkcnt;48 bool is_file;49 bool is_directory;50 aoff64_t size;51 service_id_t service;52 };53 54 extern int fstat(int, struct stat *);55 extern int stat(const char *, struct stat *);56 40 extern int mkdir(const char *, mode_t); 57 41 -
uspace/lib/c/include/vfs/vfs.h
rb5b5d84 r23a0368 49 49 }; 50 50 51 struct stat { 52 fs_handle_t fs_handle; 53 service_id_t service_id; 54 fs_index_t index; 55 unsigned int lnkcnt; 56 bool is_file; 57 bool is_directory; 58 aoff64_t size; 59 service_id_t service; 60 }; 61 51 62 struct statfs { 52 63 char fs_name[FS_NAME_MAXLEN + 1]; … … 79 90 extern int vfs_root(void); 80 91 extern void vfs_root_set(int); 92 extern int vfs_stat(int, struct stat *); 93 extern int vfs_stat_path(const char *, struct stat *); 81 94 extern int vfs_statfs(int, struct statfs *); 82 95 extern int vfs_statfs_path(const char *, struct statfs *);
Note:
See TracChangeset
for help on using the changeset viewer.