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 <syscalls.h> 15 #include <syscall_utils.h> 16 17 18 int 19 fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags) 20 { 21 status_t status = _kern_create_index(device, name, type, flags); 22 23 RETURN_AND_SET_ERRNO(status); 24 } 25 26 27 int 28 fs_remove_index(dev_t device, const char *name) 29 { 30 status_t status = _kern_remove_index(device, name); 31 32 RETURN_AND_SET_ERRNO(status); 33 } 34 35 36 int 37 fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo) 38 { 39 struct stat stat; 40 41 status_t status = _kern_read_index_stat(device, name, &stat); 42 if (status == B_OK) { 43 indexInfo->type = stat.st_type; 44 indexInfo->size = stat.st_size; 45 indexInfo->modification_time = stat.st_mtime; 46 indexInfo->creation_time = stat.st_crtime; 47 indexInfo->uid = stat.st_uid; 48 indexInfo->gid = stat.st_gid; 49 } 50 51 RETURN_AND_SET_ERRNO(status); 52 } 53 54 55 DIR * 56 fs_open_index_dir(dev_t device) 57 { 58 DIR *dir; 59 60 int fd = _kern_open_index_dir(device); 61 if (fd < 0) { 62 errno = fd; 63 return NULL; 64 } 65 66 // allocate the DIR structure 67 if ((dir = fdopendir(fd)) == NULL) { 68 _kern_close(fd); 69 return NULL; 70 } 71 72 return dir; 73 } 74 75 76 int 77 fs_close_index_dir(DIR *dir) 78 { 79 return closedir(dir); 80 } 81 82 83 struct dirent * 84 fs_read_index_dir(DIR *dir) 85 { 86 return readdir(dir); 87 } 88 89 90 void 91 fs_rewind_index_dir(DIR *dir) 92 { 93 rewinddir(dir); 94 } 95 96