1 /* 2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <fs_index.h> 8 9 #include <dirent.h> 10 #include <errno.h> 11 #include <fcntl.h> 12 #include <stdlib.h> 13 14 #include <dirent_private.h> 15 #include <syscalls.h> 16 #include <syscall_utils.h> 17 18 19 int 20 fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags) 21 { 22 status_t status = _kern_create_index(device, name, type, flags); 23 24 RETURN_AND_SET_ERRNO(status); 25 } 26 27 28 int 29 fs_remove_index(dev_t device, const char *name) 30 { 31 status_t status = _kern_remove_index(device, name); 32 33 RETURN_AND_SET_ERRNO(status); 34 } 35 36 37 int 38 fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo) 39 { 40 struct stat stat; 41 42 status_t status = _kern_read_index_stat(device, name, &stat); 43 if (status == B_OK) { 44 indexInfo->type = stat.st_type; 45 indexInfo->size = stat.st_size; 46 indexInfo->modification_time = stat.st_mtime; 47 indexInfo->creation_time = stat.st_crtime; 48 indexInfo->uid = stat.st_uid; 49 indexInfo->gid = stat.st_gid; 50 } 51 52 RETURN_AND_SET_ERRNO(status); 53 } 54 55 56 DIR * 57 fs_open_index_dir(dev_t device) 58 { 59 DIR *dir; 60 61 int fd = _kern_open_index_dir(device); 62 if (fd < 0) { 63 errno = fd; 64 return NULL; 65 } 66 67 // allocate the DIR structure 68 if ((dir = __create_dir_struct(fd)) == NULL) { 69 _kern_close(fd); 70 return NULL; 71 } 72 73 return dir; 74 } 75 76 77 int 78 fs_close_index_dir(DIR *dir) 79 { 80 return closedir(dir); 81 } 82 83 84 struct dirent * 85 fs_read_index_dir(DIR *dir) 86 { 87 return readdir(dir); 88 } 89 90 91 void 92 fs_rewind_index_dir(DIR *dir) 93 { 94 rewinddir(dir); 95 } 96 97