Changeset 24809
- Timestamp:
- 04/05/08 08:24:11 (8 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp
r24580 r24809 131 131 132 132 static status_t 133 bfs_unmount(void * ns)134 { 135 FUNCTION(); 136 Volume* volume = (Volume *) ns;133 bfs_unmount(void *_fs) 134 { 135 FUNCTION(); 136 Volume* volume = (Volume *)_fs; 137 137 138 138 status_t status = volume->Unmount(); … … 143 143 144 144 145 /** Fill in bfs_info struct for device. 146 */ 147 148 static status_t 149 bfs_read_fs_stat(void *_ns, struct fs_info *info) 150 { 151 FUNCTION(); 152 if (_ns == NULL || info == NULL) 153 return B_BAD_VALUE; 154 155 Volume *volume = (Volume *)_ns; 156 145 static status_t 146 bfs_read_fs_stat(void *_fs, struct fs_info *info) 147 { 148 FUNCTION(); 149 150 Volume *volume = (Volume *)_fs; 157 151 RecursiveLocker locker(volume->Lock()); 158 152 159 153 // File system flags. 160 info->flags = B_FS_IS_PERSISTENT | B_FS_HAS_ATTR | B_FS_HAS_MIME | B_FS_HAS_QUERY |161 (volume->IsReadOnly() ? B_FS_IS_READONLY : 0);154 info->flags = B_FS_IS_PERSISTENT | B_FS_HAS_ATTR | B_FS_HAS_MIME 155 | B_FS_HAS_QUERY | (volume->IsReadOnly() ? B_FS_IS_READONLY : 0); 162 156 163 157 info->io_size = BFS_IO_SIZE; 164 // whatever is appropriate here? Just use the same value as BFS (and iso9660) for now158 // whatever is appropriate here? 165 159 166 160 info->block_size = volume->BlockSize(); … … 179 173 180 174 static status_t 181 bfs_write_fs_stat(void *_ ns, const struct fs_info *info, uint32 mask)175 bfs_write_fs_stat(void *_fs, const struct fs_info *info, uint32 mask) 182 176 { 183 177 FUNCTION_START(("mask = %ld\n", mask)); 184 178 185 Volume *volume = (Volume *)_ns; 186 disk_super_block &superBlock = volume->SuperBlock(); 179 Volume *volume = (Volume *)_fs; 180 if (volume->IsReadOnly()) 181 return B_READ_ONLY_DEVICE; 187 182 188 183 RecursiveLocker locker(volume->Lock()); … … 191 186 192 187 if (mask & FS_WRITE_FSINFO_NAME) { 193 strncpy(superBlock.name, info->volume_name, sizeof(superBlock.name) - 1); 188 disk_super_block &superBlock = volume->SuperBlock(); 189 190 strncpy(superBlock.name, info->volume_name, 191 sizeof(superBlock.name) - 1); 194 192 superBlock.name[sizeof(superBlock.name) - 1] = '\0'; 195 193 … … 201 199 202 200 static status_t 203 bfs_sync(void *_ns) 204 { 205 FUNCTION(); 206 if (_ns == NULL) 207 return B_BAD_VALUE; 208 209 Volume *volume = (Volume *)_ns; 210 201 bfs_sync(void *_fs) 202 { 203 FUNCTION(); 204 205 Volume *volume = (Volume *)_fs; 211 206 return volume->Sync(); 212 207 } … … 219 214 */ 220 215 static status_t 221 bfs_get_vnode(void *_ ns, ino_t id, void **_node, bool reenter)216 bfs_get_vnode(void *_fs, ino_t id, void **_node, bool reenter) 222 217 { 223 218 //FUNCTION_START(("ino_t = %Ld\n", id)); 224 Volume *volume = (Volume *)_ ns;219 Volume *volume = (Volume *)_fs; 225 220 226 221 // first inode may be after the log area, we don't go through … … 285 280 286 281 static status_t 287 bfs_remove_vnode(void *_ns, void *_node, bool reenter) 288 { 289 FUNCTION(); 290 291 if (_ns == NULL || _node == NULL) 292 return B_BAD_VALUE; 293 294 Volume *volume = (Volume *)_ns; 282 bfs_remove_vnode(void *_fs, void *_node, bool reenter) 283 { 284 FUNCTION(); 285 286 Volume *volume = (Volume *)_fs; 295 287 Inode *inode = (Inode *)_node; 296 288 … … 326 318 bfs_can_page(fs_volume _fs, fs_vnode _v, fs_cookie _cookie) 327 319 { 328 // T oDo: we're obviously not even asked...320 // TODO: we're obviously not even asked... 329 321 return false; 330 322 } … … 383 375 Volume *volume = (Volume *)_fs; 384 376 Inode *inode = (Inode *)_node; 377 378 if (volume->IsReadOnly()) 379 return B_READ_ONLY_DEVICE; 385 380 386 381 if (inode->FileCache() == NULL) … … 453 448 // make sure the extent ends with the last official file 454 449 // block (without taking any preallocations into account) 455 vecs[index].length = (inode->Size() - fileOffset + volume->BlockSize() - 1)456 & ~(volume->BlockSize() - 1);450 vecs[index].length = (inode->Size() - fileOffset 451 + volume->BlockSize() - 1) & ~(volume->BlockSize() - 1); 457 452 } 458 453 *_count = index + 1; … … 479 474 480 475 static status_t 481 bfs_lookup(void *_ns, void *_directory, const char *file, ino_t *_vnodeID, int *_type) 476 bfs_lookup(void *_fs, void *_directory, const char *file, ino_t *_vnodeID, 477 int *_type) 482 478 { 483 479 //FUNCTION_START(("file = %s\n", file)); 484 if (_ns == NULL || _directory == NULL || file == NULL || _vnodeID == NULL) 485 return B_BAD_VALUE; 486 487 Volume *volume = (Volume *)_ns; 480 481 Volume *volume = (Volume *)_fs; 488 482 Inode *directory = (Inode *)_directory; 489 483 … … 497 491 RETURN_ERROR(B_BAD_VALUE); 498 492 499 if ((status = tree->Find((uint8 *)file, (uint16)strlen(file), _vnodeID)) < B_OK) { 493 status = tree->Find((uint8 *)file, (uint16)strlen(file), _vnodeID); 494 if (status < B_OK) { 500 495 //PRINT(("bfs_walk() could not find %Ld:\"%s\": %s\n", directory->BlockNumber(), file, strerror(status))); 501 496 return status; … … 507 502 508 503 Inode *inode; 509 if ((status = get_vnode(volume->ID(), *_vnodeID, (void **)&inode)) != B_OK) { 504 status = get_vnode(volume->ID(), *_vnodeID, (void **)&inode); 505 if (status != B_OK) { 510 506 REPORT_ERROR(status); 511 507 return B_ENTRY_NOT_FOUND; … … 592 588 case 56742: 593 589 { 594 // allocate all free blocks and zero them out (a test for the BlockAllocator)! 590 // allocate all free blocks and zero them out 591 // (a test for the BlockAllocator)! 595 592 BlockAllocator &allocator = volume->Allocator(); 596 593 Transaction transaction(volume, 0); 597 594 CachedBlock cached(volume); 598 595 block_run run; 599 while (allocator.AllocateBlocks(transaction, 8, 0, 64, 1, run) == B_OK) { 596 while (allocator.AllocateBlocks(transaction, 8, 0, 64, 1, run) 597 == B_OK) { 600 598 PRINT(("write block_run(%ld, %d, %d)\n", run.allocation_group, 601 599 run.start, run.length)); … … 627 625 628 626 629 /** Sets the open-mode flags for the open file cookie - only 630 * supports O_APPEND currently, but that should be sufficient 631 * for a file system. 632 */ 633 634 static status_t 635 bfs_set_flags(void *_ns, void *_node, void *_cookie, int flags) 627 /*! Sets the open-mode flags for the open file cookie - only 628 supports O_APPEND currently, but that should be sufficient 629 for a file system. 630 */ 631 static status_t 632 bfs_set_flags(void *_fs, void *_node, void *_cookie, int flags) 636 633 { 637 634 FUNCTION_START(("node = %p, flags = %d", _node, flags)); … … 644 641 645 642 646 #if 0 647 static status_t 648 bfs_select(void *ns, void *node, void *cookie, uint8 event, uint32 ref, selectsync *sync) 649 { 650 FUNCTION_START(("event = %d, ref = %lu, sync = %p\n", event, ref, sync)); 651 notify_select_event(sync, ref); 652 653 return B_OK; 654 } 655 656 657 static status_t 658 bfs_deselect(void *ns, void *node, void *cookie, uint8 event, selectsync *sync) 659 { 660 FUNCTION(); 661 return B_OK; 662 } 663 #endif 664 665 static status_t 666 bfs_fsync(void *_ns, void *_node) 667 { 668 FUNCTION(); 669 if (_node == NULL) 670 return B_BAD_VALUE; 643 static status_t 644 bfs_fsync(void *_fs, void *_node) 645 { 646 FUNCTION(); 671 647 672 648 Inode *inode = (Inode *)_node; … … 681 657 682 658 683 /** Fills in the stat struct for a node 684 */ 685 686 static status_t 687 bfs_read_stat(void *_ns, void *_node, struct stat *stat) 659 static status_t 660 bfs_read_stat(void *_fs, void *_node, struct stat *stat) 688 661 { 689 662 FUNCTION(); … … 697 670 698 671 static status_t 699 bfs_write_stat(void *_ns, void *_node, const struct stat *stat, uint32 mask) 700 { 701 FUNCTION(); 702 703 if (_ns == NULL || _node == NULL || stat == NULL) 704 RETURN_ERROR(B_BAD_VALUE); 705 706 Volume *volume = (Volume *)_ns; 672 bfs_write_stat(void *_fs, void *_node, const struct stat *stat, uint32 mask) 673 { 674 FUNCTION(); 675 676 Volume *volume = (Volume *)_fs; 707 677 Inode *inode = (Inode *)_node; 678 679 if (volume->IsReadOnly()) 680 return B_READ_ONLY_DEVICE; 708 681 709 682 // TODO: we should definitely check a bit more if the new stats are … … 789 762 790 763 status_t 791 bfs_create(void *_ ns, void *_directory, const char *name, int openMode,764 bfs_create(void *_fs, void *_directory, const char *name, int openMode, 792 765 int mode, void **_cookie, ino_t *_vnodeID) 793 766 { 794 767 FUNCTION_START(("name = \"%s\", perms = %d, openMode = %d\n", name, mode, openMode)); 795 768 796 if (_ns == NULL || _directory == NULL || _cookie == NULL 797 || name == NULL || *name == '\0') 798 RETURN_ERROR(B_BAD_VALUE); 799 800 Volume *volume = (Volume *)_ns; 769 Volume *volume = (Volume *)_fs; 801 770 Inode *directory = (Inode *)_directory; 771 772 if (volume->IsReadOnly()) 773 return B_READ_ONLY_DEVICE; 802 774 803 775 if (!directory->IsDirectory()) … … 827 799 *_cookie = cookie; 828 800 829 if (created) 830 notify_entry_created(volume->ID(), directory->ID(), name, *_vnodeID); 801 if (created) { 802 notify_entry_created(volume->ID(), directory->ID(), name, 803 *_vnodeID); 804 } 831 805 } else 832 806 free(cookie); … … 837 811 838 812 static status_t 839 bfs_create_symlink(void *_ ns, void *_directory, const char *name,813 bfs_create_symlink(void *_fs, void *_directory, const char *name, 840 814 const char *path, int mode) 841 815 { 842 816 FUNCTION_START(("name = \"%s\", path = \"%s\"\n", name, path)); 843 817 844 if (_ns == NULL || _directory == NULL || path == NULL 845 || name == NULL || *name == '\0') 846 RETURN_ERROR(B_BAD_VALUE); 847 848 Volume *volume = (Volume *)_ns; 818 Volume *volume = (Volume *)_fs; 849 819 Inode *directory = (Inode *)_directory; 820 821 if (volume->IsReadOnly()) 822 return B_READ_ONLY_DEVICE; 850 823 851 824 if (!directory->IsDirectory()) … … 900 873 901 874 status_t 902 bfs_link(void * ns, void *dir, const char *name, void *node)875 bfs_link(void *_fs, void *dir, const char *name, void *node) 903 876 { 904 877 FUNCTION_START(("name = \"%s\"\n", name)); … … 911 884 912 885 status_t 913 bfs_unlink(void *_ ns, void *_directory, const char *name)886 bfs_unlink(void *_fs, void *_directory, const char *name) 914 887 { 915 888 FUNCTION_START(("name = \"%s\"\n", name)); 916 889 917 if (_ns == NULL || _directory == NULL || name == NULL || *name == '\0')918 return B_BAD_VALUE;919 890 if (!strcmp(name, "..") || !strcmp(name, ".")) 920 891 return B_NOT_ALLOWED; 921 892 922 Volume *volume = (Volume *)_ ns;893 Volume *volume = (Volume *)_fs; 923 894 Inode *directory = (Inode *)_directory; 924 895 … … 940 911 941 912 status_t 942 bfs_rename(void *_ns, void *_oldDir, const char *oldName, void *_newDir, const char *newName) 913 bfs_rename(void *_fs, void *_oldDir, const char *oldName, void *_newDir, 914 const char *newName) 943 915 { 944 916 FUNCTION_START(("oldDir = %p, oldName = \"%s\", newDir = %p, newName = \"%s\"\n", _oldDir, oldName, _newDir, newName)); 945 917 946 918 // there might be some more tests needed?! 947 if (_ns == NULL || _oldDir == NULL || _newDir == NULL 948 || oldName == NULL || *oldName == '\0' 949 || newName == NULL || *newName == '\0' 950 || !strcmp(oldName, ".") || !strcmp(oldName, "..") 919 if (!strcmp(oldName, ".") || !strcmp(oldName, "..") 951 920 || !strcmp(newName, ".") || !strcmp(newName, "..") 952 921 || strchr(newName, '/') != NULL) 953 922 RETURN_ERROR(B_BAD_VALUE); 954 923 955 Volume *volume = (Volume *)_ ns;924 Volume *volume = (Volume *)_fs; 956 925 Inode *oldDirectory = (Inode *)_oldDir; 957 926 Inode *newDirectory = (Inode *)_newDir; … … 970 939 RecursiveLocker locker(volume->Lock()); 971 940 972 // get the directory's tree, and a pointer to the inode which should be changed 941 // Get the directory's tree, and a pointer to the inode which should be 942 // changed 973 943 BPlusTree *tree; 974 944 status = oldDirectory->GetTree(&tree); … … 1024 994 } 1025 995 1026 status = newTree->Insert(transaction, (const uint8 *)newName, strlen(newName), id); 996 status = newTree->Insert(transaction, (const uint8 *)newName, 997 strlen(newName), id); 1027 998 if (status == B_NAME_IN_USE) { 1028 999 // If there is already a file with that name, we have to remove 1029 1000 // it, as long it's not a directory with files in it 1030 1001 off_t clobber; 1031 if (newTree->Find((const uint8 *)newName, strlen(newName), &clobber) < B_OK) 1002 if (newTree->Find((const uint8 *)newName, strlen(newName), &clobber) 1003 < B_OK) 1032 1004 return B_NAME_IN_USE; 1033 1005 if (clobber == id) … … 1039 1011 return B_NAME_IN_USE; 1040 1012 1041 status = newDirectory->Remove(transaction, newName, NULL, other->IsDirectory()); 1013 status = newDirectory->Remove(transaction, newName, NULL, 1014 other->IsDirectory()); 1042 1015 if (status < B_OK) 1043 1016 return status; 1044 1017 1045 notify_entry_removed(volume->ID(), newDirectory->ID(), newName, clobber); 1046 1047 status = newTree->Insert(transaction, (const uint8 *)newName, strlen(newName), id); 1018 notify_entry_removed(volume->ID(), newDirectory->ID(), newName, 1019 clobber); 1020 1021 status = newTree->Insert(transaction, (const uint8 *)newName, 1022 strlen(newName), id); 1048 1023 } 1049 1024 if (status < B_OK) … … 1066 1041 1067 1042 if (status == B_OK) { 1068 status = tree->Remove(transaction, (const uint8 *)oldName, strlen(oldName), id); 1043 status = tree->Remove(transaction, (const uint8 *)oldName, 1044 strlen(oldName), id); 1069 1045 if (status == B_OK) { 1070 1046 inode->Parent() = newDirectory->BlockRun(); … … 1075 1051 if (oldDirectory != newDirectory 1076 1052 && inode->IsDirectory() 1077 && (status = inode->GetTree(&movedTree)) == B_OK) 1078 status = movedTree->Replace(transaction, (const uint8 *)"..", 2, newDirectory->ID()); 1053 && (status = inode->GetTree(&movedTree)) == B_OK) { 1054 status = movedTree->Replace(transaction, (const uint8 *)"..", 1055 2, newDirectory->ID()); 1056 } 1079 1057 1080 1058 if (status == B_OK) … … 1095 1073 // Anyway, if we overwrote a file in the target directory 1096 1074 // this is lost now (only in-memory, not on-disk)... 1097 bailStatus = tree->Insert(transaction, (const uint8 *)oldName, strlen(oldName), id); 1098 if (movedTree != NULL) 1099 movedTree->Replace(transaction, (const uint8 *)"..", 2, oldDirectory->ID()); 1075 bailStatus = tree->Insert(transaction, (const uint8 *)oldName, 1076 strlen(oldName), id); 1077 if (movedTree != NULL) { 1078 movedTree->Replace(transaction, (const uint8 *)"..", 2, 1079 oldDirectory->ID()); 1080 } 1100 1081 } 1101 1082 } … … 1112 1093 } 1113 1094 1114 if (bailStatus == B_OK) 1115 bailStatus = newTree->Remove(transaction, (const uint8 *)newName, strlen(newName), id); 1095 if (bailStatus == B_OK) { 1096 bailStatus = newTree->Remove(transaction, (const uint8 *)newName, 1097 strlen(newName), id); 1098 } 1116 1099 1117 1100 if (bailStatus < B_OK) … … 1134 1117 if (inode->IsDirectory() && openMode & O_RWMASK) { 1135 1118 openMode = openMode & ~O_RWMASK; 1136 // T oDo: for compatibility reasons, we don't return an error here...1119 // TODO: for compatibility reasons, we don't return an error here... 1137 1120 // e.g. "copyattr" tries to do that 1138 1121 //return B_IS_A_DIRECTORY; … … 1144 1127 RETURN_ERROR(status); 1145 1128 1146 // we could actually use the cookie to keep track of:1129 // We could actually use the cookie to keep track of: 1147 1130 // - the last block_run 1148 1131 // - the location in the data_stream (indirect, double indirect, … … 1186 1169 1187 1170 static status_t 1188 bfs_read(void *_ ns, void *_node, void *_cookie, off_t pos, void *buffer,1171 bfs_read(void *_fs, void *_node, void *_cookie, off_t pos, void *buffer, 1189 1172 size_t *_length) 1190 1173 { … … 1202 1185 1203 1186 static status_t 1204 bfs_write(void *_ ns, void *_node, void *_cookie, off_t pos, const void *buffer,1187 bfs_write(void *_fs, void *_node, void *_cookie, off_t pos, const void *buffer, 1205 1188 size_t *_length) 1206 1189 { 1207 1190 //FUNCTION(); 1208 Volume *volume = (Volume *)_ ns;1191 Volume *volume = (Volume *)_fs; 1209 1192 Inode *inode = (Inode *)_node; 1193 1194 if (volume->IsReadOnly()) 1195 return B_READ_ONLY_DEVICE; 1210 1196 1211 1197 if (!inode->HasUserAccessableStream()) { … … 1234 1220 1235 1221 // periodically notify if the file size has changed 1236 // T oDo: should we better test for a change in the last_modified time only?1222 // TODO: should we better test for a change in the last_modified time only? 1237 1223 if (!inode->IsDeleted() && cookie->last_size != inode->Size() 1238 && system_time() > cookie->last_notification + INODE_NOTIFICATION_INTERVAL) { 1224 && system_time() > cookie->last_notification 1225 + INODE_NOTIFICATION_INTERVAL) { 1239 1226 notify_stat_changed(volume->ID(), inode->ID(), 1240 1227 B_STAT_MODIFICATION_TIME | B_STAT_SIZE | B_STAT_INTERIM_UPDATE); … … 1248 1235 1249 1236 1250 /** Do whatever is necessary to close a file, EXCEPT for freeing 1251 * the cookie! 1252 */ 1253 1254 static status_t 1255 bfs_close(void *_ns, void *_node, void *_cookie) 1256 { 1257 FUNCTION(); 1258 if (_ns == NULL || _node == NULL || _cookie == NULL) 1259 return B_BAD_VALUE; 1260 1261 return B_OK; 1262 } 1263 1264 1265 static status_t 1266 bfs_free_cookie(void *_ns, void *_node, void *_cookie) 1267 { 1268 FUNCTION(); 1269 1270 if (_ns == NULL || _node == NULL || _cookie == NULL) 1271 return B_BAD_VALUE; 1237 static status_t 1238 bfs_close(void *_fs, void *_node, void *_cookie) 1239 { 1240 FUNCTION(); 1241 return B_OK; 1242 } 1243 1244 1245 static status_t 1246 bfs_free_cookie(void *_fs, void *_node, void *_cookie) 1247 { 1248 FUNCTION(); 1272 1249 1273 1250 file_cookie *cookie = (file_cookie *)_cookie; 1274 Volume *volume = (Volume *)_ ns;1251 Volume *volume = (Volume *)_fs; 1275 1252 Inode *inode = (Inode *)_node; 1276 1253 1277 1254 Transaction transaction; 1278 bool needsTrimming ;1279 1280 {1255 bool needsTrimming = false; 1256 1257 if (!volume->IsReadOnly()) { 1281 1258 ReadLocked locker(inode->Lock()); 1282 1259 needsTrimming = inode->NeedsTrimming(); … … 1292 1269 } 1293 1270 1294 WriteLocked locker(inode->Lock());1295 1271 status_t status = transaction.IsStarted() ? B_OK : B_ERROR; 1296 1272 1297 1273 if (status == B_OK) { 1274 WriteLocked locker(inode->Lock()); 1275 1298 1276 // trim the preallocated blocks and update the size, 1299 1277 // and last_modified indices if needed … … 1343 1321 1344 1322 1345 /** Checks access permissions, return B_NOT_ALLOWED if the action 1346 * is not allowed. 1347 */ 1348 1349 static status_t 1350 bfs_access(void *_ns, void *_node, int accessMode) 1323 /*! Checks access permissions, return B_NOT_ALLOWED if the action 1324 is not allowed. 1325 */
